secp256k1_context doesn't have alignment documented but looking at the code it's clearly bigger than 1 since it contains pointers and int. Possibly becuase of lacking documentation Rust bindings used array of bytes (u8 AKA uint8_t) which is very wrong.
-
Kixunil commented at 9:41 AM on March 8, 2022: none
- Kixunil cross-referenced this on Mar 8, 2022 from issue Clean up once code by Kixunil
-
elichai commented at 10:15 AM on March 8, 2022: contributor
I assume you mean the buffer to the preallocated context and not the context itself? if so, the documentation says that it should be aligned to hold "suitably aligned to hold an object of any type.": https://github.com/bitcoin-core/secp256k1/blob/ac83be33d0956faf6b7f61a60ab524ef7d6a473a/include/secp256k1_preallocated.h#L42-L43
Also, see this discussion: https://github.com/rust-bitcoin/rust-secp256k1/pull/141#discussion_r324882525
-
Kixunil commented at 11:05 AM on March 8, 2022: none
Ah, OK, I expected to find this at type not a function. Thanks!
- Kixunil closed this on Mar 8, 2022
-
elichai commented at 11:24 AM on March 8, 2022: contributor
Note that the
secp256k1_contexttype is opaque and can only be created via function calls to libsecp (either context_create/clone or context_preallocated_create/clone), so either libsecp allocates the memory and takes care of the alignment or the user supplies a buffer to the preallocated API and then they need to make sure it has the alignment that the preallocated API requires.