Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 242ab16

Browse files
committed
Merge remote-tracking branch 'origin/master' into na-bump-rand
2 parents a29264a + 6b57429 commit 242ab16

File tree

42 files changed

+676
-389
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+676
-389
lines changed

.gitlab-ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,35 @@ cargo-check 0 3:
6363
<<: *docker-cache-status
6464
script:
6565
- time cargo check --target $CARGO_TARGET --locked --no-default-features --verbose --color=always
66-
- sccache --stop-server
66+
- sccache --show-stats
6767

6868
cargo-check 1 3:
6969
stage: test
7070
<<: *docker-cache-status
7171
script:
7272
- time cargo check --target $CARGO_TARGET --locked --manifest-path util/io/Cargo.toml --no-default-features --verbose --color=always
73-
- sccache --stop-server
73+
- sccache --show-stats
7474

7575
cargo-check 2 3:
7676
stage: test
7777
<<: *docker-cache-status
7878
script:
7979
- time cargo check --target $CARGO_TARGET --locked --manifest-path util/io/Cargo.toml --features "mio" --verbose --color=always
80-
- sccache --stop-server
80+
- sccache --show-stats
8181

8282
cargo-check-evmbin:
8383
stage: test
8484
<<: *docker-cache-status
8585
script:
8686
- time cargo check -p evmbin --target $CARGO_TARGET --locked --verbose --color=always
87-
- sccache -s
87+
- sccache --show-stats
8888

8989
cargo-check-benches:
9090
stage: test
9191
<<: *docker-cache-status
9292
script:
9393
- time cargo check --all --benches --target $CARGO_TARGET --locked --verbose --color=always
94-
- sccache -s
94+
- sccache --show-stats
9595

9696
cargo-audit:
9797
stage: test

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ethstore = { path = "accounts/ethstore" }
3737
fdlimit = "0.1"
3838
futures = "0.1"
3939
journaldb = { path = "util/journaldb" }
40-
jsonrpc-core = "13.2.0"
40+
jsonrpc-core = "14.0.0"
4141
keccak-hash = "0.4.0"
4242
kvdb = "0.1"
4343
kvdb-rocksdb = "0.1.5"

cli-signer/rpc-client/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ serde_json = "1.0"
1515
url = "2.1.0"
1616
matches = "0.1"
1717
parking_lot = "0.9"
18-
jsonrpc-core = "13.2.0"
19-
jsonrpc-ws-server = "13.2.0"
18+
jsonrpc-core = "14.0.0"
19+
jsonrpc-ws-server = "14.0.0"
2020
parity-rpc = { path = "../../rpc" }
2121
keccak-hash = "0.4.0"

ethcore/builtin/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2018"
77

88
[dependencies]
99
bn = { git = "https://github.com/paritytech/bn", default-features = false }
10+
common-types = { path = "../types" }
1011
ethereum-types = "0.8.0"
1112
ethjson = { path = "../../json" }
1213
ethkey = { path = "../../accounts/ethkey" }

ethcore/builtin/src/lib.rs

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
1919
use std::{
2020
cmp::{max, min},
21+
convert::TryFrom,
2122
io::{self, Read, Cursor},
2223
mem::size_of,
2324
};
2425

2526
use bn;
2627
use byteorder::{BigEndian, LittleEndian, ReadBytesExt};
28+
use common_types::errors::EthcoreError;
2729
use ethereum_types::{H256, U256};
2830
use ethjson;
2931
use ethkey::{Signature, recover as ec_recover};
@@ -215,8 +217,10 @@ impl Builtin {
215217
}
216218
}
217219

