I am trying to use the libsecp256k1 library in a no-std environment and I get the following error when building the contract:
[wasm-validator error in module] unexpected true: memory max >= initial, on memory
It seems like this happens while using the recover function only -> The main problem is to try and recover a public key given an ethereum signature and message.
libsecp256k1 = { version="0.7.1", default-features = false, features = ["static-context"] }
It looks like I need the static-context feature to be able to use the recovery function, however, after digging through the source code, it seems like recovery actually calls recovery_with_context, which actually adds an additional parameter - context, defined like this
#[cfg(all(feature = "static-context", not(feature = "lazy-static-context")))]
/// A static ECMult context.
// Correct `pre_g` values are fed into `ECMultContext::new_from_raw`, generated by build script.
pub static ECMULT_CONTEXT: ECMultContext =
unsafe { ECMultContext::new_from_raw(include!(concat!(env!("OUT_DIR"), "/const.rs"))) };
#[cfg(all(feature = "static-context", not(feature = "lazy-static-context")))]
/// A static ECMultGen context.
// Correct `prec` values are fed into `ECMultGenContext::new_from_raw`, generated by build script.
pub static ECMULT_GEN_CONTEXT: ECMultGenContext =
unsafe { ECMultGenContext::new_from_raw(include!(concat!(env!("OUT_DIR"), "/const_gen.rs"))) };
Please note, that since this example is meant for the Phala Ink! environment, no standard libraries can be used. Alternatives are also welcome - I just want to extract the public key from the signature and message, as stated before.
pub fn recover_pubkey(&self, v: u8, r: Vec<u8>, s: Vec<u8>, message: Vec<u8>)