2

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>)

1 Answer 1

1

I encountered this too, a few weeks ago. This is an issue of the library.

See https://github.com/paritytech/libsecp256k1/issues/134.

I can use sp-io's functions which are some host functions. But I'm not sure if that works for ink.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.