218-
impl From<ethjson::spec::Builtin> for Builtin {
219-
fn from(b: ethjson::spec::Builtin) -> Self {
220+
impl TryFrom<ethjson::spec::Builtin> for Builtin {
221+
type Error = EthcoreError;
222+
223+
fn try_from(b: ethjson::spec::Builtin) -> Result<Self, Self::Error> {
220224
let pricer: Box<dyn Pricer> = match b.pricing {
221225
ethjson::spec::Pricing::Blake2F { gas_per_round } => {
222226
Box::new(gas_per_round)
@@ -259,17 +263,18 @@ impl From<ethjson::spec::Builtin> for Builtin {
259263
}
260264
};
261265

262-
Builtin {
266+
let native = ethereum_builtin(&b.name)?;
267+
Ok(Builtin {
263268
pricer,
264-
native: ethereum_builtin(&b.name),
269+
native,
265270
activate_at: b.activate_at.map_or(0, Into::into),
266-
}
271+
})
267272
}
268273
}
269274

270275
/// Ethereum built-in factory.
271-
fn ethereum_builtin(name: &str) -> Box<dyn Implementation> {
272-
match name {
276+
fn ethereum_builtin(name: &str) -> Result<Box<dyn Implementation>, EthcoreError> {
277+
let implementation = match name {
273278
"identity" => Box::new(Identity) as Box<dyn Implementation>,
274279
"ecrecover" => Box::new(EcRecover) as Box<dyn Implementation>,
275280
"sha256" => Box::new(Sha256) as Box<dyn Implementation>,
@@ -279,8 +284,9 @@ fn ethereum_builtin(name: &str) -> Box<dyn Implementation> {
279284
"alt_bn128_mul" => Box::new(Bn128Mul) as Box<dyn Implementation>,
280285
"alt_bn128_pairing" => Box::new(Bn128Pairing) as Box<dyn Implementation>,
281286
"blake2_f" => Box::new(Blake2F) as Box<dyn Implementation>,
282-
_ => panic!("invalid builtin name: {}", name),
283-
}
287+
_ => return Err(EthcoreError::Msg(format!("invalid builtin name: {}", name))),
288+
};
289+
Ok(implementation)
284290
}
285291

286292
// Ethereum builtins:
@@ -679,6 +685,7 @@ impl Bn128Pairing {
679685

680686
#[cfg(test)]
681687
mod tests {
688+
use std::convert::TryFrom;
682689
use ethereum_types::U256;
683690
use ethjson::uint::Uint;
684691
use num::{BigUint, Zero, One};
@@ -690,7 +697,7 @@ mod tests {
690697
fn blake2f_cost() {
691698
let f = Builtin {
692699
pricer: Box::new(123),
693-
native: ethereum_builtin("blake2_f"),
700+
native: ethereum_builtin("blake2_f").expect("known builtin"),
694701
activate_at: 0,
695702
};
696703
// 5 rounds
@@ -703,7 +710,7 @@ mod tests {
703710

704711
#[test]
705712
fn blake2_f_is_err_on_invalid_length() {
706-
let blake2 = ethereum_builtin("blake2_f");
713+
let blake2 = ethereum_builtin("blake2_f").expect("known builtin");
707714
// Test vector 1 and expected output from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-152.md#test-vector-1
708715
let input = hex!("00000c48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001");
709716
let mut out = [0u8; 64];
@@ -715,7 +722,7 @@ mod tests {
715722

716723
#[test]
717724
fn blake2_f_is_err_on_invalid_length_2() {
718-
let blake2 = ethereum_builtin("blake2_f");
725+
let blake2 = ethereum_builtin("blake2_f").expect("known builtin");
719726
// Test vector 2 and expected output from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-152.md#test-vector-2
720727
let input = hex!("000000000c48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001");
721728
let mut out = [0u8; 64];
@@ -727,7 +734,7 @@ mod tests {
727734

728735
#[test]
729736
fn blake2_f_is_err_on_bad_finalization_flag() {
730-
let blake2 = ethereum_builtin("blake2_f");
737+
let blake2 = ethereum_builtin("blake2_f").expect("known builtin");
731738
// Test vector 3 and expected output from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-152.md#test-vector-3
732739
let input = hex!("0000000c48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000002");
733740
let mut out = [0u8; 64];
@@ -739,7 +746,7 @@ mod tests {
739746

740747
#[test]
741748
fn blake2_f_zero_rounds_is_ok_test_vector_4() {
742-
let blake2 = ethereum_builtin("blake2_f");
749+
let blake2 = ethereum_builtin("blake2_f").expect("known builtin");
743750
// Test vector 4 and expected output from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-152.md#test-vector-4
744751
let input = hex!("0000000048c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001");
745752
let expected = hex!("08c9bcf367e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d282e6ad7f520e511f6c3e2b8c68059b9442be0454267ce079217e1319cde05b");
@@ -750,7 +757,7 @@ mod tests {
750757

751758
#[test]
752759
fn blake2_f_test_vector_5() {
753-
let blake2 = ethereum_builtin("blake2_f");
760+
let blake2 = ethereum_builtin("blake2_f").expect("known builtin");
754761
// Test vector 5 and expected output from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-152.md#test-vector-5
755762
let input = hex!("0000000c48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001");
756763
let expected = hex!("ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923");
@@ -761,7 +768,7 @@ mod tests {
761768

762769
#[test]
763770
fn blake2_f_test_vector_6() {
764-
let blake2 = ethereum_builtin("blake2_f");
771+
let blake2 = ethereum_builtin("blake2_f").expect("known builtin");
765772
// Test vector 6 and expected output from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-152.md#test-vector-6
766773
let input = hex!("0000000c48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000");
767774
let expected = hex!("75ab69d3190a562c51aef8d88f1c2775876944407270c42c9844252c26d2875298743e7f6d5ea2f2d3e8d226039cd31b4e426ac4f2d3d666a610c2116fde4735");
@@ -772,7 +779,7 @@ mod tests {
772779

773780
#[test]
774781
fn blake2_f_test_vector_7() {
775-
let blake2 = ethereum_builtin("blake2_f");
782+
let blake2 = ethereum_builtin("blake2_f").expect("known builtin");
776783
// Test vector 7 and expected output from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-152.md#test-vector-7
777784
let input = hex!("0000000148c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001");
778785
let expected = hex!("b63a380cb2897d521994a85234ee2c181b5f844d2c624c002677e9703449d2fba551b3a8333bcdf5f2f7e08993d53923de3d64fcc68c034e717b9293fed7a421");
@@ -784,7 +791,7 @@ mod tests {
784791
#[ignore]
785792
#[test]
786793
fn blake2_f_test_vector_8() {
787-
let blake2 = ethereum_builtin("blake2_f");
794+
let blake2 = ethereum_builtin("blake2_f").expect("known builtin");
788795
// Test vector 8 and expected output from https://github.com/ethereum/EIPs/blob/master/EIPS/eip-152.md#test-vector-8
789796
// Note this test is slow, 4294967295/0xffffffff rounds take a while.
790797
let input = hex!("ffffffff48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001");
@@ -829,7 +836,7 @@ mod tests {
829836

830837
#[test]
831838
fn identity() {
832-
let f = ethereum_builtin("identity");
839+
let f = ethereum_builtin("identity").expect("known builtin");
833840

834841
let i = [0u8, 1, 2, 3];
835842

@@ -849,7 +856,7 @@ mod tests {
849856

850857
#[test]
851858
fn sha256() {
852-
let f = ethereum_builtin("sha256");
859+
let f = ethereum_builtin("sha256").expect("known builtin");
853860

854861
let i = [0u8; 0];
855862

@@ -872,7 +879,7 @@ mod tests {
872879

873880
#[test]
874881
fn ripemd160() {
875-
let f = ethereum_builtin("ripemd160");
882+
let f = ethereum_builtin("ripemd160").expect("known builtin");
876883

877884
let i = [0u8; 0];
878885

@@ -891,7 +898,7 @@ mod tests {
891898

892899
#[test]
893900
fn ecrecover() {
894-
let f = ethereum_builtin("ecrecover");
901+
let f = ethereum_builtin("ecrecover").expect("known builtin");
895902

896903
let i = hex!("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad000000000000000000000000000000000000000000000000000000000000001b650acf9d3f5f0a2c799776a1254355d5f4061762a237396a99a0e0e3fc2bcd6729514a0dacb2e623ac4abd157cb18163ff942280db4d5caad66ddf941ba12e03");
897904

@@ -944,7 +951,7 @@ mod tests {
944951

945952
let f = Builtin {
946953
pricer: Box::new(ModexpPricer { divisor: 20 }),
947-
native: ethereum_builtin("modexp"),
954+
native: ethereum_builtin("modexp").expect("known builtin"),
948955
activate_at: 0,
949956
};
950957

@@ -1055,7 +1062,7 @@ mod tests {
10551062

10561063
let f = Builtin {
10571064
pricer: Box::new(Linear { base: 0, word: 0 }),
1058-
native: ethereum_builtin("alt_bn128_add"),
1065+
native: ethereum_builtin("alt_bn128_add").expect("known builtin"),
10591066
activate_at: 0,
10601067
};
10611068

@@ -1114,7 +1121,7 @@ mod tests {
11141121

11151122
let f = Builtin {
11161123
pricer: Box::new(Linear { base: 0, word: 0 }),
1117-
native: ethereum_builtin("alt_bn128_mul"),
1124+
native: ethereum_builtin("alt_bn128_mul").expect("known builtin"),
11181125
activate_at: 0,
11191126
};
11201127

@@ -1154,7 +1161,7 @@ mod tests {
11541161
fn builtin_pairing() -> Builtin {
11551162
Builtin {
11561163
pricer: Box::new(Linear { base: 0, word: 0 }),
1157-
native: ethereum_builtin("alt_bn128_pairing"),
1164+
native: ethereum_builtin("alt_bn128_pairing").expect("known builtin"),
11581165
activate_at: 0,
11591166
}
11601167
}
@@ -1226,15 +1233,15 @@ mod tests {
12261233
#[test]
12271234
#[should_panic]
12281235
fn from_unknown_linear() {
1229-
let _ = ethereum_builtin("foo");
1236+
let _ = ethereum_builtin("foo").unwrap();
12301237
}
12311238

12321239
#[test]
12331240
fn is_active() {
12341241
let pricer = Box::new(Linear { base: 10, word: 20} );
12351242
let b = Builtin {
12361243
pricer: pricer as Box<dyn Pricer>,
1237-
native: ethereum_builtin("identity"),
1244+
native: ethereum_builtin("identity").expect("known builtin"),
12381245
activate_at: 100_000,
12391246
};
12401247

@@ -1248,7 +1255,7 @@ mod tests {
12481255
let pricer = Box::new(Linear { base: 10, word: 20 });
12491256
let b = Builtin {
12501257
pricer: pricer as Box<dyn Pricer>,
1251-
native: ethereum_builtin("identity"),
1258+
native: ethereum_builtin("identity").expect("known builtin"),
12521259
activate_at: 1,
12531260
};
12541261

@@ -1265,15 +1272,15 @@ mod tests {
12651272

12661273
#[test]
12671274
fn from_json() {
1268-
let b = Builtin::from(ethjson::spec::Builtin {
1275+
let b = Builtin::try_from(ethjson::spec::Builtin {
12691276
name: "identity".to_owned(),
12701277
pricing: ethjson::spec::Pricing::Linear(ethjson::spec::Linear {
12711278
base: 10,
12721279
word: 20,
12731280
}),
12741281
activate_at: None,
12751282
eip1108_transition: None,
1276-
});
1283+
}).expect("known builtin");
12771284

12781285
assert_eq!(b.cost(&[0; 0], 0), U256::from(10));
12791286
assert_eq!(b.cost(&[0; 1], 0), U256::from(30));
@@ -1288,7 +1295,7 @@ mod tests {
12881295

12891296
#[test]
12901297
fn bn128_pairing_eip1108_transition() {
1291-
let b = Builtin::from(ethjson::spec::Builtin {
1298+
let b = Builtin::try_from(ethjson::spec::Builtin {
12921299
name: "alt_bn128_pairing".to_owned(),
12931300
pricing: ethjson::spec::Pricing::AltBn128Pairing(ethjson::spec::builtin::AltBn128Pairing {
12941301
base: 100_000,
@@ -1298,39 +1305,39 @@ mod tests {
12981305
}),
12991306
activate_at: Some(Uint(U256::from(10))),
13001307
eip1108_transition: Some(Uint(U256::from(20))),
1301-
});
1308+
}).expect("known builtin");
13021309

13031310
assert_eq!(b.cost(&[0; 192 * 3], 10), U256::from(340_000), "80 000 * 3 + 100 000 == 340 000");
13041311
assert_eq!(b.cost(&[0; 192 * 7], 20), U256::from(283_000), "34 000 * 7 + 45 000 == 283 000");
13051312
}
13061313

13071314
#[test]
13081315
fn bn128_add_eip1108_transition() {
1309-
let b = Builtin::from(ethjson::spec::Builtin {
1316+
let b = Builtin::try_from(ethjson::spec::Builtin {
13101317
name: "alt_bn128_add".to_owned(),
13111318
pricing: ethjson::spec::Pricing::AltBn128ConstOperations(ethjson::spec::builtin::AltBn128ConstOperations {
13121319
price: 500,
13131320
eip1108_transition_price: 150,
13141321
}),
13151322
activate_at: Some(Uint(U256::from(10))),
13161323
eip1108_transition: Some(Uint(U256::from(20))),
1317-
});
1324+
}).expect("known builtin");
13181325

13191326
assert_eq!(b.cost(&[0; 192], 10), U256::from(500));
13201327
assert_eq!(b.cost(&[0; 10], 20), U256::from(150), "after istanbul hardfork gas cost for add should be 150");
13211328
}
13221329

13231330
#[test]
13241331
fn bn128_mul_eip1108_transition() {
1325-
let b = Builtin::from(ethjson::spec::Builtin {
1332+
let b = Builtin::try_from(ethjson::spec::Builtin {
13261333
name: "alt_bn128_mul".to_owned(),
13271334
pricing: ethjson::spec::Pricing::AltBn128ConstOperations(ethjson::spec::builtin::AltBn128ConstOperations {
13281335
price: 40_000,
13291336
eip1108_transition_price: 6000,
13301337
}),
13311338
activate_at: Some(Uint(U256::from(10))),
13321339
eip1108_transition: Some(Uint(U256::from(20))),
1333-
});
1340+
}).expect("known builtin");
13341341

13351342
assert_eq!(b.cost(&[0; 192], 10), U256::from(40_000));
13361343
assert_eq!(b.cost(&[0; 10], 20), U256::from(6_000), "after istanbul hardfork gas cost for mul should be 6 000");

0 commit comments

Comments
 (0)