Skip to content

Commit 0662af4

Browse files
authored
Merge pull request rust-ethereum#13 from PureStake/tgm-dependency-update
Dependency update (`primitive-types`, `ethereum-types`, ..)
2 parents c66b562 + 24b58fd commit 0662af4

File tree

8 files changed

+265
-477
lines changed

8 files changed

+265
-477
lines changed

Cargo.lock

Lines changed: 221 additions & 442 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ethcore-builtin/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ edition = "2018"
99
bn = { git = "https://github.com/paritytech/bn", default-features = false }
1010
byteorder = "1.3.2"
1111
eip-152 = { path = "../EIP-152" }
12-
ethereum-types = "0.12"
12+
ethereum-types = "0.13"
1313
ethjson = { path = "../ethjson" }
1414
keccak-hash = "0.7"
1515
log = "0.4"
1616
num = "0.2"
1717
parity-bytes = "0.1"
18-
parity-crypto = { version = "0.9", features = ["publickey"] }
18+
libsecp256k1 = "0.7"
19+
ripemd = { version = "0.1", default-features = false }
20+
sha2 = { version = "0.10.0", default-features = false }
1921
eth_pairings = { git = "https://github.com/matter-labs/eip1962.git", default-features = false, features = ["eip_2537"], rev = "ece6cbabc41948db4200e41f0bfdab7ab94c7af8" }
2022

2123
[dev-dependencies]

ethcore-builtin/src/lib.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ use keccak_hash::keccak;
3838
use log::{trace, warn};
3939
use num::{BigUint, One, Zero};
4040
use parity_bytes::BytesRef;
41-
use parity_crypto::digest;
42-
use parity_crypto::publickey::{recover, Signature};
41+
use sha2::Digest;
4342

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

827-
let hash = H256::from_slice(&input[0..32]);
828-
let v = H256::from_slice(&input[32..64]);
829-
let r = H256::from_slice(&input[64..96]);
830-
let s = H256::from_slice(&input[96..128]);
826+
let mut hash = [0; 32];
827+
hash.copy_from_slice(&input[0..32]);
831828

