Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,826 changes: 1,826 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions ethcore-builtin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ edition = "2018"
bn = { package = "substrate-bn", git = "https://github.com/paritytech/bn", default-features = false }
byteorder = "1.3.2"
eip-152 = { path = "../EIP-152" }
ethereum-types = "0.12"
ethereum-types = "0.13"
ethjson = { path = "../ethjson" }
keccak-hash = "0.7"
log = "0.4"
num = "0.2"
parity-bytes = "0.1"
parity-crypto = { version = "0.9", features = ["publickey"] }
libsecp256k1 = "0.7"
ripemd = { version = "0.1", default-features = false }
sha2 = { version = "0.10.0", default-features = false }
eth_pairings = { git = "https://github.com/matter-labs/eip1962.git", default-features = false, features = ["eip_2537"], rev = "ece6cbabc41948db4200e41f0bfdab7ab94c7af8" }

[dev-dependencies]
Expand Down
42 changes: 24 additions & 18 deletions ethcore-builtin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ use keccak_hash::keccak;
use log::{trace, warn};
use num::{BigUint, One, Zero};
use parity_bytes::BytesRef;
use parity_crypto::digest;
use parity_crypto::publickey::{recover, Signature};
use sha2::Digest;

/// Native implementation of a built-in contract.
pub trait Implementation: Send + Sync {
Expand Down Expand Up @@ -824,30 +823,37 @@ impl Implementation for EcRecover {
let mut input = [0; 128];
input[..len].copy_from_slice(&i[..len]);

let hash = H256::from_slice(&input[0..32]);
let v = H256::from_slice(&input[32..64]);
let r = H256::from_slice(&input[64..96]);
let s = H256::from_slice(&input[96..128]);
let mut hash = [0; 32];
hash.copy_from_slice(&input[0..32]);

let v = H256::from_slice(&input[32..64]);
let bit = match v[31] {
27 | 28 if v.0[..31] == [0; 31] => v[31] - 27,
_ => {
return Ok(());
}
};

let s = Signature::from_rsv(&r, &s, bit);
if s.is_valid() {
let mut signature = [0; 64];
signature[..64].copy_from_slice(&input[64..128]);
let signature = libsecp256k1::Signature::parse_standard(&signature);
if bit <= 1 && signature.is_ok() {
// The builtin allows/requires all-zero messages to be valid to
// recover the public key. Use of such messages is disallowed in
// `rust-secp256k1` and this is a workaround for that. It is not an
// openethereum-level error to fail here; instead we return all
// zeroes and let the caller interpret that outcome.
let recovery_message = hash;
if let Ok(p) = recover(&s, &recovery_message) {
let r = keccak(p);
output.write(0, &[0; 12]);
output.write(12, &r.as_bytes()[12..]);
let message = libsecp256k1::Message::parse(&hash);
let recovery_id = libsecp256k1::RecoveryId::parse(bit);
if let Ok(recovery_id) = recovery_id {
if let Ok(p) = libsecp256k1::recover(
&message,
&signature.unwrap(),
&recovery_id,
) {
let r = keccak(&p.serialize()[1..65]);
output.write(0, &[0; 12]);
output.write(12, &r.as_bytes()[12..]);
}
}
}

Expand All @@ -857,8 +863,9 @@ impl Implementation for EcRecover {

impl Implementation for Sha256 {
fn execute(&self, input: &[u8], output: &mut BytesRef) -> Result<(), &'static str> {
let d = digest::sha256(input);
output.write(0, &*d);
let mut hasher = sha2::Sha256::new();
hasher.update(input);
output.write(0, &hasher.finalize());
Ok(())
}
}
Expand Down Expand Up @@ -919,9 +926,8 @@ impl Implementation for Blake2F {

impl Implementation for Ripemd160 {
fn execute(&self, input: &[u8], output: &mut BytesRef) -> Result<(), &'static str> {
let hash = digest::ripemd160(input);
output.write(0, &[0; 12][..]);
output.write(12, &hash);
output.write(12, &ripemd::Ripemd160::digest(input));
Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion ethjson/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Parity Technologies <[email protected]>"]
edition = "2018"

[dependencies]
ethereum-types = "0.12"
ethereum-types = "0.13"
rustc-hex = "2.1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion jsontests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ serde_json = "1.0"
hex = "0.4"
clap = "3.1"
ethjson = { path = "../ethjson", features = ["test-helpers"] }
parity-crypto = { version = "0.9", features = ["publickey"] }
libsecp256k1 = "0.7"
triehash-ethereum = { path = "../triehash-ethereum" }
ethcore-builtin = { path = "../ethcore-builtin" }
rlp = "0.5"
Expand Down
21 changes: 11 additions & 10 deletions jsontests/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use module_evm::{
runner::state::{PrecompileFn, StackState},
StackExecutor, StackSubstateMetadata, SubstrateStackState, Vicinity,
};
use parity_crypto::publickey;
use libsecp256k1::SecretKey;
use sha3::{Digest, Keccak256};
use primitive_types::{H160, H256, U256};
use primitives::convert_decimals_to_evm;
use serde::Deserialize;
Expand All @@ -27,15 +28,15 @@ impl Test {
}

pub fn unwrap_caller(&self) -> H160 {
let secret_key: H256 = self.0.transaction.secret.clone().unwrap().into();
let secret = publickey::Secret::import_key(&secret_key[..]).unwrap();
let public = publickey::KeyPair::from_secret(secret)
.unwrap()
.public()
.clone();
let sender = publickey::public_to_address(&public);

sender
let hash: H256 = self.0.transaction.secret.clone().unwrap().into();
let mut secret_key = [0; 32];
secret_key.copy_from_slice(&hash.as_bytes()[..]);
let secret = SecretKey::parse(&secret_key);
let public = libsecp256k1::PublicKey::from_secret_key(&secret.unwrap());
let mut res = [0u8; 64];
res.copy_from_slice(&public.serialize()[1..65]);
H160::from(H256::from_slice(Keccak256::digest(&res).as_slice()))
}

pub fn unwrap_to_vicinity(&self, spec: &ForkSpec) -> Option<Vicinity> {
Expand Down
2 changes: 1 addition & 1 deletion keccak-hasher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description = "Keccak-256 implementation of the Hasher trait"
license = "GPL-3.0"

[dependencies]
ethereum-types = "0.12"
ethereum-types = "0.13"
tiny-keccak = "2.0.2"
hash-db = "0.15.2"
plain_hasher = "0.2"
2 changes: 1 addition & 1 deletion triehash-ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ license = "GPL-3.0"

[dependencies]
triehash = "0.8"
ethereum-types = "0.12"
ethereum-types = "0.13"
keccak-hasher = { path = "../keccak-hasher" }