Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build(deps): Upgrade libsecp256k1 version 0.3.5 => 0.7.0 #515

Merged
merged 1 commit into from Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
150 changes: 69 additions & 81 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -28,6 +28,7 @@ lto = true
opt-level = 3

[workspace]
resolver = "2"
members = [
"engine",
"engine-precompiles",
Expand Down
2 changes: 1 addition & 1 deletion engine-precompiles/Cargo.toml
Expand Up @@ -20,7 +20,7 @@ borsh = { version = "0.8.2", default-features = false }
bn = { package = "aurora-bn", git = "https://github.com/aurora-is-near/aurora-bn.git", default-features = false }
evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "37448b6cacd98b06282cff5a559684505c29bd2b", default-features = false }
evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "37448b6cacd98b06282cff5a559684505c29bd2b", default-features = false }
libsecp256k1 = { version = "0.3.5", default-features = false }
libsecp256k1 = { version = "0.7.0", default-features = false, features = ["static-context", "hmac"] }
num = { version = "0.4.0", default-features = false, features = ["alloc"] }
primitive-types = { version = "0.10.0", default-features = false, features = ["rlp"] }
ripemd160 = { version = "0.9.1", default-features = false }
Expand Down
9 changes: 5 additions & 4 deletions engine-precompiles/src/secp256k1.rs
Expand Up @@ -32,16 +32,17 @@ pub fn ecrecover(hash: H256, signature: &[u8]) -> Result<Address, ExitError> {
fn internal_impl(hash: H256, signature: &[u8]) -> Result<Address, ExitError> {
use sha3::Digest;

let hash = secp256k1::Message::parse_slice(hash.as_bytes()).unwrap();
let hash = libsecp256k1::Message::parse_slice(hash.as_bytes()).unwrap();
let v = signature[64];
let signature = secp256k1::Signature::parse_slice(&signature[0..64]).unwrap();
let signature = libsecp256k1::Signature::parse_standard_slice(&signature[0..64])
.map_err(|_| ExitError::Other(Borrowed(sdk::ECRecoverErr.as_str())))?;
let bit = match v {
0..=26 => v,
_ => v - 27,
};

if let Ok(recovery_id) = secp256k1::RecoveryId::parse(bit) {
if let Ok(public_key) = secp256k1::recover(&hash, &signature, &recovery_id) {
if let Ok(recovery_id) = libsecp256k1::RecoveryId::parse(bit) {
if let Ok(public_key) = libsecp256k1::recover(&hash, &signature, &recovery_id) {
// recover returns a 65-byte key, but addresses come from the raw 64-byte key
let r = sha3::Keccak256::digest(&public_key.serialize()[1..]);
return Address::try_from_slice(&r[12..])
Expand Down