Previous to this, on latest version of Rust (1.78), the serialize_vec function was failing due to additional debug assertions in Rust:
'unsafe precondition(s) violated: slice::get_unchecked_mut requires that the index is within the slice': library/core/src/panicking.rs:215
Note that our existing code isn't incorrect; ArrayVec allocates fixed memory according to its capacity (in this case setting its capacity to constants::PUBLIC_KEY_SIZE or 72). (This is made clearer by the newer parameter format of ArrayVec 0.7x). secp256k1_ec_pubkey_serialize returns the actual length according to whether the result is compressed or uncompressed and we call ArrayVec::set_len() to set the actual length of the data, which is where the problematic assertion is being raised. This appears to be due to an issue in earlier versions of the ArrayVec crate, which seems to have been resolved in the latest.
Previous to this, on latest version of Rust (1.78), the
serialize_vec
function was failing due to additional debug assertions in Rust:Note that our existing code isn't incorrect;
ArrayVec
allocates fixed memory according to its capacity (in this case setting its capacity toconstants::PUBLIC_KEY_SIZE
or 72). (This is made clearer by the newer parameter format of ArrayVec 0.7x).secp256k1_ec_pubkey_serialize
returns the actual length according to whether the result is compressed or uncompressed and we callArrayVec::set_len()
to set the actual length of the data, which is where the problematic assertion is being raised. This appears to be due to an issue in earlier versions of theArrayVec
crate, which seems to have been resolved in the latest.