829+
let v = H256::from_slice(&input[32..64]);
832830
let bit = match v[31] {
833831
27 | 28 if v.0[..31] == [0; 31] => v[31] - 27,
834832
_ => {
835833
return Ok(());
836834
}
837835
};
838-
839-
let s = Signature::from_rsv(&r, &s, bit);
840-
if s.is_valid() {
836+
let mut signature = [0; 64];
837+
signature[..64].copy_from_slice(&input[64..128]);
838+
let signature = libsecp256k1::Signature::parse_standard(&signature);
839+
if bit <= 1 && signature.is_ok() {
841840
// The builtin allows/requires all-zero messages to be valid to
842841
// recover the public key. Use of such messages is disallowed in
843842
// `rust-secp256k1` and this is a workaround for that. It is not an
844843
// openethereum-level error to fail here; instead we return all
845844
// zeroes and let the caller interpret that outcome.
846-
let recovery_message = hash;
847-
if let Ok(p) = recover(&s, &recovery_message) {
848-
let r = keccak(p);
849-
output.write(0, &[0; 12]);
850-
output.write(12, &r.as_bytes()[12..]);
845+
let message = libsecp256k1::Message::parse(&hash);
846+
let recovery_id = libsecp256k1::RecoveryId::parse(bit);
847+
if let Ok(recovery_id) = recovery_id {
848+
if let Ok(p) = libsecp256k1::recover(
849+
&message,
850+
&signature.unwrap(),
851+
&recovery_id,
852+
) {
853+
let r = keccak(&p.serialize()[1..65]);
854+
output.write(0, &[0; 12]);
855+
output.write(12, &r.as_bytes()[12..]);
856+
}
851857
}
852858
}
853859

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

858864
impl Implementation for Sha256 {
859865
fn execute(&self, input: &[u8], output: &mut BytesRef) -> Result<(), &'static str> {
860-
let d = digest::sha256(input);
861-
output.write(0, &*d);
866+
let mut hasher = sha2::Sha256::new();
867+
hasher.update(input);
868+
output.write(0, &hasher.finalize());
862869
Ok(())
863870
}
864871
}
@@ -919,9 +926,8 @@ impl Implementation for Blake2F {
919926

920927
impl Implementation for Ripemd160 {
921928
fn execute(&self, input: &[u8], output: &mut BytesRef) -> Result<(), &'static str> {
922-
let hash = digest::ripemd160(input);
923929
output.write(0, &[0; 12][..]);
924-
output.write(12, &hash);
930+
output.write(12, &ripemd::Ripemd160::digest(input));
925931
Ok(())
926932
}
927933
}

ethjson/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = ["Parity Technologies <[email protected]>"]
66
edition = "2018"
77

88
[dependencies]
9-
ethereum-types = "0.12"
9+
ethereum-types = "0.13"
1010
rustc-hex = "2.1.0"
1111
serde = { version = "1.0", features = ["derive"] }
1212
serde_json = "1.0"

jsontests/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ edition = "2018"
1010

1111
[dependencies]
1212
evm = { path = "../evm" }
13-
primitive-types = "0.10"
13+
primitive-types = "0.11"
1414
serde = { version = "1.0", features = ["derive"] }
1515
serde_json = "1.0"
1616
hex = "0.4"
1717
clap = "2.32"
1818
ethjson = { path = "../ethjson", features = ["test-helpers"] }
19-
parity-crypto = { version = "0.9", features = ["publickey"] }
19+
libsecp256k1 = "0.7"
2020
triehash-ethereum = { path = "../triehash-ethereum" }
2121
ethcore-builtin = { path = "../ethcore-builtin" }
2222
rlp = "0.5"

jsontests/src/state.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ use evm::executor::stack::{
77
};
88
use evm::{Config, Context, ExitError, ExitSucceed};
99
use lazy_static::lazy_static;
10-
use parity_crypto::publickey;
10+
use libsecp256k1::SecretKey;
11+
use sha3::{Digest, Keccak256};
1112
use primitive_types::{H160, H256, U256};
1213
use serde::Deserialize;
1314
use std::collections::BTreeMap;
@@ -22,15 +23,15 @@ impl Test {
2223
}
2324

2425
pub fn unwrap_caller(&self) -> H160 {
25-
let secret_key: H256 = self.0.transaction.secret.clone().unwrap().into();
26-
let secret = publickey::Secret::import_key(&secret_key[..]).unwrap();
27-
let public = publickey::KeyPair::from_secret(secret)
28-
.unwrap()
29-
.public()
30-
.clone();
31-
let sender = publickey::public_to_address(&public);
32-
33-
sender
26+
let hash: H256 = self.0.transaction.secret.clone().unwrap().into();
27+
let mut secret_key = [0; 32];
28+
secret_key.copy_from_slice(&hash.as_bytes()[..]);
29+
let secret = SecretKey::parse(&secret_key);
30+
let public = libsecp256k1::PublicKey::from_secret_key(&secret.unwrap());
31+
let mut res = [0u8; 64];
32+
res.copy_from_slice(&public.serialize()[1..65]);
33+
34+
H160::from(H256::from_slice(Keccak256::digest(&res).as_slice()))
3435
}
3536

3637
pub fn unwrap_to_vicinity(&self, spec: &ForkSpec) -> Option<MemoryVicinity> {

keccak-hasher/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description = "Keccak-256 implementation of the Hasher trait"
77
license = "GPL-3.0"
88

99
[dependencies]
10-
ethereum-types = "0.12"
10+
ethereum-types = "0.13"
1111
tiny-keccak = "2.0.2"
1212
hash-db = "0.15.2"
1313
plain_hasher = "0.2"

triehash-ethereum/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ license = "GPL-3.0"
77

88
[dependencies]
99
triehash = "0.8"
10-
ethereum-types = "0.12"
10+
ethereum-types = "0.13"
1111
keccak-hasher = { path = "../keccak-hasher" }

0 commit comments

Comments
 (0)