diff --git a/Cargo.lock b/Cargo.lock index 4054c6017..c3a00e53f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,6 +73,15 @@ dependencies = [ "xdg 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "argon2rs" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "arrayref" version = "0.3.5" @@ -187,6 +196,15 @@ name = "bitflags" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "blake2-rfc" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "block-buffer" version = "0.3.3" @@ -237,7 +255,7 @@ name = "blooms-db" version = "0.1.0" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethbloom 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -343,7 +361,7 @@ dependencies = [ name = "cli-signer" version = "1.4.0" dependencies = [ - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "parity-rpc 1.12.0", "parity-rpc-client 1.4.0", @@ -382,18 +400,23 @@ dependencies = [ name = "common-types" version = "0.1.0" dependencies = [ - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", "ethkey 0.3.0", "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp_derive 0.1.0", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "unexpected 0.1.0", ] +[[package]] +name = "constant_time_eq" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "criterion" version = "0.2.5" @@ -401,29 +424,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", - "criterion-plot 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "criterion-plot 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "criterion-stats 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "csv 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "handlebars 0.32.4 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", - "itertools-num 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools-num 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "simplelog 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "walkdir 2.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "criterion-plot" -version = "0.2.5" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -650,11 +675,21 @@ name = "dir" version = "0.1.2" dependencies = [ "app_dirs 1.2.1 (git+https://github.com/paritytech/app-dirs-rs)", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "home 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", ] +[[package]] +name = "dirs" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_users 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "docopt" version = "1.0.2" @@ -676,12 +711,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "eip-712" version = "0.1.0" dependencies = [ - "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "lunarity-lexer 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -738,21 +773,21 @@ dependencies = [ [[package]] name = "eth-secp256k1" version = "0.5.7" -source = "git+https://github.com/paritytech/rust-secp256k1#ccc06e7480148b723eb44ac56cf4d20eec380b6f" +source = "git+https://github.com/paritytech/rust-secp256k1#9791e79f21a5309dcb6e0bd254b1ef88fca2f1f4" dependencies = [ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ethabi" -version = "6.1.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", @@ -762,15 +797,15 @@ dependencies = [ [[package]] name = "ethabi-contract" -version = "6.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "ethabi-derive" -version = "6.0.2" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -784,8 +819,8 @@ dependencies = [ "criterion 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -797,13 +832,13 @@ dependencies = [ [[package]] name = "ethbloom" -version = "0.5.0" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types-serialize 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "fixed-hash 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-rlp 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -820,9 +855,9 @@ dependencies = [ "crossbeam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi-contract 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi-derive 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethash 1.12.0", "ethcore-accounts 0.1.0", "ethcore-blockchain 0.1.0", @@ -832,7 +867,7 @@ dependencies = [ "ethcore-io 1.12.0", "ethcore-miner 1.12.0", "ethcore-stratum 1.12.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", "ethkey 0.3.0", "evm 0.1.0", @@ -842,7 +877,7 @@ dependencies = [ "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -862,9 +897,10 @@ dependencies = [ "parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", - "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp_compress 0.1.0", "rlp_derive 0.1.0", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -875,7 +911,7 @@ dependencies = [ "time-utils 0.1.0", "trace-time 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "trie-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "trie-standardmap 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "trie-standardmap 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", "triehash-ethereum 0.2.0", "unexpected 0.1.0", "using_queue 0.1.0", @@ -887,7 +923,7 @@ dependencies = [ name = "ethcore-accounts" version = "0.1.0" dependencies = [ - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethkey 0.3.0", "ethstore 0.2.1", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -907,18 +943,18 @@ dependencies = [ "common-types 0.1.0", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-db 0.1.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethkey 0.3.0", "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp_compress 0.1.0", "rlp_derive 0.1.0", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -937,7 +973,7 @@ name = "ethcore-call-contract" version = "0.1.0" dependencies = [ "common-types 0.1.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -946,11 +982,11 @@ name = "ethcore-db" version = "0.1.0" dependencies = [ "common-types 0.1.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp_derive 0.1.0", ] @@ -984,7 +1020,7 @@ dependencies = [ "ethcore-io 1.12.0", "ethcore-miner 1.12.0", "ethcore-network 1.12.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "failsafe 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "fastmap 0.1.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -992,7 +1028,7 @@ dependencies = [ "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1002,8 +1038,8 @@ dependencies = [ "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", - "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp_derive 0.1.0", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1038,24 +1074,24 @@ dependencies = [ "common-types 0.1.0", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi-contract 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi-derive 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethash 1.12.0", "ethcore-call-contract 0.1.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethkey 0.3.0", "fetch 0.1.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", "hyper 0.12.19 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "linked-hash-map 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-runtime 0.1.0", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "price-info 1.12.0", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1072,14 +1108,14 @@ dependencies = [ "assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-io 1.12.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethkey 0.3.0", "ipnetwork 0.12.8 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", "parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1096,11 +1132,11 @@ dependencies = [ "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-io 1.12.0", "ethcore-network 1.12.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethkey 0.3.0", "igd 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "ipnetwork 0.12.8 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1110,8 +1146,8 @@ dependencies = [ "parity-path 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1129,27 +1165,27 @@ dependencies = [ "common-types 0.1.0", "derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi-contract 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi-derive 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", "ethcore-call-contract 0.1.0", "ethcore-io 1.12.0", "ethcore-miner 1.12.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", "ethkey 0.3.0", "fetch 0.1.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", "rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp_derive 0.1.0", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1169,19 +1205,19 @@ dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "common-types 0.1.0", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi-contract 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi-derive 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", "ethcore-accounts 0.1.0", "ethcore-call-contract 0.1.0", "ethcore-sync 1.12.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethkey 0.3.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.19 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-server-utils 11.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-rocksdb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1214,7 +1250,7 @@ dependencies = [ "ethcore-io 1.12.0", "ethcore-private-tx 1.0.0", "ethcore-sync 1.12.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-rocksdb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1227,10 +1263,10 @@ name = "ethcore-stratum" version = "1.12.0" dependencies = [ "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-tcp-server 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1250,14 +1286,14 @@ dependencies = [ "ethcore-network 1.12.0", "ethcore-network-devp2p 1.12.0", "ethcore-private-tx 1.0.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethkey 0.3.0", "ethstore 0.2.1", "fastmap 0.1.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1266,8 +1302,9 @@ dependencies = [ "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-runtime 0.1.0", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "trace-time 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "triehash-ethereum 0.2.0", @@ -1275,30 +1312,22 @@ dependencies = [ [[package]] name = "ethereum-types" -version = "0.4.2" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types-serialize 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "fixed-hash 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "ethereum-types-serialize" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "ethbloom 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-rlp 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "primitive-types 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "uint 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ethjson" version = "0.1.0" dependencies = [ - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1312,14 +1341,14 @@ dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "edit-distance 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "eth-secp256k1 0.5.7 (git+https://github.com/paritytech/rust-secp256k1)", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "memzero 0.1.0", "parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wordlist 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1346,17 +1375,16 @@ name = "ethstore" version = "0.2.1" dependencies = [ "dir 0.1.2", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethkey 0.3.0", "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wordlist 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1390,13 +1418,12 @@ version = "0.1.0" dependencies = [ "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "criterion 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "memory-cache 0.1.0", - "num-bigint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1411,7 +1438,7 @@ dependencies = [ "docopt 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", "evm 0.1.0", "panic_hook 0.1.0", @@ -1473,7 +1500,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "fastmap" version = "0.1.0" dependencies = [ - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "plain_hasher 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1501,13 +1528,15 @@ dependencies = [ [[package]] name = "fixed-hash" -version = "0.2.2" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1536,6 +1565,11 @@ name = "fs_extra" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -1655,6 +1689,19 @@ name = "hash-db" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "hash-db" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "hash256-std-hasher" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "heapsize" version = "0.4.2" @@ -1818,6 +1865,30 @@ dependencies = [ "xmltree 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "impl-codec" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "impl-rlp" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "impl-serde" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "indexmap" version = "1.0.2" @@ -1865,7 +1936,7 @@ dependencies = [ [[package]] name = "itertools-num" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1905,7 +1976,7 @@ dependencies = [ "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "jni-sys 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "walkdir 2.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1918,11 +1989,11 @@ name = "journaldb" version = "0.2.0" dependencies = [ "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "fastmap 0.1.0", "hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1930,7 +2001,7 @@ dependencies = [ "memory-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2064,10 +2135,10 @@ dependencies = [ [[package]] name = "keccak-hash" -version = "0.1.2" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "primitive-types 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2075,12 +2146,22 @@ dependencies = [ name = "keccak-hasher" version = "0.1.1" dependencies = [ - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "plain_hasher 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "keccak-hasher" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", + "hash256-std-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -2417,14 +2498,14 @@ dependencies = [ name = "node-filter" version = "1.12.0" dependencies = [ - "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi-contract 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi-derive 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", "ethcore-io 1.12.0", "ethcore-network 1.12.0", "ethcore-network-devp2p 1.12.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2459,15 +2540,6 @@ dependencies = [ "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "num-bigint" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "num-integer" version = "0.1.39" @@ -2579,6 +2651,15 @@ dependencies = [ "tokio-current-thread 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parity-codec" +version = "3.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "parity-crypto" version = "0.4.0" @@ -2637,7 +2718,7 @@ dependencies = [ "ethcore-secretstore 1.0.0", "ethcore-service 0.1.0", "ethcore-sync 1.12.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethkey 0.3.0", "ethstore 0.2.1", "fake-fetch 0.0.1", @@ -2646,10 +2727,9 @@ dependencies = [ "ipnetwork 0.12.8 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", "jsonrpc-core 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-rocksdb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "migration-rocksdb 0.1.0", "node-filter 1.12.0", @@ -2671,7 +2751,7 @@ dependencies = [ "pretty_assertions 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "registrar 0.0.1", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2690,21 +2770,21 @@ dependencies = [ name = "parity-hash-fetch" version = "1.12.0" dependencies = [ - "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi-contract 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi-derive 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "fake-fetch 0.0.1", "fetch 0.1.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", "mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-runtime 0.1.0", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "registrar 0.0.1", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2715,12 +2795,12 @@ version = "1.12.0" dependencies = [ "cid 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-http-server 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "multihash 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2734,7 +2814,7 @@ dependencies = [ "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2784,7 +2864,7 @@ dependencies = [ "ethcore-network 1.12.0", "ethcore-private-tx 1.0.0", "ethcore-sync 1.12.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", "ethkey 0.3.0", "ethstore 0.2.1", @@ -2799,7 +2879,7 @@ dependencies = [ "jsonrpc-ipc-server 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-pubsub 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-ws-server 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "macros 0.1.0", "multihash 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2811,8 +2891,9 @@ dependencies = [ "parity-version 2.6.0", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2831,11 +2912,11 @@ dependencies = [ name = "parity-rpc-client" version = "1.4.0" dependencies = [ - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-ws-server 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-rpc 1.12.0", @@ -2893,13 +2974,13 @@ name = "parity-updater" version = "1.12.0" dependencies = [ "common-types 0.1.0", - "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi-contract 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi-derive 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", "ethcore-sync 1.12.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2908,7 +2989,7 @@ dependencies = [ "parity-path 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-version 2.6.0", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2919,7 +3000,7 @@ name = "parity-version" version = "2.6.0" dependencies = [ "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2941,7 +3022,7 @@ dependencies = [ "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-network 1.12.0", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethkey 0.3.0", "hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2951,9 +3032,10 @@ dependencies = [ "memzero 0.1.0", "ordered-float 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3040,14 +3122,14 @@ name = "patricia-trie-ethereum" version = "0.1.0" dependencies = [ "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", "memory-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "trie-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3200,6 +3282,18 @@ dependencies = [ "smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "primitive-types" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-rlp 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "uint 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "proc-macro2" version = "0.4.20" @@ -3222,7 +3316,7 @@ version = "0.1.0" dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3305,7 +3399,7 @@ dependencies = [ "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_xorshift 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3332,6 +3426,11 @@ name = "rand_core" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "rand_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rand_hc" version = "0.1.0" @@ -3348,6 +3447,19 @@ dependencies = [ "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rand_pcg" version = "0.1.1" @@ -3359,7 +3471,7 @@ dependencies = [ [[package]] name = "rand_xorshift" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3367,7 +3479,7 @@ dependencies = [ [[package]] name = "rayon" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3386,6 +3498,14 @@ dependencies = [ "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "redox_syscall" version = "0.1.40" @@ -3399,6 +3519,17 @@ dependencies = [ "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "redox_users" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "regex" version = "0.2.11" @@ -3443,11 +3574,11 @@ dependencies = [ name = "registrar" version = "0.0.1" dependencies = [ - "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi-contract 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethabi-derive 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3491,22 +3622,10 @@ dependencies = [ [[package]] name = "rlp" -version = "0.2.4" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rlp" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3516,7 +3635,7 @@ version = "0.1.0" dependencies = [ "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3525,7 +3644,7 @@ version = "0.1.0" dependencies = [ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3621,6 +3740,11 @@ name = "scoped-tls" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "scoped_threadpool" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "scopeguard" version = "0.3.3" @@ -3734,7 +3858,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3800,6 +3924,11 @@ name = "stable_deref_trait" version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "static_assertions" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "stats" version = "0.1.0" @@ -3890,10 +4019,11 @@ dependencies = [ [[package]] name = "term" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4276,31 +4406,29 @@ dependencies = [ [[package]] name = "trie-standardmap" -version = "0.1.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "triehash" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "triehash-ethereum" version = "0.2.0" dependencies = [ - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.1.1", - "triehash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "triehash 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4325,11 +4453,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "uint" -version = "0.4.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4471,13 +4599,13 @@ name = "vm" version = "0.1.0" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethjson 0.1.0", - "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "patricia-trie-ethereum 0.1.0", - "rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "trie-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4488,7 +4616,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "walkdir" -version = "2.2.5" +version = "2.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "same-file 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4522,7 +4650,7 @@ version = "0.1.0" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4665,6 +4793,7 @@ dependencies = [ "checksum ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6b3568b48b7cefa6b8ce125f9bb4989e52fbcc29ebea88df04cc7c5f12f70455" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum app_dirs 1.2.1 (git+https://github.com/paritytech/app-dirs-rs)" = "" +"checksum argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f67b0b6a86dae6e67ff4ca2b6201396074996379fba2b92ff649126f37cb392" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" "checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" "checksum ascii 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ae7d751998c189c1d4468cf0a39bb2eae052a9c58d50ebb3b9591ee3813ad50" @@ -4681,6 +4810,7 @@ dependencies = [ "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" +"checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" "checksum block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab" "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" "checksum block-cipher-trait 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" @@ -4701,8 +4831,9 @@ dependencies = [ "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cmake 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "6ec65ee4f9c9d16f335091d23693457ed4928657ba4982289d7fafee03bc614a" "checksum combine 3.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fc1d011beeed29187b8db2ac3925c8dd4d3e87db463dc9d2d2833985388fc5bc" +"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" "checksum criterion 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c47d2b548c5647e1a436dc0cb78d4ebf51b6bf7ab101ed76662828bdd4d3a24a" -"checksum criterion-plot 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6e649d6aacdbbdb94ec659561a309a71336fc5655ed408f3afd28df2fc0c4f4f" +"checksum criterion-plot 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "dd5f81689739e463ece7a6b62c6ec63bdab5c4e28fe05ff451769e87d1511411" "checksum criterion-stats 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ff43cac80562f91ead0b617c1be74edf350adfaa195809d355de98dfc8f9237d" "checksum crossbeam 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d7408247b1b87f480890f28b670c5f8d9a8a4274833433fe74dc0dfd46d33650" "checksum crossbeam-channel 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7b85741761b7f160bc5e7e0c14986ef685b7f8bf9b7ad081c60c604bb4649827" @@ -4727,6 +4858,7 @@ dependencies = [ "checksum difference 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3304d19798a8e067e48d8e69b2c37f0b5e9b4e462504ad9e27e9f3fce02bba8" "checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90" "checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" +"checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" "checksum docopt 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "db2906c2579b5b7207fc1e328796a9a8835dc44e22dbe8e460b1d636f9a7b225" "checksum edit-distance 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3bd26878c3d921f89797a4e1a1711919f999a9f6946bb6f5a4ffda126d297b7e" "checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0" @@ -4735,22 +4867,22 @@ dependencies = [ "checksum env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)" = "15b0a4d2e39f8420210be8b27eeda28029729e2fd4291019455016c348240c38" "checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02" "checksum eth-secp256k1 0.5.7 (git+https://github.com/paritytech/rust-secp256k1)" = "" -"checksum ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8eb362fde43ed0b50b258bb0c72b72b3dccfd29f8de9506295eaf9251c49ca31" -"checksum ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "795e25fd868e12a59ca235dbe1f6cc8f1eba8f67d6a39438b29535e0126e0c27" -"checksum ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "66a587250c8190be9d6ae28d67b8957ed97cb9eee2e272173a20593ab054a075" -"checksum ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a93a43ce2e9f09071449da36bfa7a1b20b950ee344b6904ff23de493b03b386" -"checksum ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e742184dc63a01c8ea0637369f8faa27c40f537949908a237f95c05e68d2c96" -"checksum ethereum-types-serialize 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1873d77b32bc1891a79dad925f2acbc318ee942b38b9110f9dbc5fbeffcea350" +"checksum ethabi 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b312e5740d6e0369491ebe81a8752f7797b70e495530f28bbb7cc967ded3d77c" +"checksum ethabi-contract 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "272b7fcfada8d9b2631d75693385b505efc826752dbc7ae1815e56b35d5a3f9f" +"checksum ethabi-derive 8.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "65cdef3199bf5d1821dc53b5ab992f853a13b2e28d7a63983095d9d61fae58d3" +"checksum ethbloom 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3932e82d64d347a045208924002930dc105a138995ccdc1479d0f05f0359f17c" +"checksum ethereum-types 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "62d1bc682337e2c5ec98930853674dd2b4bd5d0d246933a9e98e5280f7c76c5f" "checksum failsafe 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad3bf1642583ea2f1fa38a1e8546613a7488816941b33e5f0fccceac61879118" "checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7" "checksum failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" "checksum fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b1ee15a7050e5580b3712877157068ea713b245b080ff302ae2ca973cfcd9baa" -"checksum fixed-hash 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0d5ec8112f00ea8a483e04748a85522184418fd1cf02890b626d8fc28683f7de" +"checksum fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d1a683d1234507e4f3bf2736eeddf0de1dc65996dc0164d57eba0a74bcf29489" "checksum fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" "checksum fs-swap 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "921d332c89b3b61a826de38c61ee5b6e02c56806cade1b0e5d81bd71f57a71bb" "checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674" +"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b" @@ -4765,6 +4897,8 @@ dependencies = [ "checksum hamming 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "65043da274378d68241eb9a8f8f8aa54e349136f7b8e12f63e3ef44043cc30e1" "checksum handlebars 0.32.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d89ec99d1594f285d4590fc32bac5f75cdab383f1123d504d27862c644a807dd" "checksum hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1b03501f6e1a2a97f1618879aba3156f14ca2847faa530c4e28859638bd11483" +"checksum hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ba7fb417e5c470acdd61068c79767d0e65962e70836cf6c9dfd2409f06345ce0" +"checksum hash256-std-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f8b2027c19ec91eb304999abae7307d225cf93be42af53b0039f76e98ed5af86" "checksum heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)" = "" "checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82" "checksum hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d6a22814455d41612f41161581c2883c0c6a1c41852729b17d5ed88f01e153aa" @@ -4779,6 +4913,9 @@ dependencies = [ "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum if_chain 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4bac95d9aa0624e7b78187d6fb8ab012b41d9f6f54b1bcb61e61c4845f8357ec" "checksum igd 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8a254e265e8810deb357a9de757f784787ec415d056ededf410c0aa460afee9e" +"checksum impl-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2050d823639fbeae26b2b5ba09aca8907793117324858070ade0673c49f793b" +"checksum impl-rlp 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f39b9963cf5f12fcc4ae4b30a6927ed67d6b4ea4cbe7d17a41131163b401303b" +"checksum impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d26be4b97d738552ea423f76c4f681012ff06c3fa36fa968656b3679f60b4a1" "checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" "checksum integer-encoding 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "26746cbc2e680af687e88d717f20ff90079bd10fc984ad57d277cd0e37309fa5" "checksum interleaved-ordered 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "141340095b15ed7491bd3d4ced9d20cebfb826174b6bb03386381f62b01e3d77" @@ -4786,7 +4923,7 @@ dependencies = [ "checksum ipnetwork 0.12.8 (registry+https://github.com/rust-lang/crates.io-index)" = "70783119ac90828aaba91eae39db32c6c1b8838deea3637e5238efa0130801ab" "checksum itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4833d6978da405305126af4ac88569b5d71ff758581ce5a987dbfa3755f694fc" "checksum itertools 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)" = "f58856976b776fedd95533137617a02fb25719f40e7d9b01c7043cd65474f450" -"checksum itertools-num 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "83ca7b70b838f2e34bc6c2f367a1ed1cfe34fb82464adecadd31cdcc7da882fc" +"checksum itertools-num 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a872a22f9e6f7521ca557660adb96dd830e54f0f490fa115bb55dd69d38b27e7" "checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" "checksum jemalloc-sys 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "bfc62c8e50e381768ce8ee0428ee53741929f7ebd73e4d83f669bcf7693e00ae" "checksum jemallocator 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9f0cd42ac65f758063fea55126b0148b1ce0a6354ff78e07a4d6806bc65c4ab3" @@ -4802,7 +4939,8 @@ dependencies = [ "checksum jsonrpc-server-utils 11.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e3372b3248a53abcca8f61924f188052bb0c4cd80b482b2b4eaf9f8667efb9f4" "checksum jsonrpc-tcp-server 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c873dac37a601fb88d40ba49eeac3f1aa60953c06b2e99ddbf0569b6f8028478" "checksum jsonrpc-ws-server 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20b8333a5a6e6ccbcf5c90f90919de557cba4929efa164e9bd0e8e497eb20e46" -"checksum keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "253bbe643c32c816bf58fa5a88248fafedeebb139705ad17a62add3517854a86" +"checksum keccak-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "69e8ee697b9aa6dcc34d7657565fa5052763a1627a5b59e4c3c0ae3ed0d70a65" +"checksum keccak-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "af672553b2abac1c86c29fd62c79880638b6abc91d96db4aa42a5baab2bc1ca9" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "72ae89206cea31c32014b39d5a454b96135894221610dbfd19cf4d2d044fa546" "checksum kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "45bcdf5eb083602cff61a6f8438dce2a7900d714e893fc48781c39fb119d37aa" @@ -4841,7 +4979,6 @@ dependencies = [ "checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" "checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" "checksum num-bigint 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "e63899ad0da84ce718c14936262a41cee2c79c981fc0a0e7c7beb47d5a07e8c1" -"checksum num-bigint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "57450397855d951f1a41305e54851b1a7b8f5d2e349543a02a2effe25459f718" "checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" "checksum num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "af3fdbbc3291a5464dc57b03860ec37ca6bf915ed6ee385e7c6c052c422b2124" "checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" @@ -4855,6 +4992,7 @@ dependencies = [ "checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" "checksum parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa5168b4cf41f3835e4bc6ffb32f51bc9365dc50cb351904595b3931d917fd0c" +"checksum parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dcb43c05fb71c03b4ea7327bf15694da1e0f23f19d5b1e95bab6c6d74097e336" "checksum parity-crypto 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ded773d0b20caeb099708dcfddf85d75d34ecdba80fcdb573a69af334535d51d" "checksum parity-daemonize 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "69b1910b2793ff52713fca0a4ee92544ebec59ccd218ea74560be6f947b4ca77" "checksum parity-path 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5962540f99d3895d9addf535f37ab1397886bc2c68e59efd040ef458e5f8c3f7" @@ -4886,6 +5024,7 @@ dependencies = [ "checksum primal-check 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8e65f96c0a171f887198c274392c99a116ef65aa7f53f3b6d4902f493965c2d1" "checksum primal-estimate 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "56ea4531dde757b56906493c8604641da14607bf9cdaa80fb9c9cabd2429f8d5" "checksum primal-sieve 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "da2d6ed369bb4b0273aeeb43f07c105c0117717cbae827b20719438eb2eb798c" +"checksum primitive-types 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2288eb2a39386c4bc817974cc413afe173010dc80e470fcb1e9a35580869f024" "checksum proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "3d7b7eaaa90b4a90a932a9ea6666c95a389e424eff347f0f793979289429feee" "checksum pulldown-cmark 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8361e81576d2e02643b04950e487ec172b687180da65c731c03cf336784e6c07" "checksum pwasm-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e9135bed7b452e20dbb395a2d519abaf0c46d60e7ecc02daeeab447d29bada1" @@ -4899,14 +5038,18 @@ dependencies = [ "checksum rand_chacha 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "771b009e3a508cb67e8823dda454aaa5368c7bc1c16829fb77d3e980440dd34a" "checksum rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1961a422c4d189dfb50ffa9320bf1f2a9bd54ecb92792fb9477f99a1045f3372" "checksum rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0905b6b7079ec73b314d4c748701f6931eb79fd97c668caa3f1899b22b32c6db" +"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" "checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" "checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +"checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" "checksum rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "086bd09a33c7044e56bb44d5bdde5a60e7f119a9e95b0775f545de759a32fe05" -"checksum rand_xorshift 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "effa3fcaa47e18db002bdde6060944b6d2f9cfd8db471c30e873448ad9187be3" -"checksum rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "df7a791f788cb4c516f0e091301a29c2b71ef680db5e644a7d68835c8ae6dbfa" +"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +"checksum rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "373814f27745b2686b350dd261bfd24576a6fb0e2c5919b3a2b6005f820b0473" "checksum rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b055d1e92aba6877574d8fe604a63c8b5df60f60e5982bf7ccbb1338ea527356" +"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" +"checksum redox_users 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe5204c3a17e97dde73f285d49be585df59ed84b50a872baf416e73b62c3828" "checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" "checksum regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53ee8cfdddb2e0291adfb9f13d31d3bbe0a03c9a402c01b1e24188d86c35b24f" "checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7" @@ -4915,8 +5058,7 @@ dependencies = [ "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" "checksum ripemd160 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad5112e0dbbb87577bfbc56c42450235e3012ce336e29c5befd7807bd626da4a" -"checksum rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "524c5ad554859785dfc8469df3ed5e0b5784d4d335877ed47c8d90fc0eb238fe" -"checksum rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "16d1effe9845d54f90e7be8420ee49e5c94623140b97ee4bc6fb5bfddb745720" +"checksum rlp 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3b0d56c1450bfbef1181fdeb78b902dc1d23178de77c23d705317508e03d1b7c" "checksum rpassword 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b273c91bd242ca03ad6d71c143b6f17a48790e61f21a6c78568fa2b6774a24a4" "checksum rprompt 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1601f32bc5858aae3cbfa1c645c96c4d820cc5c16be0194f089560c00b6eb625" "checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" @@ -4930,6 +5072,7 @@ dependencies = [ "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" "checksum same-file 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "10f7794e2fda7f594866840e95f5c5962e886e228e68b6505885811a94dd728c" "checksum scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "332ffa32bf586782a3efaeb58f127980944bbc8c4d6913a86107ac2a5ab24b28" +"checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum scrypt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "656c79d0e90d0ab28ac86bf3c3d10bfbbac91450d3f190113b4e76d9fec3cfdd" "checksum sct 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f5adf8fbd58e1b1b52699dc8bed2630faecb6d8c7bee77d009d6bbe4af569b9" @@ -4954,6 +5097,7 @@ dependencies = [ "checksum socket2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c4d11a52082057d87cb5caa31ad812f4504b97ab44732cd8359df2e9ff9f48e7" "checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" +"checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5" "checksum stream-cipher 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8861bc80f649f5b4c9bd38b696ae9af74499d479dbfb327f0607de6b326a36bc" "checksum string 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00caf261d6f90f588f8450b8e1230fa0d5be49ee6140fdfbcb55335aff350970" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" @@ -4965,7 +5109,7 @@ dependencies = [ "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c63f48baada5c52e65a29eef93ab4f8982681b67f9e8d29c7b05abcfec2b9ffe" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" -"checksum term 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5e6b677dd1e8214ea1ef4297f85dbcbed8e8cdddb561040cc998ca2551c37561" +"checksum term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42" "checksum term_size 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e5b9a66db815dcfd2da92db471106457082577c3c278d4138ab3e3b4e189327" "checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" @@ -5002,13 +5146,13 @@ dependencies = [ "checksum transaction-pool 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8d8bd3123931aa6e49dd03bc8a2400490e14701d779458d1f1fff1f04c6f666" "checksum transient-hashmap 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aeb4b191d033a35edfce392a38cdcf9790b6cebcb30fa690c312c29da4dc433e" "checksum trie-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c7319e28ca295f27359d944a682f7f65b419158bf1590c92cadc0000258d788" -"checksum trie-standardmap 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0e26f52976a57a0859616d6fcec87092ac35d08eabbd78dc3dabee93b480ea5f" -"checksum triehash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d26efb4ddf87870fc08dc9a6580dc3061be350d7b9d0eb30aef1c8b4227aa46" +"checksum trie-standardmap 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ebaa4b340046196efad8872b2dffe585b5ea330230dc44ee14e399f77da29f51" +"checksum triehash 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "92148b4d8d55eff71bc8c9e3c5f714e266c2a05e724dce5405a10deabbf449a8" "checksum try-lock 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee2aa4715743892880f70885373966c83d73ef1b0838a664ef0c76fffd35e7c2" "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d" -"checksum uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "754ba11732b9161b94c41798e5197e5e75388d012f760c42adb5000353e98646" +"checksum uint 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2143cded94692b156c356508d92888acc824db5bffc0b4089732264c6fcf86d4" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" "checksum unicase 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d3218ea14b4edcaccfa0df0a64a3792a2c32cc706f1b336e48867f9d3147f90" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" @@ -5027,7 +5171,7 @@ dependencies = [ "checksum vergen 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c3365f36c57e5df714a34be40902b27a992eeddb9996eca52d0584611cf885d" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"checksum walkdir 2.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "af464bc7be7b785c7ac72e266a6b67c4c9070155606f51655a650a6686204e35" +"checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" "checksum want 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a05d9d966753fa4b5c8db73fcab5eed4549cfe0e1e4e66911e5564a0085c35d1" "checksum want 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "797464475f30ddb8830cc529aaaae648d581f99e2036a928877dfde027ddf6b3" "checksum wasmi 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b4a6d379e9332b1b1f52c5a87f2481c85c7c931d8ec411963dfb8f26b1ec1e3" diff --git a/Cargo.toml b/Cargo.toml index 2851bc97c..5a6c93d64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,11 +45,11 @@ ethcore-network = { path = "util/network" } ethcore-private-tx = { path = "ethcore/private-tx" } ethcore-service = { path = "ethcore/service" } ethcore-sync = { path = "ethcore/sync" } -ethereum-types = "0.4" +ethereum-types = "0.6.0" ethkey = { path = "accounts/ethkey" } ethstore = { path = "accounts/ethstore" } node-filter = { path = "ethcore/node-filter" } -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" cli-signer= { path = "cli-signer" } parity-daemonize = "0.3" parity-hash-fetch = { path = "updater/hash-fetch" } @@ -63,7 +63,7 @@ parity-whisper = { path = "whisper" } parity-path = "0.1" dir = { path = "util/dir" } panic_hook = { path = "util/panic-hook" } -keccak-hash = "0.1" +keccak-hash = "0.2.0" migration-rocksdb = { path = "util/migration-rocksdb" } kvdb = "0.1" kvdb-rocksdb = "0.1.3" @@ -81,7 +81,6 @@ pretty_assertions = "0.1" ipnetwork = "0.12.6" tempdir = "0.3" fake-fetch = { path = "util/fake-fetch" } -lazy_static = "1.2.0" [target.'cfg(windows)'.dependencies] winapi = { version = "0.3.4", features = ["winsock2", "winuser", "shellapi"] } diff --git a/accounts/Cargo.toml b/accounts/Cargo.toml index 3ccfb7957..61f82815f 100644 --- a/accounts/Cargo.toml +++ b/accounts/Cargo.toml @@ -17,5 +17,5 @@ serde_derive = "1.0" serde_json = "1.0" [dev-dependencies] -ethereum-types = "0.4" +ethereum-types = "0.6.0" tempdir = "0.3" diff --git a/accounts/ethkey/Cargo.toml b/accounts/ethkey/Cargo.toml index 2a46a5be4..a6c1a974b 100644 --- a/accounts/ethkey/Cargo.toml +++ b/accounts/ethkey/Cargo.toml @@ -8,13 +8,13 @@ byteorder = "1.0" edit-distance = "2.0" parity-crypto = "0.4.0" eth-secp256k1 = { git = "https://github.com/paritytech/rust-secp256k1" } -ethereum-types = "0.4" +ethereum-types = "0.6.0" lazy_static = "1.0" log = "0.4" memzero = { path = "../../util/memzero" } parity-wordlist = "1.2" quick-error = "1.2.2" -rand = "0.4" +rand = "0.6" rustc-hex = "1.0" serde = "1.0" serde_derive = "1.0" diff --git a/accounts/ethkey/src/brain_prefix.rs b/accounts/ethkey/src/brain_prefix.rs index ba0d81296..436a6594f 100644 --- a/accounts/ethkey/src/brain_prefix.rs +++ b/accounts/ethkey/src/brain_prefix.rs @@ -47,7 +47,7 @@ impl Generator for BrainPrefix { for _ in 0..self.iterations { let phrase = wordlist::random_phrase(self.no_of_words); let keypair = Brain::new(phrase.clone()).generate().unwrap(); - if keypair.address().starts_with(&self.prefix) { + if keypair.address().as_ref().starts_with(&self.prefix) { self.last_phrase = phrase; return Ok(keypair) } @@ -65,6 +65,6 @@ mod tests { fn prefix_generator() { let prefix = vec![0x00u8]; let keypair = BrainPrefix::new(prefix.clone(), usize::max_value(), 12).generate().unwrap(); - assert!(keypair.address().starts_with(&prefix)); + assert!(keypair.address().as_bytes().starts_with(&prefix)); } } diff --git a/accounts/ethkey/src/crypto.rs b/accounts/ethkey/src/crypto.rs index ec883dcb6..c2da84ecb 100644 --- a/accounts/ethkey/src/crypto.rs +++ b/accounts/ethkey/src/crypto.rs @@ -57,7 +57,7 @@ pub mod ecdh { }; let publ = key::PublicKey::from_slice(context, &pdata)?; - let sec = key::SecretKey::from_slice(context, &secret)?; + let sec = key::SecretKey::from_slice(context, secret.as_bytes())?; let shared = ecdh::SharedSecret::new_raw(context, &publ, &sec); Secret::from_unsafe_slice(&shared[0..32]) @@ -89,12 +89,12 @@ pub mod ecies { msg[0] = 0x04u8; { let msgd = &mut msg[1..]; - msgd[0..64].copy_from_slice(r.public()); + msgd[0..64].copy_from_slice(r.public().as_bytes()); let iv = H128::random(); - msgd[64..80].copy_from_slice(&iv); + msgd[64..80].copy_from_slice(iv.as_bytes()); { let cipher = &mut msgd[(64 + 16)..(64 + 16 + plain.len())]; - aes::encrypt_128_ctr(ekey, &iv, plain, cipher)?; + aes::encrypt_128_ctr(ekey, iv.as_bytes(), plain, cipher)?; } let mut hmac = hmac::Signer::with(&mkey); { @@ -156,7 +156,7 @@ pub mod ecies { let mut hasher = digest::Hasher::sha256(); let ctrs = [(ctr >> 24) as u8, (ctr >> 16) as u8, (ctr >> 8) as u8, ctr as u8]; hasher.update(&ctrs); - hasher.update(secret); + hasher.update(secret.as_bytes()); hasher.update(s1); let d = hasher.finish(); &mut dest[written..(written + 32)].copy_from_slice(&d); diff --git a/accounts/ethkey/src/extended.rs b/accounts/ethkey/src/extended.rs index 7d02271eb..64039130b 100644 --- a/accounts/ethkey/src/extended.rs +++ b/accounts/ethkey/src/extended.rs @@ -64,7 +64,7 @@ impl Label for H256 { fn len() -> usize { 32 } fn store(&self, target: &mut [u8]) { - self.copy_to(&mut target[0..32]); + (&mut target[0..32]).copy_from_slice(self.as_bytes()); } } @@ -180,7 +180,7 @@ impl ExtendedKeyPair { pub fn with_seed(seed: &[u8]) -> Result { let (master_key, chain_code) = derivation::seed_pair(seed); Ok(ExtendedKeyPair::with_secret( - Secret::from_unsafe_slice(&*master_key).map_err(|_| DerivationError::InvalidSeed)?, + Secret::from_unsafe_slice(master_key.as_bytes()).map_err(|_| DerivationError::InvalidSeed)?, chain_code, )) } @@ -208,12 +208,13 @@ impl ExtendedKeyPair { // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki mod derivation { use parity_crypto::hmac; - use ethereum_types::{U256, U512, H512, H256}; + use ethereum_types::{BigEndianHash, U256, U512, H512, H256}; use secp256k1::key::{SecretKey, PublicKey}; use SECP256K1; use keccak; use math::curve_order; use super::{Label, Derivation}; + use std::convert::TryInto; #[derive(Debug)] pub enum Error { @@ -237,18 +238,18 @@ mod derivation { } fn hmac_pair(data: &[u8], private_key: H256, chain_code: H256) -> (H256, H256) { - let private: U256 = private_key.into(); + let private: U256 = private_key.into_uint(); // produces 512-bit derived hmac (I) - let skey = hmac::SigKey::sha512(&*chain_code); + let skey = hmac::SigKey::sha512(chain_code.as_bytes()); let i_512 = hmac::sign(&skey, &data[..]); // left most 256 bits are later added to original private key - let hmac_key: U256 = H256::from_slice(&i_512[0..32]).into(); + let hmac_key: U256 = H256::from_slice(&i_512[0..32]).into_uint(); // right most 256 bits are new chain code for later derivations - let next_chain_code = H256::from(&i_512[32..64]); + let next_chain_code = H256::from_slice(&i_512[32..64]); - let child_key = private_add(hmac_key, private).into(); + let child_key = BigEndianHash::from_uint(&private_add(hmac_key, private)); (child_key, next_chain_code) } @@ -257,7 +258,7 @@ mod derivation { fn private_soft(private_key: H256, chain_code: H256, index: T) -> (H256, H256) where T: Label { let mut data = vec![0u8; 33 + T::len()]; - let sec_private = SecretKey::from_slice(&SECP256K1, &*private_key) + let sec_private = SecretKey::from_slice(&SECP256K1, private_key.as_bytes()) .expect("Caller should provide valid private key"); let sec_public = PublicKey::from_secret_key(&SECP256K1, &sec_private) .expect("Caller should provide valid private key"); @@ -276,7 +277,7 @@ mod derivation { // corresponding public keys of the original and derived private keys fn private_hard(private_key: H256, chain_code: H256, index: T) -> (H256, H256) where T: Label { let mut data: Vec = vec![0u8; 33 + T::len()]; - let private: U256 = private_key.into(); + let private: U256 = private_key.into_uint(); // 0x00 (padding) -- private_key -- index // 0 -- 1..33 -- 33..end @@ -293,9 +294,8 @@ mod derivation { // todo: surely can be optimized fn modulo(u1: U512, u2: U256) -> U256 { - let dv = u1 / U512::from(u2); - let md = u1 - (dv * U512::from(u2)); - md.into() + let m = u1 % U512::from(u2); + m.try_into().expect("U512 modulo U256 should fit into U256; qed") } pub fn public(public_key: H512, chain_code: H256, derivation: Derivation) -> Result<(H512, H256), Error> where T: Label { @@ -306,7 +306,7 @@ mod derivation { let mut public_sec_raw = [0u8; 65]; public_sec_raw[0] = 4; - public_sec_raw[1..65].copy_from_slice(&*public_key); + public_sec_raw[1..65].copy_from_slice(public_key.as_bytes()); let public_sec = PublicKey::from_slice(&SECP256K1, &public_sec_raw).map_err(|_| Error::InvalidPoint)?; let public_serialized = public_sec.serialize_vec(&SECP256K1, true); @@ -317,15 +317,15 @@ mod derivation { index.store(&mut data[33..(33 + T::len())]); // HMAC512SHA produces [derived private(256); new chain code(256)] - let skey = hmac::SigKey::sha512(&*chain_code); + let skey = hmac::SigKey::sha512(chain_code.as_bytes()); let i_512 = hmac::sign(&skey, &data[..]); - let new_private = H256::from(&i_512[0..32]); - let new_chain_code = H256::from(&i_512[32..64]); + let new_private = H256::from_slice(&i_512[0..32]); + let new_chain_code = H256::from_slice(&i_512[32..64]); // Generated private key can (extremely rarely) be out of secp256k1 key field - if curve_order() <= new_private.clone().into() { return Err(Error::MissingIndex); } - let new_private_sec = SecretKey::from_slice(&SECP256K1, &*new_private) + if curve_order() <= new_private.into_uint() { return Err(Error::MissingIndex); } + let new_private_sec = SecretKey::from_slice(&SECP256K1, new_private.as_bytes()) .expect("Private key belongs to the field [0..CURVE_ORDER) (checked above); So initializing can never fail; qed"); let mut new_public = PublicKey::from_secret_key(&SECP256K1, &new_private_sec) .expect("Valid private key produces valid public key"); @@ -337,7 +337,7 @@ mod derivation { let serialized = new_public.serialize_vec(&SECP256K1, false); Ok(( - H512::from(&serialized[1..65]), + H512::from_slice(&serialized[1..65]), new_chain_code, )) } @@ -348,18 +348,18 @@ mod derivation { pub fn chain_code(secret: H256) -> H256 { // 10,000 rounds of sha3 - let mut running_sha3 = sha3(&*secret); - for _ in 0..99999 { running_sha3 = sha3(&*running_sha3); } + let mut running_sha3 = sha3(secret.as_bytes()); + for _ in 0..99999 { running_sha3 = sha3(running_sha3.as_bytes()); } running_sha3 } pub fn point(secret: H256) -> Result { - let sec = SecretKey::from_slice(&SECP256K1, &*secret) + let sec = SecretKey::from_slice(&SECP256K1, secret.as_bytes()) .map_err(|_| Error::InvalidPoint)?; let public_sec = PublicKey::from_secret_key(&SECP256K1, &sec) .map_err(|_| Error::InvalidPoint)?; let serialized = public_sec.serialize_vec(&SECP256K1, false); - Ok(H512::from(&serialized[1..65])) + Ok(H512::from_slice(&serialized[1..65])) } pub fn seed_pair(seed: &[u8]) -> (H256, H256) { @@ -378,12 +378,13 @@ mod tests { use super::{ExtendedSecret, ExtendedPublic, ExtendedKeyPair}; use secret::Secret; use std::str::FromStr; - use ethereum_types::{H128, H256}; + use ethereum_types::{H128, H256, H512}; use super::{derivation, Derivation}; fn master_chain_basic() -> (H256, H256) { let seed = H128::from_str("000102030405060708090a0b0c0d0e0f") .expect("Seed should be valid H128") + .as_bytes() .to_vec(); derivation::seed_pair(&*seed) @@ -399,27 +400,39 @@ mod tests { #[test] fn smoky() { let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); - let extended_secret = ExtendedSecret::with_code(secret.clone(), 0u64.into()); + let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::zero()); // hardened assert_eq!(&**extended_secret.as_raw(), &*secret); - assert_eq!(&**extended_secret.derive(2147483648.into()).as_raw(), &"0927453daed47839608e414a3738dfad10aed17c459bbd9ab53f89b026c834b6".into()); - assert_eq!(&**extended_secret.derive(2147483649.into()).as_raw(), &"44238b6a29c6dcbe9b401364141ba11e2198c289a5fed243a1c11af35c19dc0f".into()); + assert_eq!( + **extended_secret.derive(2147483648.into()).as_raw(), + H256::from_str("0927453daed47839608e414a3738dfad10aed17c459bbd9ab53f89b026c834b6").unwrap(), + ); + assert_eq!( + **extended_secret.derive(2147483649.into()).as_raw(), + H256::from_str("44238b6a29c6dcbe9b401364141ba11e2198c289a5fed243a1c11af35c19dc0f").unwrap(), + ); // normal - assert_eq!(&**extended_secret.derive(0.into()).as_raw(), &"bf6a74e3f7b36fc4c96a1e12f31abc817f9f5904f5a8fc27713163d1f0b713f6".into()); - assert_eq!(&**extended_secret.derive(1.into()).as_raw(), &"bd4fca9eb1f9c201e9448c1eecd66e302d68d4d313ce895b8c134f512205c1bc".into()); - assert_eq!(&**extended_secret.derive(2.into()).as_raw(), &"86932b542d6cab4d9c65490c7ef502d89ecc0e2a5f4852157649e3251e2a3268".into()); + assert_eq!(**extended_secret.derive(0.into()).as_raw(), H256::from_str("bf6a74e3f7b36fc4c96a1e12f31abc817f9f5904f5a8fc27713163d1f0b713f6").unwrap()); + assert_eq!(**extended_secret.derive(1.into()).as_raw(), H256::from_str("bd4fca9eb1f9c201e9448c1eecd66e302d68d4d313ce895b8c134f512205c1bc").unwrap()); + assert_eq!(**extended_secret.derive(2.into()).as_raw(), H256::from_str("86932b542d6cab4d9c65490c7ef502d89ecc0e2a5f4852157649e3251e2a3268").unwrap()); let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Extended public should be created"); let derived_public = extended_public.derive(0.into()).expect("First derivation of public should succeed"); - assert_eq!(&*derived_public.public(), &"f7b3244c96688f92372bfd4def26dc4151529747bab9f188a4ad34e141d47bd66522ff048bc6f19a0a4429b04318b1a8796c000265b4fa200dae5f6dda92dd94".into()); + assert_eq!( + *derived_public.public(), + H512::from_str("f7b3244c96688f92372bfd4def26dc4151529747bab9f188a4ad34e141d47bd66522ff048bc6f19a0a4429b04318b1a8796c000265b4fa200dae5f6dda92dd94").unwrap(), + ); let keypair = ExtendedKeyPair::with_secret( Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(), - 064.into(), + H256::from_low_u64_be(64), + ); + assert_eq!( + **keypair.derive(2147483648u32.into()).expect("Derivation of keypair should succeed").secret().as_raw(), + H256::from_str("edef54414c03196557cf73774bc97a645c9a1df2164ed34f0c2a78d1375a930c").unwrap(), ); - assert_eq!(&**keypair.derive(2147483648u32.into()).expect("Derivation of keypair should succeed").secret().as_raw(), &"edef54414c03196557cf73774bc97a645c9a1df2164ed34f0c2a78d1375a930c".into()); } #[test] @@ -427,7 +440,7 @@ mod tests { let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); let derivation_secret = H256::from_str("51eaf04f9dbbc1417dc97e789edd0c37ecda88bac490434e367ea81b71b7b015").unwrap(); - let extended_secret = ExtendedSecret::with_code(secret.clone(), 0u64.into()); + let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::zero()); let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Extended public should be created"); let derived_secret0 = extended_secret.derive(Derivation::Soft(derivation_secret)); @@ -442,15 +455,18 @@ mod tests { fn h256_hard() { let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); let derivation_secret = H256::from_str("51eaf04f9dbbc1417dc97e789edd0c37ecda88bac490434e367ea81b71b7b015").unwrap(); - let extended_secret = ExtendedSecret::with_code(secret.clone(), 1u64.into()); + let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::from_low_u64_be(1)); - assert_eq!(&**extended_secret.derive(Derivation::Hard(derivation_secret)).as_raw(), &"2bc2d696fb744d77ff813b4a1ef0ad64e1e5188b622c54ba917acc5ebc7c5486".into()); + assert_eq!( + **extended_secret.derive(Derivation::Hard(derivation_secret)).as_raw(), + H256::from_str("2bc2d696fb744d77ff813b4a1ef0ad64e1e5188b622c54ba917acc5ebc7c5486").unwrap(), + ); } #[test] fn match_() { let secret = Secret::from_str("a100df7a048e50ed308ea696dc600215098141cb391e9527329df289f9383f65").unwrap(); - let extended_secret = ExtendedSecret::with_code(secret.clone(), 1.into()); + let extended_secret = ExtendedSecret::with_code(secret.clone(), H256::from_low_u64_be(1)); let extended_public = ExtendedPublic::from_secret(&extended_secret).expect("Extended public should be created"); let derived_secret0 = extended_secret.derive(0.into()); @@ -465,6 +481,7 @@ mod tests { fn test_seeds() { let seed = H128::from_str("000102030405060708090a0b0c0d0e0f") .expect("Seed should be valid H128") + .as_bytes() .to_vec(); // private key from bitcoin test vector diff --git a/accounts/ethkey/src/keypair.rs b/accounts/ethkey/src/keypair.rs index 2919f0cfb..7b350788b 100644 --- a/accounts/ethkey/src/keypair.rs +++ b/accounts/ethkey/src/keypair.rs @@ -16,14 +16,13 @@ use std::fmt; use secp256k1::key; -use rustc_hex::ToHex; -use keccak::Keccak256; use super::{Secret, Public, Address, SECP256K1, Error}; +use parity_crypto::Keccak256 as _; pub fn public_to_address(public: &Public) -> Address { let hash = public.keccak256(); - let mut result = Address::default(); - result.copy_from_slice(&hash[12..]); + let mut result = Address::zero(); + result.as_bytes_mut().copy_from_slice(&hash[12..]); result } @@ -36,9 +35,9 @@ pub struct KeyPair { impl fmt::Display for KeyPair { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - writeln!(f, "secret: {}", self.secret.to_hex())?; - writeln!(f, "public: {}", self.public.to_hex())?; - write!(f, "address: {}", self.address().to_hex()) + writeln!(f, "secret: {:x}", self.secret)?; + writeln!(f, "public: {:x}", self.public)?; + write!(f, "address: {:x}", self.address()) } } @@ -51,7 +50,7 @@ impl KeyPair { let serialized = pub_key.serialize_vec(context, false); let mut public = Public::default(); - public.copy_from_slice(&serialized[1..65]); + public.as_bytes_mut().copy_from_slice(&serialized[1..65]); let keypair = KeyPair { secret: secret, @@ -70,7 +69,7 @@ impl KeyPair { let serialized = publ.serialize_vec(context, false); let secret = Secret::from(sec); let mut public = Public::default(); - public.copy_from_slice(&serialized[1..65]); + public.as_bytes_mut().copy_from_slice(&serialized[1..65]); KeyPair { secret: secret, diff --git a/accounts/ethkey/src/math.rs b/accounts/ethkey/src/math.rs index 8c3fe650d..5025efeb6 100644 --- a/accounts/ethkey/src/math.rs +++ b/accounts/ethkey/src/math.rs @@ -17,7 +17,7 @@ use super::{SECP256K1, Public, Secret, Error}; use secp256k1::key; use secp256k1::constants::{GENERATOR_X, GENERATOR_Y, CURVE_ORDER}; -use ethereum_types::{U256, H256}; +use ethereum_types::{BigEndianHash as _, U256, H256}; /// Whether the public key is valid. pub fn public_is_valid(public: &Public) -> bool { @@ -78,7 +78,7 @@ pub fn generation_point() -> Public { /// Return secp256k1 elliptic curve order pub fn curve_order() -> U256 { - H256::from_slice(&CURVE_ORDER).into() + H256::from_slice(&CURVE_ORDER).into_uint() } fn to_secp256k1_public(public: &Public) -> Result { @@ -93,7 +93,7 @@ fn to_secp256k1_public(public: &Public) -> Result { fn set_public(public: &mut Public, key_public: &key::PublicKey) { let key_public_serialized = key_public.serialize_vec(&SECP256K1, false); - public.copy_from_slice(&key_public_serialized[1..65]); + public.as_bytes_mut().copy_from_slice(&key_public_serialized[1..65]); } #[cfg(test)] diff --git a/accounts/ethkey/src/prefix.rs b/accounts/ethkey/src/prefix.rs index 6695e93c5..32d92c186 100644 --- a/accounts/ethkey/src/prefix.rs +++ b/accounts/ethkey/src/prefix.rs @@ -37,7 +37,7 @@ impl Generator for Prefix { fn generate(&mut self) -> Result { for _ in 0..self.iterations { let keypair = Random.generate()?; - if keypair.address().starts_with(&self.prefix) { + if keypair.address().as_ref().starts_with(&self.prefix) { return Ok(keypair) } } @@ -54,6 +54,6 @@ mod tests { fn prefix_generator() { let prefix = vec![0xffu8]; let keypair = Prefix::new(prefix.clone(), usize::max_value()).generate().unwrap(); - assert!(keypair.address().starts_with(&prefix)); + assert!(keypair.address().as_bytes().starts_with(&prefix)); } } diff --git a/accounts/ethkey/src/random.rs b/accounts/ethkey/src/random.rs index 1966cb361..39f72eb0c 100644 --- a/accounts/ethkey/src/random.rs +++ b/accounts/ethkey/src/random.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use rand::os::OsRng; +use rand::rngs::OsRng; use super::{Generator, KeyPair, SECP256K1}; /// Randomly generates new keypair, instantiating the RNG each time. diff --git a/accounts/ethkey/src/secret.rs b/accounts/ethkey/src/secret.rs index 84e849cab..c9ab410f8 100644 --- a/accounts/ethkey/src/secret.rs +++ b/accounts/ethkey/src/secret.rs @@ -59,14 +59,14 @@ impl Secret { if key.len() != 32 { return None } - let mut h = H256::default(); - h.copy_from_slice(&key[0..32]); + let mut h = H256::zero(); + h.as_bytes_mut().copy_from_slice(&key[0..32]); Some(Secret { inner: Memzero::from(h) }) } /// Creates zero key, which is invalid for crypto operations, but valid for math operation. pub fn zero() -> Self { - Secret { inner: Memzero::from(H256::default()) } + Secret { inner: Memzero::from(H256::zero()) } } /// Imports and validates the key. diff --git a/accounts/ethkey/src/signature.rs b/accounts/ethkey/src/signature.rs index cc712df69..c4c4bfd9e 100644 --- a/accounts/ethkey/src/signature.rs +++ b/accounts/ethkey/src/signature.rs @@ -68,24 +68,44 @@ impl Signature { /// Create a signature object from the sig. pub fn from_rsv(r: &H256, s: &H256, v: u8) -> Self { let mut sig = [0u8; 65]; - sig[0..32].copy_from_slice(&r); - sig[32..64].copy_from_slice(&s); + sig[0..32].copy_from_slice(r.as_ref()); + sig[32..64].copy_from_slice(s.as_ref()); sig[64] = v; Signature(sig) } /// Check if this is a "low" signature. pub fn is_low_s(&self) -> bool { - H256::from_slice(self.s()) <= "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0".into() + // "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0" + const MASK: H256 = H256([ + 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x5D, 0x57, 0x6E, 0x73, 0x57, 0xA4, 0x50, 0x1D, + 0xDF, 0xE9, 0x2F, 0x46, 0x68, 0x1B, 0x20, 0xA0, + ]); + H256::from_slice(self.s()) <= MASK } /// Check if each component of the signature is in range. pub fn is_valid(&self) -> bool { + // "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141" + const MASK: H256 = H256([ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, + 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, + 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41, + ]); + const ONE: H256 = H256([ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + ]); + let r = H256::from_slice(self.r()); + let s = H256::from_slice(self.s()); self.v() <= 1 && - H256::from_slice(self.r()) < "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141".into() && - H256::from_slice(self.r()) >= 1.into() && - H256::from_slice(self.s()) < "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141".into() && - H256::from_slice(self.s()) >= 1.into() + r < MASK && r >= ONE && + s < MASK && s >= ONE } } @@ -190,7 +210,7 @@ impl DerefMut for Signature { pub fn sign(secret: &Secret, message: &Message) -> Result { let context = &SECP256K1; - let sec = SecretKey::from_slice(context, &secret)?; + let sec = SecretKey::from_slice(context, secret.as_ref())?; let s = context.sign_recoverable(&SecpMessage::from_slice(&message[..])?, &sec)?; let (rec_id, data) = s.serialize_compact(context); let mut data_arr = [0; 65]; @@ -208,7 +228,7 @@ pub fn verify_public(public: &Public, signature: &Signature, message: &Message) let pdata: [u8; 65] = { let mut temp = [4u8; 65]; - temp[1..65].copy_from_slice(&**public); + temp[1..65].copy_from_slice(public.as_bytes()); temp }; @@ -233,7 +253,7 @@ pub fn recover(signature: &Signature, message: &Message) -> Result"] [dependencies] log = "0.4" libc = "0.2" -rand = "0.4" +rand = "0.6" ethkey = { path = "../ethkey" } serde = "1.0" serde_json = "1.0" @@ -17,12 +17,11 @@ time = "0.1.34" itertools = "0.5" parking_lot = "0.7" parity-crypto = "0.4.0" -ethereum-types = "0.4" +ethereum-types = "0.6.0" dir = { path = "../../util/dir" } smallvec = "0.6" parity-wordlist = "1.0" tempdir = "0.3" -lazy_static = "1.2.0" [dev-dependencies] matches = "0.1" diff --git a/accounts/ethstore/cli/Cargo.toml b/accounts/ethstore/cli/Cargo.toml index 82858eaa7..80fcb6539 100644 --- a/accounts/ethstore/cli/Cargo.toml +++ b/accounts/ethstore/cli/Cargo.toml @@ -21,4 +21,4 @@ path = "src/main.rs" doc = false [dev-dependencies] -tempdir = "0.3.5" +tempdir = "0.3" diff --git a/accounts/ethstore/src/account/crypto.rs b/accounts/ethstore/src/account/crypto.rs index e2cc5dc51..de5b4d857 100644 --- a/accounts/ethstore/src/account/crypto.rs +++ b/accounts/ethstore/src/account/crypto.rs @@ -74,7 +74,7 @@ impl From for String { impl Crypto { /// Encrypt account secret pub fn with_secret(secret: &Secret, password: &Password, iterations: u32) -> Result { - Crypto::with_plain(&*secret, password, iterations) + Crypto::with_plain(secret.as_ref(), password, iterations) } /// Encrypt custom plain data diff --git a/accounts/ethstore/src/accounts_dir/memory.rs b/accounts/ethstore/src/accounts_dir/memory.rs index 617e7bcb0..7f623aa3a 100644 --- a/accounts/ethstore/src/accounts_dir/memory.rs +++ b/accounts/ethstore/src/accounts_dir/memory.rs @@ -68,7 +68,7 @@ impl KeyDirectory for MemoryDirectory { fn unique_repr(&self) -> Result { let mut val = 0u64; let accounts = self.accounts.read(); - for acc in accounts.keys() { val = val ^ acc.low_u64() } + for acc in accounts.keys() { val = val ^ acc.to_low_u64_be() } Ok(val) } } diff --git a/accounts/ethstore/src/ethstore.rs b/accounts/ethstore/src/ethstore.rs index 7207db726..6fce9ae62 100644 --- a/accounts/ethstore/src/ethstore.rs +++ b/accounts/ethstore/src/ethstore.rs @@ -1084,7 +1084,7 @@ mod tests { SecretVaultRef::Root, &address, &"test".into(), - Derivation::HardHash(H256::from(0)), + Derivation::HardHash(H256::zero()), ).unwrap(); // there should be 2 accounts in the store diff --git a/accounts/ethstore/src/lib.rs b/accounts/ethstore/src/lib.rs index c0955caeb..aa2bb86a4 100644 --- a/accounts/ethstore/src/lib.rs +++ b/accounts/ethstore/src/lib.rs @@ -36,8 +36,6 @@ extern crate ethereum_types; extern crate ethkey as _ethkey; extern crate parity_wordlist; -#[macro_use] -extern crate lazy_static; #[macro_use] extern crate log; #[macro_use] diff --git a/accounts/ethstore/src/random.rs b/accounts/ethstore/src/random.rs index 969c8a366..3e2df33b6 100644 --- a/accounts/ethstore/src/random.rs +++ b/accounts/ethstore/src/random.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use rand::{Rng, OsRng}; +use rand::{Rng, RngCore, rngs::OsRng, distributions::Alphanumeric}; pub trait Random { fn random() -> Self where Self: Sized; @@ -41,5 +41,5 @@ impl Random for [u8; 32] { /// Generate a random string of given length. pub fn random_string(length: usize) -> String { let mut rng = OsRng::new().expect("Not able to operate without random source."); - rng.gen_ascii_chars().take(length).collect() + rng.sample_iter(&Alphanumeric).take(length).collect() } diff --git a/accounts/ethstore/tests/api.rs b/accounts/ethstore/tests/api.rs index c27473752..74d66a666 100644 --- a/accounts/ethstore/tests/api.rs +++ b/accounts/ethstore/tests/api.rs @@ -16,6 +16,7 @@ extern crate rand; extern crate ethstore; +extern crate ethereum_types; mod util; @@ -23,6 +24,8 @@ use ethstore::{EthStore, SimpleSecretStore, SecretVaultRef, StoreAccountRef}; use ethstore::ethkey::{Random, Generator, Secret, KeyPair, verify_address}; use ethstore::accounts_dir::RootDiskDirectory; use util::TransientDir; +use ethereum_types::Address; +use std::str::FromStr; #[test] fn secret_store_create() { @@ -114,9 +117,9 @@ fn secret_store_laod_geth_files() { let dir = RootDiskDirectory::at(test_path()); let store = EthStore::open(Box::new(dir)).unwrap(); assert_eq!(store.accounts().unwrap(), vec![ - StoreAccountRef::root("3f49624084b67849c7b4e805c5988c21a430f9d9".into()), - StoreAccountRef::root("5ba4dcf897e97c2bdf8315b9ef26c13c085988cf".into()), - StoreAccountRef::root("63121b431a52f8043c16fcf0d1df9cb7b5f66649".into()), + StoreAccountRef::root(Address::from_str("3f49624084b67849c7b4e805c5988c21a430f9d9").unwrap()), + StoreAccountRef::root(Address::from_str("5ba4dcf897e97c2bdf8315b9ef26c13c085988cf").unwrap()), + StoreAccountRef::root(Address::from_str("63121b431a52f8043c16fcf0d1df9cb7b5f66649").unwrap()), ]); } @@ -125,8 +128,8 @@ fn secret_store_load_pat_files() { let dir = RootDiskDirectory::at(pat_path()); let store = EthStore::open(Box::new(dir)).unwrap(); assert_eq!(store.accounts().unwrap(), vec![ - StoreAccountRef::root("3f49624084b67849c7b4e805c5988c21a430f9d9".into()), - StoreAccountRef::root("5ba4dcf897e97c2bdf8315b9ef26c13c085988cf".into()), + StoreAccountRef::root(Address::from_str("3f49624084b67849c7b4e805c5988c21a430f9d9").unwrap()), + StoreAccountRef::root(Address::from_str("5ba4dcf897e97c2bdf8315b9ef26c13c085988cf").unwrap()), ]); } @@ -140,8 +143,8 @@ fn test_decrypting_files_with_short_ciphertext() { let store = EthStore::open(Box::new(dir)).unwrap(); let accounts = store.accounts().unwrap(); assert_eq!(accounts, vec![ - StoreAccountRef::root("31e9d1e6d844bd3a536800ef8d8be6a9975db509".into()), - StoreAccountRef::root("d1e64e5480bfaf733ba7d48712decb8227797a4e".into()), + StoreAccountRef::root(Address::from_str("31e9d1e6d844bd3a536800ef8d8be6a9975db509").unwrap()), + StoreAccountRef::root(Address::from_str("d1e64e5480bfaf733ba7d48712decb8227797a4e").unwrap()), ]); let message = Default::default(); diff --git a/accounts/ethstore/tests/util/transient_dir.rs b/accounts/ethstore/tests/util/transient_dir.rs index 67511a9b9..90fe7303b 100644 --- a/accounts/ethstore/tests/util/transient_dir.rs +++ b/accounts/ethstore/tests/util/transient_dir.rs @@ -16,7 +16,7 @@ use std::path::PathBuf; use std::{env, fs}; -use rand::{Rng, OsRng}; +use rand::{RngCore, rngs::OsRng}; use ethstore::accounts_dir::{KeyDirectory, RootDiskDirectory}; use ethstore::{Error, SafeAccount}; diff --git a/accounts/src/lib.rs b/accounts/src/lib.rs index 1cc083cf6..9f31e8f53 100644 --- a/accounts/src/lib.rs +++ b/accounts/src/lib.rs @@ -528,7 +528,7 @@ mod tests { let derived_addr = ap.derive_account( &kp.address(), None, - Derivation::SoftHash(H256::from(999)), + Derivation::SoftHash(H256::from_low_u64_be(999)), false, ).expect("Derivation should not fail"); @@ -546,7 +546,7 @@ mod tests { let derived_addr = ap.derive_account( &kp.address(), None, - Derivation::SoftHash(H256::from(999)), + Derivation::SoftHash(H256::from_low_u64_be(999)), true, ).expect("Derivation should not fail"); @@ -567,7 +567,7 @@ mod tests { let derived_addr = ap.derive_account( &kp.address(), None, - Derivation::SoftHash(H256::from(1999)), + Derivation::SoftHash(H256::from_low_u64_be(1999)), true, ).expect("Derivation should not fail"); ap.unlock_account_permanently(derived_addr, "base".into()) @@ -579,7 +579,7 @@ mod tests { let signed_msg2 = ap.sign_derived( &kp.address(), None, - Derivation::SoftHash(H256::from(1999)), + Derivation::SoftHash(H256::from_low_u64_be(1999)), msg, ).expect("Derived signing with existing unlocked account should not fail"); diff --git a/accounts/src/stores.rs b/accounts/src/stores.rs index baa26cc48..739714dfa 100644 --- a/accounts/src/stores.rs +++ b/accounts/src/stores.rs @@ -153,7 +153,7 @@ impl DiskMap { #[cfg(test)] mod tests { - use super::AddressBook; + use super::{AddressBook, Address}; use std::collections::HashMap; use tempdir::TempDir; use crate::account_data::AccountMeta; @@ -162,12 +162,12 @@ mod tests { fn should_save_and_reload_address_book() { let tempdir = TempDir::new("").unwrap(); let mut b = AddressBook::new(tempdir.path()); - b.set_name(1.into(), "One".to_owned()); - b.set_meta(1.into(), "{1:1}".to_owned()); + b.set_name(Address::from_low_u64_be(1), "One".to_owned()); + b.set_meta(Address::from_low_u64_be(1), "{1:1}".to_owned()); let b = AddressBook::new(tempdir.path()); assert_eq!(b.get(), vec![ - (1, AccountMeta {name: "One".to_owned(), meta: "{1:1}".to_owned(), uuid: None}) - ].into_iter().map(|(a, b)| (a.into(), b)).collect::>()); + (Address::from_low_u64_be(1), AccountMeta {name: "One".to_owned(), meta: "{1:1}".to_owned(), uuid: None}) + ].into_iter().collect::>()); } #[test] @@ -175,15 +175,15 @@ mod tests { let tempdir = TempDir::new("").unwrap(); let mut b = AddressBook::new(tempdir.path()); - b.set_name(1.into(), "One".to_owned()); - b.set_name(2.into(), "Two".to_owned()); - b.set_name(3.into(), "Three".to_owned()); - b.remove(2.into()); + b.set_name(Address::from_low_u64_be(1), "One".to_owned()); + b.set_name(Address::from_low_u64_be(2), "Two".to_owned()); + b.set_name(Address::from_low_u64_be(3), "Three".to_owned()); + b.remove(Address::from_low_u64_be(2).into()); let b = AddressBook::new(tempdir.path()); assert_eq!(b.get(), vec![ - (1, AccountMeta{name: "One".to_owned(), meta: "{}".to_owned(), uuid: None}), - (3, AccountMeta{name: "Three".to_owned(), meta: "{}".to_owned(), uuid: None}), - ].into_iter().map(|(a, b)| (a.into(), b)).collect::>()); + (Address::from_low_u64_be(1), AccountMeta{name: "One".to_owned(), meta: "{}".to_owned(), uuid: None}), + (Address::from_low_u64_be(3), AccountMeta{name: "Three".to_owned(), meta: "{}".to_owned(), uuid: None}), + ].into_iter().collect::>()); } } diff --git a/cli-signer/Cargo.toml b/cli-signer/Cargo.toml index 11dd06107..522eb796f 100644 --- a/cli-signer/Cargo.toml +++ b/cli-signer/Cargo.toml @@ -7,7 +7,7 @@ name = "cli-signer" version = "1.4.0" [dependencies] -ethereum-types = "0.4" +ethereum-types = "0.6.0" futures = "0.1" rpassword = "1.0" parity-rpc = { path = "../rpc" } diff --git a/cli-signer/rpc-client/Cargo.toml b/cli-signer/rpc-client/Cargo.toml index 53ec98339..6a974aa5a 100644 --- a/cli-signer/rpc-client/Cargo.toml +++ b/cli-signer/rpc-client/Cargo.toml @@ -7,7 +7,7 @@ name = "parity-rpc-client" version = "1.4.0" [dependencies] -ethereum-types = "0.4" +ethereum-types = "0.6.0" futures = "0.1" log = "0.4" serde = "1.0" @@ -18,4 +18,4 @@ parking_lot = "0.7" jsonrpc-core = "10.0.1" jsonrpc-ws-server = "10.0.1" parity-rpc = { path = "../../rpc" } -keccak-hash = "0.1" +keccak-hash = "0.2.0" diff --git a/ethash/Cargo.toml b/ethash/Cargo.toml index 929895aca..5994e338a 100644 --- a/ethash/Cargo.toml +++ b/ethash/Cargo.toml @@ -6,8 +6,8 @@ authors = ["Parity Technologies "] [dependencies] crunchy = "0.1.0" either = "1.0.0" -ethereum-types = "0.4" -keccak-hash = "0.1" +ethereum-types = "0.6.0" +keccak-hash = "0.2.0" log = "0.4" memmap = "0.6" parking_lot = "0.7" diff --git a/ethash/src/lib.rs b/ethash/src/lib.rs index e40c08920..59a620d12 100644 --- a/ethash/src/lib.rs +++ b/ethash/src/lib.rs @@ -52,14 +52,14 @@ mod progpow; pub use cache::{NodeCacheBuilder, OptimizeFor}; pub use compute::{ProofOfWork, quick_get_difficulty, slow_hash_block_number}; use compute::Light; -use ethereum_types::{U256, U512}; +use ethereum_types::{BigEndianHash, U256, U512}; use keccak::H256; use parking_lot::Mutex; pub use seed_compute::SeedHashCompute; pub use shared::ETHASH_EPOCH_LENGTH; use std::mem; use std::path::{Path, PathBuf}; - +use std::convert::TryFrom; use std::sync::Arc; struct LightCache { @@ -161,12 +161,12 @@ impl EthashManager { /// Convert an Ethash boundary to its original difficulty. Basically just `f(x) = 2^256 / x`. pub fn boundary_to_difficulty(boundary: ðereum_types::H256) -> U256 { - difficulty_to_boundary_aux(&**boundary) + difficulty_to_boundary_aux(&boundary.into_uint()) } /// Convert an Ethash difficulty to the target boundary. Basically just `f(x) = 2^256 / x`. pub fn difficulty_to_boundary(difficulty: &U256) -> ethereum_types::H256 { - difficulty_to_boundary_aux(difficulty).into() + BigEndianHash::from_uint(&difficulty_to_boundary_aux(difficulty)) } fn difficulty_to_boundary_aux>(difficulty: T) -> ethereum_types::U256 { @@ -177,8 +177,8 @@ fn difficulty_to_boundary_aux>(difficulty: T) -> ethereum_types::U if difficulty == U512::one() { U256::max_value() } else { - // difficulty > 1, so result should never overflow 256 bits - U256::from((U512::one() << 256) / difficulty) + const PROOF: &str = "difficulty > 1, so result never overflows 256 bits; qed"; + U256::try_from((U512::one() << 256) / difficulty).expect(PROOF) } } @@ -203,10 +203,10 @@ fn test_lru() { #[test] fn test_difficulty_to_boundary() { - use ethereum_types::H256; + use ethereum_types::{H256, BigEndianHash}; use std::str::FromStr; - assert_eq!(difficulty_to_boundary(&U256::from(1)), H256::from(U256::max_value())); + assert_eq!(difficulty_to_boundary(&U256::from(1)), BigEndianHash::from_uint(&U256::max_value())); assert_eq!(difficulty_to_boundary(&U256::from(2)), H256::from_str("8000000000000000000000000000000000000000000000000000000000000000").unwrap()); assert_eq!(difficulty_to_boundary(&U256::from(4)), H256::from_str("4000000000000000000000000000000000000000000000000000000000000000").unwrap()); assert_eq!(difficulty_to_boundary(&U256::from(32)), H256::from_str("0800000000000000000000000000000000000000000000000000000000000000").unwrap()); @@ -220,9 +220,18 @@ fn test_difficulty_to_boundary_regression() { // https://github.com/paritytech/parity-ethereum/issues/8397 for difficulty in 1..9 { assert_eq!(U256::from(difficulty), boundary_to_difficulty(&difficulty_to_boundary(&difficulty.into()))); - assert_eq!(H256::from(difficulty), difficulty_to_boundary(&boundary_to_difficulty(&difficulty.into()))); - assert_eq!(U256::from(difficulty), boundary_to_difficulty(&boundary_to_difficulty(&difficulty.into()).into())); - assert_eq!(H256::from(difficulty), difficulty_to_boundary(&difficulty_to_boundary(&difficulty.into()).into())); + assert_eq!( + H256::from_low_u64_be(difficulty), + difficulty_to_boundary(&boundary_to_difficulty(&H256::from_low_u64_be(difficulty))), + ); + assert_eq!( + U256::from(difficulty), + boundary_to_difficulty(&BigEndianHash::from_uint(&boundary_to_difficulty(&H256::from_low_u64_be(difficulty)))), + ); + assert_eq!( + H256::from_low_u64_be(difficulty), + difficulty_to_boundary(&difficulty_to_boundary(&difficulty.into()).into_uint()), + ); } } @@ -235,5 +244,5 @@ fn test_difficulty_to_boundary_panics_on_zero() { #[test] #[should_panic] fn test_boundary_to_difficulty_panics_on_zero() { - boundary_to_difficulty(ðereum_types::H256::from(0)); + boundary_to_difficulty(ðereum_types::H256::zero()); } diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index a3b873232..92d3bf3e2 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -15,9 +15,9 @@ common-types = { path = "types" } crossbeam = "0.4" derive_more = "0.14.0" env_logger = { version = "0.5", optional = true } -ethabi = "6.0" -ethabi-contract = "6.0" -ethabi-derive = "6.0" +ethabi = "8.0" +ethabi-contract = "8.0" +ethabi-derive = "8.0" ethash = { path = "../ethash" } ethcore-blockchain = { path = "./blockchain" } ethcore-bloom-journal = { path = "../util/bloom" } @@ -26,7 +26,7 @@ ethcore-db = { path = "./db" } ethcore-io = { path = "../util/io" } ethcore-miner = { path = "../miner" } ethcore-stratum = { path = "../miner/stratum", optional = true } -ethereum-types = "0.4" +ethereum-types = "0.6.0" ethjson = { path = "../json" } ethkey = { path = "../accounts/ethkey" } evm = { path = "evm" } @@ -35,7 +35,7 @@ hash-db = "0.11.0" heapsize = "0.4" itertools = "0.5" journaldb = { path = "../util/journaldb" } -keccak-hash = "0.1" +keccak-hash = "0.2.0" keccak-hasher = { path = "../util/keccak-hasher" } kvdb = "0.1" kvdb-memorydb = "0.1" @@ -55,15 +55,15 @@ parity-snappy = "0.1" parking_lot = "0.7" trie-db = "0.11.0" patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" } -rand = "0.4" +rand = "0.6" rayon = "1.0" -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" rlp_derive = { path = "../util/rlp-derive" } rustc-hex = "1.0" serde = "1.0" serde_derive = "1.0" stats = { path = "../util/stats" } -tempdir = {version="0.3", optional = true} +tempdir = { version = "0.3", optional = true } time-utils = { path = "../util/time-utils" } trace-time = "0.1" triehash-ethereum = { version = "0.2", path = "../util/triehash-ethereum" } @@ -71,6 +71,7 @@ unexpected = { path = "../util/unexpected" } using_queue = { path = "../miner/using-queue" } vm = { path = "vm" } wasm = { path = "wasm" } +rand_xorshift = "0.1.1" [dev-dependencies] blooms-db = { path = "../util/blooms-db" } @@ -82,7 +83,7 @@ kvdb-rocksdb = "0.1.3" parity-runtime = { path = "../util/runtime" } rlp_compress = { path = "../util/rlp-compress" } tempdir = "0.3" -trie-standardmap = "0.1" +trie-standardmap = "0.12.3" [features] parity = ["work-notify", "price-info", "stratum"] diff --git a/ethcore/blockchain/Cargo.toml b/ethcore/blockchain/Cargo.toml index a26369757..17ef11a99 100644 --- a/ethcore/blockchain/Cargo.toml +++ b/ethcore/blockchain/Cargo.toml @@ -12,7 +12,7 @@ ansi_term = "0.10" blooms-db = { path = "../../util/blooms-db" } common-types = { path = "../types" } ethcore-db = { path = "../db" } -ethereum-types = "0.4" +ethereum-types = "0.6.0" heapsize = "0.4" itertools = "0.5" kvdb = "0.1" @@ -20,14 +20,14 @@ log = "0.4" parity-bytes = "0.1" parking_lot = "0.7" rayon = "1.0" -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" rlp_compress = { path = "../../util/rlp-compress" } rlp_derive = { path = "../../util/rlp-derive" } [dev-dependencies] env_logger = "0.5" ethkey = { path = "../../accounts/ethkey" } -keccak-hash = "0.1" +keccak-hash = "0.2.0" rustc-hex = "1.0" tempdir = "0.3" kvdb-memorydb = "0.1" diff --git a/ethcore/blockchain/src/blockchain.rs b/ethcore/blockchain/src/blockchain.rs index 7ee735f78..b528334ca 100644 --- a/ethcore/blockchain/src/blockchain.rs +++ b/ethcore/blockchain/src/blockchain.rs @@ -284,7 +284,7 @@ impl BlockProvider for BlockChain { } // Read from DB and populate cache - let b = self.db.key_value().get(db::COL_HEADERS, hash) + let b = self.db.key_value().get(db::COL_HEADERS, hash.as_bytes()) .expect("Low level database error when fetching block header data. Some issue with disk?")?; let header = encoded::Header::new(decompress(&b, blocks_swapper()).into_vec()); @@ -314,7 +314,7 @@ impl BlockProvider for BlockChain { } // Read from DB and populate cache - let b = self.db.key_value().get(db::COL_BODIES, hash) + let b = self.db.key_value().get(db::COL_BODIES, hash.as_bytes()) .expect("Low level database error when fetching block body data. Some issue with disk?")?; let body = encoded::Body::new(decompress(&b, blocks_swapper()).into_vec()); @@ -469,7 +469,7 @@ impl<'a> Iterator for AncestryWithMetadataIter<'a> { }) }, _ => { - self.current = H256::default(); + self.current = H256::zero(); None }, } @@ -572,13 +572,13 @@ impl BlockChain { }; let mut batch = DBTransaction::new(); - batch.put(db::COL_HEADERS, &hash, block.header_rlp().as_raw()); - batch.put(db::COL_BODIES, &hash, &Self::block_to_body(genesis)); + batch.put(db::COL_HEADERS, hash.as_bytes(), block.header_rlp().as_raw()); + batch.put(db::COL_BODIES, hash.as_bytes(), &Self::block_to_body(genesis)); batch.write(db::COL_EXTRA, &hash, &details); batch.write(db::COL_EXTRA, &header.number(), &hash); - batch.put(db::COL_EXTRA, b"best", &hash); + batch.put(db::COL_EXTRA, b"best", hash.as_bytes()); bc.db.key_value().write(batch).expect("Low level database error when fetching 'best' block. Some issue with disk?"); hash } @@ -639,7 +639,7 @@ impl BlockChain { if hash != bc.genesis_hash() { trace!("First block calculated: {:?}", hash); let mut batch = db.key_value().transaction(); - batch.put(db::COL_EXTRA, b"first", &hash); + batch.put(db::COL_EXTRA, b"first", hash.as_bytes()); db.key_value().write(batch).expect("Low level database error when writing 'first' block. Some issue with disk?"); bc.first_block = Some(hash); } @@ -788,8 +788,8 @@ impl BlockChain { let compressed_body = compress(&Self::block_to_body(block.raw()), blocks_swapper()); // store block in db - batch.put(db::COL_HEADERS, &hash, &compressed_header); - batch.put(db::COL_BODIES, &hash, &compressed_body); + batch.put(db::COL_HEADERS, hash.as_bytes(), &compressed_header); + batch.put(db::COL_BODIES, hash.as_bytes(), &compressed_body); let maybe_parent = self.block_details(&block_parent_hash); @@ -932,7 +932,7 @@ impl BlockChain { *pending_best_ancient_block = Some(None); } else if block_number > ancient_number { trace!(target: "blockchain", "Updating the best ancient block to {}.", block_number); - batch.put(db::COL_EXTRA, b"ancient", &block_hash); + batch.put(db::COL_EXTRA, b"ancient", block_hash.as_bytes()); *pending_best_ancient_block = Some(Some(BestAncientBlock { hash: *block_hash, number: block_number, @@ -1072,8 +1072,8 @@ impl BlockChain { let compressed_body = compress(&Self::block_to_body(block.raw()), blocks_swapper()); // store block in db - batch.put(db::COL_HEADERS, &hash, &compressed_header); - batch.put(db::COL_BODIES, &hash, &compressed_body); + batch.put(db::COL_HEADERS, hash.as_bytes(), &compressed_header); + batch.put(db::COL_BODIES, hash.as_bytes(), &compressed_body); let info = self.block_info(&block.header_view(), route, &extras); @@ -1172,7 +1172,7 @@ impl BlockChain { { let mut best_block = self.pending_best_block.write(); if is_best && update.info.location != BlockLocation::Branch { - batch.put(db::COL_EXTRA, b"best", &update.info.hash); + batch.put(db::COL_EXTRA, b"best", update.info.hash.as_bytes()); *best_block = Some(BestBlock { total_difficulty: update.info.total_difficulty, header: update.block.decode_header(), @@ -1259,7 +1259,7 @@ impl BlockChain { current: if self.is_known(&first) { first } else { - H256::default() // zero hash + H256::zero() // zero hash }, chain: self } @@ -1571,6 +1571,7 @@ mod tests { use keccak_hash::keccak; use rustc_hex::FromHex; use tempdir::TempDir; + use std::str::FromStr; struct TestBlockChainDB { _blooms_dir: TempDir, @@ -1629,8 +1630,6 @@ mod tests { } fn insert_block_batch(batch: &mut DBTransaction, bc: &BlockChain, block: encoded::Block, receipts: Vec) -> ImportRoute { - use crate::ExtrasInsert; - let fork_choice = { let header = block.header_view(); let parent_hash = header.parent_hash(); @@ -2057,7 +2056,7 @@ mod tests { fn find_transaction_by_hash() { let genesis = "f901fcf901f7a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0af81e09f8c46ca322193edfda764fa7e88e81923f802f1d325ec0b0308ac2cd0a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200008083023e38808454c98c8142a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421880102030405060708c0c0".from_hex().unwrap(); let b1 = "f904a8f901faa0ce1f26f798dd03c8782d63b3e42e79a64eaea5694ea686ac5d7ce3df5171d1aea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0a65c2364cd0f1542d761823dc0109c6b072f14c20459598c5455c274601438f4a070616ebd7ad2ed6fb7860cf7e9df00163842351c38a87cac2c1cb193895035a2a05c5b4fc43c2d45787f54e1ae7d27afdb4ad16dfc567c5692070d5c4556e0b1d7b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200000183023ec683021536845685109780a029f07836e4e59229b3a065913afc27702642c683bba689910b2b2fd45db310d3888957e6d004a31802f902a7f85f800a8255f094aaaf5374fce5edbc8e2a8697c15331677e6ebf0b0a801ca0575da4e21b66fa764be5f74da9389e67693d066fb0d1312e19e17e501da00ecda06baf5a5327595f6619dfc2fcb3f2e6fb410b5810af3cb52d0e7508038e91a188f85f010a82520894bbbf5374fce5edbc8e2a8697c15331677e6ebf0b0a801ba04fa966bf34b93abc1bcd665554b7f316b50f928477b50be0f3285ead29d18c5ba017bba0eeec1625ab433746955e125d46d80b7fdc97386c51266f842d8e02192ef85f020a82520894bbbf5374fce5edbc8e2a8697c15331677e6ebf0b0a801ca004377418ae981cc32b1312b4a427a1d69a821b28db8584f5f2bd8c6d42458adaa053a1dba1af177fac92f3b6af0a9fa46a22adf56e686c93794b6a012bf254abf5f85f030a82520894bbbf5374fce5edbc8e2a8697c15331677e6ebf0b0a801ca04fe13febd28a05f4fcb2f451d7ddc2dda56486d9f8c79a62b0ba4da775122615a0651b2382dd402df9ebc27f8cb4b2e0f3cea68dda2dca0ee9603608f0b6f51668f85f040a82520894bbbf5374fce5edbc8e2a8697c15331677e6ebf0b0a801ba078e6a0ba086a08f8450e208a399bb2f2d2a0d984acd2517c7c7df66ccfab567da013254002cd45a97fac049ae00afbc43ed0d9961d0c56a3b2382c80ce41c198ddf85f050a82520894bbbf5374fce5edbc8e2a8697c15331677e6ebf0b0a801ba0a7174d8f43ea71c8e3ca9477691add8d80ac8e0ed89d8d8b572041eef81f4a54a0534ea2e28ec4da3b5b944b18c51ec84a5cf35f5b3343c5fb86521fd2d388f506f85f060a82520894bbbf5374fce5edbc8e2a8697c15331677e6ebf0b0a801ba034bd04065833536a10c77ee2a43a5371bc6d34837088b861dd9d4b7f44074b59a078807715786a13876d3455716a6b9cb2186b7a4887a5c31160fc877454958616c0".from_hex().unwrap(); - let b1_hash: H256 = "f53f268d23a71e85c7d6d83a9504298712b84c1a2ba220441c86eeda0bf0b6e3".into(); + let b1_hash = H256::from_str("f53f268d23a71e85c7d6d83a9504298712b84c1a2ba220441c86eeda0bf0b6e3").unwrap(); let db = new_db(); let bc = new_chain(encoded::Block::new(genesis), db.clone()); @@ -2130,7 +2129,7 @@ mod tests { let db = new_db(); let bc = new_chain(genesis.last().encoded(), db.clone()); insert_block(&db, &bc, b1.last().encoded(), vec![Receipt { - outcome: TransactionOutcome::StateRoot(H256::default()), + outcome: TransactionOutcome::StateRoot(H256::zero()), gas_used: 10_000.into(), log_bloom: Default::default(), logs: vec![ @@ -2139,7 +2138,7 @@ mod tests { ], }, Receipt { - outcome: TransactionOutcome::StateRoot(H256::default()), + outcome: TransactionOutcome::StateRoot(H256::zero()), gas_used: 10_000.into(), log_bloom: Default::default(), logs: vec![ @@ -2148,7 +2147,7 @@ mod tests { }]); insert_block(&db, &bc, b2.last().encoded(), vec![ Receipt { - outcome: TransactionOutcome::StateRoot(H256::default()), + outcome: TransactionOutcome::StateRoot(H256::zero()), gas_used: 10_000.into(), log_bloom: Default::default(), logs: vec![ @@ -2158,7 +2157,7 @@ mod tests { ]); insert_block(&db, &bc, b3.last().encoded(), vec![ Receipt { - outcome: TransactionOutcome::StateRoot(H256::default()), + outcome: TransactionOutcome::StateRoot(H256::zero()), gas_used: 10_000.into(), log_bloom: Default::default(), logs: vec![ @@ -2237,11 +2236,11 @@ mod tests { #[test] fn test_bloom_filter_simple() { - let bloom_b1: Bloom = "00000020000000000000000000000000000000000000000002000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000400000000000000000000002000".into(); + let bloom_b1 = Bloom::from_str("00000020000000000000000000000000000000000000000002000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000400000000000000000000002000").unwrap(); - let bloom_b2: Bloom = "00000000000000000000000000000000000000000000020000001000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000008000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into(); + let bloom_b2 = Bloom::from_str("00000000000000000000000000000000000000000000020000001000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000008000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); - let bloom_ba: Bloom = "00000000000000000000000000000000000000000000020000000800000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000008000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into(); + let bloom_ba = Bloom::from_str("00000000000000000000000000000000000000000000020000000800000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000008000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); let genesis = BlockBuilder::genesis(); let b1 = genesis.add_block_with(|| BlockOptions { @@ -2305,11 +2304,11 @@ mod tests { #[test] fn test_insert_unordered() { - let bloom_b1: Bloom = "00000020000000000000000000000000000000000000000002000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000400000000000000000000002000".into(); + let bloom_b1 = Bloom::from_str("00000020000000000000000000000000000000000000000002000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000400000000000000000000002000").unwrap(); - let bloom_b2: Bloom = "00000000000000000000000000000000000000000000020000001000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000008000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into(); + let bloom_b2 = Bloom::from_str("00000000000000000000000000000000000000000000020000001000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000008000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); - let bloom_b3: Bloom = "00000000000000000000000000000000000000000000020000000800000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000008000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into(); + let bloom_b3 = Bloom::from_str("00000000000000000000000000000000000000000000020000000800000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000008000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); let genesis = BlockBuilder::genesis(); let b1 = genesis.add_block_with_bloom(bloom_b1); diff --git a/ethcore/blockchain/src/import_route.rs b/ethcore/blockchain/src/import_route.rs index 8c635b4e5..46ebc254b 100644 --- a/ethcore/blockchain/src/import_route.rs +++ b/ethcore/blockchain/src/import_route.rs @@ -68,7 +68,7 @@ impl From for ImportRoute { #[cfg(test)] mod tests { - use ethereum_types::{H256, U256}; + use ethereum_types::{U256, BigEndianHash}; use crate::block_info::{BlockInfo, BlockLocation, BranchBecomingCanonChainData}; use super::ImportRoute; @@ -84,7 +84,7 @@ mod tests { #[test] fn import_route_branch() { let info = BlockInfo { - hash: H256::from(U256::from(1)), + hash: BigEndianHash::from_uint(&U256::from(1)), number: 0, total_difficulty: U256::from(0), location: BlockLocation::Branch, @@ -93,14 +93,14 @@ mod tests { assert_eq!(ImportRoute::from(info), ImportRoute { retracted: vec![], enacted: vec![], - omitted: vec![H256::from(U256::from(1))], + omitted: vec![BigEndianHash::from_uint(&U256::from(1))], }); } #[test] fn import_route_canon_chain() { let info = BlockInfo { - hash: H256::from(U256::from(1)), + hash: BigEndianHash::from_uint(&U256::from(1)), number: 0, total_difficulty: U256::from(0), location: BlockLocation::CanonChain, @@ -108,7 +108,7 @@ mod tests { assert_eq!(ImportRoute::from(info), ImportRoute { retracted: vec![], - enacted: vec![H256::from(U256::from(1))], + enacted: vec![BigEndianHash::from_uint(&U256::from(1))], omitted: vec![], }); } @@ -116,19 +116,19 @@ mod tests { #[test] fn import_route_branch_becoming_canon_chain() { let info = BlockInfo { - hash: H256::from(U256::from(2)), + hash: BigEndianHash::from_uint(&U256::from(2)), number: 0, total_difficulty: U256::from(0), location: BlockLocation::BranchBecomingCanonChain(BranchBecomingCanonChainData { - ancestor: H256::from(U256::from(0)), - enacted: vec![H256::from(U256::from(1))], - retracted: vec![H256::from(U256::from(3)), H256::from(U256::from(4))], + ancestor: BigEndianHash::from_uint(&U256::from(0)), + enacted: vec![BigEndianHash::from_uint(&U256::from(1))], + retracted: vec![BigEndianHash::from_uint(&U256::from(3)), BigEndianHash::from_uint(&U256::from(4))], }) }; assert_eq!(ImportRoute::from(info), ImportRoute { - retracted: vec![H256::from(U256::from(3)), H256::from(U256::from(4))], - enacted: vec![H256::from(U256::from(1)), H256::from(U256::from(2))], + retracted: vec![BigEndianHash::from_uint(&U256::from(3)), BigEndianHash::from_uint(&U256::from(4))], + enacted: vec![BigEndianHash::from_uint(&U256::from(1)), BigEndianHash::from_uint(&U256::from(2))], omitted: vec![], }); } diff --git a/ethcore/call-contract/Cargo.toml b/ethcore/call-contract/Cargo.toml index 068434a1d..8836d7b30 100644 --- a/ethcore/call-contract/Cargo.toml +++ b/ethcore/call-contract/Cargo.toml @@ -7,5 +7,5 @@ edition = "2018" [dependencies] types = { path = "../types", package = "common-types" } -ethereum-types = "0.4" +ethereum-types = "0.6.0" bytes = { version = "0.1", package = "parity-bytes" } diff --git a/ethcore/db/Cargo.toml b/ethcore/db/Cargo.toml index 53ec9f7b8..ad02e4680 100644 --- a/ethcore/db/Cargo.toml +++ b/ethcore/db/Cargo.toml @@ -9,9 +9,9 @@ edition = "2018" [dependencies] common-types = { path = "../types" } -ethereum-types = "0.4" +ethereum-types = "0.6.0" heapsize = "0.4" kvdb = "0.1" parking_lot = "0.7" -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" rlp_derive = { path = "../../util/rlp-derive" } diff --git a/ethcore/db/src/db.rs b/ethcore/db/src/db.rs index c00f63eac..08a441235 100644 --- a/ethcore/db/src/db.rs +++ b/ethcore/db/src/db.rs @@ -16,7 +16,7 @@ //! Database utilities and definitions. -use std::ops::Deref; +use std::convert::AsRef; use std::hash::Hash; use std::collections::HashMap; use parking_lot::RwLock; @@ -82,7 +82,7 @@ impl Cache for HashMap where K: Hash + Eq { /// Should be used to get database key associated with given value. pub trait Key { /// The db key associated with this value. - type Target: Deref; + type Target: AsRef<[u8]>; /// Returns db key. fn key(&self) -> Self::Target; @@ -91,16 +91,16 @@ pub trait Key { /// Should be used to write value into database. pub trait Writable { /// Writes the value into the database. - fn write(&mut self, col: Option, key: &Key, value: &T) where T: rlp::Encodable, R: Deref; + fn write(&mut self, col: Option, key: &Key, value: &T) where T: rlp::Encodable, R: AsRef<[u8]>; /// Deletes key from the databse. - fn delete(&mut self, col: Option, key: &Key) where T: rlp::Encodable, R: Deref; + fn delete(&mut self, col: Option, key: &Key) where T: rlp::Encodable, R: AsRef<[u8]>; /// Writes the value into the database and updates the cache. fn write_with_cache(&mut self, col: Option, cache: &mut Cache, key: K, value: T, policy: CacheUpdatePolicy) where K: Key + Hash + Eq, T: rlp::Encodable, - R: Deref { + R: AsRef<[u8]> { self.write(col, &key, &value); match policy { CacheUpdatePolicy::Overwrite => { @@ -116,7 +116,7 @@ pub trait Writable { fn extend_with_cache(&mut self, col: Option, cache: &mut Cache, values: HashMap, policy: CacheUpdatePolicy) where K: Key + Hash + Eq, T: rlp::Encodable, - R: Deref { + R: AsRef<[u8]> { match policy { CacheUpdatePolicy::Overwrite => { for (key, value) in values { @@ -137,7 +137,7 @@ pub trait Writable { fn extend_with_option_cache(&mut self, col: Option, cache: &mut Cache>, values: HashMap>, policy: CacheUpdatePolicy) where K: Key + Hash + Eq, T: rlp::Encodable, - R: Deref { + R: AsRef<[u8]> { match policy { CacheUpdatePolicy::Overwrite => { for (key, value) in values { @@ -167,7 +167,7 @@ pub trait Readable { /// Returns value for given key. fn read(&self, col: Option, key: &Key) -> Option where T: rlp::Decodable, - R: Deref; + R: AsRef<[u8]>; /// Returns value for given key either in cache or in database. fn read_with_cache(&self, col: Option, cache: &RwLock, key: &K) -> Option where @@ -189,12 +189,12 @@ pub trait Readable { } /// Returns true if given value exists. - fn exists(&self, col: Option, key: &Key) -> bool where R: Deref; + fn exists(&self, col: Option, key: &Key) -> bool where R: AsRef<[u8]>; /// Returns true if given value exists either in cache or in database. fn exists_with_cache(&self, col: Option, cache: &RwLock, key: &K) -> bool where K: Eq + Hash + Key, - R: Deref, + R: AsRef<[u8]>, C: Cache { { let read = cache.read(); @@ -208,31 +208,31 @@ pub trait Readable { } impl Writable for DBTransaction { - fn write(&mut self, col: Option, key: &Key, value: &T) where T: rlp::Encodable, R: Deref { - self.put(col, &key.key(), &rlp::encode(value)); + fn write(&mut self, col: Option, key: &Key, value: &T) where T: rlp::Encodable, R: AsRef<[u8]> { + self.put(col, key.key().as_ref(), &rlp::encode(value)); } - fn delete(&mut self, col: Option, key: &Key) where T: rlp::Encodable, R: Deref { - self.delete(col, &key.key()); + fn delete(&mut self, col: Option, key: &Key) where T: rlp::Encodable, R: AsRef<[u8]> { + self.delete(col, key.key().as_ref()); } } impl Readable for KVDB { fn read(&self, col: Option, key: &Key) -> Option - where T: rlp::Decodable, R: Deref { - self.get(col, &key.key()) - .expect(&format!("db get failed, key: {:?}", &key.key() as &[u8])) + where T: rlp::Decodable, R: AsRef<[u8]> { + self.get(col, key.key().as_ref()) + .expect(&format!("db get failed, key: {:?}", key.key().as_ref())) .map(|v| rlp::decode(&v).expect("decode db value failed") ) } - fn exists(&self, col: Option, key: &Key) -> bool where R: Deref { - let result = self.get(col, &key.key()); + fn exists(&self, col: Option, key: &Key) -> bool where R: AsRef<[u8]> { + let result = self.get(col, key.key().as_ref()); match result { Ok(v) => v.is_some(), Err(err) => { - panic!("db get failed, key: {:?}, err: {:?}", &key.key() as &[u8], err); + panic!("db get failed, key: {:?}, err: {:?}", key.key().as_ref(), err); } } } diff --git a/ethcore/db/src/keys.rs b/ethcore/db/src/keys.rs index 96ecde85f..3e6a2db21 100644 --- a/ethcore/db/src/keys.rs +++ b/ethcore/db/src/keys.rs @@ -17,7 +17,7 @@ //! Blockchain DB extras. use std::io::Write; -use std::ops; +use std::convert::AsRef; use common_types::BlockNumber; use common_types::engines::epoch::Transition as EpochTransition; @@ -49,19 +49,17 @@ pub enum ExtrasIndex { fn with_index(hash: &H256, i: ExtrasIndex) -> H264 { let mut result = H264::default(); - result[0] = i as u8; - (*result)[1..].clone_from_slice(hash); + result.as_bytes_mut()[0] = i as u8; + result.as_bytes_mut()[1..].clone_from_slice(hash.as_bytes()); result } /// Wrapper for block number used as a DB key. pub struct BlockNumberKey([u8; 5]); -impl ops::Deref for BlockNumberKey { - type Target = [u8]; - - fn deref(&self) -> &Self::Target { - &self.0 +impl AsRef<[u8]> for BlockNumberKey { + fn as_ref(&self) -> &[u8] { + &self.0[..] } } @@ -123,10 +121,8 @@ pub const EPOCH_KEY_PREFIX: &'static [u8; DB_PREFIX_LEN] = &[ /// Epoch transitions key pub struct EpochTransitionsKey([u8; EPOCH_KEY_LEN]); -impl ops::Deref for EpochTransitionsKey { - type Target = [u8]; - - fn deref(&self) -> &[u8] { &self.0[..] } +impl AsRef<[u8]> for EpochTransitionsKey { + fn as_ref(&self) -> &[u8] { &self.0[..] } } impl Key for u64 { diff --git a/ethcore/evm/Cargo.toml b/ethcore/evm/Cargo.toml index e40c7485f..4c6d679a9 100644 --- a/ethcore/evm/Cargo.toml +++ b/ethcore/evm/Cargo.toml @@ -6,15 +6,14 @@ authors = ["Parity Technologies "] [dependencies] bit-set = "0.4" parity-bytes = "0.1" -ethereum-types = "0.4" +ethereum-types = "0.6.0" heapsize = "0.4" lazy_static = "1.0" log = "0.4" vm = { path = "../vm" } -keccak-hash = "0.1" +keccak-hash = "0.2.0" parking_lot = "0.7" memory-cache = { path = "../../util/memory-cache" } -num-bigint = "0.2" [dev-dependencies] rustc-hex = "1.0" diff --git a/ethcore/evm/src/interpreter/gasometer.rs b/ethcore/evm/src/interpreter/gasometer.rs index 26fec2d93..fe6d0290a 100644 --- a/ethcore/evm/src/interpreter/gasometer.rs +++ b/ethcore/evm/src/interpreter/gasometer.rs @@ -15,7 +15,7 @@ // along with Parity Ethereum. If not, see . use std::cmp; -use ethereum_types::{U256, H256}; +use ethereum_types::{BigEndianHash, U256}; use super::u256_to_address; use {evm, vm}; @@ -121,12 +121,12 @@ impl Gasometer { Request::Gas(Gas::from(1)) }, instructions::SSTORE => { - let address = H256::from(stack.peek(0)); + let address = BigEndianHash::from_uint(stack.peek(0)); let newval = stack.peek(1); - let val = U256::from(&*ext.storage_at(&address)?); + let val = ext.storage_at(&address)?.into_uint(); let gas = if schedule.eip1283 { - let orig = U256::from(&*ext.initial_storage_at(&address)?); + let orig = ext.initial_storage_at(&address)?.into_uint(); calculate_eip1283_sstore_gas(schedule, &orig, &val, &newval) } else { if val.is_zero() && !newval.is_zero() { diff --git a/ethcore/evm/src/interpreter/mod.rs b/ethcore/evm/src/interpreter/mod.rs index 84231abb5..d81891d6e 100644 --- a/ethcore/evm/src/interpreter/mod.rs +++ b/ethcore/evm/src/interpreter/mod.rs @@ -26,10 +26,11 @@ mod shared_cache; use std::marker::PhantomData; use std::{cmp, mem}; use std::sync::Arc; +use std::convert::TryFrom; use hash::keccak; use bytes::Bytes; -use ethereum_types::{U256, H256, Address}; -use num_bigint::BigUint; +use ethereum_types::{U256, U512, H256, Address, BigEndianHash}; + use vm::{ self, ActionParams, ParamsType, ActionValue, CallType, MessageCallResult, @@ -62,17 +63,6 @@ const TWO_POW_96: U256 = U256([0, 0x100000000, 0, 0]); //0x1 00000000 00000000 0 const TWO_POW_224: U256 = U256([0, 0, 0, 0x100000000]); //0x1 00000000 00000000 00000000 00000000 00000000 00000000 00000000 const TWO_POW_248: U256 = U256([0, 0, 0, 0x100000000000000]); //0x1 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000000 -fn to_biguint(x: U256) -> BigUint { - let mut bytes = [0u8; 32]; - x.to_little_endian(&mut bytes); - BigUint::from_bytes_le(&bytes) -} - -fn from_biguint(x: BigUint) -> U256 { - let bytes = x.to_bytes_le(); - U256::from_little_endian(&bytes) -} - /// Abstraction over raw vector of Bytes. Easier state management of PC. struct CodeReader { position: ProgramCounter, @@ -520,7 +510,7 @@ impl Interpreter { let init_size = self.stack.pop_back(); let address_scheme = match instruction { instructions::CREATE => CreateContractAddress::FromSenderAndNonce, - instructions::CREATE2 => CreateContractAddress::FromSenderSaltAndCodeHash(self.stack.pop_back().into()), + instructions::CREATE2 => CreateContractAddress::FromSenderSaltAndCodeHash(BigEndianHash::from_uint(&self.stack.pop_back())), _ => unreachable!("instruction can only be CREATE/CREATE2 checked above; qed"), }; @@ -677,7 +667,7 @@ impl Interpreter { let size = self.stack.pop_back(); let topics = self.stack.pop_n(no_of_topics) .iter() - .map(H256::from) + .map(BigEndianHash::from_uint) .collect(); ext.log(topics, self.mem.read_slice(offset, size))?; }, @@ -714,21 +704,21 @@ impl Interpreter { let offset = self.stack.pop_back(); let size = self.stack.pop_back(); let k = keccak(self.mem.read_slice(offset, size)); - self.stack.push(U256::from(&*k)); + self.stack.push(k.into_uint()); }, instructions::SLOAD => { - let key = H256::from(&self.stack.pop_back()); - let word = U256::from(&*ext.storage_at(&key)?); + let key = BigEndianHash::from_uint(&self.stack.pop_back()); + let word = ext.storage_at(&key)?.into_uint(); self.stack.push(word); }, instructions::SSTORE => { - let address = H256::from(&self.stack.pop_back()); + let address = BigEndianHash::from_uint(&self.stack.pop_back()); let val = self.stack.pop_back(); - let current_val = U256::from(&*ext.storage_at(&address)?); + let current_val = ext.storage_at(&address)?.into_uint(); // Increase refund for clear if ext.schedule().eip1283 { - let original_val = U256::from(&*ext.initial_storage_at(&address)?); + let original_val = ext.initial_storage_at(&address)?.into_uint(); gasometer::handle_eip1283_sstore_clears_refund(ext, &original_val, ¤t_val, &val); } else { if !current_val.is_zero() && val.is_zero() { @@ -736,7 +726,7 @@ impl Interpreter { ext.add_sstore_refund(sstore_clears_schedule); } } - ext.set_storage(address, H256::from(&val))?; + ext.set_storage(address, BigEndianHash::from_uint(&val))?; }, instructions::PC => { self.stack.push(U256::from(self.reader.position - 1)); @@ -797,7 +787,7 @@ impl Interpreter { instructions::EXTCODEHASH => { let address = u256_to_address(&self.stack.pop_back()); let hash = ext.extcodehash(&address)?.unwrap_or_else(H256::zero); - self.stack.push(U256::from(hash)); + self.stack.push(hash.into_uint()); }, instructions::CALLDATACOPY => { Self::copy_data_to_memory(&mut self.mem, &mut self.stack, &self.params.data.as_ref().map_or_else(|| &[] as &[u8], |d| &*d as &[u8])); @@ -831,7 +821,7 @@ impl Interpreter { instructions::BLOCKHASH => { let block_number = self.stack.pop_back(); let block_hash = ext.blockhash(&block_number); - self.stack.push(U256::from(&*block_hash)); + self.stack.push(block_hash.into_uint()); }, instructions::COINBASE => { self.stack.push(address_to_u256(ext.env_info().author.clone())); @@ -1021,12 +1011,12 @@ impl Interpreter { let c = self.stack.pop_back(); self.stack.push(if !c.is_zero() { - let a_num = to_biguint(a); - let b_num = to_biguint(b); - let c_num = to_biguint(c); - let res = a_num + b_num; - let x = res % c_num; - from_biguint(x) + let a_512 = U512::from(a); + let b_512 = U512::from(b); + let c_512 = U512::from(c); + let res = a_512 + b_512; + let x = res % c_512; + U256::try_from(x).expect("U512 % U256 fits U256; qed") } else { U256::zero() }); @@ -1037,12 +1027,12 @@ impl Interpreter { let c = self.stack.pop_back(); self.stack.push(if !c.is_zero() { - let a_num = to_biguint(a); - let b_num = to_biguint(b); - let c_num = to_biguint(c); - let res = a_num * b_num; - let x = res % c_num; - from_biguint(x) + let a_512 = U512::from(a); + let b_512 = U512::from(b); + let c_512 = U512::from(c); + let res = a_512 * b_512; + let x = res % c_512; + U256::try_from(x).expect("U512 % U256 fits U256; qed") } else { U256::zero() }); @@ -1182,12 +1172,13 @@ fn set_sign(value: U256, sign: bool) -> U256 { #[inline] fn u256_to_address(value: &U256) -> Address { - Address::from(H256::from(value)) + let addr: H256 = BigEndianHash::from_uint(value); + Address::from(addr) } #[inline] fn address_to_u256(value: Address) -> U256 { - U256::from(&*H256::from(value)) + H256::from(value).into_uint() } #[cfg(test)] @@ -1198,6 +1189,7 @@ mod tests { use factory::Factory; use vm::{self, Exec, ActionParams, ActionValue}; use vm::tests::{FakeExt, test_finalize}; + use ethereum_types::Address; fn interpreter(params: ActionParams, ext: &vm::Ext) -> Box { Factory::new(VMType::Interpreter, 1).create(params, ext.schedule(), ext.depth()) @@ -1208,13 +1200,13 @@ mod tests { let code = "7feeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff006000527faaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa6020526000620f120660406000601773945304eb96065b2a98b57a48a06ae28d285a71b56101f4f1600055".from_hex().unwrap(); let mut params = ActionParams::default(); - params.address = 5.into(); + params.address = Address::from_low_u64_be(5); params.gas = 300_000.into(); params.gas_price = 1.into(); params.value = ActionValue::Transfer(100_000.into()); params.code = Some(Arc::new(code)); let mut ext = FakeExt::new(); - ext.balances.insert(5.into(), 1_000_000_000.into()); + ext.balances.insert(Address::from_low_u64_be(5), 1_000_000_000.into()); ext.tracing = true; let gas_left = { @@ -1231,12 +1223,12 @@ mod tests { let code = "6001600160000360003e00".from_hex().unwrap(); let mut params = ActionParams::default(); - params.address = 5.into(); + params.address = Address::from_low_u64_be(5); params.gas = 300_000.into(); params.gas_price = 1.into(); params.code = Some(Arc::new(code)); let mut ext = FakeExt::new_byzantium(); - ext.balances.insert(5.into(), 1_000_000_000.into()); + ext.balances.insert(Address::from_low_u64_be(5), 1_000_000_000.into()); ext.tracing = true; let err = { diff --git a/ethcore/evm/src/lib.rs b/ethcore/evm/src/lib.rs index 03871864d..3548a1fe5 100644 --- a/ethcore/evm/src/lib.rs +++ b/ethcore/evm/src/lib.rs @@ -24,7 +24,6 @@ extern crate vm; extern crate keccak_hash as hash; extern crate memory_cache; extern crate parity_bytes as bytes; -extern crate num_bigint; #[macro_use] extern crate lazy_static; diff --git a/ethcore/evm/src/tests.rs b/ethcore/evm/src/tests.rs index dd039311e..245b68b69 100644 --- a/ethcore/evm/src/tests.rs +++ b/ethcore/evm/src/tests.rs @@ -239,7 +239,7 @@ fn test_blockhash(factory: super::Factory) { }; assert_eq!(gas_left, U256::from(79_974)); - assert_eq!(ext.store.get(&H256::new()).unwrap(), &blockhash); + assert_eq!(ext.store.get(&H256::zero()).unwrap(), &blockhash); } evm_test!{test_calldataload: test_calldataload_int} @@ -726,8 +726,8 @@ evm_test!{test_calls: test_calls_int} fn test_calls(factory: super::Factory) { let code = "600054602d57600160005560006000600060006050610998610100f160006000600060006050610998610100f25b".from_hex().unwrap(); - let address = Address::from(0x155); - let code_address = Address::from(0x998); + let address = Address::from_low_u64_be(0x155); + let code_address = Address::from_low_u64_be(0x998); let mut params = ActionParams::default(); params.gas = U256::from(150_000); params.code = Some(Arc::new(code)); @@ -772,7 +772,7 @@ evm_test!{test_create_in_staticcall: test_create_in_staticcall_int} fn test_create_in_staticcall(factory: super::Factory) { let code = "600060006064f000".from_hex().unwrap(); - let address = Address::from(0x155); + let address = Address::from_low_u64_be(0x155); let mut params = ActionParams::default(); params.gas = U256::from(100_000); params.code = Some(Arc::new(code)); @@ -1066,5 +1066,5 @@ fn assert_set_contains(set: &HashSet, val: } fn assert_store(ext: &FakeExt, pos: u64, val: &str) { - assert_eq!(ext.store.get(&H256::from(pos)).unwrap(), &H256::from_str(val).unwrap()); + assert_eq!(ext.store.get(&H256::from_low_u64_be(pos)).unwrap(), &H256::from_str(val).unwrap()); } diff --git a/ethcore/light/Cargo.toml b/ethcore/light/Cargo.toml index e53d29a46..8f76651d0 100644 --- a/ethcore/light/Cargo.toml +++ b/ethcore/light/Cargo.toml @@ -13,7 +13,7 @@ common-types = { path = "../types" } ethcore = { path = ".."} ethcore-db = { path = "../db" } ethcore-blockchain = { path = "../blockchain" } -ethereum-types = "0.4" +ethereum-types = "0.6.0" memory-db = "0.11.0" trie-db = "0.11.0" patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" } @@ -25,18 +25,18 @@ heapsize = "0.4" vm = { path = "../vm" } fastmap = { path = "../../util/fastmap" } failsafe = { version = "0.3.0", default-features = false, features = ["parking_lot_mutex"] } -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" rlp_derive = { path = "../../util/rlp-derive" } smallvec = "0.6" futures = "0.1" -rand = "0.4" +rand = "0.6" itertools = "0.5" bincode = "0.8.0" serde = "1.0" serde_derive = "1.0" parking_lot = "0.7" stats = { path = "../../util/stats" } -keccak-hash = "0.1" +keccak-hash = "0.2.0" keccak-hasher = { path = "../../util/keccak-hasher" } triehash-ethereum = { version = "0.2", path = "../../util/triehash-ethereum" } kvdb = "0.1" diff --git a/ethcore/light/src/cht.rs b/ethcore/light/src/cht.rs index a9bc5d7f2..8aadbfc53 100644 --- a/ethcore/light/src/cht.rs +++ b/ethcore/light/src/cht.rs @@ -104,7 +104,7 @@ pub fn build(cht_num: u64, mut fetcher: F) -> Option H264 { let mut key = H264::default(); - key[0] = LEADING; - key.0[1..].copy_from_slice(&block_hash.0[..]); + { + let bytes = key.as_bytes_mut(); + bytes[0] = LEADING; + bytes[1..].copy_from_slice(block_hash.as_bytes()); + } key } @@ -165,8 +168,11 @@ fn transition_key(block_hash: H256) -> H264 { let mut key = H264::default(); - key[0] = LEADING; - key.0[1..].copy_from_slice(&block_hash.0[..]); + { + let bytes = key.as_bytes_mut(); + bytes[0] = LEADING; + bytes[1..].copy_from_slice(block_hash.as_bytes()); + } key } @@ -237,7 +243,7 @@ impl HeaderChain { for c in &entry.candidates { let key = transition_key(c.hash); - if let Some(proof) = db.get(col, &*key)? { + if let Some(proof) = db.get(col, key.as_bytes())? { live_epoch_proofs.insert(c.hash, EpochTransition { block_hash: c.hash, block_number: cur_number, @@ -431,7 +437,7 @@ impl HeaderChain { } if let Some(transition) = transition { - transaction.put(self.col, &*transition_key(hash), &transition.proof); + transaction.put(self.col, transition_key(hash).as_bytes(), &transition.proof); self.live_epoch_proofs.write().insert(hash, transition); } @@ -508,10 +514,10 @@ impl HeaderChain { for ancient in &era_entry.candidates { let maybe_transition = live_epoch_proofs.remove(&ancient.hash); if let Some(epoch_transition) = maybe_transition { - transaction.delete(self.col, &*transition_key(ancient.hash)); + transaction.delete(self.col, transition_key(ancient.hash).as_bytes()); if ancient.hash == era_entry.canonical_hash { - last_canonical_transition = match self.db.get(self.col, &ancient.hash) { + last_canonical_transition = match self.db.get(self.col, ancient.hash.as_bytes()) { Err(e) => { warn!(target: "chain", "Error reading from DB: {}\n ", e); @@ -526,7 +532,7 @@ impl HeaderChain { } } - transaction.delete(self.col, &ancient.hash); + transaction.delete(self.col, ancient.hash.as_bytes()); } let canon = &era_entry.candidates[0]; @@ -647,7 +653,7 @@ impl HeaderChain { match cache.block_header(&hash) { Some(header) => Some(header), None => { - match self.db.get(self.col, &hash) { + match self.db.get(self.col, hash.as_bytes()) { Ok(db_value) => { db_value.map(|x| x.into_vec()).map(encoded::Header::new) .and_then(|header| { @@ -772,7 +778,7 @@ impl HeaderChain { /// Get block status. pub fn status(&self, hash: &H256) -> BlockStatus { - if self.db.get(self.col, hash).ok().map_or(false, |x| x.is_some()) { + if self.db.get(self.col, hash.as_bytes()).ok().map_or(false, |x| x.is_some()) { BlockStatus::InChain } else { BlockStatus::Unknown @@ -782,13 +788,13 @@ impl HeaderChain { /// Insert a pending transition. pub fn insert_pending_transition(&self, batch: &mut DBTransaction, hash: H256, t: &PendingEpochTransition) { let key = pending_transition_key(hash); - batch.put(self.col, &*key, &*::rlp::encode(t)); + batch.put(self.col, key.as_bytes(), &*::rlp::encode(t)); } /// Get pending transition for a specific block hash. pub fn pending_transition(&self, hash: H256) -> Option { let key = pending_transition_key(hash); - match self.db.get(self.col, &*key) { + match self.db.get(self.col, key.as_bytes()) { Ok(db_fetch) => db_fetch.map(|bytes| ::rlp::decode(&bytes).expect("decoding value from db failed")), Err(e) => { warn!(target: "chain", "Error reading from database: {}", e); diff --git a/ethcore/light/src/net/status.rs b/ethcore/light/src/net/status.rs index ecbe1d3cc..fb491af57 100644 --- a/ethcore/light/src/net/status.rs +++ b/ethcore/light/src/net/status.rs @@ -382,7 +382,7 @@ mod tests { protocol_version: 1, network_id: 1, head_td: U256::default(), - head_hash: H256::default(), + head_hash: H256::zero(), head_num: 10, genesis_hash: H256::zero(), last_head: None, @@ -417,7 +417,7 @@ mod tests { protocol_version: 1, network_id: 1, head_td: U256::default(), - head_hash: H256::default(), + head_hash: H256::zero(), head_num: 10, genesis_hash: H256::zero(), last_head: None, @@ -452,7 +452,7 @@ mod tests { protocol_version: 1, network_id: 1, head_td: U256::default(), - head_hash: H256::default(), + head_hash: H256::zero(), head_num: 10, genesis_hash: H256::zero(), last_head: None, @@ -550,7 +550,7 @@ mod tests { protocol_version: 1, network_id: 1, head_td: U256::default(), - head_hash: H256::default(), + head_hash: H256::zero(), head_num: 10, genesis_hash: H256::zero(), last_head: None, diff --git a/ethcore/light/src/net/tests/mod.rs b/ethcore/light/src/net/tests/mod.rs index 2ca7477f2..70d6bbbd4 100644 --- a/ethcore/light/src/net/tests/mod.rs +++ b/ethcore/light/src/net/tests/mod.rs @@ -22,7 +22,7 @@ use common_types::encoded; use common_types::ids::BlockId; use common_types::transaction::{Action, PendingTransaction}; use ethcore::client::{EachBlockWith, TestBlockChainClient}; -use ethereum_types::{H256, U256, Address}; +use ethereum_types::{H256, U256, Address, BigEndianHash}; use net::context::IoContext; use net::load_timer::MOVING_SAMPLE_SIZE; use net::status::{Capabilities, Status}; @@ -158,7 +158,7 @@ impl Provider for TestProvider { fn contract_code(&self, req: request::CompleteCodeRequest) -> Option { Some(CodeResponse { - code: req.block_hash.iter().chain(req.code_hash.iter()).cloned().collect(), + code: req.block_hash.as_bytes().iter().chain(req.code_hash.as_bytes().iter()).cloned().collect(), }) } @@ -261,7 +261,7 @@ fn genesis_mismatch() { let (provider, proto) = setup(capabilities); let mut status = status(provider.client.chain_info()); - status.genesis_hash = H256::default(); + status.genesis_hash = H256::zero(); let packet_body = write_handshake(&status, &capabilities, &proto); @@ -472,16 +472,16 @@ fn get_state_proofs() { } let req_id = 112; - let key1: H256 = U256::from(11223344).into(); - let key2: H256 = U256::from(99988887).into(); + let key1: H256 = BigEndianHash::from_uint(&U256::from(11223344)); + let key2: H256 = BigEndianHash::from_uint(&U256::from(99988887)); let mut builder = Builder::default(); builder.push(Request::Account(IncompleteAccountRequest { - block_hash: H256::default().into(), + block_hash: H256::zero().into(), address_hash: key1.into(), })).unwrap(); builder.push(Request::Storage(IncompleteStorageRequest { - block_hash: H256::default().into(), + block_hash: H256::zero().into(), address_hash: key1.into(), key_hash: key2.into(), })).unwrap(); @@ -492,11 +492,11 @@ fn get_state_proofs() { let response = { let responses = vec![ Response::Account(provider.account_proof(CompleteAccountRequest { - block_hash: H256::default(), + block_hash: H256::zero(), address_hash: key1, }).unwrap()), Response::Storage(provider.storage_proof(CompleteStorageRequest { - block_hash: H256::default(), + block_hash: H256::zero(), address_hash: key1, key_hash: key2, }).unwrap()), @@ -529,8 +529,8 @@ fn get_contract_code() { } let req_id = 112; - let key1: H256 = U256::from(11223344).into(); - let key2: H256 = U256::from(99988887).into(); + let key1: H256 = BigEndianHash::from_uint(&U256::from(11223344)); + let key2: H256 = BigEndianHash::from_uint(&U256::from(99988887)); let request = Request::Code(IncompleteCodeRequest { block_hash: key1.into(), @@ -541,7 +541,7 @@ fn get_contract_code() { let request_body = make_packet(req_id, &requests); let response = { let response = vec![Response::Code(CodeResponse { - code: key1.iter().chain(key2.iter()).cloned().collect(), + code: key1.as_bytes().iter().chain(key2.as_bytes().iter()).cloned().collect(), })]; let new_creds = *flow_params.limit() - flow_params.compute_cost_multi(requests.requests()).unwrap(); @@ -616,9 +616,9 @@ fn proof_of_execution() { let req_id = 112; let mut request = Request::Execution(request::IncompleteExecutionRequest { - block_hash: H256::default().into(), - from: Address::default(), - action: Action::Call(Address::default()), + block_hash: H256::zero().into(), + from: Address::zero(), + action: Action::Call(Address::zero()), gas: 100.into(), gas_price: 0.into(), value: 0.into(), @@ -755,7 +755,7 @@ fn get_transaction_index() { } let req_id = 112; - let key1: H256 = U256::from(11223344).into(); + let key1: H256 = BigEndianHash::from_uint(&U256::from(11223344)); let request = Request::TransactionIndex(IncompleteTransactionIndexRequest { hash: key1.into(), diff --git a/ethcore/light/src/on_demand/request.rs b/ethcore/light/src/on_demand/request.rs index a183dcbca..db174219a 100644 --- a/ethcore/light/src/on_demand/request.rs +++ b/ethcore/light/src/on_demand/request.rs @@ -983,7 +983,7 @@ impl Account { let mut db = journaldb::new_memory_db(); for node in proof { db.insert(&node[..]); } - match TrieDB::new(&db, &state_root).and_then(|t| t.get(&keccak(&self.address)))? { + match TrieDB::new(&db, &state_root).and_then(|t| t.get(keccak(&self.address).as_bytes()))? { Some(val) => { let rlp = Rlp::new(&val); Ok(Some(BasicAccount { @@ -1162,7 +1162,7 @@ mod tests { #[test] fn check_header_with_ancestors() { - let mut last_header_hash = H256::default(); + let mut last_header_hash = H256::zero(); let mut headers = (0..11).map(|num| { let mut header = Header::new(); header.set_number(num); @@ -1278,7 +1278,7 @@ mod tests { fn check_state_proof() { use rlp::RlpStream; - let mut root = H256::default(); + let mut root = H256::zero(); let mut db = journaldb::new_memory_db(); let mut header = Header::new(); header.set_number(123_456); @@ -1298,17 +1298,17 @@ mod tests { let mut trie = SecTrieDBMut::new(&mut db, &mut root); for _ in 0..100 { let address = Address::random(); - trie.insert(&*address, &rand_acc()).unwrap(); + trie.insert(address.as_bytes(), &rand_acc()).unwrap(); } - trie.insert(&*addr, &rand_acc()).unwrap(); + trie.insert(addr.as_bytes(), &rand_acc()).unwrap(); } let proof = { let trie = SecTrieDB::new(&db, &root).unwrap(); let mut recorder = Recorder::new(); - trie.get_with(&*addr, &mut recorder).unwrap().unwrap(); + trie.get_with(addr.as_bytes(), &mut recorder).unwrap().unwrap(); recorder.drain().into_iter().map(|r| r.data).collect::>() }; diff --git a/ethcore/light/src/on_demand/tests.rs b/ethcore/light/src/on_demand/tests.rs index 49ec35f10..d3e9cfc96 100644 --- a/ethcore/light/src/on_demand/tests.rs +++ b/ethcore/light/src/on_demand/tests.rs @@ -117,9 +117,9 @@ fn dummy_status() -> Status { protocol_version: 1, network_id: 999, head_td: 1.into(), - head_hash: H256::default(), + head_hash: H256::zero(), head_num: 1359, - genesis_hash: H256::default(), + genesis_hash: H256::zero(), last_head: None, } } @@ -138,7 +138,7 @@ fn detects_hangup() { let on_demand = Harness::create().service; let result = on_demand.request_raw( &Context::NoOp, - vec![request::HeaderByHash(H256::default().into()).into()], + vec![request::HeaderByHash(H256::zero().into()).into()], ); assert_eq!(on_demand.pending.read().len(), 1); @@ -199,7 +199,7 @@ fn no_capabilities() { let _recv = harness.service.request_raw( &Context::NoOp, - vec![request::HeaderByHash(H256::default().into()).into()] + vec![request::HeaderByHash(H256::zero().into()).into()] ).unwrap(); assert_eq!(harness.service.pending.read().len(), 1); @@ -395,7 +395,7 @@ fn wrong_kind() { let _recv = harness.service.request_raw( &Context::NoOp, - vec![request::HeaderByHash(H256::default().into()).into()] + vec![request::HeaderByHash(H256::zero().into()).into()] ).unwrap(); assert_eq!(harness.service.pending.read().len(), 1); diff --git a/ethcore/light/src/transaction_queue.rs b/ethcore/light/src/transaction_queue.rs index f996a4847..2040eabe2 100644 --- a/ethcore/light/src/transaction_queue.rs +++ b/ethcore/light/src/transaction_queue.rs @@ -395,7 +395,7 @@ mod tests { #[test] fn queued_senders() { - let sender = Address::default(); + let sender = Address::zero(); let mut txq = TransactionQueue::default(); let tx = Transaction::default().fake_sign(sender); @@ -411,7 +411,7 @@ mod tests { #[test] fn next_nonce() { - let sender = Address::default(); + let sender = Address::zero(); let mut txq = TransactionQueue::default(); for i in (0..5).chain(10..15) { @@ -442,7 +442,7 @@ mod tests { #[test] fn current_to_future() { - let sender = Address::default(); + let sender = Address::zero(); let mut txq = TransactionQueue::default(); for i in 5..10 { @@ -485,7 +485,7 @@ mod tests { #[test] fn conditional() { let mut txq = TransactionQueue::default(); - let sender = Address::default(); + let sender = Address::zero(); for i in 0..5 { let mut tx = Transaction::default(); @@ -507,7 +507,7 @@ mod tests { #[test] fn cull_from_future() { - let sender = Address::default(); + let sender = Address::zero(); let mut txq = TransactionQueue::default(); for i in (0..1).chain(3..10) { @@ -527,7 +527,7 @@ mod tests { #[test] fn import_old() { - let sender = Address::default(); + let sender = Address::zero(); let mut txq = TransactionQueue::default(); let mut tx_a = Transaction::default(); @@ -544,7 +544,7 @@ mod tests { #[test] fn replace_is_removed() { - let sender = Address::default(); + let sender = Address::zero(); let mut txq = TransactionQueue::default(); let tx_b: PendingTransaction = Transaction::default().fake_sign(sender).into(); @@ -564,7 +564,7 @@ mod tests { #[test] fn future_transactions() { - let sender = Address::default(); + let sender = Address::zero(); let mut txq = TransactionQueue::default(); for i in (0..1).chain(3..10) { diff --git a/ethcore/light/src/types/request/batch.rs b/ethcore/light/src/types/request/batch.rs index 63641b5da..caeba2940 100644 --- a/ethcore/light/src/types/request/batch.rs +++ b/ethcore/light/src/types/request/batch.rs @@ -220,7 +220,7 @@ mod tests { num: 100.into(), })).unwrap(); builder.push(Request::Receipts(IncompleteReceiptsRequest { - hash: H256::default().into(), + hash: H256::zero().into(), })).unwrap(); } @@ -267,7 +267,7 @@ mod tests { })).unwrap(); let mut batch = builder.build(); - batch.requests[1].fill(|_req_idx, _out_idx| Ok(Output::Hash(42.into()))); + batch.requests[1].fill(|_req_idx, _out_idx| Ok(Output::Hash(H256::from_low_u64_be(42)))); assert!(batch.next_complete().is_some()); batch.answered += 1; @@ -289,7 +289,7 @@ mod tests { assert!(batch.next_complete().is_some()); let hdr_proof_res = header_proof::Response { proof: vec![], - hash: 12.into(), + hash: H256::from_low_u64_be(12), td: 21.into(), }; batch.supply_response_unchecked(&hdr_proof_res); @@ -308,7 +308,7 @@ mod tests { })).unwrap(); let mut batch = builder.build(); - batch.requests[1].fill(|_req_idx, _out_idx| Ok(Output::Hash(42.into()))); + batch.requests[1].fill(|_req_idx, _out_idx| Ok(Output::Hash(H256::from_low_u64_be(42)))); assert!(batch.next_complete().is_some()); batch.answered += 1; diff --git a/ethcore/light/src/types/request/mod.rs b/ethcore/light/src/types/request/mod.rs index cacfbcbe5..685c3ba30 100644 --- a/ethcore/light/src/types/request/mod.rs +++ b/ethcore/light/src/types/request/mod.rs @@ -1648,7 +1648,7 @@ mod tests { #[test] fn hash_or_number_roundtrip() { - let hash = HashOrNumber::Hash(H256::default()); + let hash = HashOrNumber::Hash(H256::zero()); let number = HashOrNumber::Number(5); check_roundtrip(hash); @@ -1808,7 +1808,7 @@ mod tests { let full_req = Request::Storage(req.clone()); let res = StorageResponse { proof: vec![vec![1, 2, 3], vec![4, 5, 6]], - value: H256::default(), + value: H256::zero(), }; let full_res = Response::Storage(res.clone()); @@ -1909,7 +1909,7 @@ mod tests { code_hash: Default::default(), storage_root: Default::default() }), - Response::Storage(StorageResponse { proof: vec![], value: H256::default() }), + Response::Storage(StorageResponse { proof: vec![], value: H256::zero() }), Response::Code(CodeResponse { code: vec![1, 2, 3, 4, 5] }), Response::Execution(ExecutionResponse { items: vec![] }), ]; diff --git a/ethcore/node-filter/Cargo.toml b/ethcore/node-filter/Cargo.toml index bd1846852..4ad60d0dd 100644 --- a/ethcore/node-filter/Cargo.toml +++ b/ethcore/node-filter/Cargo.toml @@ -10,12 +10,12 @@ authors = ["Parity Technologies "] ethcore = { path = ".."} ethcore-network = { path = "../../util/network" } ethcore-network-devp2p = { path = "../../util/network-devp2p" } -ethereum-types = "0.4" +ethereum-types = "0.6.0" log = "0.4" parking_lot = "0.7" -ethabi = "6.0" -ethabi-derive = "6.0" -ethabi-contract = "6.0" +ethabi = "8.0" +ethabi-derive = "8.0" +ethabi-contract = "8.0" lru-cache = "0.1" [dev-dependencies] diff --git a/ethcore/node-filter/src/lib.rs b/ethcore/node-filter/src/lib.rs index db158cbe7..17b46c6a5 100644 --- a/ethcore/node-filter/src/lib.rs +++ b/ethcore/node-filter/src/lib.rs @@ -135,11 +135,13 @@ mod test { use io::IoChannel; use super::NodeFilter; use tempdir::TempDir; + use ethereum_types::Address; + use std::str::FromStr; /// Contract code: https://gist.github.com/arkpar/467dbcc73cbb85b0997a7a10ffa0695f #[test] fn node_filter() { - let contract_addr = "0000000000000000000000000000000000000005".into(); + let contract_addr = Address::from_str("0000000000000000000000000000000000000005").unwrap(); let data = include_bytes!("../res/node_filter.json"); let tempdir = TempDir::new("").unwrap(); let spec = Spec::load(&tempdir.path(), &data[..]).unwrap(); @@ -153,11 +155,11 @@ mod test { IoChannel::disconnected(), ).unwrap(); let filter = NodeFilter::new(Arc::downgrade(&client) as Weak, contract_addr); - let self1: NodeId = "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002".into(); - let self2: NodeId = "00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003".into(); - let node1: NodeId = "00000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000012".into(); - let node2: NodeId = "00000000000000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000000000000000000000000022".into(); - let nodex: NodeId = "77000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".into(); + let self1 = NodeId::from_str("00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002").unwrap(); + let self2 = NodeId::from_str("00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003").unwrap(); + let node1 = NodeId::from_str("00000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000012").unwrap(); + let node2 = NodeId::from_str("00000000000000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000000000000000000000000022").unwrap(); + let nodex = NodeId::from_str("77000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").unwrap(); assert!(filter.connection_allowed(&self1, &node1, ConnectionDirection::Inbound)); assert!(filter.connection_allowed(&self1, &nodex, ConnectionDirection::Inbound)); diff --git a/ethcore/private-tx/Cargo.toml b/ethcore/private-tx/Cargo.toml index 3002eddc1..23cd51cda 100644 --- a/ethcore/private-tx/Cargo.toml +++ b/ethcore/private-tx/Cargo.toml @@ -8,20 +8,20 @@ authors = ["Parity Technologies "] [dependencies] common-types = { path = "../types" } derive_more = "0.14.0" -ethabi = "6.0" -ethabi-contract = "6.0" -ethabi-derive = "6.0" +ethabi = "8.0" +ethabi-contract = "8.0" +ethabi-derive = "8.0" ethcore = { path = ".." } ethcore-call-contract = { path = "../call-contract" } ethcore-io = { path = "../../util/io" } ethcore-miner = { path = "../../miner" } -ethereum-types = "0.4" +ethereum-types = "0.6.0" ethjson = { path = "../../json" } ethkey = { path = "../../accounts/ethkey" } fetch = { path = "../../util/fetch" } futures = "0.1" heapsize = "0.4" -keccak-hash = "0.1.2" +keccak-hash = "0.2.0" log = "0.4" parity-bytes = "0.1" parity-crypto = "0.4.0" @@ -29,7 +29,7 @@ parking_lot = "0.7" trie-db = "0.11.0" patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" } rand = "0.3" -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" rlp_derive = { path = "../../util/rlp-derive" } rustc-hex = "1.0" serde = "1.0" diff --git a/ethcore/private-tx/src/encryptor.rs b/ethcore/private-tx/src/encryptor.rs index 597cc8879..8d5504d34 100644 --- a/ethcore/private-tx/src/encryptor.rs +++ b/ethcore/private-tx/src/encryptor.rs @@ -114,7 +114,7 @@ impl SecretStoreEncryptor { let requester = self.config.key_server_account.ok_or_else(|| Error::KeyServerAccountNotSet)?; // key id in SS is H256 && we have H160 here => expand with assitional zeros - let contract_address_extended: H256 = contract_address.into(); + let contract_address_extended: H256 = (*contract_address).into(); let base_url = self.config.base_url.clone().ok_or_else(|| Error::KeyServerNotSet)?; // prepare request url @@ -156,7 +156,7 @@ impl SecretStoreEncryptor { let decrypted_key = Public::from_slice(&decrypted_bytes); // and now take x coordinate of Public as a key - let key: Bytes = (*decrypted_key)[..INIT_VEC_LEN].into(); + let key: Bytes = decrypted_key.as_bytes()[..INIT_VEC_LEN].into(); // cache the key in the session and clear expired sessions self.sessions.lock().insert(*contract_address, EncryptionSession{ @@ -212,11 +212,11 @@ impl Encryptor for SecretStoreEncryptor { }?; // encrypt data - let mut cypher = Vec::with_capacity(plain_data.len() + initialisation_vector.len()); + let mut cypher = Vec::with_capacity(plain_data.len() + initialisation_vector.as_bytes().len()); cypher.extend(repeat(0).take(plain_data.len())); - crypto::aes::encrypt_128_ctr(&key, initialisation_vector, plain_data, &mut cypher) + crypto::aes::encrypt_128_ctr(&key, initialisation_vector.as_bytes(), plain_data, &mut cypher) .map_err(|e| Error::Encrypt(e.to_string()))?; - cypher.extend_from_slice(&initialisation_vector); + cypher.extend_from_slice(&initialisation_vector.as_bytes()); Ok(cypher) } diff --git a/ethcore/private-tx/src/key_server_keys.rs b/ethcore/private-tx/src/key_server_keys.rs index 28d9b3cb9..50bdb6662 100644 --- a/ethcore/private-tx/src/key_server_keys.rs +++ b/ethcore/private-tx/src/key_server_keys.rs @@ -29,15 +29,15 @@ use_contract!(keys_acl_contract, "res/keys_acl.json"); /// Returns the address (of the contract), that corresponds to the key pub fn key_to_address(key: &H256) -> Address { - Address::from_slice(&key.to_vec()[..10]) + Address::from_slice(&key.as_bytes()[..10]) } /// Returns the key from the key server associated with the contract pub fn address_to_key(contract_address: &Address) -> H256 { // Current solution uses contract address extended with 0 as id - let contract_address_extended: H256 = contract_address.into(); + let contract_address_extended: H256 = (*contract_address).into(); - H256::from_slice(&contract_address_extended) + H256::from_slice(contract_address_extended.as_bytes()) } /// Trait for keys server keys provider. @@ -118,7 +118,7 @@ impl Default for StoringKeyProvider { fn default() -> Self { StoringKeyProvider { available_keys: RwLock::new(None), - key_server_account: Some(Address::default()), + key_server_account: Some(Address::zero()), } } } @@ -170,4 +170,4 @@ mod tests { keys_data.update_acl_contract(); assert_eq!(keys_data.keys_acl_contract.read().unwrap(), key.address()); } -} \ No newline at end of file +} diff --git a/ethcore/private-tx/src/lib.rs b/ethcore/private-tx/src/lib.rs index aaf44d572..b5d36d359 100644 --- a/ethcore/private-tx/src/lib.rs +++ b/ethcore/private-tx/src/lib.rs @@ -80,7 +80,7 @@ pub use log::{Logging, TransactionLog, ValidatorLog, PrivateTxStatus, FileLogsSe use std::sync::{Arc, Weak}; use std::collections::{HashMap, HashSet, BTreeMap}; -use ethereum_types::{H128, H256, U256, Address}; +use ethereum_types::{H128, H256, U256, Address, BigEndianHash}; use hash::keccak; use rlp::*; use parking_lot::RwLock; @@ -285,9 +285,10 @@ impl Provider { /// Calculate hash from united private state and contract nonce pub fn calculate_state_hash(&self, state: &Bytes, nonce: U256) -> H256 { let state_hash = keccak(state); + let nonce_h256: H256 = BigEndianHash::from_uint(&nonce); let mut state_buf = [0u8; 64]; - state_buf[..32].clone_from_slice(&state_hash); - state_buf[32..].clone_from_slice(&H256::from(nonce)); + state_buf[..32].clone_from_slice(state_hash.as_bytes()); + state_buf[32..].clone_from_slice(nonce_h256.as_bytes()); keccak(&state_buf.as_ref()) } @@ -481,13 +482,13 @@ impl Provider { fn iv_from_transaction(transaction: &SignedTransaction) -> H128 { let nonce = keccak(&transaction.nonce.rlp_bytes()); - let (iv, _) = nonce.split_at(INIT_VEC_LEN); + let (iv, _) = nonce.as_bytes().split_at(INIT_VEC_LEN); H128::from_slice(iv) } fn iv_from_address(contract_address: &Address) -> H128 { let address = keccak(&contract_address.rlp_bytes()); - let (iv, _) = address.split_at(INIT_VEC_LEN); + let (iv, _) = address.as_bytes().split_at(INIT_VEC_LEN); H128::from_slice(iv) } @@ -536,8 +537,8 @@ impl Provider { // Sort the storage to guarantee the order for all parties let sorted_storage: BTreeMap<&H256, &H256> = storage.iter().collect(); for (key, value) in sorted_storage { - raw.extend_from_slice(key); - raw.extend_from_slice(value); + raw.extend_from_slice(key.as_bytes()); + raw.extend_from_slice(value.as_bytes()); }; raw } @@ -621,8 +622,8 @@ impl Provider { v[31] = s.v(); v }).collect::>(), - signatures.iter().map(|s| s.r()).collect::>(), - signatures.iter().map(|s| s.s()).collect::>() + signatures.iter().map(|s| H256::from_slice(s.r())).collect::>(), + signatures.iter().map(|s| H256::from_slice(s.s())).collect::>(), ) } diff --git a/ethcore/private-tx/src/log.rs b/ethcore/private-tx/src/log.rs index d836dfa36..2d2be0181 100644 --- a/ethcore/private-tx/src/log.rs +++ b/ethcore/private-tx/src/log.rs @@ -292,10 +292,11 @@ impl Drop for Logging { mod tests { use serde_json; use error::Error; - use ethereum_types::H256; + use ethereum_types::{H256, Address}; use std::collections::{HashMap, BTreeMap}; use std::sync::Arc; use std::time::{SystemTime, Duration}; + use std::str::FromStr; use types::transaction::Transaction; use parking_lot::RwLock; use super::{TransactionLog, Logging, PrivateTxStatus, LogsSerializer, ValidatorLog}; @@ -360,8 +361,8 @@ mod tests { let logger = Logging::new(Arc::new(StringLogSerializer::new("".into()))); let private_tx = Transaction::default(); let hash = private_tx.hash(None); - logger.private_tx_created(&hash, &vec!["0x82a978b3f5962a5b0957d9ee9eef472ee55b42f1".into()]); - logger.signature_added(&hash, &"0x82a978b3f5962a5b0957d9ee9eef472ee55b42f1".into()); + logger.private_tx_created(&hash, &vec![Address::from_str("82a978b3f5962a5b0957d9ee9eef472ee55b42f1").unwrap()]); + logger.signature_added(&hash, &Address::from_str("82a978b3f5962a5b0957d9ee9eef472ee55b42f1").unwrap()); logger.tx_deployed(&hash, &hash); let tx_log = logger.tx_log(&hash).unwrap(); assert_eq!(tx_log.status, PrivateTxStatus::Deployed); @@ -371,38 +372,38 @@ mod tests { fn serialization() { let current_timestamp = SystemTime::now(); let initial_validator_log = ValidatorLog { - account: "0x82a978b3f5962a5b0957d9ee9eef472ee55b42f1".into(), + account: Address::from_str("82a978b3f5962a5b0957d9ee9eef472ee55b42f1").unwrap(), validation_timestamp: Some(current_timestamp.checked_add(Duration::from_secs(1)).unwrap()), }; let initial_log = TransactionLog { - tx_hash: "0x64f648ca7ae7f4138014f860ae56164d8d5732969b1cea54d8be9d144d8aa6f6".into(), + tx_hash: H256::from_str("64f648ca7ae7f4138014f860ae56164d8d5732969b1cea54d8be9d144d8aa6f6").unwrap(), status: PrivateTxStatus::Deployed, creation_timestamp: current_timestamp, validators: vec![initial_validator_log], deployment_timestamp: Some(current_timestamp.checked_add(Duration::from_secs(2)).unwrap()), - public_tx_hash: Some("0x69b9c691ede7993effbcc88911c309af1c82be67b04b3882dd446b808ae146da".into()), + public_tx_hash: Some(H256::from_str("69b9c691ede7993effbcc88911c309af1c82be67b04b3882dd446b808ae146da").unwrap()), }; let serializer = Arc::new(StringLogSerializer::new(serde_json::to_string(&vec![initial_log.clone()]).unwrap())); let logger = Logging::new(serializer.clone()); - let hash: H256 = "0x63c715e88f7291e66069302f6fcbb4f28a19ef5d7cbd1832d0c01e221c0061c6".into(); - logger.private_tx_created(&hash, &vec!["0x7ffbe3512782069be388f41be4d8eb350672d3a5".into()]); - logger.signature_added(&hash, &"0x7ffbe3512782069be388f41be4d8eb350672d3a5".into()); - logger.tx_deployed(&hash, &"0xde2209a8635b9cab9eceb67928b217c70ab53f6498e5144492ec01e6f43547d7".into()); + let hash = H256::from_str("63c715e88f7291e66069302f6fcbb4f28a19ef5d7cbd1832d0c01e221c0061c6").unwrap(); + logger.private_tx_created(&hash, &vec![Address::from_str("7ffbe3512782069be388f41be4d8eb350672d3a5").unwrap()]); + logger.signature_added(&hash, &Address::from_str("7ffbe3512782069be388f41be4d8eb350672d3a5").unwrap()); + logger.tx_deployed(&hash, &H256::from_str("de2209a8635b9cab9eceb67928b217c70ab53f6498e5144492ec01e6f43547d7").unwrap()); drop(logger); let added_validator_log = ValidatorLog { - account: "0x7ffbe3512782069be388f41be4d8eb350672d3a5".into(), + account: Address::from_str("7ffbe3512782069be388f41be4d8eb350672d3a5").unwrap(), validation_timestamp: Some(current_timestamp.checked_add(Duration::from_secs(7)).unwrap()), }; let added_log = TransactionLog { - tx_hash: "0x63c715e88f7291e66069302f6fcbb4f28a19ef5d7cbd1832d0c01e221c0061c6".into(), + tx_hash: H256::from_str("63c715e88f7291e66069302f6fcbb4f28a19ef5d7cbd1832d0c01e221c0061c6").unwrap(), status: PrivateTxStatus::Deployed, creation_timestamp: current_timestamp.checked_add(Duration::from_secs(6)).unwrap(), validators: vec![added_validator_log], deployment_timestamp: Some(current_timestamp.checked_add(Duration::from_secs(8)).unwrap()), - public_tx_hash: Some("0xde2209a8635b9cab9eceb67928b217c70ab53f6498e5144492ec01e6f43547d7".into()), + public_tx_hash: Some(H256::from_str("de2209a8635b9cab9eceb67928b217c70ab53f6498e5144492ec01e6f43547d7").unwrap()), }; let should_be_final = vec![added_log, initial_log]; let deserialized_logs: Vec = serde_json::from_str(&serializer.log()).unwrap(); assert_eq!(deserialized_logs, should_be_final); } -} \ No newline at end of file +} diff --git a/ethcore/private-tx/src/messages.rs b/ethcore/private-tx/src/messages.rs index 2990fb9b0..5130b83e5 100644 --- a/ethcore/private-tx/src/messages.rs +++ b/ethcore/private-tx/src/messages.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use ethereum_types::{H256, U256, Address}; +use ethereum_types::{H256, U256, Address, BigEndianHash}; use bytes::Bytes; use hash::keccak; use rlp::Encodable; @@ -38,7 +38,7 @@ impl PrivateTransaction { PrivateTransaction { encrypted, contract, - hash: 0.into(), + hash: H256::zero(), }.compute_hash() } @@ -87,7 +87,7 @@ impl SignedPrivateTransaction { r: sig.r().into(), s: sig.s().into(), v: add_chain_replay_protection(sig.v() as u64, chain_id), - hash: 0.into(), + hash: H256::zero(), }.compute_hash() } @@ -100,7 +100,11 @@ impl SignedPrivateTransaction { /// Construct a signature object from the sig. pub fn signature(&self) -> Signature { - Signature::from_rsv(&self.r.into(), &self.s.into(), self.standard_v()) + Signature::from_rsv( + &BigEndianHash::from_uint(&self.r), + &BigEndianHash::from_uint(&self.s), + self.standard_v(), + ) } /// Get the hash of of the original transaction. diff --git a/ethcore/private-tx/tests/private_contract.rs b/ethcore/private-tx/tests/private_contract.rs index 5d760fe07..3bb854285 100644 --- a/ethcore/private-tx/tests/private_contract.rs +++ b/ethcore/private-tx/tests/private_contract.rs @@ -231,7 +231,7 @@ fn call_other_private_contract() { trace!("Creating private contract B"); // Build constructor data let mut deploy_data = "6060604052341561000f57600080fd5b6040516020806101c583398101604052808051906020019091905050806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505061014a8061007b6000396000f300606060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680635197c7aa14610046575b600080fd5b341561005157600080fd5b61005961006f565b6040518082815260200191505060405180910390f35b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16630c55699c6000604051602001526040518163ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401602060405180830381600087803b15156100fe57600080fd5b6102c65a03f1151561010f57600080fd5b505050604051805190509050905600a165627a7a723058207f8994e02725b47d76ec73e5c54a338d27b306dd1c830276bff2d75fcd1a5c920029000000000000000000000000".to_string(); - deploy_data.push_str(&address_a.to_vec().to_hex()); + deploy_data.push_str(&address_a.as_bytes().to_vec().to_hex()); let private_contract_b_test = deploy_data.from_hex().unwrap(); let mut private_create_tx2 = Transaction::default(); private_create_tx2.action = Action::Create; diff --git a/ethcore/service/Cargo.toml b/ethcore/service/Cargo.toml index 7db0ad277..218d4f475 100644 --- a/ethcore/service/Cargo.toml +++ b/ethcore/service/Cargo.toml @@ -11,7 +11,7 @@ ethcore-blockchain = { path = "../blockchain" } ethcore-io = { path = "../../util/io" } ethcore-private-tx = { path = "../private-tx" } ethcore-sync = { path = "../sync" } -ethereum-types = "0.4" +ethereum-types = "0.6.0" kvdb = "0.1" log = "0.4" trace-time = "0.1" diff --git a/ethcore/src/account_db.rs b/ethcore/src/account_db.rs index a389c009b..fcc6f74c6 100644 --- a/ethcore/src/account_db.rs +++ b/ethcore/src/account_db.rs @@ -31,8 +31,8 @@ use ethereum_types::Address; fn combine_key<'a>(address_hash: &'a H256, key: &'a H256) -> H256 { let mut dst = key.clone(); { - let last_src: &[u8] = &*address_hash; - let last_dst: &mut [u8] = &mut *dst; + let last_src: &[u8] = address_hash.as_bytes(); + let last_dst: &mut [u8] = dst.as_bytes_mut(); for (k, a) in last_dst[12..].iter_mut().zip(&last_src[12..]) { *k ^= *a } diff --git a/ethcore/src/block.rs b/ethcore/src/block.rs index 613929f4d..fcecc53ab 100644 --- a/ethcore/src/block.rs +++ b/ethcore/src/block.rs @@ -603,7 +603,7 @@ mod tests { db, parent, last_hashes, - Address::new(), + Address::zero(), (3141562.into(), 31415620.into()), vec![], false, diff --git a/ethcore/src/builtin.rs b/ethcore/src/builtin.rs index 499e3c8f6..b9d79fc3d 100644 --- a/ethcore/src/builtin.rs +++ b/ethcore/src/builtin.rs @@ -95,7 +95,7 @@ impl Pricer for ModexpPricer { // read lengths as U256 here for accurate gas calculation. let mut read_len = || { reader.read_exact(&mut buf[..]).expect("reading from zero-extended memory cannot fail; qed"); - U256::from(H256::from_slice(&buf[..])) + U256::from_big_endian(&buf[..]) }; let base_len = read_len(); let exp_len = read_len(); @@ -118,7 +118,7 @@ impl Pricer for ModexpPricer { let mut reader = input[(96 + base_len as usize)..].chain(io::repeat(0)); let len = min(exp_len, 32) as usize; reader.read_exact(&mut buf[(32 - len)..]).expect("reading from zero-extended memory cannot fail; qed"); - U256::from(H256::from_slice(&buf[..])) + U256::from_big_endian(&buf[..]) }; let adjusted_exp_len = Self::adjusted_exp_len(exp_len, exp_low); @@ -286,7 +286,7 @@ impl Impl for EcRecover { if let Ok(p) = ec_recover(&s, &hash) { let r = keccak(p); output.write(0, &[0; 12]); - output.write(12, &r[12..r.len()]); + output.write(12, &r.as_bytes()[12..]); } } diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index 02f1f2f82..d22cff094 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -33,7 +33,7 @@ use itertools::Itertools; use journaldb; use kvdb::{DBValue, KeyValueDB, DBTransaction}; use parking_lot::{Mutex, RwLock}; -use rand::OsRng; +use rand::rngs::OsRng; use types::transaction::{self, LocalizedTransaction, UnverifiedTransaction, SignedTransaction, Action}; use trie::{TrieSpec, TrieFactory, Trie}; use types::ancestry_action::AncestryAction; @@ -456,7 +456,7 @@ impl Importer { { trace_time!("import_old_block"); // verify the block, passing the chain for updating the epoch verifier. - let mut rng = OsRng::new()?; + let mut rng = OsRng::new().map_err(|e| format!("{}", e))?; self.ancient_verifier.verify(&mut rng, &unverified.header, &chain)?; // Commit results @@ -908,12 +908,12 @@ impl Client { let hashes = self.last_hashes.read(); if hashes.front().map_or(false, |h| h == parent_hash) { let mut res = Vec::from(hashes.clone()); - res.resize(256, H256::default()); + res.resize(256, H256::zero()); return Arc::new(res); } } let mut last_hashes = LastHashes::new(); - last_hashes.resize(256, H256::default()); + last_hashes.resize(256, H256::zero()); last_hashes[0] = parent_hash.clone(); let chain = self.chain.read(); for i in 0..255 { @@ -1223,7 +1223,7 @@ impl Client { // transaction for calling contracts from services like engine. // from the null sender, with 50M gas. fn contract_call_tx(&self, block_id: BlockId, address: Address, data: Bytes) -> SignedTransaction { - let from = Address::default(); + let from = Address::zero(); transaction::Transaction { nonce: self.nonce(&from, block_id).unwrap_or_else(|| self.engine.account_start_nonce(0)), action: Action::Call(address), @@ -1341,8 +1341,8 @@ impl BlockChainReset for Client { best_block_hash = current_header.parent_hash(); let (number, hash) = (current_header.number(), current_header.hash()); - batch.delete(::db::COL_HEADERS, &hash); - batch.delete(::db::COL_BODIES, &hash); + batch.delete(::db::COL_HEADERS, hash.as_bytes()); + batch.delete(::db::COL_BODIES, hash.as_bytes()); Writable::delete:: (&mut batch, ::db::COL_EXTRA, &hash); Writable::delete:: @@ -1375,7 +1375,7 @@ impl BlockChainReset for Client { &best_block_details ); // update the new best block hash - batch.put(::db::COL_EXTRA, b"best", &best_block_hash); + batch.put(::db::COL_EXTRA, b"best", best_block_hash.as_bytes()); self.db.read() .key_value() @@ -1822,7 +1822,7 @@ impl BlockChainClient for Client { }; if let Some(after) = after { - if let Err(e) = iter.seek(after) { + if let Err(e) = iter.seek(after.as_bytes()) { trace!(target: "fatdb", "list_accounts: Couldn't seek the DB: {:?}", e); } else { // Position the iterator after the `after` element @@ -1870,7 +1870,7 @@ impl BlockChainClient for Client { }; if let Some(after) = after { - if let Err(e) = iter.seek(after) { + if let Err(e) = iter.seek(after.as_bytes()) { trace!(target: "fatdb", "list_storage: Couldn't seek the DB: {:?}", e); } else { // Position the iterator after the `after` element @@ -2592,6 +2592,7 @@ fn transaction_receipt( #[cfg(test)] mod tests { + use ethereum_types::{H256, Address}; #[test] fn should_not_cache_details_before_commit() { @@ -2667,19 +2668,19 @@ mod tests { use types::transaction::{Transaction, LocalizedTransaction, Action}; // given - let key = KeyPair::from_secret_slice(&keccak("test")).unwrap(); + let key = KeyPair::from_secret_slice(keccak("test").as_bytes()).unwrap(); let secret = key.secret(); let machine = ::ethereum::new_frontier_test_machine(); let block_number = 1; - let block_hash = 5.into(); - let state_root = 99.into(); + let block_hash = H256::from_low_u64_be(5); + let state_root = H256::from_low_u64_be(99); let gas_used = 10.into(); let raw_tx = Transaction { nonce: 0.into(), gas_price: 0.into(), gas: 21000.into(), - action: Action::Call(10.into()), + action: Action::Call(Address::from_low_u64_be(10)), value: 0.into(), data: vec![], }; @@ -2692,11 +2693,11 @@ mod tests { cached_sender: Some(tx1.sender()), }; let logs = vec![LogEntry { - address: 5.into(), + address: Address::from_low_u64_be(5), topics: vec![], data: vec![], }, LogEntry { - address: 15.into(), + address: Address::from_low_u64_be(15), topics: vec![], data: vec![], }]; diff --git a/ethcore/src/client/evm_test_client.rs b/ethcore/src/client/evm_test_client.rs index d6c03e65a..1e56e8c2d 100644 --- a/ethcore/src/client/evm_test_client.rs +++ b/ethcore/src/client/evm_test_client.rs @@ -204,7 +204,7 @@ impl<'a> EvmTestClient<'a> { author: *genesis.author(), timestamp: genesis.timestamp(), difficulty: *genesis.difficulty(), - last_hashes: Arc::new([H256::default(); 256].to_vec()), + last_hashes: Arc::new([H256::zero(); 256].to_vec()), gas_used: 0.into(), gas_limit: *genesis.gas_limit(), }; diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 1ae1a501c..c9c81ecb8 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -16,6 +16,7 @@ //! Test client. +use std::str::FromStr; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering as AtomicOrder}; use std::sync::Arc; use std::collections::{HashMap, BTreeMap}; @@ -167,9 +168,9 @@ impl TestBlockChainClient { let mut client = TestBlockChainClient { blocks: RwLock::new(HashMap::new()), numbers: RwLock::new(HashMap::new()), - genesis_hash: H256::new(), + genesis_hash: H256::zero(), extra_data: extra_data, - last_hash: RwLock::new(H256::new()), + last_hash: RwLock::new(H256::zero()), difficulty: RwLock::new(spec.genesis_header().difficulty().clone()), balances: RwLock::new(HashMap::new()), nonces: RwLock::new(HashMap::new()), @@ -326,7 +327,7 @@ impl TestBlockChainClient { pub fn corrupt_block_parent(&self, n: BlockNumber) { let hash = self.block_hash(BlockId::Number(n)).unwrap(); let mut header: Header = self.block_header(BlockId::Number(n)).unwrap().decode().expect("decoding failed"); - header.set_parent_hash(H256::from(42)); + header.set_parent_hash(H256::from_low_u64_be(42)); let mut rlp = RlpStream::new_list(3); rlp.append(&header); rlp.append_raw(&::rlp::NULL_RLP, 1); @@ -432,7 +433,7 @@ impl ScheduleInfo for TestBlockChainClient { impl ImportSealedBlock for TestBlockChainClient { fn import_sealed_block(&self, _block: SealedBlock) -> EthcoreResult { - Ok(H256::default()) + Ok(H256::zero()) } } @@ -661,7 +662,15 @@ impl BlockChainClient for TestBlockChainClient { } fn replay_block_transactions(&self, _block: BlockId, _analytics: CallAnalytics) -> Result>, CallError> { - Ok(Box::new(self.traces.read().clone().unwrap().into_iter().map(|t| t.transaction_hash.unwrap_or(H256::new())).zip(self.execution_result.read().clone().unwrap().into_iter()))) + Ok(Box::new( + self.traces + .read() + .clone() + .unwrap() + .into_iter() + .map(|t| t.transaction_hash.unwrap_or_default()) + .zip(self.execution_result.read().clone().unwrap().into_iter()) + )) } fn block_total_difficulty(&self, _id: BlockId) -> Option { @@ -685,7 +694,8 @@ impl BlockChainClient for TestBlockChainClient { fn storage_at(&self, address: &Address, position: &H256, state: StateOrBlock) -> Option { match state { - StateOrBlock::Block(BlockId::Latest) => Some(self.storage.read().get(&(address.clone(), position.clone())).cloned().unwrap_or_else(H256::new)), + StateOrBlock::Block(BlockId::Latest) => + Some(self.storage.read().get(&(address.clone(), position.clone())).cloned().unwrap_or_default()), _ => None, } } @@ -773,7 +783,7 @@ impl BlockChainClient for TestBlockChainClient { // works only if blocks are one after another 1 -> 2 -> 3 fn tree_route(&self, from: &H256, to: &H256) -> Option { Some(TreeRoute { - ancestor: H256::new(), + ancestor: H256::zero(), index: 0, blocks: { let numbers_read = self.numbers.read(); @@ -808,7 +818,7 @@ impl BlockChainClient for TestBlockChainClient { // TODO: returns just hashes instead of node state rlp(?) fn state_data(&self, hash: &H256) -> Option { // starts with 'f' ? - if *hash > H256::from("f000000000000000000000000000000000000000000000000000000000000000") { + if *hash > H256::from_str("f000000000000000000000000000000000000000000000000000000000000000").unwrap() { let mut rlp = RlpStream::new(); rlp.append(&hash.clone()); return Some(rlp.out()); @@ -818,7 +828,7 @@ impl BlockChainClient for TestBlockChainClient { fn block_receipts(&self, hash: &H256) -> Option { // starts with 'f' ? - if *hash > H256::from("f000000000000000000000000000000000000000000000000000000000000000") { + if *hash > H256::from_str("f000000000000000000000000000000000000000000000000000000000000000").unwrap() { let receipt = BlockReceipts::new(vec![Receipt::new( TransactionOutcome::StateRoot(H256::zero()), U256::zero(), diff --git a/ethcore/src/engines/authority_round/mod.rs b/ethcore/src/engines/authority_round/mod.rs index dc4c65c81..0942c0881 100644 --- a/ethcore/src/engines/authority_round/mod.rs +++ b/ethcore/src/engines/authority_round/mod.rs @@ -212,7 +212,7 @@ struct EpochManager { impl EpochManager { fn blank() -> Self { EpochManager { - epoch_transition_hash: H256::default(), + epoch_transition_hash: H256::zero(), epoch_transition_number: 0, finality_checker: RollingFinality::blank(Vec::new()), force: true, @@ -502,7 +502,7 @@ impl super::EpochVerifier for EpochVerifier { fn header_seal_hash(header: &Header, empty_steps_rlp: Option<&[u8]>) -> H256 { match empty_steps_rlp { Some(empty_steps_rlp) => { - let mut message = header.bare_hash().to_vec(); + let mut message = header.bare_hash().as_bytes().to_vec(); message.extend_from_slice(empty_steps_rlp); keccak(message) }, @@ -1170,7 +1170,7 @@ impl Engine for AuthorityRound { let mut fields = vec![ encode(&step), - encode(&(&H520::from(signature) as &[u8])), + encode(&(H520::from(signature).as_bytes())), ]; if let Some(empty_steps_rlp) = empty_steps_rlp { @@ -2138,7 +2138,7 @@ mod tests { let signature = tap.sign(addr1, Some("1".into()), header.bare_hash()).unwrap(); // empty step with invalid step - let empty_steps = vec![SealedEmptyStep { signature: 0.into(), step: 2 }]; + let empty_steps = vec![SealedEmptyStep { signature: H520::zero(), step: 2 }]; set_empty_steps_seal(&mut header, 2, &signature, &empty_steps); assert_insufficient_proof( @@ -2147,7 +2147,7 @@ mod tests { ); // empty step with invalid signature - let empty_steps = vec![SealedEmptyStep { signature: 0.into(), step: 1 }]; + let empty_steps = vec![SealedEmptyStep { signature: H520::zero(), step: 1 }]; set_empty_steps_seal(&mut header, 2, &signature, &empty_steps); assert_insufficient_proof( @@ -2289,7 +2289,7 @@ mod tests { p.maximum_empty_steps = 0; }); - let parent_hash: H256 = 1.into(); + let parent_hash = H256::from_low_u64_be(1); let signature = H520::default(); let step = |step: u64| EmptyStep { step, diff --git a/ethcore/src/engines/basic_authority.rs b/ethcore/src/engines/basic_authority.rs index 0dd7d8e85..21652f0a1 100644 --- a/ethcore/src/engines/basic_authority.rs +++ b/ethcore/src/engines/basic_authority.rs @@ -113,7 +113,7 @@ impl Engine for BasicAuthority { if self.validators.contains(header.parent_hash(), author) { // account should be pernamently unlocked, otherwise sealing will fail if let Ok(signature) = self.sign(header.bare_hash()) { - return Seal::Regular(vec![::rlp::encode(&(&H520::from(signature) as &[u8]))]); + return Seal::Regular(vec![::rlp::encode(&(H520::from(signature).as_bytes()))]); } else { trace!(target: "basicauthority", "generate_seal: FAIL: accounts secret key unavailable"); } diff --git a/ethcore/src/engines/block_reward.rs b/ethcore/src/engines/block_reward.rs index 58b55408e..42b08560f 100644 --- a/ethcore/src/engines/block_reward.rs +++ b/ethcore/src/engines/block_reward.rs @@ -177,8 +177,9 @@ pub fn apply_block_rewards( #[cfg(test)] mod test { + use std::str::FromStr; use client::PrepareOpenBlock; - use ethereum_types::U256; + use ethereum_types::{U256, Address}; use spec::Spec; use test_helpers::generate_dummy_client_with_spec; @@ -193,12 +194,12 @@ mod test { // the spec has a block reward contract defined at the given address let block_reward_contract = BlockRewardContract::new_from_address( - "0000000000000000000000000000000000000042".into(), + Address::from_str("0000000000000000000000000000000000000042").unwrap(), ); let mut call = |to, data| { let mut block = client.prepare_open_block( - "0000000000000000000000000000000000000001".into(), + Address::from_str("0000000000000000000000000000000000000001").unwrap(), (3141562.into(), 31415620.into()), vec![], ).unwrap(); @@ -223,16 +224,16 @@ mod test { // the contract rewards (1000 + kind) for each benefactor let beneficiaries = vec![ - ("0000000000000000000000000000000000000033".into(), RewardKind::Author), - ("0000000000000000000000000000000000000034".into(), RewardKind::Uncle(1)), - ("0000000000000000000000000000000000000035".into(), RewardKind::EmptyStep), + (Address::from_str("0000000000000000000000000000000000000033").unwrap(), RewardKind::Author), + (Address::from_str("0000000000000000000000000000000000000034").unwrap(), RewardKind::Uncle(1)), + (Address::from_str("0000000000000000000000000000000000000035").unwrap(), RewardKind::EmptyStep), ]; let rewards = block_reward_contract.reward(&beneficiaries, &mut call).unwrap(); let expected = vec![ - ("0000000000000000000000000000000000000033".into(), U256::from(1000)), - ("0000000000000000000000000000000000000034".into(), U256::from(1000 + 101)), - ("0000000000000000000000000000000000000035".into(), U256::from(1000 + 2)), + (Address::from_str("0000000000000000000000000000000000000033").unwrap(), U256::from(1000)), + (Address::from_str("0000000000000000000000000000000000000034").unwrap(), U256::from(1000 + 101)), + (Address::from_str("0000000000000000000000000000000000000035").unwrap(), U256::from(1000 + 2)), ]; assert_eq!(expected, rewards); diff --git a/ethcore/src/engines/clique/block_state.rs b/ethcore/src/engines/clique/block_state.rs index 4257076c0..5e1c5f2fb 100644 --- a/ethcore/src/engines/clique/block_state.rs +++ b/ethcore/src/engines/clique/block_state.rs @@ -194,7 +194,7 @@ impl CliqueBlockState { Err(BlockError::InvalidSealArity(Mismatch { expected: 2, found: decoded_seal.len() }))? } - let nonce: H64 = decoded_seal[1].into(); + let nonce = H64::from_slice(decoded_seal[1]); self.update_signers_on_vote(VoteType::from_nonce(nonce)?, creator, *header.author(), header.number())?; } diff --git a/ethcore/src/engines/clique/mod.rs b/ethcore/src/engines/clique/mod.rs index 7d771068a..180237b01 100644 --- a/ethcore/src/engines/clique/mod.rs +++ b/ethcore/src/engines/clique/mod.rs @@ -570,7 +570,7 @@ impl Engine for Clique { if is_checkpoint && *header.author() != NULL_AUTHOR { return Err(EngineError::CliqueWrongAuthorCheckpoint(Mismatch { - expected: 0.into(), + expected: H160::zero(), found: *header.author(), }))?; } @@ -583,8 +583,8 @@ impl Engine for Clique { }))? } - let mixhash: H256 = seal_fields[0].into(); - let nonce: H64 = seal_fields[1].into(); + let mixhash = H256::from_slice(seal_fields[0]); + let nonce = H64::from_slice(seal_fields[1]); // Nonce must be 0x00..0 or 0xff..f if nonce != NONCE_DROP_VOTE && nonce != NONCE_AUTH_VOTE { diff --git a/ethcore/src/engines/clique/tests.rs b/ethcore/src/engines/clique/tests.rs index f1189dbd4..76140284f 100644 --- a/ethcore/src/engines/clique/tests.rs +++ b/ethcore/src/engines/clique/tests.rs @@ -70,10 +70,10 @@ impl CliqueTester { let mut extra_data = vec![0; VANITY_LENGTH]; for &signer in SIGNER_TAGS.iter() { - let secret = Secret::from(H256::from(signer as u64)); + let secret = Secret::from(H256::from_low_u64_be(signer as u64)); let keypair = KeyPair::from_secret(secret).unwrap(); if initial_signers.contains(&signer) { - extra_data.extend(&*keypair.address()); + extra_data.extend(keypair.address().as_bytes()); } signers.insert(signer, keypair); } @@ -151,7 +151,7 @@ impl CliqueTester { CliqueBlockType::Checkpoint => { let signers = self.clique.state(&last_header).unwrap().signers().clone(); for signer in signers { - extra_data.extend(&*signer); + extra_data.extend(signer.as_bytes()); } } CliqueBlockType::Vote(v) => seal = v.as_rlp(), diff --git a/ethcore/src/engines/clique/util.rs b/ethcore/src/engines/clique/util.rs index 3f75289e9..79b74bb73 100644 --- a/ethcore/src/engines/clique/util.rs +++ b/ethcore/src/engines/clique/util.rs @@ -102,7 +102,7 @@ pub fn extract_signers(header: &Header) -> Result, Error> { .map(|i| { let start = i * ADDRESS_LENGTH; let end = start + ADDRESS_LENGTH; - signers_raw[start..end].into() + Address::from_slice(&signers_raw[start..end]) }) .collect(); @@ -111,5 +111,5 @@ pub fn extract_signers(header: &Header) -> Result, Error> { /// Retrieve `null_seal` pub fn null_seal() -> Vec> { - vec![encode(&NULL_MIXHASH.to_vec()), encode(&NULL_NONCE.to_vec())] + vec![encode(&NULL_MIXHASH.as_bytes().to_vec()), encode(&NULL_NONCE.as_bytes().to_vec())] } diff --git a/ethcore/src/engines/instant_seal.rs b/ethcore/src/engines/instant_seal.rs index 71ef193c6..2daa0aa55 100644 --- a/ethcore/src/engines/instant_seal.rs +++ b/ethcore/src/engines/instant_seal.rs @@ -108,7 +108,7 @@ mod tests { let db = spec.ensure_db_good(get_temp_state_db(), &Default::default()).unwrap(); let genesis_header = spec.genesis_header(); let last_hashes = Arc::new(vec![genesis_header.hash()]); - let b = OpenBlock::new(engine, Default::default(), false, db, &genesis_header, last_hashes, Address::default(), (3141562.into(), 31415620.into()), vec![], false, None).unwrap(); + let b = OpenBlock::new(engine, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![], false, None).unwrap(); let b = b.close_and_lock().unwrap(); if let Seal::Regular(seal) = engine.generate_seal(&b, &genesis_header) { assert!(b.try_seal(engine, seal).is_ok()); diff --git a/ethcore/src/engines/validator_set/contract.rs b/ethcore/src/engines/validator_set/contract.rs index f0064a8c2..dbf92ce4b 100644 --- a/ethcore/src/engines/validator_set/contract.rs +++ b/ethcore/src/engines/validator_set/contract.rs @@ -175,7 +175,7 @@ mod tests { // Check a block that is a bit in future, reject it but don't report the validator. let mut header = Header::default(); - let seal = vec![encode(&4u8), encode(&(&H520::default() as &[u8]))]; + let seal = vec![encode(&4u8), encode(&H520::zero().as_bytes())]; header.set_seal(seal); header.set_author(v1); header.set_number(2); @@ -186,7 +186,7 @@ mod tests { // Now create one that is more in future. That one should be rejected and validator should be reported. let mut header = Header::default(); - let seal = vec![encode(&8u8), encode(&(&H520::default() as &[u8]))]; + let seal = vec![encode(&8u8), encode(&H520::zero().as_bytes())]; header.set_seal(seal); header.set_author(v1); header.set_number(2); diff --git a/ethcore/src/engines/validator_set/safe_contract.rs b/ethcore/src/engines/validator_set/safe_contract.rs index 49d539df3..c210bcc00 100644 --- a/ethcore/src/engines/validator_set/safe_contract.rs +++ b/ethcore/src/engines/validator_set/safe_contract.rs @@ -106,7 +106,7 @@ fn check_first_proof(machine: &EthereumMachine, contract_address: Address, old_h timestamp: old_header.timestamp(), last_hashes: { // this will break if we don't inclue all 256 last hashes. - let mut last_hashes: Vec<_> = (0..256).map(|_| H256::default()).collect(); + let mut last_hashes: Vec<_> = (0..256).map(|_| H256::zero()).collect(); last_hashes[255] = *old_header.parent_hash(); Arc::new(last_hashes) }, @@ -117,7 +117,7 @@ fn check_first_proof(machine: &EthereumMachine, contract_address: Address, old_h let number = old_header.number(); let (data, decoder) = validator_set::functions::get_validators::call(); - let from = Address::default(); + let from = Address::zero(); let tx = Transaction { nonce: machine.account_start_nonce(number), action: Action::Call(contract_address), @@ -516,7 +516,7 @@ mod tests { nonce: 2.into(), gas_price: 0.into(), gas: 21000.into(), - action: Action::Call(Address::default()), + action: Action::Call(Address::zero()), value: 0.into(), data: Vec::new(), }.sign(&s0, Some(chain_id)); diff --git a/ethcore/src/ethereum/ethash.rs b/ethcore/src/ethereum/ethash.rs index 8a19d9a01..f2f0d0003 100644 --- a/ethcore/src/ethereum/ethash.rs +++ b/ethcore/src/ethereum/ethash.rs @@ -324,7 +324,7 @@ impl Engine for Arc { let difficulty = ethash::boundary_to_difficulty(&H256(quick_get_difficulty( &header.bare_hash().0, - seal.nonce.low_u64(), + seal.nonce.to_low_u64_be(), &seal.mix_hash.0, header.number() >= self.ethash_params.progpow_transition ))); @@ -339,14 +339,14 @@ impl Engine for Arc { fn verify_block_unordered(&self, header: &Header) -> Result<(), Error> { let seal = Seal::parse_seal(header.seal())?; - let result = self.pow.compute_light(header.number() as u64, &header.bare_hash().0, seal.nonce.low_u64()); + let result = self.pow.compute_light(header.number() as u64, &header.bare_hash().0, seal.nonce.to_low_u64_be()); let mix = H256(result.mix_hash); let difficulty = ethash::boundary_to_difficulty(&H256(result.value)); trace!(target: "miner", "num: {num}, seed: {seed}, h: {h}, non: {non}, mix: {mix}, res: {res}", num = header.number() as u64, seed = H256(slow_hash_block_number(header.number() as u64)), h = header.bare_hash(), - non = seal.nonce.low_u64(), + non = seal.nonce.to_low_u64_be(), mix = H256(result.mix_hash), res = H256(result.value)); if mix != seal.mix_hash { @@ -591,7 +591,7 @@ mod tests { let last_hashes = Arc::new(vec![genesis_header.hash()]); let mut b = OpenBlock::new(engine, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![], false, None).unwrap(); let mut uncle = Header::new(); - let uncle_author: Address = "ef2d6d194084c2de36e0dabfce45d046b37d1106".into(); + let uncle_author = Address::from_str("ef2d6d194084c2de36e0dabfce45d046b37d1106").unwrap(); uncle.set_author(uncle_author); b.push_uncle(uncle).unwrap(); @@ -610,8 +610,8 @@ mod tests { let b = OpenBlock::new(engine, Default::default(), false, db, &genesis_header, last_hashes, Address::zero(), (3141562.into(), 31415620.into()), vec![], false, None).unwrap(); let b = b.close().unwrap(); - let ubi_contract: Address = "00efdd5883ec628983e9063c7d969fe268bbf310".into(); - let dev_contract: Address = "00756cf8159095948496617f5fb17ed95059f536".into(); + let ubi_contract = Address::from_str("00efdd5883ec628983e9063c7d969fe268bbf310").unwrap(); + let dev_contract = Address::from_str("00756cf8159095948496617f5fb17ed95059f536").unwrap(); assert_eq!(b.state.balance(&Address::zero()).unwrap(), U256::from_str("d8d726b7177a80000").unwrap()); assert_eq!(b.state.balance(&ubi_contract).unwrap(), U256::from_str("2b5e3af16b1880000").unwrap()); assert_eq!(b.state.balance(&dev_contract).unwrap(), U256::from_str("c249fdd327780000").unwrap()); @@ -721,7 +721,7 @@ mod tests { fn can_do_proof_of_work_unordered_verification_fail() { let engine = test_spec().engine; let mut header: Header = Header::default(); - header.set_seal(vec![rlp::encode(&H256::from("b251bd2e0283d0658f2cadfdc8ca619b5de94eca5742725e2e757dd13ed7503d")), rlp::encode(&H64::zero())]); + header.set_seal(vec![rlp::encode(&H256::from_str("b251bd2e0283d0658f2cadfdc8ca619b5de94eca5742725e2e757dd13ed7503d").unwrap()), rlp::encode(&H64::zero())]); header.set_difficulty(U256::from_str("ffffffffffffffffffffffffffffffffffffffffffffaaaaaaaaaaaaaaaaaaaa").unwrap()); let verify_result = engine.verify_block_unordered(&header); @@ -914,7 +914,7 @@ mod tests { let tempdir = TempDir::new("").unwrap(); let ethash = Ethash::new(tempdir.path(), ethparams, machine, None); let mut header = Header::default(); - header.set_seal(vec![rlp::encode(&H256::from("b251bd2e0283d0658f2cadfdc8ca619b5de94eca5742725e2e757dd13ed7503d")), rlp::encode(&H64::zero())]); + header.set_seal(vec![rlp::encode(&H256::from_str("b251bd2e0283d0658f2cadfdc8ca619b5de94eca5742725e2e757dd13ed7503d").unwrap()), rlp::encode(&H64::zero())]); let info = ethash.extra_info(&header); assert_eq!(info["nonce"], "0x0000000000000000"); assert_eq!(info["mixHash"], "0xb251bd2e0283d0658f2cadfdc8ca619b5de94eca5742725e2e757dd13ed7503d"); diff --git a/ethcore/src/ethereum/mod.rs b/ethcore/src/ethereum/mod.rs index d85fbf9b7..38bf970a8 100644 --- a/ethcore/src/ethereum/mod.rs +++ b/ethcore/src/ethereum/mod.rs @@ -187,7 +187,8 @@ pub fn new_kovan_wasm_test_machine() -> EthereumMachine { load_machine(include_b #[cfg(test)] mod tests { - use ethereum_types::U256; + use std::str::FromStr; + use ethereum_types::{U256, H256, Address}; use state::*; use super::*; use test_helpers::get_temp_state_db; @@ -201,21 +202,21 @@ mod tests { let genesis_header = spec.genesis_header(); let db = spec.ensure_db_good(get_temp_state_db(), &Default::default()).unwrap(); let s = State::from_existing(db, genesis_header.state_root().clone(), engine.account_start_nonce(0), Default::default()).unwrap(); - assert_eq!(s.balance(&"0000000000000000000000000000000000000001".into()).unwrap(), 1u64.into()); - assert_eq!(s.balance(&"0000000000000000000000000000000000000002".into()).unwrap(), 1u64.into()); - assert_eq!(s.balance(&"0000000000000000000000000000000000000003".into()).unwrap(), 1u64.into()); - assert_eq!(s.balance(&"0000000000000000000000000000000000000004".into()).unwrap(), 1u64.into()); - assert_eq!(s.balance(&"102e61f5d8f9bc71d0ad4a084df4e65e05ce0e1c".into()).unwrap(), U256::from(1u64) << 200); - assert_eq!(s.balance(&"0000000000000000000000000000000000000000".into()).unwrap(), 0u64.into()); + assert_eq!(s.balance(&Address::from_str("0000000000000000000000000000000000000001").unwrap()).unwrap(), 1u64.into()); + assert_eq!(s.balance(&Address::from_str("0000000000000000000000000000000000000002").unwrap()).unwrap(), 1u64.into()); + assert_eq!(s.balance(&Address::from_str("0000000000000000000000000000000000000003").unwrap()).unwrap(), 1u64.into()); + assert_eq!(s.balance(&Address::from_str("0000000000000000000000000000000000000004").unwrap()).unwrap(), 1u64.into()); + assert_eq!(s.balance(&Address::from_str("102e61f5d8f9bc71d0ad4a084df4e65e05ce0e1c").unwrap()).unwrap(), U256::from(1u64) << 200); + assert_eq!(s.balance(&Address::from_str("0000000000000000000000000000000000000000").unwrap()).unwrap(), 0u64.into()); } #[test] fn morden() { let morden = new_morden(&::std::env::temp_dir()); - assert_eq!(morden.state_root(), "f3f4696bbf3b3b07775128eb7a3763279a394e382130f27c21e70233e04946a9".into()); + assert_eq!(morden.state_root(), H256::from_str("f3f4696bbf3b3b07775128eb7a3763279a394e382130f27c21e70233e04946a9").unwrap()); let genesis = morden.genesis_block(); - assert_eq!(view!(BlockView, &genesis).header_view().hash(), "0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303".into()); + assert_eq!(view!(BlockView, &genesis).header_view().hash(), H256::from_str("0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303").unwrap()); let _ = morden.engine; } @@ -224,9 +225,9 @@ mod tests { fn frontier() { let frontier = new_foundation(&::std::env::temp_dir()); - assert_eq!(frontier.state_root(), "d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544".into()); + assert_eq!(frontier.state_root(), H256::from_str("d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544").unwrap()); let genesis = frontier.genesis_block(); - assert_eq!(view!(BlockView, &genesis).header_view().hash(), "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3".into()); + assert_eq!(view!(BlockView, &genesis).header_view().hash(), H256::from_str("d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3").unwrap()); let _ = frontier.engine; } diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index 68d4edc79..2d96db070 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -16,6 +16,7 @@ //! Transaction Execution environment. use std::cmp; +use std::convert::TryFrom; use std::sync::Arc; use hash::keccak; use ethereum_types::{H256, U256, U512, Address}; @@ -858,7 +859,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> { if !schedule.keep_unsigned_nonce || !t.is_unsigned() { self.state.inc_nonce(&sender)?; } - self.state.sub_balance(&sender, &U256::from(gas_cost), &mut substate.to_cleanup_mode(&schedule))?; + self.state.sub_balance(&sender, &U256::try_from(gas_cost).expect("Total cost (value + gas_cost) is lower than max allowed balance (U256); gas_cost has to fit U256; qed"), &mut substate.to_cleanup_mode(&schedule))?; let (result, output) = match t.action { Action::Create => { @@ -1174,7 +1175,7 @@ mod tests { use rustc_hex::FromHex; use ethkey::{Generator, Random}; use super::*; - use ethereum_types::{H256, U256, U512, Address}; + use ethereum_types::{H256, U256, U512, Address, BigEndianHash}; use vm::{ActionParams, ActionValue, CallType, EnvInfo, CreateContractAddress}; use evm::{Factory, VMType}; use error::ExecutionError; @@ -1229,7 +1230,7 @@ mod tests { }; assert_eq!(gas_left, U256::from(79_975)); - assert_eq!(state.storage_at(&address, &H256::new()).unwrap(), H256::from(&U256::from(0xf9u64))); + assert_eq!(state.storage_at(&address, &H256::zero()).unwrap(), BigEndianHash::from_uint(&U256::from(0xf9u64))); assert_eq!(state.balance(&sender).unwrap(), U256::from(0xf9)); assert_eq!(state.balance(&address).unwrap(), U256::from(0x7)); assert_eq!(substate.contracts_created.len(), 0); @@ -1331,8 +1332,8 @@ mod tests { assert_eq!(tracer.drain(), vec![FlatTrace { action: trace::Action::Call(trace::Call { - from: "4444444444444444444444444444444444444444".into(), - to: "5555555555555555555555555555555555555555".into(), + from: Address::from_str("4444444444444444444444444444444444444444").unwrap(), + to: Address::from_str("5555555555555555555555555555555555555555").unwrap(), value: 100.into(), gas: 100_000.into(), input: vec![], @@ -1346,8 +1347,8 @@ mod tests { trace_address: Default::default() }, FlatTrace { action: trace::Action::Call(trace::Call { - from: "5555555555555555555555555555555555555555".into(), - to: "0000000000000000000000000000000000000003".into(), + from: Address::from_str("5555555555555555555555555555555555555555").unwrap(), + to: Address::from_str("0000000000000000000000000000000000000003").unwrap(), value: 1.into(), gas: 66560.into(), input: vec![], @@ -1421,8 +1422,8 @@ mod tests { trace_address: Default::default(), subtraces: 1, action: trace::Action::Call(trace::Call { - from: "cd1722f3947def4cf144679da39c4c32bdc35681".into(), - to: "b010143a42d5980c7e5ef0e4a4416dc098a4fed3".into(), + from: Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap(), + to: Address::from_str("b010143a42d5980c7e5ef0e4a4416dc098a4fed3").unwrap(), value: 100.into(), gas: 100000.into(), input: vec![], @@ -1436,7 +1437,7 @@ mod tests { trace_address: vec![0].into_iter().collect(), subtraces: 0, action: trace::Action::Create(trace::Create { - from: "b010143a42d5980c7e5ef0e4a4416dc098a4fed3".into(), + from: Address::from_str("b010143a42d5980c7e5ef0e4a4416dc098a4fed3").unwrap(), value: 23.into(), gas: 67979.into(), init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85] @@ -1537,8 +1538,8 @@ mod tests { trace_address: Default::default(), subtraces: 1, action: trace::Action::Call(trace::Call { - from: "cd1722f3947def4cf144679da39c4c32bdc35681".into(), - to: "b010143a42d5980c7e5ef0e4a4416dc098a4fed3".into(), + from: Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap(), + to: Address::from_str("b010143a42d5980c7e5ef0e4a4416dc098a4fed3").unwrap(), value: 100.into(), gas: 100_000.into(), input: vec![], @@ -1552,7 +1553,7 @@ mod tests { trace_address: vec![0].into_iter().collect(), subtraces: 0, action: trace::Action::Create(trace::Create { - from: "b010143a42d5980c7e5ef0e4a4416dc098a4fed3".into(), + from: Address::from_str("b010143a42d5980c7e5ef0e4a4416dc098a4fed3").unwrap(), value: 23.into(), gas: 66_917.into(), init: vec![0x60, 0x01, 0x60, 0x00, 0xfd] @@ -1803,7 +1804,13 @@ mod tests { }; assert_eq!(gas_left, U256::from(73_237)); - assert_eq!(state.storage_at(&address_a, &H256::from(&U256::from(0x23))).unwrap(), H256::from(&U256::from(1))); + assert_eq!( + state.storage_at( + &address_a, + &BigEndianHash::from_uint(&U256::from(0x23)), + ).unwrap(), + BigEndianHash::from_uint(&U256::from(1)), + ); } // test is incorrect, mk @@ -1848,8 +1855,8 @@ mod tests { }; assert_eq!(gas_left, U256::from(59_870)); - assert_eq!(state.storage_at(&address, &H256::from(&U256::zero())).unwrap(), H256::from(&U256::from(1))); - assert_eq!(state.storage_at(&address, &H256::from(&U256::one())).unwrap(), H256::from(&U256::from(1))); + assert_eq!(state.storage_at(&address, &BigEndianHash::from_uint(&U256::zero())).unwrap(), BigEndianHash::from_uint(&U256::from(1))); + assert_eq!(state.storage_at(&address, &BigEndianHash::from_uint(&U256::one())).unwrap(), BigEndianHash::from_uint(&U256::from(1))); } // test is incorrect, mk @@ -1890,7 +1897,7 @@ mod tests { assert_eq!(state.balance(&sender).unwrap(), U256::from(1)); assert_eq!(state.balance(&contract).unwrap(), U256::from(17)); assert_eq!(state.nonce(&sender).unwrap(), U256::from(1)); - assert_eq!(state.storage_at(&contract, &H256::new()).unwrap(), H256::from(&U256::from(1))); + assert_eq!(state.storage_at(&contract, &H256::zero()).unwrap(), BigEndianHash::from_uint(&U256::from(1))); } evm_test!{test_transact_invalid_nonce: test_transact_invalid_nonce_int} @@ -2059,17 +2066,17 @@ mod tests { assert_eq!(result, U256::from(1)); assert_eq!(output[..], returns[..]); - assert_eq!(state.storage_at(&contract_address, &H256::from(&U256::zero())).unwrap(), H256::from(&U256::from(0))); + assert_eq!(state.storage_at(&contract_address, &H256::zero()).unwrap(), H256::zero()); } evm_test!{test_eip1283: test_eip1283_int} fn test_eip1283(factory: Factory) { - let x1 = Address::from(0x1000); - let x2 = Address::from(0x1001); - let y1 = Address::from(0x2001); - let y2 = Address::from(0x2002); - let operating_address = Address::from(0); - let k = H256::new(); + let x1 = Address::from_low_u64_be(0x1000); + let x2 = Address::from_low_u64_be(0x1001); + let y1 = Address::from_low_u64_be(0x2001); + let y2 = Address::from_low_u64_be(0x2002); + let operating_address = Address::zero(); + let k = H256::zero(); let mut state = get_temp_state_with_factory(factory.clone()); state.new_contract(&x1, U256::zero(), U256::from(1)).unwrap(); @@ -2085,7 +2092,7 @@ mod tests { let machine = ::ethereum::new_constantinople_test_machine(); let schedule = machine.schedule(info.number); - assert_eq!(state.storage_at(&operating_address, &k).unwrap(), H256::from(U256::from(0))); + assert_eq!(state.storage_at(&operating_address, &k).unwrap(), BigEndianHash::from_uint(&U256::from(0))); // Test a call via top-level -> y1 -> x1 let (FinalizationResult { gas_left, .. }, refund, gas) = { let gas = U256::from(0xffffffffffu64); @@ -2103,7 +2110,7 @@ mod tests { assert_eq!(gas_used, U256::from(41860)); assert_eq!(refund, 19800); - assert_eq!(state.storage_at(&operating_address, &k).unwrap(), H256::from(U256::from(1))); + assert_eq!(state.storage_at(&operating_address, &k).unwrap(), BigEndianHash::from_uint(&U256::from(1))); // Test a call via top-level -> y2 -> x2 let (FinalizationResult { gas_left, .. }, refund, gas) = { let gas = U256::from(0xffffffffffu64); diff --git a/ethcore/src/externalities.rs b/ethcore/src/externalities.rs index 23a4a83c3..54c913c73 100644 --- a/ethcore/src/externalities.rs +++ b/ethcore/src/externalities.rs @@ -17,7 +17,7 @@ //! Transaction Execution environment. use std::cmp; use std::sync::Arc; -use ethereum_types::{H256, U256, Address}; +use ethereum_types::{H256, U256, Address, BigEndianHash}; use bytes::Bytes; use state::{Backend as StateBackend, State, Substate, CleanupMode}; use machine::EthereumMachine as Machine; @@ -166,6 +166,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B> Ok((code, hash)) => (code, hash), Err(_) => return H256::zero(), }; + let data: H256 = BigEndianHash::from_uint(number); let params = ActionParams { sender: self.origin_info.address.clone(), @@ -177,7 +178,7 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B> gas_price: 0.into(), code: code, code_hash: code_hash, - data: Some(H256::from(number).to_vec()), + data: Some(data.as_bytes().to_vec()), call_type: CallType::Call, params_type: vm::ParamsType::Separate, }; @@ -185,8 +186,8 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B> let mut ex = Executive::new(self.state, self.env_info, self.machine, self.schedule); let r = ex.call_with_crossbeam(params, self.substate, self.stack_depth + 1, self.tracer, self.vm_tracer); let output = match &r { - Ok(ref r) => H256::from(&r.return_data[..32]), - _ => H256::new(), + Ok(ref r) => H256::from_slice(&r.return_data[..32]), + _ => H256::zero(), }; trace!("ext: blockhash contract({}) -> {:?}({}) self.env_info.number={}\n", number, r, output, self.env_info.number); output @@ -428,6 +429,7 @@ mod tests { use test_helpers::get_temp_state; use super::*; use trace::{NoopTracer, NoopVMTracer}; + use std::str::FromStr; fn get_test_origin() -> OriginInfo { OriginInfo { @@ -441,7 +443,7 @@ mod tests { fn get_test_env_info() -> EnvInfo { EnvInfo { number: 100, - author: 0.into(), + author: Address::from_low_u64_be(0), timestamp: 0, difficulty: 0.into(), last_hashes: Arc::new(vec![]), @@ -509,7 +511,7 @@ mod tests { #[test] fn can_return_block_hash() { - let test_hash = H256::from("afafafafafafafafafafafbcbcbcbcbcbcbcbcbcbeeeeeeeeeeeeedddddddddd"); + let test_hash = H256::from_str("afafafafafafafafafafafbcbcbcbcbcbcbcbcbcbeeeeeeeeeeeeedddddddddd").unwrap(); let test_env_number = 0x120001; let mut setup = TestSetup::new(); @@ -546,11 +548,11 @@ mod tests { // this should panic because we have no balance on any account ext.call( &"0000000000000000000000000000000000000000000000000000000000120000".parse::().unwrap(), - &Address::new(), - &Address::new(), + &Address::zero(), + &Address::zero(), Some("0000000000000000000000000000000000000000000000000000000000150000".parse::().unwrap()), &[], - &Address::new(), + &Address::zero(), CallType::Call, false, ).ok().unwrap(); @@ -559,7 +561,7 @@ mod tests { #[test] fn can_log() { let log_data = vec![120u8, 110u8]; - let log_topics = vec![H256::from("af0fa234a6af46afa23faf23bcbc1c1cb4bcb7bcbe7e7e7ee3ee2edddddddddd")]; + let log_topics = vec![H256::from_str("af0fa234a6af46afa23faf23bcbc1c1cb4bcb7bcbe7e7e7ee3ee2edddddddddd").unwrap()]; let mut setup = TestSetup::new(); let state = &mut setup.state; @@ -577,7 +579,7 @@ mod tests { #[test] fn can_suicide() { - let refund_account = &Address::new(); + let refund_account = &Address::zero(); let mut setup = TestSetup::new(); let state = &mut setup.state; @@ -627,7 +629,7 @@ mod tests { let address = { let mut ext = Externalities::new(state, &setup.env_info, &setup.machine, &setup.schedule, 0, 0, &origin_info, &mut setup.sub_state, OutputPolicy::InitContract, &mut tracer, &mut vm_tracer, false); - match ext.create(&U256::max_value(), &U256::zero(), &[], CreateContractAddress::FromSenderSaltAndCodeHash(H256::default()), false) { + match ext.create(&U256::max_value(), &U256::zero(), &[], CreateContractAddress::FromSenderSaltAndCodeHash(H256::zero()), false) { Ok(ContractCreateResult::Created(address, _)) => address, _ => panic!("Test create failed; expected Created, got Failed/Reverted."), } diff --git a/ethcore/src/json_tests/executive.rs b/ethcore/src/json_tests/executive.rs index cd9e8f2ae..dafc29e41 100644 --- a/ethcore/src/json_tests/executive.rs +++ b/ethcore/src/json_tests/executive.rs @@ -35,6 +35,7 @@ use ethtrie; use rlp::RlpStream; use hash::keccak; use machine::EthereumMachine as Machine; +use ethereum_types::BigEndianHash; use super::HookType; @@ -339,8 +340,8 @@ fn do_json_test_for(vm_type: &VMType, json_data: &[u8] for (k, v) in account.storage { let key: U256 = k.into(); let value: U256 = v.into(); - let found_storage = try_fail!(state.storage_at(&address, &From::from(key))); - fail_unless(found_storage == From::from(value), "storage is incorrect"); + let found_storage = try_fail!(state.storage_at(&address, &BigEndianHash::from_uint(&key))); + fail_unless(found_storage == BigEndianHash::from_uint(&value), "storage is incorrect"); } } diff --git a/ethcore/src/json_tests/test_common.rs b/ethcore/src/json_tests/test_common.rs index 7e3842ecb..521b6d4ec 100644 --- a/ethcore/src/json_tests/test_common.rs +++ b/ethcore/src/json_tests/test_common.rs @@ -111,6 +111,7 @@ macro_rules! test { } } +/// Declares a test #[macro_export] macro_rules! declare_test { (skip => $arr: expr, $id: ident, $name: expr) => { diff --git a/ethcore/src/json_tests/trie.rs b/ethcore/src/json_tests/trie.rs index d56490ec7..31ca6135e 100644 --- a/ethcore/src/json_tests/trie.rs +++ b/ethcore/src/json_tests/trie.rs @@ -35,7 +35,7 @@ fn test_trie(json: &[u8], trie: TrieSpec, start_stop_h start_stop_hook(&name, HookType::OnStart); let mut memdb = journaldb::new_memory_db(); - let mut root = H256::default(); + let mut root = H256::zero(); let mut t = factory.create(&mut memdb, &mut root); for (key, value) in test.input.data.into_iter() { diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 463d22fd4..315cd0bb5 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -107,6 +107,8 @@ extern crate using_queue; extern crate vm; extern crate wasm; +#[cfg(test)] +extern crate rand_xorshift; #[cfg(test)] extern crate ethcore_accounts as accounts; #[cfg(feature = "stratum")] diff --git a/ethcore/src/machine/impls.rs b/ethcore/src/machine/impls.rs index 72f20ecdf..4962f1ea2 100644 --- a/ethcore/src/machine/impls.rs +++ b/ethcore/src/machine/impls.rs @@ -60,7 +60,7 @@ impl From<::ethjson::spec::EthashParams> for EthashExtensions { EthashExtensions { homestead_transition: p.homestead_transition.map_or(0, Into::into), dao_hardfork_transition: p.dao_hardfork_transition.map_or(u64::max_value(), Into::into), - dao_hardfork_beneficiary: p.dao_hardfork_beneficiary.map_or_else(Address::new, Into::into), + dao_hardfork_beneficiary: p.dao_hardfork_beneficiary.map_or_else(Address::zero, Into::into), dao_hardfork_accounts: p.dao_hardfork_accounts.unwrap_or_else(Vec::new).into_iter().map(Into::into).collect(), } } @@ -203,7 +203,7 @@ impl EthereumMachine { block, params.eip210_contract_address, params.eip210_contract_gas, - Some(parent_hash.to_vec()), + Some(parent_hash.as_bytes().to_vec()), )?; } Ok(()) @@ -462,12 +462,13 @@ fn round_block_gas_limit(gas_limit: U256, lower_limit: U256, upper_limit: U256) #[cfg(test)] mod tests { use super::*; + use std::str::FromStr; fn get_default_ethash_extensions() -> EthashExtensions { EthashExtensions { homestead_transition: 1150000, dao_hardfork_transition: u64::max_value(), - dao_hardfork_beneficiary: "0000000000000000000000000000000000000001".into(), + dao_hardfork_beneficiary: Address::from_str("0000000000000000000000000000000000000001").unwrap(), dao_hardfork_accounts: Vec::new(), } } diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 070cf6fe9..0c3f94acd 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -1499,7 +1499,7 @@ mod tests { // when new block is imported let client = generate_dummy_client(2); - let imported = [0.into()]; + let imported = [H256::zero()]; let empty = &[]; miner.chain_new_blocks(&*client, &imported, empty, &imported, empty, false); @@ -1745,7 +1745,6 @@ mod tests { #[cfg(feature = "price-info")] fn dynamic_gas_pricer() -> GasPricer { - use std::time::Duration; use parity_runtime::Executor; use fetch::Client as FetchClient; use ethcore_miner::gas_price_calibrator::{GasPriceCalibrator, GasPriceCalibratorOptions}; diff --git a/ethcore/src/miner/stratum.rs b/ethcore/src/miner/stratum.rs index 71862225a..aad646753 100644 --- a/ethcore/src/miner/stratum.rs +++ b/ethcore/src/miner/stratum.rs @@ -21,7 +21,7 @@ use std::net::{SocketAddr, AddrParseError}; use std::fmt; use client::{Client, ImportSealedBlock}; -use ethereum_types::{H64, H256, clean_0x, U256}; +use ethereum_types::{H64, H256, U256}; use ethash::{self, SeedHashCompute}; #[cfg(feature = "work-notify")] use ethcore_miner::work_notify::NotifyWork; @@ -47,6 +47,14 @@ pub struct Options { pub secret: Option, } +fn clean_0x(s: &str) -> &str { + if s.starts_with("0x") { + &s[2..] + } else { + s + } +} + struct SubmitPayload { nonce: H64, pow_hash: H256, diff --git a/ethcore/src/pod_account.rs b/ethcore/src/pod_account.rs index 39dce6e36..c02074f95 100644 --- a/ethcore/src/pod_account.rs +++ b/ethcore/src/pod_account.rs @@ -20,7 +20,7 @@ use std::fmt; use std::collections::BTreeMap; use itertools::Itertools; use hash::{keccak}; -use ethereum_types::{H256, U256}; +use ethereum_types::{H256, U256, BigEndianHash}; use hash_db::HashDB; use kvdb::DBValue; use keccak_hasher::KeccakHasher; @@ -73,7 +73,7 @@ impl PodAccount { let mut stream = RlpStream::new_list(4); stream.append(&self.nonce); stream.append(&self.balance); - stream.append(&sec_trie_root(self.storage.iter().map(|(k, v)| (k, rlp::encode(&U256::from(&**v)))))); + stream.append(&sec_trie_root(self.storage.iter().map(|(k, v)| (k, rlp::encode(&v.into_uint()))))); stream.append(&keccak(&self.code.as_ref().unwrap_or(&vec![]))); stream.out() } @@ -84,10 +84,10 @@ impl PodAccount { Some(ref c) if !c.is_empty() => { db.insert(c); } _ => {} } - let mut r = H256::new(); + let mut r = H256::zero(); let mut t = factory.create(db, &mut r); for (k, v) in &self.storage { - if let Err(e) = t.insert(k, &rlp::encode(&U256::from(&**v))) { + if let Err(e) = t.insert(k.as_bytes(), &rlp::encode(&v.into_uint())) { warn!("Encountered potential DB corruption: {}", e); } } @@ -103,7 +103,7 @@ impl From for PodAccount { storage: a.storage.into_iter().map(|(key, value)| { let key: U256 = key.into(); let value: U256 = value.into(); - (H256::from(key), H256::from(value)) + (BigEndianHash::from_uint(&key), BigEndianHash::from_uint(&value)) }).collect(), } } @@ -118,7 +118,7 @@ impl From for PodAccount { storage: a.storage.map_or_else(BTreeMap::new, |s| s.into_iter().map(|(key, value)| { let key: U256 = key.into(); let value: U256 = value.into(); - (H256::from(key), H256::from(value)) + (BigEndianHash::from_uint(&key), BigEndianHash::from_uint(&value)) }).collect()), } } @@ -130,7 +130,7 @@ impl fmt::Display for PodAccount { self.balance, self.nonce, self.code.as_ref().map_or(0, |c| c.len()), - self.code.as_ref().map_or_else(H256::new, |c| keccak(c)), + self.code.as_ref().map_or_else(H256::zero, |c| keccak(c)), self.storage.len(), ) } @@ -154,7 +154,7 @@ pub fn diff_pod(pre: Option<&PodAccount>, post: Option<&PodAccount>) -> Option { let storage: Vec<_> = pre.storage.keys().merge(post.storage.keys()) - .filter(|k| pre.storage.get(k).unwrap_or(&H256::new()) != post.storage.get(k).unwrap_or(&H256::new())) + .filter(|k| pre.storage.get(k).unwrap_or(&H256::zero()) != post.storage.get(k).unwrap_or(&H256::zero())) .collect(); let r = AccountDiff { balance: Diff::new(pre.balance, post.balance), @@ -165,8 +165,8 @@ pub fn diff_pod(pre: Option<&PodAccount>, post: Option<&PodAccount>) -> Option 1, 2 => 2, 3 => 3, 4 => 4, 5 => 0, 6 => 0, 7 => 0] + storage: map![ + H256::from_low_u64_be(1) => H256::from_low_u64_be(1), + H256::from_low_u64_be(2) => H256::from_low_u64_be(2), + H256::from_low_u64_be(3) => H256::from_low_u64_be(3), + H256::from_low_u64_be(4) => H256::from_low_u64_be(4), + H256::from_low_u64_be(5) => H256::from_low_u64_be(0), + H256::from_low_u64_be(6) => H256::from_low_u64_be(0), + H256::from_low_u64_be(7) => H256::from_low_u64_be(0) + ], }; let b = PodAccount { balance: 0.into(), nonce: 0.into(), code: Some(vec![]), - storage: map_into![1 => 1, 2 => 3, 3 => 0, 5 => 0, 7 => 7, 8 => 0, 9 => 9] + storage: map![ + H256::from_low_u64_be(1) => H256::from_low_u64_be(1), + H256::from_low_u64_be(2) => H256::from_low_u64_be(3), + H256::from_low_u64_be(3) => H256::from_low_u64_be(0), + H256::from_low_u64_be(5) => H256::from_low_u64_be(0), + H256::from_low_u64_be(7) => H256::from_low_u64_be(7), + H256::from_low_u64_be(8) => H256::from_low_u64_be(0), + H256::from_low_u64_be(9) => H256::from_low_u64_be(9) + ] }; assert_eq!(diff_pod(Some(&a), Some(&b)), Some(AccountDiff { balance: Diff::Same, nonce: Diff::Same, code: Diff::Same, storage: map![ - 2.into() => Diff::new(2.into(), 3.into()), - 3.into() => Diff::new(3.into(), 0.into()), - 4.into() => Diff::new(4.into(), 0.into()), - 7.into() => Diff::new(0.into(), 7.into()), - 9.into() => Diff::new(0.into(), 9.into()) + H256::from_low_u64_be(2) => Diff::new(H256::from_low_u64_be(2), H256::from_low_u64_be(3)), + H256::from_low_u64_be(3) => Diff::new(H256::from_low_u64_be(3), H256::from_low_u64_be(0)), + H256::from_low_u64_be(4) => Diff::new(H256::from_low_u64_be(4), H256::from_low_u64_be(0)), + H256::from_low_u64_be(7) => Diff::new(H256::from_low_u64_be(0), H256::from_low_u64_be(7)), + H256::from_low_u64_be(9) => Diff::new(H256::from_low_u64_be(0), H256::from_low_u64_be(9)) ], })); } diff --git a/ethcore/src/pod_state.rs b/ethcore/src/pod_state.rs index c1130faa7..1c5ecc840 100644 --- a/ethcore/src/pod_state.rs +++ b/ethcore/src/pod_state.rs @@ -90,12 +90,12 @@ mod test { use types::state_diff::*; use types::account_diff::*; use pod_account::PodAccount; - use super::PodState; + use super::{PodState, Address}; #[test] fn create_delete() { let a = PodState::from(map![ - 1.into() => PodAccount { + Address::from_low_u64_be(1) => PodAccount { balance: 69.into(), nonce: 0.into(), code: Some(Vec::new()), @@ -103,7 +103,7 @@ mod test { } ]); assert_eq!(super::diff_pod(&a, &PodState::new()), StateDiff { raw: map![ - 1.into() => AccountDiff{ + Address::from_low_u64_be(1) => AccountDiff{ balance: Diff::Died(69.into()), nonce: Diff::Died(0.into()), code: Diff::Died(vec![]), @@ -111,7 +111,7 @@ mod test { } ]}); assert_eq!(super::diff_pod(&PodState::new(), &a), StateDiff{ raw: map![ - 1.into() => AccountDiff{ + Address::from_low_u64_be(1) => AccountDiff{ balance: Diff::Born(69.into()), nonce: Diff::Born(0.into()), code: Diff::Born(vec![]), @@ -123,7 +123,7 @@ mod test { #[test] fn create_delete_with_unchanged() { let a = PodState::from(map![ - 1.into() => PodAccount { + Address::from_low_u64_be(1) => PodAccount { balance: 69.into(), nonce: 0.into(), code: Some(Vec::new()), @@ -131,13 +131,13 @@ mod test { } ]); let b = PodState::from(map![ - 1.into() => PodAccount { + Address::from_low_u64_be(1) => PodAccount { balance: 69.into(), nonce: 0.into(), code: Some(Vec::new()), storage: map![], }, - 2.into() => PodAccount { + Address::from_low_u64_be(2) => PodAccount { balance: 69.into(), nonce: 0.into(), code: Some(Vec::new()), @@ -145,7 +145,7 @@ mod test { } ]); assert_eq!(super::diff_pod(&a, &b), StateDiff { raw: map![ - 2.into() => AccountDiff{ + Address::from_low_u64_be(2) => AccountDiff{ balance: Diff::Born(69.into()), nonce: Diff::Born(0.into()), code: Diff::Born(vec![]), @@ -153,7 +153,7 @@ mod test { } ]}); assert_eq!(super::diff_pod(&b, &a), StateDiff { raw: map![ - 2.into() => AccountDiff{ + Address::from_low_u64_be(2) => AccountDiff{ balance: Diff::Died(69.into()), nonce: Diff::Died(0.into()), code: Diff::Died(vec![]), @@ -165,13 +165,13 @@ mod test { #[test] fn change_with_unchanged() { let a = PodState::from(map![ - 1.into() => PodAccount { + Address::from_low_u64_be(1) => PodAccount { balance: 69.into(), nonce: 0.into(), code: Some(Vec::new()), storage: map![], }, - 2.into() => PodAccount { + Address::from_low_u64_be(2) => PodAccount { balance: 69.into(), nonce: 0.into(), code: Some(Vec::new()), @@ -179,13 +179,13 @@ mod test { } ]); let b = PodState::from(map![ - 1.into() => PodAccount { + Address::from_low_u64_be(1) => PodAccount { balance: 69.into(), nonce: 1.into(), code: Some(Vec::new()), storage: map![], }, - 2.into() => PodAccount { + Address::from_low_u64_be(2) => PodAccount { balance: 69.into(), nonce: 0.into(), code: Some(Vec::new()), @@ -193,7 +193,7 @@ mod test { } ]); assert_eq!(super::diff_pod(&a, &b), StateDiff { raw: map![ - 1.into() => AccountDiff{ + Address::from_low_u64_be(1) => AccountDiff{ balance: Diff::Same, nonce: Diff::Changed(0.into(), 1.into()), code: Diff::Same, diff --git a/ethcore/src/snapshot/account.rs b/ethcore/src/snapshot/account.rs index ed56e2435..d18ecacbc 100644 --- a/ethcore/src/snapshot/account.rs +++ b/ethcore/src/snapshot/account.rs @@ -350,6 +350,6 @@ mod tests { #[test] fn encoding_empty_acc() { let mut db = get_temp_state_db(); - assert_eq!(from_fat_rlp(&mut AccountDBMut::new(db.as_hash_db_mut(), &Address::default()), Rlp::new(&::rlp::NULL_RLP), H256::zero()).unwrap(), (ACC_EMPTY, None)); + assert_eq!(from_fat_rlp(&mut AccountDBMut::new(db.as_hash_db_mut(), &Address::zero()), Rlp::new(&::rlp::NULL_RLP), H256::zero()).unwrap(), (ACC_EMPTY, None)); } } diff --git a/ethcore/src/snapshot/block.rs b/ethcore/src/snapshot/block.rs index 0fc590763..f19b2611b 100644 --- a/ethcore/src/snapshot/block.rs +++ b/ethcore/src/snapshot/block.rs @@ -152,7 +152,7 @@ mod tests { let encoded = encode_block(&b); let abridged = AbridgedBlock::from_block_view(&view!(BlockView, &encoded)); - assert_eq!(abridged.to_block(H256::new(), 0, receipts_root).unwrap(), b); + assert_eq!(abridged.to_block(H256::zero(), 0, receipts_root).unwrap(), b); } #[test] @@ -163,7 +163,7 @@ mod tests { let encoded = encode_block(&b); let abridged = AbridgedBlock::from_block_view(&view!(BlockView, &encoded)); - assert_eq!(abridged.to_block(H256::new(), 2, receipts_root).unwrap(), b); + assert_eq!(abridged.to_block(H256::zero(), 2, receipts_root).unwrap(), b); } #[test] @@ -177,7 +177,7 @@ mod tests { gas: U256::from(50_000), value: U256::from(1), data: b"Hello!".to_vec() - }.fake_sign(Address::from(0x69)); + }.fake_sign(Address::from_low_u64_be(0x69)); let t2 = Transaction { action: Action::Create, @@ -186,7 +186,7 @@ mod tests { gas: U256::from(300000), value: U256::from(1000000000), data: "Eep!".into(), - }.fake_sign(Address::from(0x55)); + }.fake_sign(Address::from_low_u64_be(0x55)); b.transactions.push(t1.into()); b.transactions.push(t2.into()); @@ -199,6 +199,6 @@ mod tests { let encoded = encode_block(&b); let abridged = AbridgedBlock::from_block_view(&view!(BlockView, &encoded[..])); - assert_eq!(abridged.to_block(H256::new(), 0, receipts_root).unwrap(), b); + assert_eq!(abridged.to_block(H256::zero(), 0, receipts_root).unwrap(), b); } } diff --git a/ethcore/src/snapshot/consensus/work.rs b/ethcore/src/snapshot/consensus/work.rs index 106fe4474..a3d4da1c2 100644 --- a/ethcore/src/snapshot/consensus/work.rs +++ b/ethcore/src/snapshot/consensus/work.rs @@ -34,7 +34,7 @@ use ethereum_types::H256; use kvdb::KeyValueDB; use bytes::Bytes; use rlp::{RlpStream, Rlp}; -use rand::OsRng; +use rand::rngs::OsRng; use types::encoded; /// Snapshot creation and restoration for PoW chains. @@ -210,7 +210,7 @@ impl PowRebuilder { Ok(PowRebuilder { chain: chain, db: db, - rng: OsRng::new()?, + rng: OsRng::new().map_err(|e| format!("{}", e))?, disconnected: Vec::new(), best_number: manifest.block_number, best_hash: manifest.block_hash, diff --git a/ethcore/src/snapshot/mod.rs b/ethcore/src/snapshot/mod.rs index 19a5f8ce6..155182ed5 100644 --- a/ethcore/src/snapshot/mod.rs +++ b/ethcore/src/snapshot/mod.rs @@ -51,7 +51,7 @@ use super::state_db::StateDB; use super::state::Account as StateAccount; use crossbeam::scope; -use rand::{Rng, OsRng}; +use rand::{Rng, rngs::OsRng}; pub use self::error::Error; @@ -411,7 +411,7 @@ impl StateRebuilder { let mut pairs = Vec::with_capacity(rlp.item_count()?); // initialize the pairs vector with empty values so we have slots to write into. - pairs.resize(rlp.item_count()?, (H256::new(), Vec::new())); + pairs.resize(rlp.item_count()?, (H256::zero(), Vec::new())); let status = rebuild_accounts( self.db.as_hash_db_mut(), @@ -450,9 +450,9 @@ impl StateRebuilder { if !flag.load(Ordering::SeqCst) { return Err(Error::RestorationAborted.into()) } if &thin_rlp[..] != &empty_rlp[..] { - self.bloom.set(&*hash); + self.bloom.set(hash.as_bytes()); } - account_trie.insert(&hash, &thin_rlp)?; + account_trie.insert(hash.as_bytes(), &thin_rlp)?; } } diff --git a/ethcore/src/snapshot/service.rs b/ethcore/src/snapshot/service.rs index e8b380c3e..8120f47b8 100644 --- a/ethcore/src/snapshot/service.rs +++ b/ethcore/src/snapshot/service.rs @@ -928,9 +928,9 @@ mod tests { version: 2, state_hashes: state_hashes.clone(), block_hashes: block_hashes.clone(), - state_root: H256::default(), + state_root: H256::zero(), block_number: 100000, - block_hash: H256::default(), + block_hash: H256::zero(), }, pruning: Algorithm::Archive, db: restoration_db_handler(db_config).open(&tempdir.path().to_owned()).unwrap(), diff --git a/ethcore/src/snapshot/tests/helpers.rs b/ethcore/src/snapshot/tests/helpers.rs index 817e02499..a70c7b7e2 100644 --- a/ethcore/src/snapshot/tests/helpers.rs +++ b/ethcore/src/snapshot/tests/helpers.rs @@ -124,7 +124,7 @@ pub fn fill_storage(mut db: AccountDBMut, root: &mut H256, seed: &mut H256) { SecTrieDBMut::from_existing(&mut db, root).unwrap() }; - for (k, v) in map.make_with(seed) { + for (k, v) in map.make_with(&mut seed.to_fixed_bytes()) { trie.insert(&k, &v).unwrap(); } } @@ -157,7 +157,6 @@ pub fn restore( genesis: &[u8], ) -> Result<(), ::error::Error> { use std::sync::atomic::AtomicBool; - use snappy; let flag = AtomicBool::new(true); let components = engine.snapshot_components().unwrap(); diff --git a/ethcore/src/snapshot/tests/proof_of_authority.rs b/ethcore/src/snapshot/tests/proof_of_authority.rs index f1610e6cc..f16357b0f 100644 --- a/ethcore/src/snapshot/tests/proof_of_authority.rs +++ b/ethcore/src/snapshot/tests/proof_of_authority.rs @@ -126,7 +126,7 @@ fn make_chain(accounts: Arc, blocks_beyond: usize, transitions: nonce: *nonce, gas_price: 1.into(), gas: 21_000.into(), - action: Action::Call(Address::new()), + action: Action::Call(Address::zero()), value: 1.into(), data: Vec::new(), }.sign(&*RICH_SECRET, client.signing_chain_id()); diff --git a/ethcore/src/snapshot/tests/proof_of_work.rs b/ethcore/src/snapshot/tests/proof_of_work.rs index 0040f4967..fb714e667 100644 --- a/ethcore/src/snapshot/tests/proof_of_work.rs +++ b/ethcore/src/snapshot/tests/proof_of_work.rs @@ -119,7 +119,7 @@ fn checks_flag() { let mut stream = RlpStream::new_list(5); stream.append(&100u64) - .append(&H256::default()) + .append(&H256::zero()) .append(&(!0u64)); stream.append_empty_data().append_empty_data(); @@ -137,7 +137,7 @@ fn checks_flag() { block_hashes: Vec::new(), state_root: ::hash::KECCAK_NULL_RLP, block_number: 102, - block_hash: H256::default(), + block_hash: H256::zero(), }; let mut rebuilder = SNAPSHOT_MODE.rebuilder(chain, db.clone(), &manifest).unwrap(); diff --git a/ethcore/src/snapshot/tests/state.rs b/ethcore/src/snapshot/tests/state.rs index 7855b3d68..bbf3bfa62 100644 --- a/ethcore/src/snapshot/tests/state.rs +++ b/ethcore/src/snapshot/tests/state.rs @@ -28,18 +28,21 @@ use super::helpers::StateProducer; use error::Error; -use rand::{XorShiftRng, SeedableRng}; +use rand::SeedableRng; +use rand_xorshift::XorShiftRng; use ethereum_types::H256; use journaldb::{self, Algorithm}; use kvdb_rocksdb::{Database, DatabaseConfig}; use parking_lot::Mutex; use tempdir::TempDir; +const RNG_SEED: [u8; 16] = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; + #[test] fn snap_and_restore() { use hash_db::HashDB; let mut producer = StateProducer::new(); - let mut rng = XorShiftRng::from_seed([1, 2, 3, 4]); + let mut rng = XorShiftRng::from_seed(RNG_SEED); let mut old_db = journaldb::new_memory_db(); let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS); @@ -65,7 +68,7 @@ fn snap_and_restore() { block_hashes: Vec::new(), state_root: state_root, block_number: 1000, - block_hash: H256::default(), + block_hash: H256::zero(), }).unwrap(); let db_path = tempdir.path().join("db"); @@ -84,7 +87,7 @@ fn snap_and_restore() { } assert_eq!(rebuilder.state_root(), state_root); - rebuilder.finalize(1000, H256::default()).unwrap(); + rebuilder.finalize(1000, H256::zero()).unwrap(); new_db }; @@ -157,7 +160,7 @@ fn get_code_from_prev_chunk() { #[test] fn checks_flag() { let mut producer = StateProducer::new(); - let mut rng = XorShiftRng::from_seed([5, 6, 7, 8]); + let mut rng = XorShiftRng::from_seed(RNG_SEED); let mut old_db = journaldb::new_memory_db(); let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS); @@ -179,7 +182,7 @@ fn checks_flag() { block_hashes: Vec::new(), state_root: state_root, block_number: 0, - block_hash: H256::default(), + block_hash: H256::zero(), }).unwrap(); let tempdir = TempDir::new("").unwrap(); diff --git a/ethcore/src/snapshot/watcher.rs b/ethcore/src/snapshot/watcher.rs index 5c4712cff..9df21c3cd 100644 --- a/ethcore/src/snapshot/watcher.rs +++ b/ethcore/src/snapshot/watcher.rs @@ -123,7 +123,7 @@ mod tests { use client::{ChainNotify, NewBlocks, ChainRoute}; - use ethereum_types::{H256, U256}; + use ethereum_types::{H256, U256, BigEndianHash}; use std::collections::HashMap; use std::time::Duration; @@ -151,7 +151,7 @@ mod tests { fn harness(numbers: Vec, period: u64, history: u64, expected: Option) { const DURATION_ZERO: Duration = Duration::from_millis(0); - let hashes: Vec<_> = numbers.clone().into_iter().map(|x| H256::from(U256::from(x))).collect(); + let hashes: Vec<_> = numbers.clone().into_iter().map(|x| BigEndianHash::from_uint(&U256::from(x))).collect(); let map = hashes.clone().into_iter().zip(numbers).collect(); let watcher = Watcher { diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index 0287a59f2..fd00dd56f 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -266,7 +266,7 @@ impl From for CommonParams { BlockNumber::max_value, Into::into, ), - eip210_contract_address: p.eip210_contract_address.map_or(0xf0.into(), Into::into), + eip210_contract_address: p.eip210_contract_address.map_or(Address::from_low_u64_be(0xf0), Into::into), eip210_contract_code: p.eip210_contract_code.map_or_else( || { DEFAULT_BLOCKHASH_CONTRACT.from_hex().expect( @@ -315,7 +315,7 @@ impl From for CommonParams { nonce_cap_increment: p.nonce_cap_increment.map_or(64, Into::into), remove_dust_contracts: p.remove_dust_contracts.unwrap_or(false), gas_limit_bound_divisor: p.gas_limit_bound_divisor.into(), - registrar: p.registrar.map_or_else(Address::new, Into::into), + registrar: p.registrar.map_or_else(Address::zero, Into::into), node_permission_contract: p.node_permission_contract.map(Into::into), max_code_size: p.max_code_size.map_or(u64::max_value(), Into::into), max_transaction_size: p.max_transaction_size.map_or(MAX_TRANSACTION_SIZE, Into::into), @@ -627,7 +627,7 @@ impl Spec { let mut t = factories.trie.create(db.as_hash_db_mut(), &mut root); for (address, account) in self.genesis_state.get().iter() { - t.insert(&**address, &account.rlp())?; + t.insert(address.as_bytes(), &account.rlp())?; } } @@ -658,7 +658,7 @@ impl Spec { gas_limit: U256::max_value(), }; - let from = Address::default(); + let from = Address::zero(); for &(ref address, ref constructor) in self.constructors.iter() { trace!(target: "spec", "run_constructors: Creating a contract at {}.", address); trace!(target: "spec", " .. root before = {}", state.root()); @@ -872,7 +872,7 @@ impl Spec { gas_used: 0.into(), }; - let from = Address::default(); + let from = Address::zero(); let tx = Transaction { nonce: self.engine.account_start_nonce(0), action: Action::Call(a), @@ -996,6 +996,7 @@ mod tests { use tempdir::TempDir; use types::view; use types::views::BlockView; + use std::str::FromStr; #[test] fn test_load_empty() { @@ -1009,12 +1010,12 @@ mod tests { assert_eq!( test_spec.state_root(), - "f3f4696bbf3b3b07775128eb7a3763279a394e382130f27c21e70233e04946a9".into() + H256::from_str("f3f4696bbf3b3b07775128eb7a3763279a394e382130f27c21e70233e04946a9").unwrap() ); let genesis = test_spec.genesis_block(); assert_eq!( view!(BlockView, &genesis).header_view().hash(), - "0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303".into() + H256::from_str("0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303").unwrap() ); } @@ -1030,8 +1031,8 @@ mod tests { spec.engine.account_start_nonce(0), Default::default(), ).unwrap(); - let expected = "0000000000000000000000000000000000000000000000000000000000000001".into(); - let address = "0000000000000000000000000000000000001337".into(); + let expected = H256::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap(); + let address = Address::from_str("0000000000000000000000000000000000001337").unwrap(); assert_eq!(state.storage_at(&address, &H256::zero()).unwrap(), expected); assert_eq!(state.balance(&address).unwrap(), 1.into()); diff --git a/ethcore/src/state/account.rs b/ethcore/src/state/account.rs index fea9444b1..36260ca2c 100644 --- a/ethcore/src/state/account.rs +++ b/ethcore/src/state/account.rs @@ -20,7 +20,7 @@ use std::fmt; use std::sync::Arc; use std::collections::{HashMap, BTreeMap}; use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak}; -use ethereum_types::{H256, U256, Address}; +use ethereum_types::{H256, U256, Address, BigEndianHash}; use error::Error; use hash_db::HashDB; use keccak_hasher::KeccakHasher; @@ -255,8 +255,8 @@ impl Account { fn get_and_cache_storage(storage_root: &H256, storage_cache: &mut LruCache, db: &HashDB, key: &H256) -> TrieResult { let db = SecTrieDB::new(&db, storage_root)?; let panicky_decoder = |bytes:&[u8]| ::rlp::decode(&bytes).expect("decoding db value failed"); - let item: U256 = db.get_with(key, panicky_decoder)?.unwrap_or_else(U256::zero); - let value: H256 = item.into(); + let item: U256 = db.get_with(key.as_bytes(), panicky_decoder)?.unwrap_or_else(U256::zero); + let value: H256 = BigEndianHash::from_uint(&item); storage_cache.insert(key.clone(), value.clone()); Ok(value) } @@ -291,7 +291,7 @@ impl Account { // If storage root is empty RLP, then early return zero value. Practically, this makes it so that if // `original_storage_cache` is used, then `storage_cache` will always remain empty. if self.storage_root == KECCAK_NULL_RLP { - return Some(H256::new()); + return Some(H256::zero()); } if let Some(value) = self.storage_cache.borrow_mut().get_mut(key) { @@ -488,8 +488,8 @@ impl Account { // cast key and value to trait type, // so we can call overloaded `to_bytes` method match v.is_zero() { - true => t.remove(&k)?, - false => t.insert(&k, &encode(&U256::from(&*v)))?, + true => t.remove(k.as_bytes())?, + false => t.insert(k.as_bytes(), &encode(&v.into_uint()))?, }; self.storage_cache.borrow_mut().insert(k, v); @@ -595,10 +595,10 @@ impl Account { let item: U256 = { let panicky_decoder = |bytes:&[u8]| ::rlp::decode(bytes).expect("decoding db value failed"); let query = (&mut recorder, panicky_decoder); - trie.get_with(&storage_key, query)?.unwrap_or_else(U256::zero) + trie.get_with(storage_key.as_bytes(), query)?.unwrap_or_else(U256::zero) }; - Ok((recorder.drain().into_iter().map(|r| r.data).collect(), item.into())) + Ok((recorder.drain().into_iter().map(|r| r.data).collect(), BigEndianHash::from_uint(&item))) } } @@ -621,6 +621,7 @@ mod tests { use bytes::Bytes; use super::*; use account_db::*; + use std::str::FromStr; #[test] fn account_compress() { @@ -634,10 +635,10 @@ mod tests { #[test] fn storage_at() { let mut db = new_memory_db(); - let mut db = AccountDBMut::new(&mut db, &Address::new()); + let mut db = AccountDBMut::new(&mut db, &Address::zero()); let rlp = { let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP); - a.set_storage(0x00u64.into(), 0x1234u64.into()); + a.set_storage(H256::zero(), H256::from_low_u64_be(0x1234)); a.commit_storage(&Default::default(), &mut db).unwrap(); a.init_code(vec![]); a.commit_code(&mut db); @@ -645,15 +646,15 @@ mod tests { }; let a = Account::from_rlp(&rlp).expect("decoding db value failed"); - assert_eq!(a.storage_root().unwrap(), "c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2".into()); - assert_eq!(a.storage_at(&db.immutable(), &0x00u64.into()).unwrap(), 0x1234u64.into()); - assert_eq!(a.storage_at(&db.immutable(), &0x01u64.into()).unwrap(), H256::default()); + assert_eq!(a.storage_root().unwrap(), H256::from_str("c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2").unwrap()); + assert_eq!(a.storage_at(&db.immutable(), &H256::zero()).unwrap(), H256::from_low_u64_be(0x1234)); + assert_eq!(a.storage_at(&db.immutable(), &H256::from_low_u64_be(0x01)).unwrap(), H256::zero()); } #[test] fn note_code() { let mut db = new_memory_db(); - let mut db = AccountDBMut::new(&mut db, &Address::new()); + let mut db = AccountDBMut::new(&mut db, &Address::zero()); let rlp = { let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP); @@ -673,53 +674,53 @@ mod tests { fn commit_storage() { let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP); let mut db = new_memory_db(); - let mut db = AccountDBMut::new(&mut db, &Address::new()); - a.set_storage(0.into(), 0x1234.into()); + let mut db = AccountDBMut::new(&mut db, &Address::zero()); + a.set_storage(H256::from_low_u64_be(0), H256::from_low_u64_be(0x1234)); assert_eq!(a.storage_root(), None); a.commit_storage(&Default::default(), &mut db).unwrap(); - assert_eq!(a.storage_root().unwrap(), "c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2".into()); + assert_eq!(a.storage_root().unwrap(), H256::from_str("c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2").unwrap()); } #[test] fn commit_remove_commit_storage() { let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP); let mut db = new_memory_db(); - let mut db = AccountDBMut::new(&mut db, &Address::new()); - a.set_storage(0.into(), 0x1234.into()); + let mut db = AccountDBMut::new(&mut db, &Address::zero()); + a.set_storage(H256::from_low_u64_be(0), H256::from_low_u64_be(0x1234)); a.commit_storage(&Default::default(), &mut db).unwrap(); - a.set_storage(1.into(), 0x1234.into()); + a.set_storage(H256::from_low_u64_be(1), H256::from_low_u64_be(0x1234)); a.commit_storage(&Default::default(), &mut db).unwrap(); - a.set_storage(1.into(), 0.into()); + a.set_storage(H256::from_low_u64_be(1), H256::from_low_u64_be(0)); a.commit_storage(&Default::default(), &mut db).unwrap(); - assert_eq!(a.storage_root().unwrap(), "c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2".into()); + assert_eq!(a.storage_root().unwrap(), H256::from_str("c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2").unwrap()); } #[test] fn commit_code() { let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP); let mut db = new_memory_db(); - let mut db = AccountDBMut::new(&mut db, &Address::new()); + let mut db = AccountDBMut::new(&mut db, &Address::zero()); a.init_code(vec![0x55, 0x44, 0xffu8]); assert_eq!(a.code_filth, Filth::Dirty); assert_eq!(a.code_size(), Some(3)); a.commit_code(&mut db); - assert_eq!(a.code_hash(), "af231e631776a517ca23125370d542873eca1fb4d613ed9b5d5335a46ae5b7eb".into()); + assert_eq!(a.code_hash(), H256::from_str("af231e631776a517ca23125370d542873eca1fb4d613ed9b5d5335a46ae5b7eb").unwrap()); } #[test] fn reset_code() { let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP); let mut db = new_memory_db(); - let mut db = AccountDBMut::new(&mut db, &Address::new()); + let mut db = AccountDBMut::new(&mut db, &Address::zero()); a.init_code(vec![0x55, 0x44, 0xffu8]); assert_eq!(a.code_filth, Filth::Dirty); a.commit_code(&mut db); assert_eq!(a.code_filth, Filth::Clean); - assert_eq!(a.code_hash(), "af231e631776a517ca23125370d542873eca1fb4d613ed9b5d5335a46ae5b7eb".into()); + assert_eq!(a.code_hash(), H256::from_str("af231e631776a517ca23125370d542873eca1fb4d613ed9b5d5335a46ae5b7eb").unwrap()); a.reset_code(vec![0x55]); assert_eq!(a.code_filth, Filth::Dirty); a.commit_code(&mut db); - assert_eq!(a.code_hash(), "37bf2238b11b68cdc8382cece82651b59d3c3988873b6e0f33d79694aa45f1be".into()); + assert_eq!(a.code_hash(), H256::from_str("37bf2238b11b68cdc8382cece82651b59d3c3988873b6e0f33d79694aa45f1be").unwrap()); } #[test] diff --git a/ethcore/src/state/mod.rs b/ethcore/src/state/mod.rs index ddad10c40..d0d57287d 100644 --- a/ethcore/src/state/mod.rs +++ b/ethcore/src/state/mod.rs @@ -363,7 +363,7 @@ impl State { /// Creates new state with empty state root /// Used for tests. pub fn new(mut db: B, account_start_nonce: U256, factories: Factories) -> State { - let mut root = H256::new(); + let mut root = H256::zero(); { // init trie and reset root to null let _ = factories.trie.create(db.as_hash_db_mut(), &mut root); @@ -502,7 +502,7 @@ impl State { let original_storage_root = self.original_storage_root(contract)?; let (nonce, overflow) = self.account_start_nonce.overflowing_add(nonce_offset); if overflow { - return Err(Box::new(TrieError::DecoderError(H256::from(contract), + return Err(Box::new(TrieError::DecoderError(H256::from(*contract), rlp::DecoderError::Custom("Nonce overflow".into())))); } self.insert_cache(contract, AccountEntry::new_dirty(Some(Account::new_contract(balance, nonce, original_storage_root)))); @@ -603,12 +603,12 @@ impl State { // would always be empty. Note that this branch is actually never called, because // `cached_storage_at` handled this case. warn!(target: "state", "Trying to get an account's cached storage value, but base storage root does not equal to original storage root! Assuming the value is empty."); - return Ok(Some(H256::new())); + return Ok(Some(H256::zero())); } } }, // The account didn't exist at that point. Return empty value. - Some(Some(AccountEntry { account: None, .. })) => return Ok(Some(H256::new())), + Some(Some(AccountEntry { account: None, .. })) => return Ok(Some(H256::zero())), // The value was not cached at that checkpoint, meaning it was not modified at all. Some(None) => { kind = Some(ReturnKind::OriginalAt); @@ -658,12 +658,12 @@ impl State { local_account = Some(maybe_acc); } }, - _ => return Ok(H256::new()), + _ => return Ok(H256::zero()), } } // check the global cache and and cache storage key there if found, let trie_res = self.db.get_cached(address, |acc| match acc { - None => Ok(H256::new()), + None => Ok(H256::zero()), Some(a) => { let account_db = self.factories.accountdb.readonly(self.db.as_hash_db(), a.address_hash(address)); f_at(a, account_db.as_hash_db(), key) @@ -680,7 +680,7 @@ impl State { let account_db = self.factories.accountdb.readonly(self.db.as_hash_db(), account.address_hash(address)); return f_at(account, account_db.as_hash_db(), key) } else { - return Ok(H256::new()) + return Ok(H256::zero()) } } } @@ -692,8 +692,8 @@ impl State { let db = &self.db.as_hash_db(); let db = self.factories.trie.readonly(db, &self.root).expect(SEC_TRIE_DB_UNWRAP_STR); let from_rlp = |b: &[u8]| Account::from_rlp(b).expect("decoding db value failed"); - let maybe_acc = db.get_with(address, from_rlp)?; - let r = maybe_acc.as_ref().map_or(Ok(H256::new()), |a| { + let maybe_acc = db.get_with(address.as_bytes(), from_rlp)?; + let r = maybe_acc.as_ref().map_or(Ok(H256::zero()), |a| { let account_db = self.factories.accountdb.readonly(self.db.as_hash_db(), a.address_hash(address)); f_at(a, account_db.as_hash_db(), key) }); @@ -904,10 +904,10 @@ impl State { a.state = AccountState::Committed; match a.account { Some(ref mut account) => { - trie.insert(address, &account.rlp())?; + trie.insert(address.as_bytes(), &account.rlp())?; }, None => { - trie.remove(address)?; + trie.remove(address.as_bytes())?; }, }; } @@ -1011,6 +1011,8 @@ impl State { /// It requires FatDB. #[cfg(feature="to-pod-full")] fn account_to_pod_account(&self, account: &Account, address: &Address) -> Result { + use ethereum_types::BigEndianHash; + let mut pod_storage = BTreeMap::new(); let addr_hash = account.address_hash(address); let accountdb = self.factories.accountdb.readonly(self.db.as_hash_db(), addr_hash); @@ -1020,7 +1022,12 @@ impl State { let trie = self.factories.trie.readonly(accountdb, &root)?; for o_kv in trie.iter()? { if let Ok((key, val)) = o_kv { - pod_storage.insert(key[..].into(), rlp::decode::(&val[..]).expect("Decoded from trie which was encoded from the same type; qed").into()); + pod_storage.insert( + H256::from_slice(&key[..]), + BigEndianHash::from_uint( + &rlp::decode::(&val[..]).expect("Decoded from trie which was encoded from the same type; qed") + ), + ); } } @@ -1141,7 +1148,7 @@ impl State { if Self::update_account_cache(require, account, &self.db, accountdb.as_hash_db()) { return Ok(f(Some(account))); } else { - return Err(Box::new(TrieError::IncompleteDatabase(H256::from(a)))); + return Err(Box::new(TrieError::IncompleteDatabase(H256::from(*a)))); } } return Ok(f(None)); @@ -1151,7 +1158,7 @@ impl State { if let Some(ref mut account) = acc { let accountdb = self.factories.accountdb.readonly(self.db.as_hash_db(), account.address_hash(a)); if !Self::update_account_cache(require, account, &self.db, accountdb.as_hash_db()) { - return Err(Box::new(TrieError::IncompleteDatabase(H256::from(a)))); + return Err(Box::new(TrieError::IncompleteDatabase(H256::from(*a)))); } } Ok(f(acc.map(|a| &*a))) @@ -1166,11 +1173,11 @@ impl State { let db = &self.db.as_hash_db(); let db = self.factories.trie.readonly(db, &self.root)?; let from_rlp = |b: &[u8]| Account::from_rlp(b).expect("decoding db value failed"); - let mut maybe_acc = db.get_with(a, from_rlp)?; + let mut maybe_acc = db.get_with(a.as_bytes(), from_rlp)?; if let Some(ref mut account) = maybe_acc.as_mut() { let accountdb = self.factories.accountdb.readonly(self.db.as_hash_db(), account.address_hash(a)); if !Self::update_account_cache(require, account, &self.db, accountdb.as_hash_db()) { - return Err(Box::new(TrieError::IncompleteDatabase(H256::from(a)))); + return Err(Box::new(TrieError::IncompleteDatabase(H256::from(*a)))); } } let r = f(maybe_acc.as_ref()); @@ -1199,7 +1206,7 @@ impl State { let db = &self.db.as_hash_db(); let db = self.factories.trie.readonly(db, &self.root)?; let from_rlp = |b:&[u8]| { Account::from_rlp(b).expect("decoding db value failed") }; - AccountEntry::new_clean(db.get_with(a, from_rlp)?) + AccountEntry::new_clean(db.get_with(a.as_bytes(), from_rlp)?) } else { AccountEntry::new_clean(None) }; @@ -1228,7 +1235,7 @@ impl State { let accountdb = self.factories.accountdb.readonly(self.db.as_hash_db(), addr_hash); if !Self::update_account_cache(RequireCache::Code, &mut account, &self.db, accountdb.as_hash_db()) { - return Err(Box::new(TrieError::IncompleteDatabase(H256::from(a)))) + return Err(Box::new(TrieError::IncompleteDatabase(H256::from(*a)))) } } @@ -1257,7 +1264,7 @@ impl State { ::rlp::decode(bytes).unwrap_or_else(|_| panic!("prove_account, could not query trie for account key={}", &account_key)) }; let query = (&mut recorder, panicky_decoder); - trie.get_with(&account_key, query)? + trie.get_with(account_key.as_bytes(), query)? }; let account = maybe_account.unwrap_or_else(|| BasicAccount { balance: 0.into(), @@ -1280,9 +1287,9 @@ impl State { let db = &self.db.as_hash_db(); let trie = TrieDB::new(db, &self.root)?; let from_rlp = |b: &[u8]| Account::from_rlp(b).expect("decoding db value failed"); - let acc = match trie.get_with(&account_key, from_rlp)? { + let acc = match trie.get_with(account_key.as_bytes(), from_rlp)? { Some(acc) => acc, - None => return Ok((Vec::new(), H256::new())), + None => return Ok((Vec::new(), H256::zero())), }; let account_db = self.factories.accountdb.readonly(self.db.as_hash_db(), account_key); @@ -1336,7 +1343,7 @@ mod tests { use hash::{keccak, KECCAK_NULL_RLP}; use super::*; use ethkey::Secret; - use ethereum_types::{H256, U256, Address}; + use ethereum_types::{H256, U256, Address, BigEndianHash}; use test_helpers::{get_temp_state, get_temp_state_db}; use machine::EthereumMachine; use vm::EnvInfo; @@ -1380,7 +1387,7 @@ mod tests { trace_address: Default::default(), subtraces: 0, action: trace::Action::Create(trace::Create { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), + from: Address::from_str("9cce34f7ab185c7aba1b7c8140d620b4bda941d6").unwrap(), value: 100.into(), gas: 77412.into(), init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85], @@ -1437,7 +1444,7 @@ mod tests { let expected_trace = vec![FlatTrace { trace_address: Default::default(), action: trace::Action::Create(trace::Create { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), + from: Address::from_str("9cce34f7ab185c7aba1b7c8140d620b4bda941d6").unwrap(), value: 100.into(), gas: 78792.into(), init: vec![91, 96, 0, 86], @@ -1463,19 +1470,19 @@ mod tests { nonce: 0.into(), gas_price: 0.into(), gas: 100_000.into(), - action: Action::Call(0xa.into()), + action: Action::Call(Address::from_low_u64_be(0xa)), value: 100.into(), data: vec![], }.sign(&secret(), None); - state.init_code(&0xa.into(), FromHex::from_hex("6000").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xa), FromHex::from_hex("6000").unwrap()).unwrap(); state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap(); let result = state.apply(&info, &machine, &t, true).unwrap(); let expected_trace = vec![FlatTrace { trace_address: Default::default(), action: trace::Action::Call(trace::Call { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), - to: 0xa.into(), + from: Address::from_str("9cce34f7ab185c7aba1b7c8140d620b4bda941d6").unwrap(), + to: Address::from_low_u64_be(0xa), value: 100.into(), gas: 79000.into(), input: vec![], @@ -1505,7 +1512,7 @@ mod tests { nonce: 0.into(), gas_price: 0.into(), gas: 100_000.into(), - action: Action::Call(0xa.into()), + action: Action::Call(Address::from_low_u64_be(0xa)), value: 100.into(), data: vec![], }.sign(&secret(), None); @@ -1515,8 +1522,8 @@ mod tests { let expected_trace = vec![FlatTrace { trace_address: Default::default(), action: trace::Action::Call(trace::Call { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), - to: 0xa.into(), + from: Address::from_str("9cce34f7ab185c7aba1b7c8140d620b4bda941d6").unwrap(), + to: Address::from_low_u64_be(0xa), value: 100.into(), gas: 79000.into(), input: vec![], @@ -1546,7 +1553,7 @@ mod tests { nonce: 0.into(), gas_price: 0.into(), gas: 100_000.into(), - action: Action::Call(0x1.into()), + action: Action::Call(Address::from_low_u64_be(0x1)), value: 0.into(), data: vec![], }.sign(&secret(), None); @@ -1556,8 +1563,8 @@ mod tests { let expected_trace = vec![FlatTrace { trace_address: Default::default(), action: trace::Action::Call(trace::Call { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), - to: "0000000000000000000000000000000000000001".into(), + from: Address::from_str("9cce34f7ab185c7aba1b7c8140d620b4bda941d6").unwrap(), + to: Address::from_str("0000000000000000000000000000000000000001").unwrap(), value: 0.into(), gas: 79_000.into(), input: vec![], @@ -1587,19 +1594,19 @@ mod tests { nonce: 0.into(), gas_price: 0.into(), gas: 100_000.into(), - action: Action::Call(0xa.into()), + action: Action::Call(Address::from_low_u64_be(0xa)), value: 0.into(), data: vec![], }.sign(&secret(), None); - state.init_code(&0xa.into(), FromHex::from_hex("600060006000600060006001610be0f1").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xa), FromHex::from_hex("600060006000600060006001610be0f1").unwrap()).unwrap(); let result = state.apply(&info, &machine, &t, true).unwrap(); let expected_trace = vec![FlatTrace { trace_address: Default::default(), action: trace::Action::Call(trace::Call { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), - to: 0xa.into(), + from: Address::from_str("9cce34f7ab185c7aba1b7c8140d620b4bda941d6").unwrap(), + to: Address::from_low_u64_be(0xa), value: 0.into(), gas: 79000.into(), input: vec![], @@ -1629,21 +1636,21 @@ mod tests { nonce: 0.into(), gas_price: 0.into(), gas: 100_000.into(), - action: Action::Call(0xa.into()), + action: Action::Call(Address::from_low_u64_be(0xa)), value: 0.into(), data: vec![], }.sign(&secret(), None); - state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b611000f2").unwrap()).unwrap(); - state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xa), FromHex::from_hex("60006000600060006000600b611000f2").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xb), FromHex::from_hex("6000").unwrap()).unwrap(); let result = state.apply(&info, &machine, &t, true).unwrap(); let expected_trace = vec![FlatTrace { trace_address: Default::default(), subtraces: 1, action: trace::Action::Call(trace::Call { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), - to: 0xa.into(), + from: Address::from_str("9cce34f7ab185c7aba1b7c8140d620b4bda941d6").unwrap(), + to: Address::from_low_u64_be(0xa), value: 0.into(), gas: 79000.into(), input: vec![], @@ -1657,8 +1664,8 @@ mod tests { trace_address: vec![0].into_iter().collect(), subtraces: 0, action: trace::Action::Call(trace::Call { - from: 0xa.into(), - to: 0xb.into(), + from: Address::from_low_u64_be(0xa), + to: Address::from_low_u64_be(0xb), value: 0.into(), gas: 4096.into(), input: vec![], @@ -1688,21 +1695,21 @@ mod tests { nonce: 0.into(), gas_price: 0.into(), gas: 100_000.into(), - action: Action::Call(0xa.into()), + action: Action::Call(Address::from_low_u64_be(0xa)), value: 0.into(), data: vec![], }.sign(&secret(), None); - state.init_code(&0xa.into(), FromHex::from_hex("6000600060006000600b618000f4").unwrap()).unwrap(); - state.init_code(&0xb.into(), FromHex::from_hex("60056000526001601ff3").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xa), FromHex::from_hex("6000600060006000600b618000f4").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xb), FromHex::from_hex("60056000526001601ff3").unwrap()).unwrap(); let result = state.apply(&info, &machine, &t, true).unwrap(); let expected_trace = vec![FlatTrace { trace_address: Default::default(), subtraces: 1, action: trace::Action::Call(trace::Call { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), - to: 0xa.into(), + from: Address::from_str("9cce34f7ab185c7aba1b7c8140d620b4bda941d6").unwrap(), + to: Address::from_low_u64_be(0xa), value: 0.into(), gas: 79000.into(), input: vec![], @@ -1716,8 +1723,8 @@ mod tests { trace_address: vec![0].into_iter().collect(), subtraces: 0, action: trace::Action::Call(trace::Call { - from: 0xa.into(), - to: 0xb.into(), + from: Address::from_low_u64_be(0xa), + to: Address::from_low_u64_be(0xb), value: 0.into(), gas: 32768.into(), input: vec![], @@ -1746,19 +1753,19 @@ mod tests { nonce: 0.into(), gas_price: 0.into(), gas: 100_000.into(), - action: Action::Call(0xa.into()), + action: Action::Call(Address::from_low_u64_be(0xa)), value: 100.into(), data: vec![], }.sign(&secret(), None); - state.init_code(&0xa.into(), FromHex::from_hex("5b600056").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xa), FromHex::from_hex("5b600056").unwrap()).unwrap(); state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap(); let result = state.apply(&info, &machine, &t, true).unwrap(); let expected_trace = vec![FlatTrace { trace_address: Default::default(), action: trace::Action::Call(trace::Call { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), - to: 0xa.into(), + from: Address::from_str("9cce34f7ab185c7aba1b7c8140d620b4bda941d6").unwrap(), + to: Address::from_low_u64_be(0xa), value: 100.into(), gas: 79000.into(), input: vec![], @@ -1785,13 +1792,13 @@ mod tests { nonce: 0.into(), gas_price: 0.into(), gas: 100_000.into(), - action: Action::Call(0xa.into()), + action: Action::Call(Address::from_low_u64_be(0xa)), value: 100.into(), data: vec![], }.sign(&secret(), None); - state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap()).unwrap(); - state.init_code(&0xb.into(), FromHex::from_hex("6000").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xa), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xb), FromHex::from_hex("6000").unwrap()).unwrap(); state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap(); let result = state.apply(&info, &machine, &t, true).unwrap(); @@ -1799,8 +1806,8 @@ mod tests { trace_address: Default::default(), subtraces: 1, action: trace::Action::Call(trace::Call { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), - to: 0xa.into(), + from: Address::from_str("9cce34f7ab185c7aba1b7c8140d620b4bda941d6").unwrap(), + to: Address::from_low_u64_be(0xa), value: 100.into(), gas: 79000.into(), input: vec![], @@ -1814,8 +1821,8 @@ mod tests { trace_address: vec![0].into_iter().collect(), subtraces: 0, action: trace::Action::Call(trace::Call { - from: 0xa.into(), - to: 0xb.into(), + from: Address::from_low_u64_be(0xa), + to: Address::from_low_u64_be(0xb), value: 0.into(), gas: 78934.into(), input: vec![], @@ -1844,20 +1851,20 @@ mod tests { nonce: 0.into(), gas_price: 0.into(), gas: 100_000.into(), - action: Action::Call(0xa.into()), + action: Action::Call(Address::from_low_u64_be(0xa)), value: 100.into(), data: vec![], }.sign(&secret(), None); - state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006045600b6000f1").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xa), FromHex::from_hex("60006000600060006045600b6000f1").unwrap()).unwrap(); state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap(); let result = state.apply(&info, &machine, &t, true).unwrap(); let expected_trace = vec![FlatTrace { trace_address: Default::default(), subtraces: 1, action: trace::Action::Call(trace::Call { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), - to: 0xa.into(), + from: Address::from_str("9cce34f7ab185c7aba1b7c8140d620b4bda941d6").unwrap(), + to: Address::from_low_u64_be(0xa), value: 100.into(), gas: 79000.into(), input: vec![], @@ -1871,8 +1878,8 @@ mod tests { trace_address: vec![0].into_iter().collect(), subtraces: 0, action: trace::Action::Call(trace::Call { - from: 0xa.into(), - to: 0xb.into(), + from: Address::from_low_u64_be(0xa), + to: Address::from_low_u64_be(0xb), value: 69.into(), gas: 2300.into(), input: vec![], @@ -1898,20 +1905,20 @@ mod tests { nonce: 0.into(), gas_price: 0.into(), gas: 100_000.into(), - action: Action::Call(0xa.into()), + action: Action::Call(Address::from_low_u64_be(0xa)), value: 100.into(), data: vec![], }.sign(&secret(), None); - state.init_code(&0xa.into(), FromHex::from_hex("600060006000600060ff600b6000f1").unwrap()).unwrap(); // not enough funds. + state.init_code(&Address::from_low_u64_be(0xa), FromHex::from_hex("600060006000600060ff600b6000f1").unwrap()).unwrap(); // not enough funds. state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap(); let result = state.apply(&info, &machine, &t, true).unwrap(); let expected_trace = vec![FlatTrace { trace_address: Default::default(), subtraces: 0, action: trace::Action::Call(trace::Call { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), - to: 0xa.into(), + from: Address::from_str("9cce34f7ab185c7aba1b7c8140d620b4bda941d6").unwrap(), + to: Address::from_low_u64_be(0xa), value: 100.into(), gas: 79000.into(), input: vec![], @@ -1940,21 +1947,21 @@ mod tests { nonce: 0.into(), gas_price: 0.into(), gas: 100_000.into(), - action: Action::Call(0xa.into()), + action: Action::Call(Address::from_low_u64_be(0xa)), value: 100.into(), data: vec![],//600480600b6000396000f35b600056 }.sign(&secret(), None); - state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap()).unwrap(); - state.init_code(&0xb.into(), FromHex::from_hex("5b600056").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xa), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xb), FromHex::from_hex("5b600056").unwrap()).unwrap(); state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap(); let result = state.apply(&info, &machine, &t, true).unwrap(); let expected_trace = vec![FlatTrace { trace_address: Default::default(), subtraces: 1, action: trace::Action::Call(trace::Call { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), - to: 0xa.into(), + from: Address::from_str("9cce34f7ab185c7aba1b7c8140d620b4bda941d6").unwrap(), + to: Address::from_low_u64_be(0xa), value: 100.into(), gas: 79000.into(), input: vec![], @@ -1968,8 +1975,8 @@ mod tests { trace_address: vec![0].into_iter().collect(), subtraces: 0, action: trace::Action::Call(trace::Call { - from: 0xa.into(), - to: 0xb.into(), + from: Address::from_low_u64_be(0xa), + to: Address::from_low_u64_be(0xb), value: 0.into(), gas: 78934.into(), input: vec![], @@ -1995,22 +2002,22 @@ mod tests { nonce: 0.into(), gas_price: 0.into(), gas: 100_000.into(), - action: Action::Call(0xa.into()), + action: Action::Call(Address::from_low_u64_be(0xa)), value: 100.into(), data: vec![], }.sign(&secret(), None); - state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap()).unwrap(); - state.init_code(&0xb.into(), FromHex::from_hex("60006000600060006000600c602b5a03f1").unwrap()).unwrap(); - state.init_code(&0xc.into(), FromHex::from_hex("6000").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xa), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xb), FromHex::from_hex("60006000600060006000600c602b5a03f1").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xc), FromHex::from_hex("6000").unwrap()).unwrap(); state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap(); let result = state.apply(&info, &machine, &t, true).unwrap(); let expected_trace = vec![FlatTrace { trace_address: Default::default(), subtraces: 1, action: trace::Action::Call(trace::Call { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), - to: 0xa.into(), + from: Address::from_str("9cce34f7ab185c7aba1b7c8140d620b4bda941d6").unwrap(), + to: Address::from_low_u64_be(0xa), value: 100.into(), gas: 79000.into(), input: vec![], @@ -2024,8 +2031,8 @@ mod tests { trace_address: vec![0].into_iter().collect(), subtraces: 1, action: trace::Action::Call(trace::Call { - from: 0xa.into(), - to: 0xb.into(), + from: Address::from_low_u64_be(0xa), + to: Address::from_low_u64_be(0xb), value: 0.into(), gas: 78934.into(), input: vec![], @@ -2039,8 +2046,8 @@ mod tests { trace_address: vec![0, 0].into_iter().collect(), subtraces: 0, action: trace::Action::Call(trace::Call { - from: 0xb.into(), - to: 0xc.into(), + from: Address::from_low_u64_be(0xb), + to: Address::from_low_u64_be(0xc), value: 0.into(), gas: 78868.into(), input: vec![], @@ -2069,14 +2076,14 @@ mod tests { nonce: 0.into(), gas_price: 0.into(), gas: 100_000.into(), - action: Action::Call(0xa.into()), + action: Action::Call(Address::from_low_u64_be(0xa)), value: 100.into(), data: vec![],//600480600b6000396000f35b600056 }.sign(&secret(), None); - state.init_code(&0xa.into(), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap()).unwrap(); - state.init_code(&0xb.into(), FromHex::from_hex("60006000600060006000600c602b5a03f1505b601256").unwrap()).unwrap(); - state.init_code(&0xc.into(), FromHex::from_hex("6000").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xa), FromHex::from_hex("60006000600060006000600b602b5a03f1").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xb), FromHex::from_hex("60006000600060006000600c602b5a03f1505b601256").unwrap()).unwrap(); + state.init_code(&Address::from_low_u64_be(0xc), FromHex::from_hex("6000").unwrap()).unwrap(); state.add_balance(&t.sender(), &(100.into()), CleanupMode::NoEmpty).unwrap(); let result = state.apply(&info, &machine, &t, true).unwrap(); @@ -2084,8 +2091,8 @@ mod tests { trace_address: Default::default(), subtraces: 1, action: trace::Action::Call(trace::Call { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), - to: 0xa.into(), + from: Address::from_str("9cce34f7ab185c7aba1b7c8140d620b4bda941d6").unwrap(), + to: Address::from_low_u64_be(0xa), value: 100.into(), gas: 79000.into(), input: vec![], @@ -2099,8 +2106,8 @@ mod tests { trace_address: vec![0].into_iter().collect(), subtraces: 1, action: trace::Action::Call(trace::Call { - from: 0xa.into(), - to: 0xb.into(), + from: Address::from_low_u64_be(0xa), + to: Address::from_low_u64_be(0xb), value: 0.into(), gas: 78934.into(), input: vec![], @@ -2111,8 +2118,8 @@ mod tests { trace_address: vec![0, 0].into_iter().collect(), subtraces: 0, action: trace::Action::Call(trace::Call { - from: 0xb.into(), - to: 0xc.into(), + from: Address::from_low_u64_be(0xb), + to: Address::from_low_u64_be(0xc), value: 0.into(), gas: 78868.into(), call_type: CallType::Call, @@ -2141,21 +2148,21 @@ mod tests { nonce: 0.into(), gas_price: 0.into(), gas: 100_000.into(), - action: Action::Call(0xa.into()), + action: Action::Call(Address::from_low_u64_be(0xa)), value: 100.into(), data: vec![], }.sign(&secret(), None); - state.init_code(&0xa.into(), FromHex::from_hex("73000000000000000000000000000000000000000bff").unwrap()).unwrap(); - state.add_balance(&0xa.into(), &50.into(), CleanupMode::NoEmpty).unwrap(); + state.init_code(&Address::from_low_u64_be(0xa), FromHex::from_hex("73000000000000000000000000000000000000000bff").unwrap()).unwrap(); + state.add_balance(&Address::from_low_u64_be(0xa), &50.into(), CleanupMode::NoEmpty).unwrap(); state.add_balance(&t.sender(), &100.into(), CleanupMode::NoEmpty).unwrap(); let result = state.apply(&info, &machine, &t, true).unwrap(); let expected_trace = vec![FlatTrace { trace_address: Default::default(), subtraces: 1, action: trace::Action::Call(trace::Call { - from: "9cce34f7ab185c7aba1b7c8140d620b4bda941d6".into(), - to: 0xa.into(), + from: Address::from_str("9cce34f7ab185c7aba1b7c8140d620b4bda941d6").unwrap(), + to: Address::from_low_u64_be(0xa), value: 100.into(), gas: 79000.into(), input: vec![], @@ -2169,8 +2176,8 @@ mod tests { trace_address: vec![0].into_iter().collect(), subtraces: 0, action: trace::Action::Suicide(trace::Suicide { - address: 0xa.into(), - refund_address: 0xb.into(), + address: Address::from_low_u64_be(0xa), + refund_address: Address::from_low_u64_be(0xb), balance: 150.into(), }), result: trace::Res::None, @@ -2201,13 +2208,15 @@ mod tests { let a = Address::zero(); let (root, db) = { let mut state = get_temp_state(); - state.set_storage(&a, H256::from(&U256::from(1u64)), H256::from(&U256::from(69u64))).unwrap(); + state.set_storage(&a, BigEndianHash::from_uint(&U256::from(1u64)), BigEndianHash::from_uint(&U256::from(69u64))).unwrap(); state.commit().unwrap(); state.drop() }; let s = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap(); - assert_eq!(s.storage_at(&a, &H256::from(&U256::from(1u64))).unwrap(), H256::from(&U256::from(69u64))); + let h1 = BigEndianHash::from_uint(&U256::from(1u64)); + let h2 = BigEndianHash::from_uint(&U256::from(69u64)); + assert_eq!(s.storage_at(&a, &h1).unwrap(), h2); } #[test] @@ -2305,7 +2314,7 @@ mod tests { fn alter_balance() { let mut state = get_temp_state(); let a = Address::zero(); - let b = 1u64.into(); + let b = Address::from_low_u64_be(1u64); state.add_balance(&a, &U256::from(69u64), CleanupMode::NoEmpty).unwrap(); assert_eq!(state.balance(&a).unwrap(), U256::from(69u64)); state.commit().unwrap(); @@ -2355,7 +2364,7 @@ mod tests { let a = Address::zero(); state.require(&a, false).unwrap(); state.commit().unwrap(); - assert_eq!(*state.root(), "0ce23f3c809de377b008a4a3ee94a0834aac8bec1f86e28ffe4fdb5a15b0c785".into()); + assert_eq!(*state.root(), H256::from_str("0ce23f3c809de377b008a4a3ee94a0834aac8bec1f86e28ffe4fdb5a15b0c785").unwrap()); } #[test] @@ -2392,162 +2401,162 @@ mod tests { fn checkpoint_revert_to_get_storage_at() { let mut state = get_temp_state(); let a = Address::zero(); - let k = H256::from(U256::from(0)); + let k = BigEndianHash::from_uint(&U256::from(0)); let c0 = state.checkpoint(); let c1 = state.checkpoint(); - state.set_storage(&a, k, H256::from(U256::from(1))).unwrap(); + state.set_storage(&a, k, BigEndianHash::from_uint(&U256::from(1))).unwrap(); - assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); - assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); - assert_eq!(state.storage_at(&a, &k).unwrap(), H256::from(U256::from(1))); + assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); + assert_eq!(state.storage_at(&a, &k).unwrap(), BigEndianHash::from_uint(&U256::from(1))); state.revert_to_checkpoint(); // Revert to c1. - assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); - assert_eq!(state.storage_at(&a, &k).unwrap(), H256::from(U256::from(0))); + assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); + assert_eq!(state.storage_at(&a, &k).unwrap(), BigEndianHash::from_uint(&U256::from(0))); } #[test] fn checkpoint_from_empty_get_storage_at() { let mut state = get_temp_state(); let a = Address::zero(); - let k = H256::from(U256::from(0)); - let k2 = H256::from(U256::from(1)); + let k = BigEndianHash::from_uint(&U256::from(0)); + let k2 = BigEndianHash::from_uint(&U256::from(1)); - assert_eq!(state.storage_at(&a, &k).unwrap(), H256::from(U256::from(0))); + assert_eq!(state.storage_at(&a, &k).unwrap(), BigEndianHash::from_uint(&U256::from(0))); state.clear(); let c0 = state.checkpoint(); state.new_contract(&a, U256::zero(), U256::zero()).unwrap(); let c1 = state.checkpoint(); - state.set_storage(&a, k, H256::from(U256::from(1))).unwrap(); + state.set_storage(&a, k, BigEndianHash::from_uint(&U256::from(1))).unwrap(); let c2 = state.checkpoint(); let c3 = state.checkpoint(); - state.set_storage(&a, k2, H256::from(U256::from(3))).unwrap(); - state.set_storage(&a, k, H256::from(U256::from(3))).unwrap(); + state.set_storage(&a, k2, BigEndianHash::from_uint(&U256::from(3))).unwrap(); + state.set_storage(&a, k, BigEndianHash::from_uint(&U256::from(3))).unwrap(); let c4 = state.checkpoint(); - state.set_storage(&a, k, H256::from(U256::from(4))).unwrap(); + state.set_storage(&a, k, BigEndianHash::from_uint(&U256::from(4))).unwrap(); let c5 = state.checkpoint(); - assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); - assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); - assert_eq!(state.checkpoint_storage_at(c2, &a, &k).unwrap(), Some(H256::from(U256::from(1)))); - assert_eq!(state.checkpoint_storage_at(c3, &a, &k).unwrap(), Some(H256::from(U256::from(1)))); - assert_eq!(state.checkpoint_storage_at(c4, &a, &k).unwrap(), Some(H256::from(U256::from(3)))); - assert_eq!(state.checkpoint_storage_at(c5, &a, &k).unwrap(), Some(H256::from(U256::from(4)))); + assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(c2, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(1)))); + assert_eq!(state.checkpoint_storage_at(c3, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(1)))); + assert_eq!(state.checkpoint_storage_at(c4, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(3)))); + assert_eq!(state.checkpoint_storage_at(c5, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(4)))); state.discard_checkpoint(); // Commit/discard c5. - assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); - assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); - assert_eq!(state.checkpoint_storage_at(c2, &a, &k).unwrap(), Some(H256::from(U256::from(1)))); - assert_eq!(state.checkpoint_storage_at(c3, &a, &k).unwrap(), Some(H256::from(U256::from(1)))); - assert_eq!(state.checkpoint_storage_at(c4, &a, &k).unwrap(), Some(H256::from(U256::from(3)))); + assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(c2, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(1)))); + assert_eq!(state.checkpoint_storage_at(c3, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(1)))); + assert_eq!(state.checkpoint_storage_at(c4, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(3)))); state.revert_to_checkpoint(); // Revert to c4. - assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); - assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); - assert_eq!(state.checkpoint_storage_at(c2, &a, &k).unwrap(), Some(H256::from(U256::from(1)))); - assert_eq!(state.checkpoint_storage_at(c3, &a, &k).unwrap(), Some(H256::from(U256::from(1)))); + assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(c2, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(1)))); + assert_eq!(state.checkpoint_storage_at(c3, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(1)))); state.discard_checkpoint(); // Commit/discard c3. - assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); - assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); - assert_eq!(state.checkpoint_storage_at(c2, &a, &k).unwrap(), Some(H256::from(U256::from(1)))); + assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(c2, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(1)))); state.revert_to_checkpoint(); // Revert to c2. - assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); - assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); state.discard_checkpoint(); // Commit/discard c1. - assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); } #[test] fn checkpoint_get_storage_at() { let mut state = get_temp_state(); let a = Address::zero(); - let k = H256::from(U256::from(0)); - let k2 = H256::from(U256::from(1)); + let k = BigEndianHash::from_uint(&U256::from(0)); + let k2 = BigEndianHash::from_uint(&U256::from(1)); - state.set_storage(&a, k, H256::from(U256::from(0xffff))).unwrap(); + state.set_storage(&a, k, BigEndianHash::from_uint(&U256::from(0xffff))).unwrap(); state.commit().unwrap(); state.clear(); - assert_eq!(state.storage_at(&a, &k).unwrap(), H256::from(U256::from(0xffff))); + assert_eq!(state.storage_at(&a, &k).unwrap(), BigEndianHash::from_uint(&U256::from(0xffff))); state.clear(); let cm1 = state.checkpoint(); let c0 = state.checkpoint(); state.new_contract(&a, U256::zero(), U256::zero()).unwrap(); let c1 = state.checkpoint(); - state.set_storage(&a, k, H256::from(U256::from(1))).unwrap(); + state.set_storage(&a, k, BigEndianHash::from_uint(&U256::from(1))).unwrap(); let c2 = state.checkpoint(); let c3 = state.checkpoint(); - state.set_storage(&a, k2, H256::from(U256::from(3))).unwrap(); - state.set_storage(&a, k, H256::from(U256::from(3))).unwrap(); + state.set_storage(&a, k2, BigEndianHash::from_uint(&U256::from(3))).unwrap(); + state.set_storage(&a, k, BigEndianHash::from_uint(&U256::from(3))).unwrap(); let c4 = state.checkpoint(); - state.set_storage(&a, k, H256::from(U256::from(4))).unwrap(); + state.set_storage(&a, k, BigEndianHash::from_uint(&U256::from(4))).unwrap(); let c5 = state.checkpoint(); - assert_eq!(state.checkpoint_storage_at(cm1, &a, &k).unwrap(), Some(H256::from(U256::from(0xffff)))); - assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(H256::from(U256::from(0xffff)))); - assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); - assert_eq!(state.checkpoint_storage_at(c2, &a, &k).unwrap(), Some(H256::from(U256::from(1)))); - assert_eq!(state.checkpoint_storage_at(c3, &a, &k).unwrap(), Some(H256::from(U256::from(1)))); - assert_eq!(state.checkpoint_storage_at(c4, &a, &k).unwrap(), Some(H256::from(U256::from(3)))); - assert_eq!(state.checkpoint_storage_at(c5, &a, &k).unwrap(), Some(H256::from(U256::from(4)))); + assert_eq!(state.checkpoint_storage_at(cm1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0xffff)))); + assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0xffff)))); + assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(c2, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(1)))); + assert_eq!(state.checkpoint_storage_at(c3, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(1)))); + assert_eq!(state.checkpoint_storage_at(c4, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(3)))); + assert_eq!(state.checkpoint_storage_at(c5, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(4)))); state.discard_checkpoint(); // Commit/discard c5. - assert_eq!(state.checkpoint_storage_at(cm1, &a, &k).unwrap(), Some(H256::from(U256::from(0xffff)))); - assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(H256::from(U256::from(0xffff)))); - assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); - assert_eq!(state.checkpoint_storage_at(c2, &a, &k).unwrap(), Some(H256::from(U256::from(1)))); - assert_eq!(state.checkpoint_storage_at(c3, &a, &k).unwrap(), Some(H256::from(U256::from(1)))); - assert_eq!(state.checkpoint_storage_at(c4, &a, &k).unwrap(), Some(H256::from(U256::from(3)))); + assert_eq!(state.checkpoint_storage_at(cm1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0xffff)))); + assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0xffff)))); + assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(c2, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(1)))); + assert_eq!(state.checkpoint_storage_at(c3, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(1)))); + assert_eq!(state.checkpoint_storage_at(c4, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(3)))); state.revert_to_checkpoint(); // Revert to c4. - assert_eq!(state.checkpoint_storage_at(cm1, &a, &k).unwrap(), Some(H256::from(U256::from(0xffff)))); - assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(H256::from(U256::from(0xffff)))); - assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); - assert_eq!(state.checkpoint_storage_at(c2, &a, &k).unwrap(), Some(H256::from(U256::from(1)))); - assert_eq!(state.checkpoint_storage_at(c3, &a, &k).unwrap(), Some(H256::from(U256::from(1)))); + assert_eq!(state.checkpoint_storage_at(cm1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0xffff)))); + assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0xffff)))); + assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(c2, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(1)))); + assert_eq!(state.checkpoint_storage_at(c3, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(1)))); state.discard_checkpoint(); // Commit/discard c3. - assert_eq!(state.checkpoint_storage_at(cm1, &a, &k).unwrap(), Some(H256::from(U256::from(0xffff)))); - assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(H256::from(U256::from(0xffff)))); - assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); - assert_eq!(state.checkpoint_storage_at(c2, &a, &k).unwrap(), Some(H256::from(U256::from(1)))); + assert_eq!(state.checkpoint_storage_at(cm1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0xffff)))); + assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0xffff)))); + assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(c2, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(1)))); state.revert_to_checkpoint(); // Revert to c2. - assert_eq!(state.checkpoint_storage_at(cm1, &a, &k).unwrap(), Some(H256::from(U256::from(0xffff)))); - assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(H256::from(U256::from(0xffff)))); - assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(H256::from(U256::from(0)))); + assert_eq!(state.checkpoint_storage_at(cm1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0xffff)))); + assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0xffff)))); + assert_eq!(state.checkpoint_storage_at(c1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0)))); state.discard_checkpoint(); // Commit/discard c1. - assert_eq!(state.checkpoint_storage_at(cm1, &a, &k).unwrap(), Some(H256::from(U256::from(0xffff)))); - assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(H256::from(U256::from(0xffff)))); + assert_eq!(state.checkpoint_storage_at(cm1, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0xffff)))); + assert_eq!(state.checkpoint_storage_at(c0, &a, &k).unwrap(), Some(BigEndianHash::from_uint(&U256::from(0xffff)))); } #[test] fn kill_account_with_checkpoints() { let mut state = get_temp_state(); let a = Address::zero(); - let k = H256::from(U256::from(0)); + let k = BigEndianHash::from_uint(&U256::from(0)); state.checkpoint(); - state.set_storage(&a, k, H256::from(U256::from(1))).unwrap(); + state.set_storage(&a, k, BigEndianHash::from_uint(&U256::from(1))).unwrap(); state.checkpoint(); state.kill_account(&a); - assert_eq!(state.storage_at(&a, &k).unwrap(), H256::from(U256::from(0))); + assert_eq!(state.storage_at(&a, &k).unwrap(), BigEndianHash::from_uint(&U256::from(0))); state.revert_to_checkpoint(); - assert_eq!(state.storage_at(&a, &k).unwrap(), H256::from(U256::from(1))); + assert_eq!(state.storage_at(&a, &k).unwrap(), BigEndianHash::from_uint(&U256::from(1))); } #[test] fn create_contract_fail() { let mut state = get_temp_state(); let orig_root = state.root().clone(); - let a: Address = 1000.into(); + let a = Address::from_low_u64_be(1000); state.checkpoint(); // c1 state.new_contract(&a, U256::zero(), U256::zero()).unwrap(); @@ -2565,25 +2574,25 @@ mod tests { #[test] fn create_contract_fail_previous_storage() { let mut state = get_temp_state(); - let a: Address = 1000.into(); - let k = H256::from(U256::from(0)); + let a = Address::from_low_u64_be(1000); + let k = BigEndianHash::from_uint(&U256::from(0)); - state.set_storage(&a, k, H256::from(U256::from(0xffff))).unwrap(); + state.set_storage(&a, k, BigEndianHash::from_uint(&U256::from(0xffff))).unwrap(); state.commit().unwrap(); state.clear(); let orig_root = state.root().clone(); - assert_eq!(state.storage_at(&a, &k).unwrap(), H256::from(U256::from(0xffff))); + assert_eq!(state.storage_at(&a, &k).unwrap(), BigEndianHash::from_uint(&U256::from(0xffff))); state.clear(); state.checkpoint(); // c1 state.new_contract(&a, U256::zero(), U256::zero()).unwrap(); state.checkpoint(); // c2 - state.set_storage(&a, k, H256::from(U256::from(2))).unwrap(); + state.set_storage(&a, k, BigEndianHash::from_uint(&U256::from(2))).unwrap(); state.revert_to_checkpoint(); // revert to c2 - assert_eq!(state.storage_at(&a, &k).unwrap(), H256::from(U256::from(0))); + assert_eq!(state.storage_at(&a, &k).unwrap(), BigEndianHash::from_uint(&U256::from(0))); state.revert_to_checkpoint(); // revert to c1 - assert_eq!(state.storage_at(&a, &k).unwrap(), H256::from(U256::from(0xffff))); + assert_eq!(state.storage_at(&a, &k).unwrap(), BigEndianHash::from_uint(&U256::from(0xffff))); state.commit().unwrap(); assert_eq!(orig_root, state.root().clone()); @@ -2593,32 +2602,31 @@ mod tests { fn create_empty() { let mut state = get_temp_state(); state.commit().unwrap(); - assert_eq!(*state.root(), "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".into()); + assert_eq!(*state.root(), H256::from_str("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").unwrap()); } #[test] fn should_not_panic_on_state_diff_with_storage() { let mut state = get_temp_state(); - - let a: Address = 0xa.into(); + let a = Address::from_low_u64_be(0xa); state.init_code(&a, b"abcdefg".to_vec()).unwrap();; state.add_balance(&a, &256.into(), CleanupMode::NoEmpty).unwrap(); - state.set_storage(&a, 0xb.into(), 0xc.into()).unwrap(); + state.set_storage(&a, H256::from_low_u64_be(0xb), H256::from_low_u64_be(0xc).into()).unwrap(); let mut new_state = state.clone(); - new_state.set_storage(&a, 0xb.into(), 0xd.into()).unwrap(); + new_state.set_storage(&a, H256::from_low_u64_be(0xb), H256::from_low_u64_be(0xd).into()).unwrap(); new_state.diff_from(state).unwrap(); } #[test] fn should_kill_garbage() { - let a = 10.into(); - let b = 20.into(); - let c = 30.into(); - let d = 40.into(); - let e = 50.into(); - let x = 0.into(); + let a = Address::from_low_u64_be(10); + let b = Address::from_low_u64_be(20); + let c = Address::from_low_u64_be(30); + let d = Address::from_low_u64_be(40); + let e = Address::from_low_u64_be(50); + let x = Address::from_low_u64_be(0); let db = get_temp_state_db(); let (root, db) = { let mut state = State::new(db, U256::from(0), Default::default()); @@ -2656,7 +2664,7 @@ mod tests { fn should_trace_diff_suicided_accounts() { use pod_account; - let a = 10.into(); + let a = Address::from_low_u64_be(10); let db = get_temp_state_db(); let (root, db) = { let mut state = State::new(db, U256::from(0), Default::default()); @@ -2686,19 +2694,19 @@ mod tests { fn should_trace_diff_unmodified_storage() { use pod_account; - let a = 10.into(); + let a = Address::from_low_u64_be(10); let db = get_temp_state_db(); let (root, db) = { let mut state = State::new(db, U256::from(0), Default::default()); - state.set_storage(&a, H256::from(&U256::from(1u64)), H256::from(&U256::from(20u64))).unwrap(); + state.set_storage(&a, BigEndianHash::from_uint(&U256::from(1u64)), BigEndianHash::from_uint(&U256::from(20u64))).unwrap(); state.commit().unwrap(); state.drop() }; let mut state = State::from_existing(db, root, U256::from(0u8), Default::default()).unwrap(); let original = state.clone(); - state.set_storage(&a, H256::from(&U256::from(1u64)), H256::from(&U256::from(100u64))).unwrap(); + state.set_storage(&a, BigEndianHash::from_uint(&U256::from(1u64)), BigEndianHash::from_uint(&U256::from(100u64))).unwrap(); let diff = state.diff_from(original).unwrap(); let diff_map = diff.get(); @@ -2709,13 +2717,13 @@ mod tests { balance: U256::zero(), nonce: U256::zero(), code: Some(Default::default()), - storage: vec![(H256::from(&U256::from(1u64)), H256::from(&U256::from(20u64)))] + storage: vec![(BigEndianHash::from_uint(&U256::from(1u64)), BigEndianHash::from_uint(&U256::from(20u64)))] .into_iter().collect(), }), Some(&PodAccount { balance: U256::zero(), nonce: U256::zero(), code: Some(Default::default()), - storage: vec![(H256::from(&U256::from(1u64)), H256::from(&U256::from(100u64)))] + storage: vec![(BigEndianHash::from_uint(&U256::from(1u64)), BigEndianHash::from_uint(&U256::from(100u64)))] .into_iter().collect(), })).as_ref()); } @@ -2725,7 +2733,7 @@ mod tests { fn should_get_full_pod_storage_values() { use trie::{TrieFactory, TrieSpec}; - let a = 10.into(); + let a = Address::from_low_u64_be(10); let db = get_temp_state_db(); let factories = Factories { @@ -2738,29 +2746,29 @@ mod tests { pod_state.get().get(ak).unwrap().storage.get(&k).unwrap().clone() }; - let storage_address = H256::from(&U256::from(1u64)); + let storage_address: H256 = BigEndianHash::from_uint(&U256::from(1u64)); let (root, db) = { let mut state = State::new(db, U256::from(0), factories.clone()); - state.set_storage(&a, storage_address.clone(), H256::from(&U256::from(20u64))).unwrap(); + state.set_storage(&a, storage_address.clone(), BigEndianHash::from_uint(&U256::from(20u64))).unwrap(); let dump = state.to_pod_full().unwrap(); - assert_eq!(get_pod_state_val(&dump, &a, storage_address.clone()), H256::from(&U256::from(20u64))); + assert_eq!(get_pod_state_val(&dump, &a, storage_address.clone()), BigEndianHash::from_uint(&U256::from(20u64))); state.commit().unwrap(); let dump = state.to_pod_full().unwrap(); - assert_eq!(get_pod_state_val(&dump, &a, storage_address.clone()), H256::from(&U256::from(20u64))); + assert_eq!(get_pod_state_val(&dump, &a, storage_address.clone()), BigEndianHash::from_uint(&U256::from(20u64))); state.drop() }; let mut state = State::from_existing(db, root, U256::from(0u8), factories).unwrap(); let dump = state.to_pod_full().unwrap(); - assert_eq!(get_pod_state_val(&dump, &a, storage_address.clone()), H256::from(&U256::from(20u64))); - state.set_storage(&a, storage_address.clone(), H256::from(&U256::from(21u64))).unwrap(); + assert_eq!(get_pod_state_val(&dump, &a, storage_address.clone()), BigEndianHash::from_uint(&U256::from(20u64))); + state.set_storage(&a, storage_address.clone(), BigEndianHash::from_uint(&U256::from(21u64))).unwrap(); let dump = state.to_pod_full().unwrap(); - assert_eq!(get_pod_state_val(&dump, &a, storage_address.clone()), H256::from(&U256::from(21u64))); + assert_eq!(get_pod_state_val(&dump, &a, storage_address.clone()), BigEndianHash::from_uint(&U256::from(21u64))); state.commit().unwrap(); - state.set_storage(&a, storage_address.clone(), H256::from(&U256::from(0u64))).unwrap(); + state.set_storage(&a, storage_address.clone(), BigEndianHash::from_uint(&U256::from(0u64))).unwrap(); let dump = state.to_pod_full().unwrap(); - assert_eq!(get_pod_state_val(&dump, &a, storage_address.clone()), H256::from(&U256::from(0u64))); + assert_eq!(get_pod_state_val(&dump, &a, storage_address.clone()), BigEndianHash::from_uint(&U256::from(0u64))); } diff --git a/ethcore/src/state/substate.rs b/ethcore/src/state/substate.rs index 86f6e37f8..cb6981437 100644 --- a/ethcore/src/state/substate.rs +++ b/ethcore/src/state/substate.rs @@ -68,7 +68,7 @@ impl Substate { #[cfg(test)] mod tests { - use super::Substate; + use super::{Substate, Address}; use types::log_entry::LogEntry; #[test] @@ -80,19 +80,19 @@ mod tests { #[test] fn accrue() { let mut sub_state = Substate::new(); - sub_state.contracts_created.push(1u64.into()); + sub_state.contracts_created.push(Address::from_low_u64_be(1)); sub_state.logs.push(LogEntry { - address: 1u64.into(), + address: Address::from_low_u64_be(1), topics: vec![], data: vec![] }); sub_state.sstore_clears_refund = (15000 * 5).into(); - sub_state.suicides.insert(10u64.into()); + sub_state.suicides.insert(Address::from_low_u64_be(10)); let mut sub_state_2 = Substate::new(); - sub_state_2.contracts_created.push(2u64.into()); + sub_state_2.contracts_created.push(Address::from_low_u64_be(2u64)); sub_state_2.logs.push(LogEntry { - address: 1u64.into(), + address: Address::from_low_u64_be(1), topics: vec![], data: vec![] }); diff --git a/ethcore/src/state_db.rs b/ethcore/src/state_db.rs index 066a4f616..2613411e4 100644 --- a/ethcore/src/state_db.rs +++ b/ethcore/src/state_db.rs @@ -458,13 +458,13 @@ impl state::Backend for StateDB { fn note_non_null_account(&self, address: &Address) { trace!(target: "account_bloom", "Note account bloom: {:?}", address); let mut bloom = self.account_bloom.lock(); - bloom.set(&*keccak(address)); + bloom.set(keccak(address).as_bytes()); } fn is_known_null(&self, address: &Address) -> bool { trace!(target: "account_bloom", "Check account bloom: {:?}", address); let bloom = self.account_bloom.lock(); - let is_null = !bloom.check(&*keccak(address)); + let is_null = !bloom.check(keccak(address).as_bytes()); is_null } } diff --git a/ethcore/src/test_helpers.rs b/ethcore/src/test_helpers.rs index b5575f36c..e59a41d34 100644 --- a/ethcore/src/test_helpers.rs +++ b/ethcore/src/test_helpers.rs @@ -136,7 +136,7 @@ pub fn generate_dummy_client_with_spec_and_data(test_spec: F, block_number: u let mut last_hashes = vec![]; let mut last_header = genesis_header.clone(); - let kp = KeyPair::from_secret_slice(&keccak("")).unwrap(); + let kp = KeyPair::from_secret_slice(keccak("").as_bytes()).unwrap(); let author = kp.address(); let mut n = 0; @@ -223,7 +223,7 @@ pub fn push_block_with_transactions(client: &Arc, transactions: &[Signed let test_engine = &*test_spec.engine; let block_number = client.chain_info().best_block_number as u64 + 1; - let mut b = client.prepare_open_block(Address::default(), (0.into(), 5000000.into()), Bytes::new()).unwrap(); + let mut b = client.prepare_open_block(Address::zero(), (0.into(), 5000000.into()), Bytes::new()).unwrap(); b.set_timestamp(block_number * 10); for t in transactions { @@ -493,7 +493,7 @@ pub fn get_bad_state_dummy_block() -> Bytes { block_header.set_timestamp(40); block_header.set_number(1); block_header.set_parent_hash(test_spec.genesis_header().hash()); - block_header.set_state_root(0xbad.into()); + block_header.set_state_root(H256::from_low_u64_be(0xbad)); create_test_block(&block_header) } diff --git a/ethcore/src/tests/client.rs b/ethcore/src/tests/client.rs index 9086d07e0..6edd16dba 100644 --- a/ethcore/src/tests/client.rs +++ b/ethcore/src/tests/client.rs @@ -251,7 +251,7 @@ fn can_mine() { let dummy_blocks = get_good_dummy_block_seq(2); let client = get_test_client_with_blocks(vec![dummy_blocks[0].clone()]); - let b = client.prepare_open_block(Address::default(), (3141562.into(), 31415620.into()), vec![]).unwrap().close().unwrap(); + let b = client.prepare_open_block(Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap().close().unwrap(); assert_eq!(*b.header.parent_hash(), view!(BlockView, &dummy_blocks[0]).header_view().hash()); } @@ -274,7 +274,7 @@ fn change_history_size() { ).unwrap(); for _ in 0..20 { - let mut b = client.prepare_open_block(Address::default(), (3141562.into(), 31415620.into()), vec![]).unwrap(); + let mut b = client.prepare_open_block(Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); b.block_mut().state_mut().add_balance(&address, &5.into(), CleanupMode::NoEmpty).unwrap(); b.block_mut().state_mut().commit().unwrap(); let b = b.close_and_lock().unwrap().seal(&*test_spec.engine, vec![]).unwrap(); @@ -301,7 +301,7 @@ fn does_not_propagate_delayed_transactions() { nonce: 0.into(), gas_price: 0.into(), gas: 21000.into(), - action: Action::Call(Address::default()), + action: Action::Call(Address::zero()), value: 0.into(), data: Vec::new(), }.sign(secret, None), Some(Condition::Number(2))); @@ -309,7 +309,7 @@ fn does_not_propagate_delayed_transactions() { nonce: 1.into(), gas_price: 0.into(), gas: 21000.into(), - action: Action::Call(Address::default()), + action: Action::Call(Address::zero()), value: 0.into(), data: Vec::new(), }.sign(secret, None), None); @@ -333,7 +333,7 @@ fn transaction_proof() { let address = Address::random(); let test_spec = Spec::new_test(); for _ in 0..20 { - let mut b = client.prepare_open_block(Address::default(), (3141562.into(), 31415620.into()), vec![]).unwrap(); + let mut b = client.prepare_open_block(Address::zero(), (3141562.into(), 31415620.into()), vec![]).unwrap(); b.block_mut().state_mut().add_balance(&address, &5.into(), CleanupMode::NoEmpty).unwrap(); b.block_mut().state_mut().commit().unwrap(); let b = b.close_and_lock().unwrap().seal(&*test_spec.engine, vec![]).unwrap(); @@ -344,7 +344,7 @@ fn transaction_proof() { nonce: 0.into(), gas_price: 0.into(), gas: 21000.into(), - action: Action::Call(Address::default()), + action: Action::Call(Address::zero()), value: 5.into(), data: Vec::new(), }.fake_sign(address); @@ -363,7 +363,7 @@ fn transaction_proof() { Executive::new(&mut state, &env_info, &machine, &schedule) .transact(&transaction, TransactOptions::with_no_tracing().dont_check_nonce()).unwrap(); - assert_eq!(state.balance(&Address::default()).unwrap(), 5.into()); + assert_eq!(state.balance(&Address::zero()).unwrap(), 5.into()); assert_eq!(state.balance(&address).unwrap(), 95.into()); } diff --git a/ethcore/src/tests/evm.rs b/ethcore/src/tests/evm.rs index ec0b1dd8e..de1c14b27 100644 --- a/ethcore/src/tests/evm.rs +++ b/ethcore/src/tests/evm.rs @@ -43,7 +43,7 @@ fn test_blockhash_eip210(factory: Factory) { // populate state with 256 last hashes let mut state = get_temp_state_with_factory(factory); - let contract_address: Address = 0xf0.into(); + let contract_address = Address::from_low_u64_be(0xf0); state.init_code(&contract_address, (*blockhash_contract_code).clone()).unwrap(); for i in 1 .. 257 { env_info.number = i.into(); @@ -57,7 +57,7 @@ fn test_blockhash_eip210(factory: Factory) { value: ActionValue::Transfer(0.into()), code: Some(blockhash_contract_code.clone()), code_hash: Some(blockhash_contract_code_hash), - data: Some(H256::from(i - 1).to_vec()), + data: Some(H256::from_low_u64_be(i - 1).as_bytes().to_vec()), call_type: CallType::Call, params_type: ParamsType::Separate, }; @@ -71,10 +71,10 @@ fn test_blockhash_eip210(factory: Factory) { env_info.number = 256; let params = ActionParams { - code_address: Address::new(), - address: Address::new(), - sender: Address::new(), - origin: Address::new(), + code_address: Address::zero(), + address: Address::zero(), + sender: Address::zero(), + origin: Address::zero(), gas: 100000.into(), gas_price: 0.into(), value: ActionValue::Transfer(0.into()), @@ -89,10 +89,10 @@ fn test_blockhash_eip210(factory: Factory) { let mut substate = Substate::new(); let res = ex.call(params, &mut substate, &mut NoopTracer, &mut NoopVMTracer); let output = match res { - Ok(res) => H256::from(&res.return_data[..32]), + Ok(res) => H256::from_slice(&res.return_data[..32]), Err(e) => { panic!("Encountered error on getting last hash: {}", e); }, }; - assert_eq!(output, 255.into()); + assert_eq!(output, H256::from_low_u64_be(255)); } diff --git a/ethcore/src/tests/trace.rs b/ethcore/src/tests/trace.rs index c14f13cf5..882fed443 100644 --- a/ethcore/src/tests/trace.rs +++ b/ethcore/src/tests/trace.rs @@ -26,6 +26,7 @@ use client::*; use test_helpers::get_temp_state_db; use client::{BlockChainClient, Client, ClientConfig}; use std::sync::Arc; +use std::str::FromStr; use miner::Miner; use types::transaction::{Action, Transaction}; use trace::{RewardType, LocalizedTrace}; @@ -71,7 +72,7 @@ fn can_trace_block_and_uncle_reward() { let mut last_header = genesis_header.clone(); last_hashes.push(last_header.hash()); - let kp = KeyPair::from_secret_slice(&keccak("")).unwrap(); + let kp = KeyPair::from_secret_slice(keccak("").as_bytes()).unwrap(); let author = kp.address(); // Add root block first @@ -162,7 +163,7 @@ fn can_trace_block_and_uncle_reward() { } let mut uncle = Header::new(); - let uncle_author: Address = "ef2d6d194084c2de36e0dabfce45d046b37d1106".into(); + let uncle_author = Address::from_str("ef2d6d194084c2de36e0dabfce45d046b37d1106").unwrap(); uncle.set_author(uncle_author); uncle.set_parent_hash(root_header.hash()); uncle.set_gas_limit(genesis_gas); diff --git a/ethcore/src/trace/db.rs b/ethcore/src/trace/db.rs index 8dbd38449..2ee521a4a 100644 --- a/ethcore/src/trace/db.rs +++ b/ethcore/src/trace/db.rs @@ -43,8 +43,11 @@ impl Key for H256 { fn key(&self) -> H264 { let mut result = H264::default(); - result[0] = TraceDBIndex::BlockTraces as u8; - result[1..33].copy_from_slice(self); + { + let bytes = result.as_bytes_mut(); + bytes[0] = TraceDBIndex::BlockTraces as u8; + bytes[1..33].copy_from_slice(self.as_bytes()); + } result } } @@ -348,7 +351,7 @@ mod tests { impl DatabaseExtras for NoopExtras { fn block_hash(&self, block_number: BlockNumber) -> Option { if block_number == 0 { - Some(H256::default()) + Some(H256::zero()) } else { unimplemented!() } @@ -419,8 +422,8 @@ mod tests { trace_address: Default::default(), subtraces: 0, action: Action::Call(Call { - from: 1.into(), - to: 2.into(), + from: Address::from_low_u64_be(1), + to: Address::from_low_u64_be(2), value: 3.into(), gas: 4.into(), input: vec![], @@ -441,8 +444,8 @@ mod tests { trace_address: Default::default(), subtraces: 0, action: Action::Call(Call { - from: 1.into(), - to: 2.into(), + from: Address::from_low_u64_be(1), + to: Address::from_low_u64_be(2), value: 3.into(), gas: 4.into(), input: vec![], @@ -460,8 +463,8 @@ mod tests { fn create_simple_localized_trace(block_number: BlockNumber, block_hash: H256, tx_hash: H256) -> LocalizedTrace { LocalizedTrace { action: Action::Call(Call { - from: Address::from(1), - to: Address::from(2), + from: Address::from_low_u64_be(1), + to: Address::from_low_u64_be(2), value: U256::from(3), gas: U256::from(4), input: vec![], @@ -482,10 +485,10 @@ mod tests { let db = new_db(); let mut config = Config::default(); config.enabled = true; - let block_0 = H256::from(0xa1); - let block_1 = H256::from(0xa2); - let tx_0 = H256::from(0xff); - let tx_1 = H256::from(0xaf); + let block_0 = H256::from_low_u64_be(0xa1); + let block_1 = H256::from_low_u64_be(0xa2); + let tx_0 = H256::from_low_u64_be(0xff); + let tx_1 = H256::from_low_u64_be(0xaf); let mut extras = Extras::default(); extras.block_hashes.insert(0, block_0.clone()); @@ -509,13 +512,13 @@ mod tests { let db = new_db(); let mut config = Config::default(); config.enabled = true; - let block_1 = H256::from(0xa1); - let block_2 = H256::from(0xa2); - let tx_1 = H256::from(0xff); - let tx_2 = H256::from(0xaf); + let block_1 = H256::from_low_u64_be(0xa1); + let block_2 = H256::from_low_u64_be(0xa2); + let tx_1 = H256::from_low_u64_be(0xff); + let tx_2 = H256::from_low_u64_be(0xaf); let mut extras = Extras::default(); - extras.block_hashes.insert(0, H256::default()); + extras.block_hashes.insert(0, H256::zero()); extras.block_hashes.insert(1, block_1.clone()); extras.block_hashes.insert(2, block_2.clone()); @@ -532,7 +535,7 @@ mod tests { let filter = Filter { range: (1..1), - from_address: AddressesFilter::from(vec![Address::from(1)]), + from_address: AddressesFilter::from(vec![Address::from_low_u64_be(1)]), to_address: AddressesFilter::from(vec![]), }; @@ -548,7 +551,7 @@ mod tests { let filter = Filter { range: (1..2), - from_address: AddressesFilter::from(vec![Address::from(1)]), + from_address: AddressesFilter::from(vec![Address::from_low_u64_be(1)]), to_address: AddressesFilter::from(vec![]), }; @@ -588,10 +591,10 @@ mod tests { let db = new_db(); let mut config = Config::default(); let mut extras = Extras::default(); - let block_0 = H256::from(0xa1); - let tx_0 = H256::from(0xff); + let block_0 = H256::from_low_u64_be(0xa1); + let tx_0 = H256::from_low_u64_be(0xff); - extras.block_hashes.insert(0, H256::default()); + extras.block_hashes.insert(0, H256::zero()); extras.transaction_hashes.insert(0, vec![]); extras.block_hashes.insert(1, block_0.clone()); extras.transaction_hashes.insert(1, vec![tx_0.clone()]); @@ -621,7 +624,7 @@ mod tests { let db = new_db(); let mut config = Config::default(); let mut extras = Extras::default(); - let block_0 = H256::from(0xa1); + let block_0 = H256::from_low_u64_be(0xa1); extras.block_hashes.insert(0, block_0.clone()); extras.transaction_hashes.insert(0, vec![]); diff --git a/ethcore/src/trace/executive_tracer.rs b/ethcore/src/trace/executive_tracer.rs index 015deaea0..fdd9428b5 100644 --- a/ethcore/src/trace/executive_tracer.rs +++ b/ethcore/src/trace/executive_tracer.rs @@ -75,7 +75,7 @@ impl Tracer for ExecutiveTracer { result: Res::Create(CreateResult { gas_used: U256::zero(), code: Vec::new(), - address: Address::default(), + address: Address::zero(), }), }; self.vecindex_stack.push(self.traces.len()); diff --git a/ethcore/src/trace/types/filter.rs b/ethcore/src/trace/types/filter.rs index d7b8fcc18..f4c8598d9 100644 --- a/ethcore/src/trace/types/filter.rs +++ b/ethcore/src/trace/types/filter.rs @@ -51,7 +51,7 @@ impl AddressesFilter { match self.list.is_empty() { true => vec![Bloom::default()], false => self.list.iter() - .map(|address| Bloom::from(BloomInput::Raw(address))) + .map(|address| Bloom::from(BloomInput::Raw(address.as_bytes()))) .collect(), } } @@ -65,7 +65,7 @@ impl AddressesFilter { .flat_map(|bloom| self.list.iter() .map(|address| { let mut bloom = bloom.clone(); - bloom.accrue(BloomInput::Raw(address)); + bloom.accrue(BloomInput::Raw(address.as_bytes())); bloom }) .collect::>()) @@ -147,31 +147,31 @@ mod tests { fn single_trace_filter_bloom_possibility() { let filter = Filter { range: (0..0), - from_address: AddressesFilter::from(vec![Address::from(1)]), - to_address: AddressesFilter::from(vec![Address::from(2)]), + from_address: AddressesFilter::from(vec![Address::from_low_u64_be(1)]), + to_address: AddressesFilter::from(vec![Address::from_low_u64_be(2)]), }; let blooms = filter.bloom_possibilities(); assert_eq!(blooms.len(), 1); - assert!(blooms[0].contains_input(BloomInput::Raw(&Address::from(1)))); - assert!(blooms[0].contains_input(BloomInput::Raw(&Address::from(2)))); - assert!(!blooms[0].contains_input(BloomInput::Raw(&Address::from(3)))); + assert!(blooms[0].contains_input(BloomInput::Raw(Address::from_low_u64_be(1).as_bytes()))); + assert!(blooms[0].contains_input(BloomInput::Raw(Address::from_low_u64_be(2).as_bytes()))); + assert!(!blooms[0].contains_input(BloomInput::Raw(Address::from_low_u64_be(3).as_bytes()))); } #[test] fn only_from_trace_filter_bloom_possibility() { let filter = Filter { range: (0..0), - from_address: AddressesFilter::from(vec![Address::from(1)]), + from_address: AddressesFilter::from(vec![Address::from_low_u64_be(1)]), to_address: AddressesFilter::from(vec![]), }; let blooms = filter.bloom_possibilities(); assert_eq!(blooms.len(), 1); - assert!(blooms[0].contains_input(BloomInput::Raw(&Address::from(1)))); - assert!(!blooms[0].contains_input(BloomInput::Raw(&Address::from(2)))); + assert!(blooms[0].contains_input(BloomInput::Raw(Address::from_low_u64_be(1).as_bytes()))); + assert!(!blooms[0].contains_input(BloomInput::Raw(Address::from_low_u64_be(2).as_bytes()))); } #[test] @@ -179,59 +179,59 @@ mod tests { let filter = Filter { range: (0..0), from_address: AddressesFilter::from(vec![]), - to_address: AddressesFilter::from(vec![Address::from(1)]), + to_address: AddressesFilter::from(vec![Address::from_low_u64_be(1)]), }; let blooms = filter.bloom_possibilities(); assert_eq!(blooms.len(), 1); - assert!(blooms[0].contains_input(BloomInput::Raw(&Address::from(1)))); - assert!(!blooms[0].contains_input(BloomInput::Raw(&Address::from(2)))); + assert!(blooms[0].contains_input(BloomInput::Raw(Address::from_low_u64_be(1).as_bytes()))); + assert!(!blooms[0].contains_input(BloomInput::Raw(Address::from_low_u64_be(2).as_bytes()))); } #[test] fn multiple_trace_filter_bloom_possibility() { let filter = Filter { range: (0..0), - from_address: AddressesFilter::from(vec![Address::from(1), Address::from(3)]), - to_address: AddressesFilter::from(vec![Address::from(2), Address::from(4)]), + from_address: AddressesFilter::from(vec![Address::from_low_u64_be(1), Address::from_low_u64_be(3)]), + to_address: AddressesFilter::from(vec![Address::from_low_u64_be(2), Address::from_low_u64_be(4)]), }; let blooms = filter.bloom_possibilities(); assert_eq!(blooms.len(), 4); - assert!(blooms[0].contains_input(BloomInput::Raw(&Address::from(1)))); - assert!(blooms[0].contains_input(BloomInput::Raw(&Address::from(2)))); - assert!(!blooms[0].contains_input(BloomInput::Raw(&Address::from(3)))); - assert!(!blooms[0].contains_input(BloomInput::Raw(&Address::from(4)))); + assert!(blooms[0].contains_input(BloomInput::Raw(Address::from_low_u64_be(1).as_bytes()))); + assert!(blooms[0].contains_input(BloomInput::Raw(Address::from_low_u64_be(2).as_bytes()))); + assert!(!blooms[0].contains_input(BloomInput::Raw(Address::from_low_u64_be(3).as_bytes()))); + assert!(!blooms[0].contains_input(BloomInput::Raw(Address::from_low_u64_be(4).as_bytes()))); - assert!(blooms[1].contains_input(BloomInput::Raw(&Address::from(1)))); - assert!(blooms[1].contains_input(BloomInput::Raw(&Address::from(4)))); - assert!(!blooms[1].contains_input(BloomInput::Raw(&Address::from(2)))); - assert!(!blooms[1].contains_input(BloomInput::Raw(&Address::from(3)))); + assert!(blooms[1].contains_input(BloomInput::Raw(Address::from_low_u64_be(1).as_bytes()))); + assert!(blooms[1].contains_input(BloomInput::Raw(Address::from_low_u64_be(4).as_bytes()))); + assert!(!blooms[1].contains_input(BloomInput::Raw(Address::from_low_u64_be(2).as_bytes()))); + assert!(!blooms[1].contains_input(BloomInput::Raw(Address::from_low_u64_be(3).as_bytes()))); - assert!(blooms[2].contains_input(BloomInput::Raw(&Address::from(2)))); - assert!(blooms[2].contains_input(BloomInput::Raw(&Address::from(3)))); - assert!(!blooms[2].contains_input(BloomInput::Raw(&Address::from(1)))); - assert!(!blooms[2].contains_input(BloomInput::Raw(&Address::from(4)))); + assert!(blooms[2].contains_input(BloomInput::Raw(Address::from_low_u64_be(2).as_bytes()))); + assert!(blooms[2].contains_input(BloomInput::Raw(Address::from_low_u64_be(3).as_bytes()))); + assert!(!blooms[2].contains_input(BloomInput::Raw(Address::from_low_u64_be(1).as_bytes()))); + assert!(!blooms[2].contains_input(BloomInput::Raw(Address::from_low_u64_be(4).as_bytes()))); - assert!(blooms[3].contains_input(BloomInput::Raw(&Address::from(3)))); - assert!(blooms[3].contains_input(BloomInput::Raw(&Address::from(4)))); - assert!(!blooms[3].contains_input(BloomInput::Raw(&Address::from(1)))); - assert!(!blooms[3].contains_input(BloomInput::Raw(&Address::from(2)))); + assert!(blooms[3].contains_input(BloomInput::Raw(Address::from_low_u64_be(3).as_bytes()))); + assert!(blooms[3].contains_input(BloomInput::Raw(Address::from_low_u64_be(4).as_bytes()))); + assert!(!blooms[3].contains_input(BloomInput::Raw(Address::from_low_u64_be(1).as_bytes()))); + assert!(!blooms[3].contains_input(BloomInput::Raw(Address::from_low_u64_be(2).as_bytes()))); } #[test] fn filter_matches() { let f0 = Filter { range: (0..0), - from_address: AddressesFilter::from(vec![Address::from(1)]), + from_address: AddressesFilter::from(vec![Address::from_low_u64_be(1)]), to_address: AddressesFilter::from(vec![]), }; let f1 = Filter { range: (0..0), - from_address: AddressesFilter::from(vec![Address::from(3), Address::from(1)]), + from_address: AddressesFilter::from(vec![Address::from_low_u64_be(3), Address::from_low_u64_be(1)]), to_address: AddressesFilter::from(vec![]), }; @@ -244,31 +244,31 @@ mod tests { let f3 = Filter { range: (0..0), from_address: AddressesFilter::from(vec![]), - to_address: AddressesFilter::from(vec![Address::from(2)]), + to_address: AddressesFilter::from(vec![Address::from_low_u64_be(2)]), }; let f4 = Filter { range: (0..0), from_address: AddressesFilter::from(vec![]), - to_address: AddressesFilter::from(vec![Address::from(2), Address::from(3)]), + to_address: AddressesFilter::from(vec![Address::from_low_u64_be(2), Address::from_low_u64_be(3)]), }; let f5 = Filter { range: (0..0), - from_address: AddressesFilter::from(vec![Address::from(1)]), - to_address: AddressesFilter::from(vec![Address::from(2), Address::from(3)]), + from_address: AddressesFilter::from(vec![Address::from_low_u64_be(1)]), + to_address: AddressesFilter::from(vec![Address::from_low_u64_be(2), Address::from_low_u64_be(3)]), }; let f6 = Filter { range: (0..0), - from_address: AddressesFilter::from(vec![Address::from(1)]), - to_address: AddressesFilter::from(vec![Address::from(4)]), + from_address: AddressesFilter::from(vec![Address::from_low_u64_be(1)]), + to_address: AddressesFilter::from(vec![Address::from_low_u64_be(4)]), }; let trace = FlatTrace { action: Action::Call(Call { - from: 1.into(), - to: 2.into(), + from: Address::from_low_u64_be(1), + to: Address::from_low_u64_be(2), value: 3.into(), gas: 4.into(), input: vec![0x5], @@ -289,7 +289,7 @@ mod tests { let trace = FlatTrace { action: Action::Create(Create { - from: 1.into(), + from: Address::from_low_u64_be(1), value: 3.into(), gas: 4.into(), init: vec![0x5], @@ -297,7 +297,7 @@ mod tests { result: Res::Create(CreateResult { gas_used: 10.into(), code: vec![], - address: 2.into(), + address: Address::from_low_u64_be(2), }), trace_address: vec![0].into_iter().collect(), subtraces: 0, @@ -313,8 +313,8 @@ mod tests { let trace = FlatTrace { action: Action::Suicide(Suicide { - address: 1.into(), - refund_address: 2.into(), + address: Address::from_low_u64_be(1), + refund_address: Address::from_low_u64_be(2), balance: 3.into(), }), result: Res::None, @@ -332,7 +332,7 @@ mod tests { let trace = FlatTrace { action: Action::Reward(Reward { - author: 2.into(), + author: Address::from_low_u64_be(2), value: 100.into(), reward_type: RewardType::Block, }), @@ -354,7 +354,7 @@ mod tests { fn filter_match_block_reward_fix_8070() { let f0 = Filter { range: (0..0), - from_address: vec![1.into()].into(), + from_address: vec![Address::from_low_u64_be(1)].into(), to_address: vec![].into(), }; @@ -367,12 +367,12 @@ mod tests { let f2 = Filter { range: (0..0), from_address: vec![].into(), - to_address: vec![2.into()].into(), + to_address: vec![Address::from_low_u64_be(2)].into(), }; let trace = FlatTrace { action: Action::Reward(Reward { - author: 2.into(), + author: Address::from_low_u64_be(2), value: 10.into(), reward_type: RewardType::Block, }), @@ -391,7 +391,7 @@ mod tests { let f0 = Filter { range: (0..0), - from_address: vec![1.into()].into(), + from_address: vec![Address::from_low_u64_be(1)].into(), to_address: vec![].into(), }; @@ -404,12 +404,12 @@ mod tests { let f2 = Filter { range: (0..0), from_address: vec![].into(), - to_address: vec![2.into()].into(), + to_address: vec![Address::from_low_u64_be(2)].into(), }; let trace = FlatTrace { action: Action::Create(Create { - from: 1.into(), + from: Address::from_low_u64_be(1), gas: 4.into(), init: vec![0x5], value: 3.into(), @@ -425,4 +425,3 @@ mod tests { } } - diff --git a/ethcore/src/trace/types/trace.rs b/ethcore/src/trace/types/trace.rs index 16084e94c..6878cef9b 100644 --- a/ethcore/src/trace/types/trace.rs +++ b/ethcore/src/trace/types/trace.rs @@ -47,7 +47,7 @@ pub struct CreateResult { impl CreateResult { /// Returns bloom. pub fn bloom(&self) -> Bloom { - BloomInput::Raw(&self.address).into() + BloomInput::Raw(self.address.as_bytes()).into() } } @@ -96,8 +96,8 @@ impl Call { /// The bloom contains from and to addresses. pub fn bloom(&self) -> Bloom { let mut bloom = Bloom::default(); - bloom.accrue(BloomInput::Raw(&self.from)); - bloom.accrue(BloomInput::Raw(&self.to)); + bloom.accrue(BloomInput::Raw(self.from.as_bytes())); + bloom.accrue(BloomInput::Raw(self.to.as_bytes())); bloom } } @@ -130,7 +130,7 @@ impl Create { /// Returns bloom create action bloom. /// The bloom contains only from address. pub fn bloom(&self) -> Bloom { - BloomInput::Raw(&self.from).into() + BloomInput::Raw(self.from.as_bytes()).into() } } @@ -185,7 +185,7 @@ pub struct Reward { impl Reward { /// Return reward action bloom. pub fn bloom(&self) -> Bloom { - BloomInput::Raw(&self.author).into() + BloomInput::Raw(self.author.as_bytes()).into() } } @@ -225,8 +225,8 @@ impl Suicide { /// Return suicide action bloom. pub fn bloom(&self) -> Bloom { let mut bloom = Bloom::default(); - bloom.accrue(BloomInput::Raw(&self.address)); - bloom.accrue(BloomInput::Raw(&self.refund_address)); + bloom.accrue(BloomInput::Raw(self.address.as_bytes())); + bloom.accrue(BloomInput::Raw(self.refund_address.as_bytes())); bloom } } diff --git a/ethcore/src/tx_filter.rs b/ethcore/src/tx_filter.rs index 3f32ab365..2b9a7c941 100644 --- a/ethcore/src/tx_filter.rs +++ b/ethcore/src/tx_filter.rs @@ -71,7 +71,7 @@ impl TransactionFilter { let mut contract_version_cache = self.contract_version_cache.lock(); let (tx_type, to) = match transaction.action { - Action::Create => (tx_permissions::CREATE, Address::new()), + Action::Create => (tx_permissions::CREATE, Address::zero()), Action::Call(address) => if client.code_hash(&address, BlockId::Hash(*parent_hash)).map_or(false, |c| c != KECCAK_EMPTY) { (tx_permissions::CALL, address) } else { @@ -143,6 +143,7 @@ impl TransactionFilter { #[cfg(test)] mod test { use std::sync::Arc; + use std::str::FromStr; use spec::Spec; use client::{BlockChainClient, Client, ClientConfig, BlockId}; use miner::Miner; @@ -180,22 +181,22 @@ mod test { let filter = TransactionFilter::from_params(spec.params()).unwrap(); let mut basic_tx = Transaction::default(); - basic_tx.action = Action::Call(Address::from("d41c057fd1c78805aac12b0a94a405c0461a6fbb")); + basic_tx.action = Action::Call(Address::from_str("d41c057fd1c78805aac12b0a94a405c0461a6fbb").unwrap()); let create_tx = Transaction::default(); let mut call_tx = Transaction::default(); - call_tx.action = Action::Call(Address::from("0000000000000000000000000000000000000005")); + call_tx.action = Action::Call(Address::from_str("0000000000000000000000000000000000000005").unwrap()); let mut basic_tx_with_ether_and_to_key7 = Transaction::default(); - basic_tx_with_ether_and_to_key7.action = Action::Call(Address::from("d41c057fd1c78805aac12b0a94a405c0461a6fbb")); + basic_tx_with_ether_and_to_key7.action = Action::Call(Address::from_str("d41c057fd1c78805aac12b0a94a405c0461a6fbb").unwrap()); basic_tx_with_ether_and_to_key7.value = U256::from(123123); let mut call_tx_with_ether = Transaction::default(); - call_tx_with_ether.action = Action::Call(Address::from("0000000000000000000000000000000000000005")); + call_tx_with_ether.action = Action::Call(Address::from_str("0000000000000000000000000000000000000005").unwrap()); call_tx_with_ether.value = U256::from(123123); let mut basic_tx_to_key6 = Transaction::default(); - basic_tx_to_key6.action = Action::Call(Address::from("e57bfe9f44b819898f47bf37e5af72a0783e1141")); + basic_tx_to_key6.action = Action::Call(Address::from_str("e57bfe9f44b819898f47bf37e5af72a0783e1141").unwrap()); let mut basic_tx_with_ether_and_to_key6 = Transaction::default(); - basic_tx_with_ether_and_to_key6.action = Action::Call(Address::from("e57bfe9f44b819898f47bf37e5af72a0783e1141")); + basic_tx_with_ether_and_to_key6.action = Action::Call(Address::from_str("e57bfe9f44b819898f47bf37e5af72a0783e1141").unwrap()); basic_tx_with_ether_and_to_key6.value = U256::from(123123); let genesis = client.block_hash(BlockId::Latest).unwrap(); @@ -256,10 +257,10 @@ mod test { let filter = TransactionFilter::from_params(spec.params()).unwrap(); let mut basic_tx = Transaction::default(); - basic_tx.action = Action::Call(Address::from("000000000000000000000000000000000000032")); + basic_tx.action = Action::Call(Address::from_str("0000000000000000000000000000000000000032").unwrap()); let create_tx = Transaction::default(); let mut call_tx = Transaction::default(); - call_tx.action = Action::Call(Address::from("0000000000000000000000000000000000000005")); + call_tx.action = Action::Call(Address::from_str("0000000000000000000000000000000000000005").unwrap()); let genesis = client.block_hash(BlockId::Latest).unwrap(); let block_number = 1; diff --git a/ethcore/src/verification/verification.rs b/ethcore/src/verification/verification.rs index 4dbe64b3f..eff7ae406 100644 --- a/ethcore/src/verification/verification.rs +++ b/ethcore/src/verification/verification.rs @@ -385,7 +385,7 @@ mod tests { use std::collections::{BTreeMap, HashMap}; use std::time::{SystemTime, UNIX_EPOCH}; - use ethereum_types::{H256, BloomRef, U256}; + use ethereum_types::{H256, BloomRef, U256, Address}; use blockchain::{BlockDetails, TransactionAddress, BlockReceipts}; use types::encoded; use hash::keccak; @@ -615,7 +615,7 @@ mod tests { }.sign(keypair.secret(), None); let tr3 = Transaction { - action: Action::Call(0x0.into()), + action: Action::Call(Address::from_low_u64_be(0x0)), value: U256::from(0), data: Bytes::new(), gas: U256::from(30_000), diff --git a/ethcore/sync/Cargo.toml b/ethcore/sync/Cargo.toml index 3cbb5b983..832840639 100644 --- a/ethcore/sync/Cargo.toml +++ b/ethcore/sync/Cargo.toml @@ -15,21 +15,21 @@ ethcore-io = { path = "../../util/io" } ethcore-light = { path = "../light" } ethcore-network = { path = "../../util/network" } ethcore-network-devp2p = { path = "../../util/network-devp2p" } -ethereum-types = "0.4" +ethereum-types = "0.6.0" ethkey = { path = "../../accounts/ethkey" } ethstore = { path = "../../accounts/ethstore" } fastmap = { path = "../../util/fastmap" } hash-db = "0.11.0" heapsize = "0.4" -keccak-hash = "0.1" +keccak-hash = "0.2.0" keccak-hasher = { path = "../../util/keccak-hasher" } kvdb = "0.1" log = "0.4" macros = { path = "../../util/macros" } parity-bytes = "0.1" parking_lot = "0.7" -rand = "0.4" -rlp = { version = "0.3.0", features = ["ethereum"] } +rand = "0.6" +rlp = "0.4.0" trace-time = "0.1" triehash-ethereum = {version = "0.2", path = "../../util/triehash-ethereum" } futures = "0.1" @@ -42,3 +42,4 @@ ethcore-io = { path = "../../util/io", features = ["mio"] } ethcore-private-tx = { path = "../private-tx" } kvdb-memorydb = "0.1" rustc-hex = "1.0" +rand_xorshift = "0.1.1" diff --git a/ethcore/sync/src/blocks.rs b/ethcore/sync/src/blocks.rs index 125c8d0b9..7d9ad428a 100644 --- a/ethcore/sync/src/blocks.rs +++ b/ethcore/sync/src/blocks.rs @@ -520,7 +520,7 @@ impl BlockCollection { (None, receipt_root) } } else { - (None, H256::new()) + (None, H256::zero()) }; self.parents.insert(*info.header.parent_hash(), hash); diff --git a/ethcore/sync/src/chain/mod.rs b/ethcore/sync/src/chain/mod.rs index ecbc27db7..20d5b2cd5 100644 --- a/ethcore/sync/src/chain/mod.rs +++ b/ethcore/sync/src/chain/mod.rs @@ -113,7 +113,7 @@ use ethcore::snapshot::{RestorationStatus}; use sync_io::SyncIo; use super::{WarpSync, SyncConfig}; use block_sync::{BlockDownloader, DownloadAction}; -use rand::Rng; +use rand::{Rng, seq::SliceRandom}; use snapshot::{Snapshot}; use api::{EthProtocolInfo as PeerInfoDigest, WARP_SYNC_PROTOCOL_ID, PriorityTask}; use private_tx::PrivateTxHandler; @@ -360,12 +360,13 @@ impl PeerInfo { #[cfg(not(test))] pub mod random { use rand; - pub fn new() -> rand::ThreadRng { rand::thread_rng() } + pub fn new() -> rand::rngs::ThreadRng { rand::thread_rng() } } #[cfg(test)] pub mod random { - use rand::{self, SeedableRng}; - pub fn new() -> rand::XorShiftRng { rand::XorShiftRng::from_seed([0, 1, 2, 3]) } + use rand::SeedableRng; + const RNG_SEED: [u8; 16] = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; + pub fn new() -> rand_xorshift::XorShiftRng { rand_xorshift::XorShiftRng::from_seed(RNG_SEED) } } pub type RlpResponseResult = Result, PacketDecodeError>; @@ -559,7 +560,7 @@ impl ChainSync { let mut count = (peers.len() as f64).powf(0.5).round() as usize; count = cmp::min(count, MAX_PEERS_PROPAGATION); count = cmp::max(count, MIN_PEERS_PROPAGATION); - random::new().shuffle(&mut peers); + peers.shuffle(&mut random::new()); peers.truncate(count); peers } @@ -908,7 +909,7 @@ impl ChainSync { self.active_peers.len(), peers.len(), self.peers.len() ); - random::new().shuffle(&mut peers); // TODO (#646): sort by rating + peers.shuffle(&mut random::new()); // TODO (#646): sort by rating // prefer peers with higher protocol version peers.sort_by(|&(_, ref v1), &(_, ref v2)| v1.cmp(v2)); @@ -1154,7 +1155,7 @@ impl ChainSync { if warp_protocol { let manifest = io.snapshot_service().manifest(); let block_number = manifest.as_ref().map_or(0, |m| m.block_number); - let manifest_hash = manifest.map_or(H256::new(), |m| keccak(m.into_rlp())); + let manifest_hash = manifest.map_or(H256::zero(), |m| keccak(m.into_rlp())); packet.append(&manifest_hash); packet.append(&block_number); if private_tx_protocol { @@ -1398,7 +1399,7 @@ pub mod tests { let mut rlp = RlpStream::new_list(5); for _ in 0..5 { let mut hash_d_rlp = RlpStream::new_list(2); - let hash: H256 = H256::from(0u64); + let hash: H256 = H256::zero(); let diff: U256 = U256::from(1u64); hash_d_rlp.append(&hash); hash_d_rlp.append(&diff); diff --git a/ethcore/sync/src/chain/propagator.rs b/ethcore/sync/src/chain/propagator.rs index c3654553f..bb85fc95d 100644 --- a/ethcore/sync/src/chain/propagator.rs +++ b/ethcore/sync/src/chain/propagator.rs @@ -22,7 +22,7 @@ use ethereum_types::H256; use fastmap::H256FastSet; use network::client_version::ClientCapabilities; use network::PeerId; -use rand::Rng; +use rand::RngCore; use rlp::{Encodable, RlpStream}; use sync_io::SyncIo; use types::transaction::SignedTransaction; diff --git a/ethcore/sync/src/chain/supplier.rs b/ethcore/sync/src/chain/supplier.rs index 7e71e6aee..ee20f1289 100644 --- a/ethcore/sync/src/chain/supplier.rs +++ b/ethcore/sync/src/chain/supplier.rs @@ -377,6 +377,7 @@ mod test { use super::{*, super::tests::*}; use blocks::SyncHeader; use ethcore::client::{BlockChainClient, EachBlockWith, TestBlockChainClient}; + use std::str::FromStr; #[test] fn return_block_headers() { @@ -412,7 +413,7 @@ mod test { let ss = TestSnapshotService::new(); let io = TestIo::new(&mut client, &ss, &queue, None); - let unknown: H256 = H256::new(); + let unknown: H256 = H256::zero(); let result = SyncSupplier::return_block_headers(&io, &Rlp::new(&make_hash_req(&unknown, 1, 0, false)), 0); assert!(to_header_vec(result).is_empty()); let result = SyncSupplier::return_block_headers(&io, &Rlp::new(&make_hash_req(&unknown, 1, 0, true)), 0); @@ -483,14 +484,14 @@ mod test { fn return_nodes() { let mut client = TestBlockChainClient::new(); let queue = RwLock::new(VecDeque::new()); - let sync = dummy_sync_with_peer(H256::new(), &client); + let sync = dummy_sync_with_peer(H256::zero(), &client); let ss = TestSnapshotService::new(); let mut io = TestIo::new(&mut client, &ss, &queue, None); let mut node_list = RlpStream::new_list(3); - node_list.append(&H256::from("0000000000000000000000000000000000000000000000005555555555555555")); - node_list.append(&H256::from("ffffffffffffffffffffffffffffffffffffffffffffaaaaaaaaaaaaaaaaaaaa")); - node_list.append(&H256::from("aff0000000000000000000000000000000000000000000000000000000000000")); + node_list.append(&H256::from_str("0000000000000000000000000000000000000000000000005555555555555555").unwrap()); + node_list.append(&H256::from_str("ffffffffffffffffffffffffffffffffffffffffffffaaaaaaaaaaaaaaaaaaaa").unwrap()); + node_list.append(&H256::from_str("aff0000000000000000000000000000000000000000000000000000000000000").unwrap()); let node_request = node_list.out(); // it returns rlp ONLY for hashes started with "f" @@ -527,15 +528,15 @@ mod test { fn return_receipts() { let mut client = TestBlockChainClient::new(); let queue = RwLock::new(VecDeque::new()); - let sync = dummy_sync_with_peer(H256::new(), &client); + let sync = dummy_sync_with_peer(H256::zero(), &client); let ss = TestSnapshotService::new(); let mut io = TestIo::new(&mut client, &ss, &queue, None); let mut receipt_list = RlpStream::new_list(4); - receipt_list.append(&H256::from("0000000000000000000000000000000000000000000000005555555555555555")); - receipt_list.append(&H256::from("ff00000000000000000000000000000000000000000000000000000000000000")); - receipt_list.append(&H256::from("fff0000000000000000000000000000000000000000000000000000000000000")); - receipt_list.append(&H256::from("aff0000000000000000000000000000000000000000000000000000000000000")); + receipt_list.append(&H256::from_str("0000000000000000000000000000000000000000000000005555555555555555").unwrap()); + receipt_list.append(&H256::from_str("ff00000000000000000000000000000000000000000000000000000000000000").unwrap()); + receipt_list.append(&H256::from_str("fff0000000000000000000000000000000000000000000000000000000000000").unwrap()); + receipt_list.append(&H256::from_str("aff0000000000000000000000000000000000000000000000000000000000000").unwrap()); let receipts_request = receipt_list.out(); // it returns rlp ONLY for hashes started with "f" diff --git a/ethcore/sync/src/lib.rs b/ethcore/sync/src/lib.rs index 712a47801..aecf8fbb8 100644 --- a/ethcore/sync/src/lib.rs +++ b/ethcore/sync/src/lib.rs @@ -45,6 +45,7 @@ extern crate ethcore_light as light; #[cfg(test)] extern crate ethcore_private_tx; #[cfg(test)] extern crate kvdb_memorydb; #[cfg(test)] extern crate rustc_hex; +#[cfg(test)] extern crate rand_xorshift; #[macro_use] extern crate enum_primitive; diff --git a/ethcore/sync/src/light_sync/mod.rs b/ethcore/sync/src/light_sync/mod.rs index ccb1ec504..c37042544 100644 --- a/ethcore/sync/src/light_sync/mod.rs +++ b/ethcore/sync/src/light_sync/mod.rs @@ -50,7 +50,7 @@ use light::request::{self, CompleteHeadersRequest as HeadersRequest}; use network::PeerId; use ethereum_types::{H256, U256}; use parking_lot::{Mutex, RwLock}; -use rand::{Rng, OsRng}; +use rand::{rngs::OsRng, seq::SliceRandom}; use futures::sync::mpsc; use self::sync_round::{AbortReason, SyncRound, ResponseContext}; @@ -637,7 +637,7 @@ impl LightSync { // naive request dispatcher: just give to any peer which says it will // give us responses. but only one request per peer per state transition. let dispatcher = move |req: HeadersRequest| { - rng.shuffle(&mut peer_ids); + peer_ids.shuffle(&mut *rng); let request = { let mut builder = request::Builder::default(); diff --git a/ethcore/sync/src/private_tx.rs b/ethcore/sync/src/private_tx.rs index c9396af5b..121ad081f 100644 --- a/ethcore/sync/src/private_tx.rs +++ b/ethcore/sync/src/private_tx.rs @@ -33,11 +33,11 @@ pub struct NoopPrivateTxHandler; impl PrivateTxHandler for NoopPrivateTxHandler { fn import_private_transaction(&self, _rlp: &[u8]) -> Result { - Ok(H256::default()) + Ok(H256::zero()) } fn import_signed_private_transaction(&self, _rlp: &[u8]) -> Result { - Ok(H256::default()) + Ok(H256::zero()) } } @@ -53,11 +53,11 @@ pub struct SimplePrivateTxHandler { impl PrivateTxHandler for SimplePrivateTxHandler { fn import_private_transaction(&self, rlp: &[u8]) -> Result { self.txs.lock().push(rlp.to_vec()); - Ok(H256::default()) + Ok(H256::zero()) } fn import_signed_private_transaction(&self, rlp: &[u8]) -> Result { self.signed_txs.lock().push(rlp.to_vec()); - Ok(H256::default()) + Ok(H256::zero()) } } diff --git a/ethcore/sync/src/snapshot.rs b/ethcore/sync/src/snapshot.rs index 64e463c7b..e7c2c3dce 100644 --- a/ethcore/sync/src/snapshot.rs +++ b/ethcore/sync/src/snapshot.rs @@ -188,15 +188,15 @@ mod test { } fn test_manifest() -> (ManifestData, H256, Vec, Vec) { - let state_chunks: Vec = (0..20).map(|_| H256::random().to_vec()).collect(); - let block_chunks: Vec = (0..20).map(|_| H256::random().to_vec()).collect(); + let state_chunks: Vec = (0..20).map(|_| H256::random().as_bytes().to_vec()).collect(); + let block_chunks: Vec = (0..20).map(|_| H256::random().as_bytes().to_vec()).collect(); let manifest = ManifestData { version: 2, state_hashes: state_chunks.iter().map(|data| keccak(data)).collect(), block_hashes: block_chunks.iter().map(|data| keccak(data)).collect(), - state_root: H256::new(), + state_root: H256::zero(), block_number: 42, - block_hash: H256::new(), + block_hash: H256::zero(), }; let mhash = keccak(manifest.clone().into_rlp()); (manifest, mhash, state_chunks, block_chunks) @@ -219,7 +219,7 @@ mod test { let (manifest, mhash, state_chunks, block_chunks) = test_manifest(); snapshot.reset_to(&manifest, &mhash); assert_eq!(snapshot.done_chunks(), 0); - assert!(snapshot.validate_chunk(&H256::random().to_vec()).is_err()); + assert!(snapshot.validate_chunk(&H256::random().as_bytes().to_vec()).is_err()); let requested: Vec = (0..40).map(|_| snapshot.needed_chunk().unwrap()).collect(); assert!(snapshot.needed_chunk().is_none()); diff --git a/ethcore/sync/src/tests/consensus.rs b/ethcore/sync/src/tests/consensus.rs index df0936633..ca6d4102a 100644 --- a/ethcore/sync/src/tests/consensus.rs +++ b/ethcore/sync/src/tests/consensus.rs @@ -32,7 +32,7 @@ fn new_tx(secret: &Secret, nonce: U256, chain_id: u64) -> PendingTransaction { nonce: nonce.into(), gas_price: 0.into(), gas: 21000.into(), - action: Action::Call(Address::default()), + action: Action::Call(Address::zero()), value: 0.into(), data: Vec::new(), }.sign(secret, Some(chain_id)); @@ -41,8 +41,8 @@ fn new_tx(secret: &Secret, nonce: U256, chain_id: u64) -> PendingTransaction { #[test] fn authority_round() { - let s0 = KeyPair::from_secret_slice(&keccak("1")).unwrap(); - let s1 = KeyPair::from_secret_slice(&keccak("0")).unwrap(); + let s0 = KeyPair::from_secret_slice(keccak("1").as_bytes()).unwrap(); + let s1 = KeyPair::from_secret_slice(keccak("0").as_bytes()).unwrap(); let chain_id = Spec::new_test_round().chain_id(); let mut net = TestNet::with_spec(2, SyncConfig::default(), Spec::new_test_round); diff --git a/ethcore/sync/src/tests/private.rs b/ethcore/sync/src/tests/private.rs index b56f0ecc2..dd421cef8 100644 --- a/ethcore/sync/src/tests/private.rs +++ b/ethcore/sync/src/tests/private.rs @@ -41,8 +41,8 @@ fn seal_spec() -> Spec { #[test] fn send_private_transaction() { // Setup two clients - let s0 = KeyPair::from_secret_slice(&keccak("1")).unwrap(); - let s1 = KeyPair::from_secret_slice(&keccak("0")).unwrap(); + let s0 = KeyPair::from_secret_slice(keccak("1").as_bytes()).unwrap(); + let s1 = KeyPair::from_secret_slice(keccak("0").as_bytes()).unwrap(); let signer = Arc::new(ethcore_private_tx::KeyPairSigner(vec![s0.clone(), s1.clone()])); diff --git a/ethcore/sync/src/tests/snapshot.rs b/ethcore/sync/src/tests/snapshot.rs index a3aa77d36..60459defb 100644 --- a/ethcore/sync/src/tests/snapshot.rs +++ b/ethcore/sync/src/tests/snapshot.rs @@ -49,13 +49,13 @@ impl TestSnapshotService { pub fn new_with_snapshot(num_chunks: usize, block_hash: H256, block_number: BlockNumber) -> TestSnapshotService { let num_state_chunks = num_chunks / 2; let num_block_chunks = num_chunks - num_state_chunks; - let state_chunks: Vec = (0..num_state_chunks).map(|_| H256::random().to_vec()).collect(); - let block_chunks: Vec = (0..num_block_chunks).map(|_| H256::random().to_vec()).collect(); + let state_chunks: Vec = (0..num_state_chunks).map(|_| H256::random().as_bytes().to_vec()).collect(); + let block_chunks: Vec = (0..num_block_chunks).map(|_| H256::random().as_bytes().to_vec()).collect(); let manifest = ManifestData { version: 2, state_hashes: state_chunks.iter().map(|data| keccak(data)).collect(), block_hashes: block_chunks.iter().map(|data| keccak(data)).collect(), - state_root: H256::new(), + state_root: H256::zero(), block_number: block_number, block_hash: block_hash, }; @@ -145,7 +145,7 @@ fn snapshot_sync() { let mut config = SyncConfig::default(); config.warp_sync = WarpSync::Enabled; let mut net = TestNet::new_with_config(5, config); - let snapshot_service = Arc::new(TestSnapshotService::new_with_snapshot(16, H256::new(), 500000)); + let snapshot_service = Arc::new(TestSnapshotService::new_with_snapshot(16, H256::zero(), 500000)); for i in 0..4 { net.peer_mut(i).snapshot_service = snapshot_service.clone(); net.peer(i).chain.add_blocks(1, EachBlockWith::Nothing); diff --git a/ethcore/sync/src/transactions_stats.rs b/ethcore/sync/src/transactions_stats.rs index 91094fa5f..5f4ab0ab3 100644 --- a/ethcore/sync/src/transactions_stats.rs +++ b/ethcore/sync/src/transactions_stats.rs @@ -91,15 +91,15 @@ impl TransactionsStats { mod tests { use std::collections::{HashMap, HashSet}; - use super::{Stats, TransactionsStats}; + use super::{Stats, TransactionsStats, NodeId, H256}; #[test] fn should_keep_track_of_propagations() { // given let mut stats = TransactionsStats::default(); - let hash = 5.into(); - let enodeid1 = 2.into(); - let enodeid2 = 5.into(); + let hash = H256::from_low_u64_be(5); + let enodeid1 = NodeId::from_low_u64_be(2); + let enodeid2 = NodeId::from_low_u64_be(5); // when stats.propagated(&hash, Some(enodeid1), 5); @@ -121,8 +121,8 @@ mod tests { fn should_remove_hash_from_tracking() { // given let mut stats = TransactionsStats::default(); - let hash = 5.into(); - let enodeid1 = 5.into(); + let hash = H256::from_low_u64_be(5); + let enodeid1 = NodeId::from_low_u64_be(5); stats.propagated(&hash, Some(enodeid1), 10); // when diff --git a/ethcore/types/Cargo.toml b/ethcore/types/Cargo.toml index e3f9bd1db..98e7c325b 100644 --- a/ethcore/types/Cargo.toml +++ b/ethcore/types/Cargo.toml @@ -5,13 +5,13 @@ version = "0.1.0" authors = ["Parity Technologies "] [dependencies] -ethereum-types = "0.4" +ethereum-types = "0.6.0" ethjson = { path = "../../json" } ethkey = { path = "../../accounts/ethkey" } heapsize = "0.4" -keccak-hash = "0.1" +keccak-hash = "0.2.0" parity-bytes = "0.1" -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" rlp_derive = { path = "../../util/rlp-derive" } unexpected = { path = "../../util/unexpected" } diff --git a/ethcore/types/src/account_diff.rs b/ethcore/types/src/account_diff.rs index 09751ba45..90ee73305 100644 --- a/ethcore/types/src/account_diff.rs +++ b/ethcore/types/src/account_diff.rs @@ -19,7 +19,8 @@ use std::cmp::*; use std::fmt; use std::collections::BTreeMap; -use ethereum_types::{H256, U256}; +use std::convert::TryFrom; +use ethereum_types::{BigEndianHash as _, H256, U256}; use bytes::Bytes; #[derive(Debug, PartialEq, Eq, Clone)] @@ -104,12 +105,9 @@ impl AccountDiff { // TODO: refactor into something nicer. fn interpreted_hash(u: &H256) -> String { - if u <= &H256::from(0xffffffff) { - format!("{} = 0x{:x}", U256::from(&**u).low_u32(), U256::from(&**u).low_u32()) - } else if u <= &H256::from(u64::max_value()) { - format!("{} = 0x{:x}", U256::from(&**u).low_u64(), U256::from(&**u).low_u64()) -// } else if u <= &H256::from("0xffffffffffffffffffffffffffffffffffffffff") { -// format!("@{}", Address::from(u)) + let uint = u.into_uint(); + if let Ok(n) = u64::try_from(uint) { + format!("{} = {:#x}", n, n) } else { format!("#{}", u) } diff --git a/ethcore/types/src/filter.rs b/ethcore/types/src/filter.rs index 71e8d3944..86f679769 100644 --- a/ethcore/types/src/filter.rs +++ b/ethcore/types/src/filter.rs @@ -76,7 +76,7 @@ impl Filter { let blooms = match self.address { Some(ref addresses) if !addresses.is_empty() => addresses.iter() - .map(|ref address| Bloom::from(BloomInput::Raw(address))) + .map(|ref address| Bloom::from(BloomInput::Raw(address.as_bytes()))) .collect(), _ => vec![Bloom::default()] }; @@ -86,7 +86,7 @@ impl Filter { Some(ref topics) => bs.into_iter().flat_map(|bloom| { topics.into_iter().map(|topic| { let mut b = bloom.clone(); - b.accrue(BloomInput::Raw(topic)); + b.accrue(BloomInput::Raw(topic.as_bytes())); b }).collect::>() }).collect() @@ -109,10 +109,11 @@ impl Filter { #[cfg(test)] mod tests { - use ethereum_types::Bloom; + use ethereum_types::{Bloom, Address, H256}; use filter::Filter; use ids::BlockId; use log_entry::LogEntry; + use std::str::FromStr; #[test] fn test_bloom_possibilities_none() { @@ -135,9 +136,9 @@ mod tests { let filter = Filter { from_block: BlockId::Earliest, to_block: BlockId::Latest, - address: Some(vec!["b372018f3be9e171df0581136b59d2faf73a7d5d".into()]), + address: Some(vec![Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap()]), topics: vec![ - Some(vec!["ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into()]), + Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]), None, None, None, @@ -146,7 +147,7 @@ mod tests { }; let possibilities = filter.bloom_possibilities(); - assert_eq!(possibilities, vec!["00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000004000000004000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000".into()] as Vec); + assert_eq!(possibilities, vec![Bloom::from_str("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000004000000004000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000").unwrap()]); } #[test] @@ -154,10 +155,10 @@ mod tests { let filter = Filter { from_block: BlockId::Earliest, to_block: BlockId::Latest, - address: Some(vec!["b372018f3be9e171df0581136b59d2faf73a7d5d".into()]), + address: Some(vec![Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap()]), topics: vec![ - Some(vec!["ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into()]), - Some(vec!["ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into()]), + Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]), + Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]), None, None, ], @@ -165,7 +166,7 @@ mod tests { }; let possibilities = filter.bloom_possibilities(); - assert_eq!(possibilities, vec!["00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000004000000004000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000".into()] as Vec); + assert_eq!(possibilities, vec![Bloom::from_str("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000004000000004000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000").unwrap()]); } #[test] @@ -174,19 +175,19 @@ mod tests { from_block: BlockId::Earliest, to_block: BlockId::Latest, address: Some(vec![ - "b372018f3be9e171df0581136b59d2faf73a7d5d".into(), - "b372018f3be9e171df0581136b59d2faf73a7d5d".into(), + Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap(), + Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap(), ]), topics: vec![ Some(vec![ - "ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into(), - "ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into() + H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap(), + H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap() ]), Some(vec![ - "ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into(), - "ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into() + H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap(), + H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap() ]), - Some(vec!["ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into()]), + Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]), None ], limit: None, @@ -195,7 +196,7 @@ mod tests { // number of possibilites should be equal 2 * 2 * 2 * 1 = 8 let possibilities = filter.bloom_possibilities(); assert_eq!(possibilities.len(), 8); - assert_eq!(possibilities[0], Bloom::from("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000004000000004000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000")); + assert_eq!(possibilities[0], Bloom::from_str("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000004000000004000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000").unwrap()); } #[test] @@ -203,10 +204,10 @@ mod tests { let filter = Filter { from_block: BlockId::Earliest, to_block: BlockId::Latest, - address: Some(vec!["b372018f3be9e171df0581136b59d2faf73a7d5d".into()]), + address: Some(vec![Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap()]), topics: vec![ - Some(vec!["ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into()]), - Some(vec!["ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23fa".into()]), + Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap()]), + Some(vec![H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23fa").unwrap()]), None, None, ], @@ -214,29 +215,29 @@ mod tests { }; let entry0 = LogEntry { - address: "b372018f3be9e171df0581136b59d2faf73a7d5d".into(), + address: Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap(), topics: vec![ - "ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into(), - "ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23fa".into(), - "ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into(), + H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap(), + H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23fa").unwrap(), + H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap(), ], data: vec![] }; let entry1 = LogEntry { - address: "b372018f3be9e171df0581136b59d2faf73a7d5e".into(), + address: Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5e").unwrap(), topics: vec![ - "ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into(), - "ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23fa".into(), - "ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into(), + H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap(), + H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23fa").unwrap(), + H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap(), ], data: vec![] }; let entry2 = LogEntry { - address: "b372018f3be9e171df0581136b59d2faf73a7d5d".into(), + address: Address::from_str("b372018f3be9e171df0581136b59d2faf73a7d5d").unwrap(), topics: vec![ - "ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9".into(), + H256::from_str("ff74e91598aed6ae5d2fdcf8b24cd2c7be49a0808112a305069355b7160f23f9").unwrap(), ], data: vec![] }; diff --git a/ethcore/types/src/header.rs b/ethcore/types/src/header.rs index cfe8f5bb6..408253bc5 100644 --- a/ethcore/types/src/header.rs +++ b/ethcore/types/src/header.rs @@ -115,10 +115,10 @@ impl PartialEq for Header { impl Default for Header { fn default() -> Self { Header { - parent_hash: H256::default(), + parent_hash: H256::zero(), timestamp: 0, number: 0, - author: Address::default(), + author: Address::zero(), transactions_root: KECCAK_NULL_RLP, uncles_hash: KECCAK_EMPTY_LIST_RLP, diff --git a/ethcore/types/src/log_entry.rs b/ethcore/types/src/log_entry.rs index a5087b2a0..cbbfb55bb 100644 --- a/ethcore/types/src/log_entry.rs +++ b/ethcore/types/src/log_entry.rs @@ -44,8 +44,8 @@ impl HeapSizeOf for LogEntry { impl LogEntry { /// Calculates the bloom of this log entry. pub fn bloom(&self) -> Bloom { - self.topics.iter().fold(Bloom::from(BloomInput::Raw(&self.address)), |mut b, t| { - b.accrue(BloomInput::Raw(t)); + self.topics.iter().fold(Bloom::from(BloomInput::Raw(self.address.as_bytes())), |mut b, t| { + b.accrue(BloomInput::Raw(t.as_bytes())); b }) } diff --git a/ethcore/types/src/receipt.rs b/ethcore/types/src/receipt.rs index aedb208a7..797eea816 100644 --- a/ethcore/types/src/receipt.rs +++ b/ethcore/types/src/receipt.rs @@ -168,8 +168,9 @@ pub struct LocalizedReceipt { #[cfg(test)] mod tests { - use super::{Receipt, TransactionOutcome}; + use super::{Receipt, TransactionOutcome, Address, H256}; use log_entry::LogEntry; + use std::str::FromStr; #[test] fn test_no_state_root() { @@ -178,7 +179,7 @@ mod tests { TransactionOutcome::Unknown, 0x40cae.into(), vec![LogEntry { - address: "dcf421d093428b096ca501a7cd1a740855a7976f".into(), + address: Address::from_str("dcf421d093428b096ca501a7cd1a740855a7976f").unwrap(), topics: vec![], data: vec![0u8; 32] }] @@ -190,10 +191,10 @@ mod tests { fn test_basic() { let expected = ::rustc_hex::FromHex::from_hex("f90162a02f697d671e9ae4ee24a43c4b0d7e15f1cb4ba6de1561120d43b9a4e8c4a8a6ee83040caeb9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000f838f794dcf421d093428b096ca501a7cd1a740855a7976fc0a00000000000000000000000000000000000000000000000000000000000000000").unwrap(); let r = Receipt::new( - TransactionOutcome::StateRoot("2f697d671e9ae4ee24a43c4b0d7e15f1cb4ba6de1561120d43b9a4e8c4a8a6ee".into()), + TransactionOutcome::StateRoot(H256::from_str("2f697d671e9ae4ee24a43c4b0d7e15f1cb4ba6de1561120d43b9a4e8c4a8a6ee").unwrap()), 0x40cae.into(), vec![LogEntry { - address: "dcf421d093428b096ca501a7cd1a740855a7976f".into(), + address: Address::from_str("dcf421d093428b096ca501a7cd1a740855a7976f").unwrap(), topics: vec![], data: vec![0u8; 32] }] @@ -211,7 +212,7 @@ mod tests { TransactionOutcome::StatusCode(0), 0x40cae.into(), vec![LogEntry { - address: "dcf421d093428b096ca501a7cd1a740855a7976f".into(), + address: Address::from_str("dcf421d093428b096ca501a7cd1a740855a7976f").unwrap(), topics: vec![], data: vec![0u8; 32] }] diff --git a/ethcore/types/src/transaction/transaction.rs b/ethcore/types/src/transaction/transaction.rs index 248bc2646..87241591c 100644 --- a/ethcore/types/src/transaction/transaction.rs +++ b/ethcore/types/src/transaction/transaction.rs @@ -18,7 +18,7 @@ use std::ops::Deref; -use ethereum_types::{H256, H160, Address, U256}; +use ethereum_types::{H256, H160, Address, U256, BigEndianHash}; use ethjson; use ethkey::{self, Signature, Secret, Public, recover, public_to_address}; use hash::keccak; @@ -179,7 +179,7 @@ impl From for UnverifiedTransaction { r: t.r.into(), s: t.s.into(), v: t.v.into(), - hash: 0.into(), + hash: H256::zero(), }.compute_hash() } } @@ -207,7 +207,7 @@ impl Transaction { r: sig.r().into(), s: sig.s().into(), v: signature::add_chain_replay_protection(sig.v() as u64, chain_id), - hash: 0.into(), + hash: H256::zero(), }.compute_hash() } @@ -219,7 +219,7 @@ impl Transaction { r: U256::one(), s: U256::one(), v: 0, - hash: 0.into(), + hash: H256::zero(), }.compute_hash() } @@ -231,7 +231,7 @@ impl Transaction { r: U256::one(), s: U256::one(), v: 0, - hash: 0.into(), + hash: H256::zero(), }.compute_hash(), sender: from, public: None, @@ -246,7 +246,7 @@ impl Transaction { r: U256::zero(), s: U256::zero(), v: chain_id, - hash: 0.into(), + hash: H256::zero(), }.compute_hash(), sender: UNSIGNED_SENDER, public: None, @@ -360,7 +360,9 @@ impl UnverifiedTransaction { /// Construct a signature object from the sig. pub fn signature(&self) -> Signature { - Signature::from_rsv(&self.r.into(), &self.s.into(), self.standard_v()) + let r: H256 = BigEndianHash::from_uint(&self.r); + let s: H256 = BigEndianHash::from_uint(&self.s); + Signature::from_rsv(&r, &s, self.standard_v()) } /// Checks whether the signature has a low 's' value. @@ -553,8 +555,9 @@ impl From for PendingTransaction { #[cfg(test)] mod tests { use super::*; - use ethereum_types::U256; + use ethereum_types::{U256, Address}; use hash::keccak; + use std::str::FromStr; #[test] fn sender_test() { @@ -565,10 +568,10 @@ mod tests { assert_eq!(t.gas_price, U256::from(0x01u64)); assert_eq!(t.nonce, U256::from(0x00u64)); if let Action::Call(ref to) = t.action { - assert_eq!(*to, "095e7baea6a6c7c4c2dfeb977efac326af552d87".into()); + assert_eq!(*to, Address::from_str("095e7baea6a6c7c4c2dfeb977efac326af552d87").unwrap()); } else { panic!(); } assert_eq!(t.value, U256::from(0x0au64)); - assert_eq!(public_to_address(&t.recover_public().unwrap()), "0f65fe9276bc9a24ae7083ae28e2660ef72df99e".into()); + assert_eq!(public_to_address(&t.recover_public().unwrap()), Address::from_str("0f65fe9276bc9a24ae7083ae28e2660ef72df99e").unwrap()); assert_eq!(t.chain_id(), None); } @@ -619,12 +622,12 @@ mod tests { gas: U256::from(50_000), value: U256::from(1), data: b"Hello!".to_vec() - }.fake_sign(Address::from(0x69)); - assert_eq!(Address::from(0x69), t.sender()); + }.fake_sign(Address::from_low_u64_be(0x69)); + assert_eq!(Address::from_low_u64_be(0x69), t.sender()); assert_eq!(t.chain_id(), None); let t = t.clone(); - assert_eq!(Address::from(0x69), t.sender()); + assert_eq!(Address::from_low_u64_be(0x69), t.sender()); assert_eq!(t.chain_id(), None); } @@ -651,7 +654,7 @@ mod tests { let test_vector = |tx_data: &str, address: &'static str| { let signed = rlp::decode(&FromHex::from_hex(tx_data).unwrap()).expect("decoding tx data failed"); let signed = SignedTransaction::new(signed).unwrap(); - assert_eq!(signed.sender(), address.into()); + assert_eq!(signed.sender(), Address::from_str(&address[2..]).unwrap()); println!("chainid: {:?}", signed.chain_id()); }; diff --git a/ethcore/types/src/views/block.rs b/ethcore/types/src/views/block.rs index 9ad67ddd6..5909da739 100644 --- a/ethcore/types/src/views/block.rs +++ b/ethcore/types/src/views/block.rs @@ -177,7 +177,8 @@ impl<'a> BlockView<'a> { #[cfg(test)] mod tests { use rustc_hex::FromHex; - use super::BlockView; + use super::{BlockView, H256}; + use std::str::FromStr; #[test] fn test_block_view() { @@ -185,7 +186,7 @@ mod tests { let rlp = "f90261f901f9a0d405da4e66f1445d455195229624e133f5baafe72b5cf7b3c36c12c8146e98b7a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a05fb2b4bfdef7b314451cb138a534d225c922fc0e5fbe25e451142732c3e25c25a088d2ec6b9860aae1a2c3b299f72b6a5d70d7f7ba4722c78f2c49ba96273c2158a007c6fdfa8eea7e86b81f5b0fc0f78f90cc19f4aa60d323151e0cac660199e9a1b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302008003832fefba82524d84568e932a80a0a0349d8c3df71f1a48a9df7d03fd5f14aeee7d91332c009ecaff0a71ead405bd88ab4e252a7e8c2a23f862f86002018304cb2f94ec0e71ad0a90ffe1909d27dac207f7680abba42d01801ba03a347e72953c860f32b1eb2c78a680d8734b2ea08085d949d729479796f218d5a047ea6239d9e31ccac8af3366f5ca37184d26e7646e3191a3aeb81c4cf74de500c0".from_hex().unwrap(); let view = view!(BlockView, &rlp); - assert_eq!(view.hash(), "2c9747e804293bd3f1a986484343f23bc88fd5be75dfe9d5c2860aff61e6f259".into()); + assert_eq!(view.hash(), H256::from_str("2c9747e804293bd3f1a986484343f23bc88fd5be75dfe9d5c2860aff61e6f259").unwrap()); assert_eq!(view.transactions_count(), 1); assert_eq!(view.uncles_count(), 0); } diff --git a/ethcore/types/src/views/header.rs b/ethcore/types/src/views/header.rs index 400989291..eaf91f179 100644 --- a/ethcore/types/src/views/header.rs +++ b/ethcore/types/src/views/header.rs @@ -120,8 +120,9 @@ impl<'a> HeaderView<'a> { #[cfg(test)] mod tests { use rustc_hex::FromHex; - use ethereum_types::Bloom; + use ethereum_types::{Bloom, H256, Address}; use super::HeaderView; + use std::str::FromStr; #[test] fn test_header_view() { @@ -131,13 +132,13 @@ mod tests { let nonce = "88ab4e252a7e8c2a23".from_hex().unwrap(); let view = view!(HeaderView, &rlp); - assert_eq!(view.hash(), "2c9747e804293bd3f1a986484343f23bc88fd5be75dfe9d5c2860aff61e6f259".into()); - assert_eq!(view.parent_hash(), "d405da4e66f1445d455195229624e133f5baafe72b5cf7b3c36c12c8146e98b7".into()); - assert_eq!(view.uncles_hash(), "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347".into()); - assert_eq!(view.author(), "8888f1f195afa192cfee860698584c030f4c9db1".into()); - assert_eq!(view.state_root(), "5fb2b4bfdef7b314451cb138a534d225c922fc0e5fbe25e451142732c3e25c25".into()); - assert_eq!(view.transactions_root(), "88d2ec6b9860aae1a2c3b299f72b6a5d70d7f7ba4722c78f2c49ba96273c2158".into()); - assert_eq!(view.receipts_root(), "07c6fdfa8eea7e86b81f5b0fc0f78f90cc19f4aa60d323151e0cac660199e9a1".into()); + assert_eq!(view.hash(), H256::from_str("2c9747e804293bd3f1a986484343f23bc88fd5be75dfe9d5c2860aff61e6f259").unwrap()); + assert_eq!(view.parent_hash(), H256::from_str("d405da4e66f1445d455195229624e133f5baafe72b5cf7b3c36c12c8146e98b7").unwrap()); + assert_eq!(view.uncles_hash(), H256::from_str("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347").unwrap()); + assert_eq!(view.author(), Address::from_str("8888f1f195afa192cfee860698584c030f4c9db1").unwrap()); + assert_eq!(view.state_root(), H256::from_str("5fb2b4bfdef7b314451cb138a534d225c922fc0e5fbe25e451142732c3e25c25").unwrap()); + assert_eq!(view.transactions_root(), H256::from_str("88d2ec6b9860aae1a2c3b299f72b6a5d70d7f7ba4722c78f2c49ba96273c2158").unwrap()); + assert_eq!(view.receipts_root(), H256::from_str("07c6fdfa8eea7e86b81f5b0fc0f78f90cc19f4aa60d323151e0cac660199e9a1").unwrap()); assert_eq!(view.log_bloom(), Bloom::default()); assert_eq!(view.difficulty(), 0x020080.into()); assert_eq!(view.number(), 3); diff --git a/ethcore/vm/Cargo.toml b/ethcore/vm/Cargo.toml index 19b84a6ec..cde8ed79e 100644 --- a/ethcore/vm/Cargo.toml +++ b/ethcore/vm/Cargo.toml @@ -6,10 +6,10 @@ authors = ["Parity Technologies "] [dependencies] byteorder = "1.0" parity-bytes = "0.1" -ethereum-types = "0.4" +ethereum-types = "0.6.0" trie-db = "0.11.0" patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" } log = "0.4" ethjson = { path = "../../json" } -rlp = { version = "0.3.0", features = ["ethereum"] } -keccak-hash = "0.1" +rlp = "0.4.0" +keccak-hash = "0.2.0" diff --git a/ethcore/vm/src/action_params.rs b/ethcore/vm/src/action_params.rs index 0d4959c18..3b974310c 100644 --- a/ethcore/vm/src/action_params.rs +++ b/ethcore/vm/src/action_params.rs @@ -96,11 +96,11 @@ impl Default for ActionParams { /// Returns default ActionParams initialized with zeros fn default() -> ActionParams { ActionParams { - code_address: Address::new(), + code_address: Address::zero(), code_hash: Some(KECCAK_EMPTY), - address: Address::new(), - sender: Address::new(), - origin: Address::new(), + address: Address::zero(), + sender: Address::zero(), + origin: Address::zero(), gas: U256::zero(), gas_price: U256::zero(), value: ActionValue::Transfer(U256::zero()), @@ -116,7 +116,7 @@ impl From for ActionParams { fn from(t: ethjson::vm::Transaction) -> Self { let address: Address = t.address.into(); ActionParams { - code_address: Address::new(), + code_address: Address::zero(), code_hash: Some(keccak(&*t.code)), address: address, sender: t.sender.into(), diff --git a/ethcore/vm/src/env_info.rs b/ethcore/vm/src/env_info.rs index e5bd3f64e..6c602d80f 100644 --- a/ethcore/vm/src/env_info.rs +++ b/ethcore/vm/src/env_info.rs @@ -51,7 +51,7 @@ impl Default for EnvInfo { fn default() -> Self { EnvInfo { number: 0, - author: Address::default(), + author: Address::zero(), timestamp: 0, difficulty: 0.into(), gas_limit: 0.into(), diff --git a/ethcore/vm/src/tests.rs b/ethcore/vm/src/tests.rs index 306ad871d..49af84259 100644 --- a/ethcore/vm/src/tests.rs +++ b/ethcore/vm/src/tests.rs @@ -107,11 +107,11 @@ impl FakeExt { impl Ext for FakeExt { fn initial_storage_at(&self, _key: &H256) -> Result { - Ok(H256::new()) + Ok(H256::zero()) } fn storage_at(&self, key: &H256) -> Result { - Ok(self.store.get(key).unwrap_or(&H256::new()).clone()) + Ok(self.store.get(key).unwrap_or(&H256::zero()).clone()) } fn set_storage(&mut self, key: H256, value: H256) -> Result<()> { @@ -136,7 +136,7 @@ impl Ext for FakeExt { } fn blockhash(&mut self, number: &U256) -> H256 { - self.blockhashes.get(number).unwrap_or(&H256::new()).clone() + self.blockhashes.get(number).unwrap_or(&H256::zero()).clone() } fn create( diff --git a/ethcore/wasm/Cargo.toml b/ethcore/wasm/Cargo.toml index 02aa978d7..9447642c6 100644 --- a/ethcore/wasm/Cargo.toml +++ b/ethcore/wasm/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] [dependencies] byteorder = "1.0" -ethereum-types = "0.4" +ethereum-types = "0.6.0" log = "0.4" parity-wasm = "0.31" libc = "0.2" diff --git a/ethcore/wasm/run/Cargo.toml b/ethcore/wasm/run/Cargo.toml index 9260d1eee..029183d67 100644 --- a/ethcore/wasm/run/Cargo.toml +++ b/ethcore/wasm/run/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Parity Technologies "] serde = "1" serde_json = "1" serde_derive = "1" -ethereum-types = "0.4" +ethereum-types = "0.6.0" ethjson = { path = "../../../json" } vm = { path = "../../vm" } wasm = { path = "../" } diff --git a/ethcore/wasm/run/src/runner.rs b/ethcore/wasm/run/src/runner.rs index a69fe6bf6..f43b4fa57 100644 --- a/ethcore/wasm/run/src/runner.rs +++ b/ethcore/wasm/run/src/runner.rs @@ -21,7 +21,7 @@ use vm::tests::FakeExt; use std::io::{self, Read}; use std::{fs, path, fmt}; use std::sync::Arc; -use ethereum_types::{U256, H256, H160}; +use ethereum_types::{U256, H256, H160, BigEndianHash}; use rustc_hex::ToHex; fn load_code>(p: P) -> io::Result> { @@ -95,17 +95,17 @@ impl fmt::Display for Fail { write!( f, "Storage key {} value mismatch, expected {}, got: {}", - key.to_vec().to_hex(), - expected.to_vec().to_hex(), - actual.to_vec().to_hex(), + key.as_bytes().to_vec().to_hex(), + expected.as_bytes().to_vec().to_hex(), + actual.as_bytes().to_vec().to_hex(), ), StorageMismatch { ref key, ref expected, actual: None} => write!( f, "No expected storage value for key {} found, expected {}", - key.to_vec().to_hex(), - expected.to_vec().to_hex(), + key.as_bytes().to_vec().to_hex(), + expected.as_bytes().to_vec().to_hex(), ), Nonconformity(SpecNonconformity::Address) => @@ -188,7 +188,7 @@ pub fn run_fixture(fixture: &Fixture) -> Vec { for storage_entry in storage.iter() { let key: U256 = storage_entry.key.into(); let val: U256 = storage_entry.value.into(); - ext.store.insert(key.into(), val.into()); + ext.store.insert(BigEndianHash::from_uint(&key), BigEndianHash::from_uint(&val)); } } diff --git a/ethcore/wasm/src/runtime.rs b/ethcore/wasm/src/runtime.rs index 8466c3b8d..164bde99e 100644 --- a/ethcore/wasm/src/runtime.rs +++ b/ethcore/wasm/src/runtime.rs @@ -15,7 +15,7 @@ // along with Parity Ethereum. If not, see . use std::cmp; -use ethereum_types::{U256, H256, Address}; +use ethereum_types::{BigEndianHash, U256, H256, Address}; use vm::{self, CallType}; use wasmi::{self, MemoryRef, RuntimeArgs, RuntimeValue, Error as InterpreterError, Trap, TrapKind}; use super::panic_payload; @@ -168,7 +168,7 @@ impl<'a> Runtime<'a> { let mut buf = [0u8; 32]; self.memory.get_into(ptr, &mut buf[..])?; - Ok(H256::from(&buf[..])) + Ok(H256::from_slice(&buf[..])) } /// Loads 160-bit hash (Ethereum address) from the specified sandboxed memory pointer @@ -176,7 +176,7 @@ impl<'a> Runtime<'a> { let mut buf = [0u8; 20]; self.memory.get_into(ptr, &mut buf[..])?; - Ok(Address::from(&buf[..])) + Ok(Address::from_slice(&buf[..])) } /// Loads 256-bit integer represented with bigendian from the specified sandboxed memory pointer @@ -262,7 +262,7 @@ impl<'a> Runtime<'a> { self.adjusted_charge(|schedule| schedule.sload_gas as u64)?; - self.memory.set(val_ptr as u32, &*val)?; + self.memory.set(val_ptr as u32, val.as_bytes())?; Ok(()) } @@ -502,14 +502,14 @@ impl<'a> Runtime<'a> { fn return_address_ptr(&mut self, ptr: u32, val: Address) -> Result<()> { self.charge(|schedule| schedule.wasm().static_address as u64)?; - self.memory.set(ptr, &*val)?; + self.memory.set(ptr, val.as_bytes())?; Ok(()) } fn return_u256_ptr(&mut self, ptr: u32, val: U256) -> Result<()> { - let value: H256 = val.into(); + let value: H256 = BigEndianHash::from_uint(&val); self.charge(|schedule| schedule.wasm().static_u256 as u64)?; - self.memory.set(ptr, &*value)?; + self.memory.set(ptr, value.as_bytes())?; Ok(()) } @@ -531,7 +531,7 @@ impl<'a> Runtime<'a> { match self.ext.create(&gas_left, &endowment, &code, scheme, false).ok().expect("Trap is false; trap error will not happen; qed") { vm::ContractCreateResult::Created(address, gas_left) => { - self.memory.set(result_ptr, &*address)?; + self.memory.set(result_ptr, address.as_bytes())?; self.gas_counter = self.gas_limit - // this cannot overflow, since initial gas is in [0..u64::max) range, // and gas_left cannot be bigger @@ -598,7 +598,7 @@ impl<'a> Runtime<'a> { trace!(target: "wasm", "runtime: CREATE2"); let endowment = self.u256_at(args.nth_checked(0)?)?; trace!(target: "wasm", " val: {:?}", endowment); - let salt: H256 = self.u256_at(args.nth_checked(1)?)?.into(); + let salt: H256 = BigEndianHash::from_uint(&self.u256_at(args.nth_checked(1)?)?); trace!(target: "wasm", " salt: {:?}", salt); let code_ptr: u32 = args.nth_checked(2)?; trace!(target: "wasm", " code_ptr: {:?}", code_ptr); @@ -646,7 +646,7 @@ impl<'a> Runtime<'a> { pub fn blockhash(&mut self, args: RuntimeArgs) -> Result<()> { self.adjusted_charge(|schedule| schedule.blockhash_gas as u64)?; let hash = self.ext.blockhash(&U256::from(args.nth_checked::(0)?)); - self.memory.set(args.nth_checked(1)?, &*hash)?; + self.memory.set(args.nth_checked(1)?, hash.as_bytes())?; Ok(()) } @@ -736,7 +736,7 @@ impl<'a> Runtime<'a> { *topics.get_mut(i as usize) .expect("topics is resized to `topic_count`, i is in 0..topic count iterator, get_mut uses i as an indexer, get_mut cannot fail; qed") - = H256::from(&self.memory.get(offset, 32)?[..]); + = H256::from_slice(&self.memory.get(offset, 32)?[..]); } self.ext.log(topics, &self.memory.get(data_ptr, data_len as usize)?).map_err(|_| Error::Log)?; diff --git a/ethcore/wasm/src/tests.rs b/ethcore/wasm/src/tests.rs index 9ed7053da..477d72314 100644 --- a/ethcore/wasm/src/tests.rs +++ b/ethcore/wasm/src/tests.rs @@ -16,8 +16,9 @@ use std::sync::Arc; use std::collections::HashMap; +use std::str::FromStr; use byteorder::{LittleEndian, ByteOrder}; -use ethereum_types::{H256, U256, Address}; +use ethereum_types::{H256, U256, Address, BigEndianHash as _}; use super::WasmInterpreter; use vm::{self, Exec, GasLeft, ActionParams, ActionValue, CreateContractAddress}; @@ -134,7 +135,10 @@ fn logger() { "Logger sets 0x03 key to the provided origin" ); assert_eq!( - U256::from(ext.store.get(&"0400000000000000000000000000000000000000000000000000000000000000".parse().unwrap()).expect("storage key to exist")), + ext.store + .get(&"0400000000000000000000000000000000000000000000000000000000000000".parse().unwrap()) + .expect("storage key to exist") + .into_uint(), U256::from(1_000_000_000), "Logger sets 0x04 key to the trasferred value" ); @@ -250,7 +254,7 @@ fn suicide() { params.code = Some(Arc::new(code)); let mut args = vec![127u8]; - args.extend(refund.to_vec()); + args.extend(refund.as_bytes().to_vec()); params.data = Some(args); let mut ext = FakeExt::new().with_wasm(); @@ -311,10 +315,13 @@ fn create() { code_address: None, } )); + let mut salt = [0u8; 32]; + salt[0] = 5; + let salt = H256::from_slice(salt.as_ref()); assert!(ext.calls.contains( &FakeCall { call_type: FakeCallType::Create, - create_scheme: Some(CreateContractAddress::FromSenderSaltAndCodeHash(H256::from([5u8].as_ref()))), + create_scheme: Some(CreateContractAddress::FromSenderSaltAndCodeHash(salt)), gas: U256::from(6039), sender_address: None, receive_address: None, @@ -572,7 +579,8 @@ fn storage_read() { params.gas = U256::from(100_000); params.code = Some(Arc::new(code)); let mut ext = FakeExt::new().with_wasm(); - ext.store.insert("0100000000000000000000000000000000000000000000000000000000000000".into(), address.into()); + let hash = H256::from_str("0100000000000000000000000000000000000000000000000000000000000000").unwrap(); + ext.store.insert(hash, address.into()); let (gas_left, result) = { let mut interpreter = wasm_interpreter(params); @@ -583,7 +591,7 @@ fn storage_read() { } }; - assert_eq!(Address::from(&result[12..32]), address); + assert_eq!(Address::from_slice(&result[12..32]), address); assert_eq!(gas_left, U256::from(98_369)); } @@ -609,7 +617,10 @@ fn keccak() { } }; - assert_eq!(H256::from_slice(&result), H256::from("68371d7e884c168ae2022c82bd837d51837718a7f7dfb7aa3f753074a35e1d87")); + assert_eq!( + H256::from_slice(&result), + H256::from_str("68371d7e884c168ae2022c82bd837d51837718a7f7dfb7aa3f753074a35e1d87").unwrap(), + ); assert_eq!(gas_left, U256::from(85_949)); } @@ -786,7 +797,7 @@ fn externs() { number: 0x9999999999u64.into(), author: "efefefefefefefefefefefefefefefefefefefef".parse().unwrap(), timestamp: 0x8888888888u64.into(), - difficulty: H256::from("0f1f2f3f4f5f6f7f8f9fafbfcfdfefff0d1d2d3d4d5d6d7d8d9dadbdcdddedfd").into(), + difficulty: U256::from_str("0f1f2f3f4f5f6f7f8f9fafbfcfdfefff0d1d2d3d4d5d6d7d8d9dadbdcdddedfd").unwrap(), gas_limit: 0x777777777777u64.into(), last_hashes: Default::default(), gas_used: 0.into(), @@ -795,11 +806,11 @@ fn externs() { let mut hashes = HashMap::new(); hashes.insert( U256::from(0), - H256::from("9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d") + H256::from_str("9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d9d").unwrap(), ); hashes.insert( U256::from(1), - H256::from("7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b") + H256::from_str("7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b7b").unwrap(), ); hashes } @@ -926,7 +937,10 @@ fn embedded_keccak() { } }; - assert_eq!(H256::from_slice(&result), H256::from("68371d7e884c168ae2022c82bd837d51837718a7f7dfb7aa3f753074a35e1d87")); + assert_eq!( + H256::from_slice(&result), + H256::from_str("68371d7e884c168ae2022c82bd837d51837718a7f7dfb7aa3f753074a35e1d87").unwrap(), + ); assert_eq!(gas_left, U256::from(85_949)); } @@ -957,9 +971,15 @@ fn events() { assert_eq!(ext.logs.len(), 1); let log_entry = &ext.logs[0]; assert_eq!(log_entry.topics.len(), 2); - assert_eq!(&log_entry.topics[0], &H256::from("68371d7e884c168ae2022c82bd837d51837718a7f7dfb7aa3f753074a35e1d87")); - assert_eq!(&log_entry.topics[1], &H256::from("871d5ea37430753faab7dff7a7187783517d83bd822c02e28a164c887e1d3768")); - assert_eq!(&log_entry.data, b"gnihtemos"); + assert_eq!( + log_entry.topics[0], + H256::from_str("68371d7e884c168ae2022c82bd837d51837718a7f7dfb7aa3f753074a35e1d87").unwrap(), + ); + assert_eq!( + log_entry.topics[1], + H256::from_str("871d5ea37430753faab7dff7a7187783517d83bd822c02e28a164c887e1d3768").unwrap(), + ); + assert_eq!(log_entry.data, b"gnihtemos"); assert_eq!(&result, b"gnihtemos"); assert_eq!(gas_left, U256::from(83_161)); diff --git a/evmbin/Cargo.toml b/evmbin/Cargo.toml index 95b532366..a483a4b19 100644 --- a/evmbin/Cargo.toml +++ b/evmbin/Cargo.toml @@ -13,7 +13,7 @@ common-types = { path = "../ethcore/types" } docopt = "1.0" env_logger = "0.5" ethcore = { path = "../ethcore", features = ["test-helpers", "json-tests", "to-pod-full"] } -ethereum-types = "0.4" +ethereum-types = "0.6.0" ethjson = { path = "../json" } evm = { path = "../ethcore/evm" } panic_hook = { path = "../util/panic-hook" } diff --git a/evmbin/src/display/json.rs b/evmbin/src/display/json.rs index eec5131c7..449938eab 100644 --- a/evmbin/src/display/json.rs +++ b/evmbin/src/display/json.rs @@ -19,7 +19,7 @@ use std::collections::HashMap; use std::mem; -use ethereum_types::{U256, H256}; +use ethereum_types::{U256, H256, BigEndianHash}; use bytes::ToPretty; use ethcore::trace; @@ -168,7 +168,7 @@ impl trace::VMTracer for Informant { } if let Some((pos, val)) = store_diff { - informant.storage.insert(pos.into(), val.into()); + informant.storage.insert(BigEndianHash::from_uint(&pos), BigEndianHash::from_uint(&val)); } if !informant.subtraces.is_empty() { diff --git a/evmbin/src/display/std_json.rs b/evmbin/src/display/std_json.rs index a0071b174..74d9e0040 100644 --- a/evmbin/src/display/std_json.rs +++ b/evmbin/src/display/std_json.rs @@ -19,7 +19,7 @@ use std::collections::HashMap; use std::io; -use ethereum_types::{H256, U256}; +use ethereum_types::{H256, U256, BigEndianHash}; use bytes::ToPretty; use ethcore::{trace, pod_state}; @@ -197,7 +197,7 @@ impl trace::VMTracer for Informant { let subdepth = self.subdepth; Self::with_informant_in_depth(self, subdepth, |informant: &mut Informant| { if let Some((pos, val)) = store_written { - informant.storage.insert(pos.into(), val.into()); + informant.storage.insert(BigEndianHash::from_uint(&pos), BigEndianHash::from_uint(&val)); } }); } diff --git a/evmbin/src/info.rs b/evmbin/src/info.rs index 74ea3175a..9090c5377 100644 --- a/evmbin/src/info.rs +++ b/evmbin/src/info.rs @@ -96,7 +96,7 @@ pub fn run_action( Ok(r) => (Ok(r.return_data.to_vec()), Some(r.gas_left)), Err(err) => (Err(err), None), }; - (result.0, 0.into(), None, result.1, informant.drain()) + (result.0, H256::from_low_u64_be(0), None, result.1, informant.drain()) }) } @@ -174,7 +174,7 @@ pub fn run<'a, F, X>( error, time: Duration::from_secs(0), traces: None, - state_root: H256::default(), + state_root: H256::zero(), end_state: None, })?; @@ -212,6 +212,7 @@ pub mod tests { use rustc_hex::FromHex; use super::*; use tempdir::TempDir; + use ethereum_types::Address; pub fn run_test( informant: I, @@ -247,7 +248,7 @@ pub mod tests { let (inf, res) = informant(); let mut params = ActionParams::default(); - params.code_address = 0x20.into(); + params.code_address = Address::from_low_u64_be(0x20); params.gas = 0xffff.into(); let spec = ::ethcore::ethereum::load(None, include_bytes!("../res/testchain.json")); diff --git a/evmbin/src/main.rs b/evmbin/src/main.rs index d69884867..ee75f9174 100644 --- a/evmbin/src/main.rs +++ b/evmbin/src/main.rs @@ -238,7 +238,7 @@ fn run_call(args: Args, informant: T) { let gas_price = arg(args.gas_price(), "--gas-price"); let data = arg(args.data(), "--input"); - if code.is_none() && to == Address::default() { + if code.is_none() && to == Address::zero() { die("Either --code or --to is required."); } @@ -305,14 +305,14 @@ impl Args { pub fn from(&self) -> Result { match self.flag_from { Some(ref from) => from.parse().map_err(to_string), - None => Ok(Address::default()), + None => Ok(Address::zero()), } } pub fn to(&self) -> Result { match self.flag_to { Some(ref to) => to.parse().map_err(to_string), - None => Ok(Address::default()), + None => Ok(Address::zero()), } } @@ -359,7 +359,7 @@ fn die(msg: T) -> ! { #[cfg(test)] mod tests { use docopt::Docopt; - use super::{Args, USAGE}; + use super::{Args, USAGE, Address}; fn run>(args: &[T]) -> Args { Docopt::new(USAGE).and_then(|d| d.argv(args.into_iter()).deserialize()).unwrap() @@ -388,8 +388,8 @@ mod tests { assert_eq!(args.flag_std_out_only, true); assert_eq!(args.gas(), Ok(1.into())); assert_eq!(args.gas_price(), Ok(2.into())); - assert_eq!(args.from(), Ok(3.into())); - assert_eq!(args.to(), Ok(4.into())); + assert_eq!(args.from(), Ok(Address::from_low_u64_be(3))); + assert_eq!(args.to(), Ok(Address::from_low_u64_be(4))); assert_eq!(args.code(), Ok(Some(vec![05]))); assert_eq!(args.data(), Ok(Some(vec![06]))); assert_eq!(args.flag_chain, Some("./testfile".to_owned())); diff --git a/ipfs/Cargo.toml b/ipfs/Cargo.toml index 23dc8d689..2fc02a7f6 100644 --- a/ipfs/Cargo.toml +++ b/ipfs/Cargo.toml @@ -8,10 +8,10 @@ authors = ["Parity Technologies "] [dependencies] ethcore = { path = "../ethcore" } parity-bytes = "0.1" -ethereum-types = "0.4" +ethereum-types = "0.6.0" jsonrpc-core = "10.0.1" jsonrpc-http-server = "10.0.1" -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" cid = "0.3" multihash = "0.8" unicase = "2.0" diff --git a/ipfs/src/route.rs b/ipfs/src/route.rs index f4a730338..1a4b5128f 100644 --- a/ipfs/src/route.rs +++ b/ipfs/src/route.rs @@ -56,7 +56,7 @@ impl IpfsHandler { if mh.alg != Hash::Keccak256 { return Err(Error::UnsupportedHash); } - let hash: H256 = mh.digest.into(); + let hash = H256::from_slice(&mh.digest); match cid.codec { Codec::EthereumBlock => self.block(hash), diff --git a/json/Cargo.toml b/json/Cargo.toml index 2a6d8c7f3..747042e85 100644 --- a/json/Cargo.toml +++ b/json/Cargo.toml @@ -4,9 +4,8 @@ version = "0.1.0" authors = ["Parity Technologies "] [dependencies] -ethereum-types = "0.4" +ethereum-types = "0.6.0" rustc-hex = "1.0" serde = "1.0" serde_json = "1.0" serde_derive = "1.0" - diff --git a/json/src/hash.rs b/json/src/hash.rs index a025dc454..3e364b950 100644 --- a/json/src/hash.rs +++ b/json/src/hash.rs @@ -20,7 +20,6 @@ use std::str::FromStr; use std::fmt; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::de::{Error, Visitor}; -use rustc_hex::ToHex; use ethereum_types::{H64 as Hash64, H160 as Hash160, H256 as Hash256, H520 as Hash520, Bloom as Hash2048}; macro_rules! impl_hash { @@ -56,8 +55,8 @@ macro_rules! impl_hash { fn visit_str(self, value: &str) -> Result where E: Error { let value = match value.len() { - 0 => $inner::from(0), - 2 if value == "0x" => $inner::from(0), + 0 => $inner::from_low_u64_be(0), + 2 if value == "0x" => $inner::from_low_u64_be(0), _ if value.starts_with("0x") => $inner::from_str(&value[2..]).map_err(|e| { Error::custom(format!("Invalid hex value {}: {}", value, e).as_str()) })?, @@ -80,14 +79,13 @@ macro_rules! impl_hash { impl Serialize for $name { fn serialize(&self, serializer: S) -> Result where S: Serializer { - let mut hex = "0x".to_owned(); - hex.push_str(&self.0.to_hex()); - serializer.serialize_str(&hex) + serializer.serialize_str(&format!("{:#x}", self.0)) } } } } + impl_hash!(H64, Hash64); impl_hash!(Address, Hash160); impl_hash!(H256, Hash256); @@ -106,13 +104,13 @@ mod test { let s = r#"["", "5a39ed1020c04d4d84539975b893a4e7c53eab6c2965db8bc3468093a31bc5ae"]"#; let deserialized: Vec = serde_json::from_str(s).unwrap(); assert_eq!(deserialized, vec![ - H256(ethereum_types::H256::from(0)), + H256(ethereum_types::H256::zero()), H256(ethereum_types::H256::from_str("5a39ed1020c04d4d84539975b893a4e7c53eab6c2965db8bc3468093a31bc5ae").unwrap()) ]); } #[test] fn hash_into() { - assert_eq!(ethereum_types::H256::from(0), H256(ethereum_types::H256::from(0)).into()); + assert_eq!(ethereum_types::H256::zero(), H256(ethereum_types::H256::zero()).into()); } } diff --git a/json/src/spec/authority_round.rs b/json/src/spec/authority_round.rs index 61936a5f9..cc437f6b9 100644 --- a/json/src/spec/authority_round.rs +++ b/json/src/spec/authority_round.rs @@ -76,6 +76,7 @@ mod tests { use hash::Address; use spec::validator_set::ValidatorSet; use spec::authority_round::AuthorityRound; + use std::str::FromStr; #[test] fn authority_round_deserialization() { @@ -95,7 +96,10 @@ mod tests { let deserialized: AuthorityRound = serde_json::from_str(s).unwrap(); assert_eq!(deserialized.params.step_duration, Uint(U256::from(0x02))); - assert_eq!(deserialized.params.validators, ValidatorSet::List(vec![Address(H160::from("0xc6d9d2cd449a754c494264e1809c50e34d64562b"))])); + assert_eq!( + deserialized.params.validators, + ValidatorSet::List(vec![Address(H160::from_str("c6d9d2cd449a754c494264e1809c50e34d64562b").unwrap())]), + ); assert_eq!(deserialized.params.start_step, Some(Uint(U256::from(24)))); assert_eq!(deserialized.params.immediate_transitions, None); assert_eq!(deserialized.params.maximum_uncle_count_transition, Some(Uint(10_000_000.into()))); diff --git a/json/src/spec/basic_authority.rs b/json/src/spec/basic_authority.rs index 195b89beb..c21333a12 100644 --- a/json/src/spec/basic_authority.rs +++ b/json/src/spec/basic_authority.rs @@ -46,6 +46,7 @@ mod tests { use hash::Address; use spec::basic_authority::BasicAuthority; use spec::validator_set::ValidatorSet; + use std::str::FromStr; #[test] fn basic_authority_deserialization() { @@ -61,7 +62,7 @@ mod tests { let deserialized: BasicAuthority = serde_json::from_str(s).unwrap(); assert_eq!(deserialized.params.duration_limit, Uint(U256::from(0x0d))); - let vs = ValidatorSet::List(vec![Address(H160::from("0xc6d9d2cd449a754c494264e1809c50e34d64562b"))]); + let vs = ValidatorSet::List(vec![Address(H160::from_str("c6d9d2cd449a754c494264e1809c50e34d64562b").unwrap())]); assert_eq!(deserialized.params.validators, vs); } } diff --git a/json/src/spec/clique.rs b/json/src/spec/clique.rs index 64be9c569..cef0ebfb8 100644 --- a/json/src/spec/clique.rs +++ b/json/src/spec/clique.rs @@ -37,8 +37,6 @@ pub struct Clique { #[cfg(test)] mod tests { use serde_json; - use uint::Uint; - use ethereum_types::U256; use super::*; #[test] diff --git a/json/src/spec/ethash.rs b/json/src/spec/ethash.rs index 6051ac90d..c9748c944 100644 --- a/json/src/spec/ethash.rs +++ b/json/src/spec/ethash.rs @@ -115,6 +115,7 @@ mod tests { use ethereum_types::{H160, U256}; use hash::Address; use spec::ethash::{Ethash, EthashParams, BlockReward}; + use std::str::FromStr; #[test] fn ethash_deserialization() { @@ -171,28 +172,28 @@ mod tests { block_reward_contract_code: None, block_reward_contract_transition: None, dao_hardfork_transition: Some(Uint(U256::from(0x08))), - dao_hardfork_beneficiary: Some(Address(H160::from("0xabcabcabcabcabcabcabcabcabcabcabcabcabca"))), + dao_hardfork_beneficiary: Some(Address(H160::from_str("abcabcabcabcabcabcabcabcabcabcabcabcabca").unwrap())), dao_hardfork_accounts: Some(vec![ - Address(H160::from("0x304a554a310c7e546dfe434669c62820b7d83490")), - Address(H160::from("0x914d1b8b43e92723e64fd0a06f5bdb8dd9b10c79")), - Address(H160::from("0xfe24cdd8648121a43a7c86d289be4dd2951ed49f")), - Address(H160::from("0x17802f43a0137c506ba92291391a8a8f207f487d")), - Address(H160::from("0xb136707642a4ea12fb4bae820f03d2562ebff487")), - Address(H160::from("0xdbe9b615a3ae8709af8b93336ce9b477e4ac0940")), - Address(H160::from("0xf14c14075d6c4ed84b86798af0956deef67365b5")), - Address(H160::from("0xca544e5c4687d109611d0f8f928b53a25af72448")), - Address(H160::from("0xaeeb8ff27288bdabc0fa5ebb731b6f409507516c")), - Address(H160::from("0xcbb9d3703e651b0d496cdefb8b92c25aeb2171f7")), - Address(H160::from("0xaccc230e8a6e5be9160b8cdf2864dd2a001c28b6")), - Address(H160::from("0x2b3455ec7fedf16e646268bf88846bd7a2319bb2")), - Address(H160::from("0x4613f3bca5c44ea06337a9e439fbc6d42e501d0a")), - Address(H160::from("0xd343b217de44030afaa275f54d31a9317c7f441e")), - Address(H160::from("0x84ef4b2357079cd7a7c69fd7a37cd0609a679106")), - Address(H160::from("0xda2fef9e4a3230988ff17df2165440f37e8b1708")), - Address(H160::from("0xf4c64518ea10f995918a454158c6b61407ea345c")), - Address(H160::from("0x7602b46df5390e432ef1c307d4f2c9ff6d65cc97")), - Address(H160::from("0xbb9bc244d798123fde783fcc1c72d3bb8c189413")), - Address(H160::from("0x807640a13483f8ac783c557fcdf27be11ea4ac7a")), + Address(H160::from_str("304a554a310c7e546dfe434669c62820b7d83490").unwrap()), + Address(H160::from_str("914d1b8b43e92723e64fd0a06f5bdb8dd9b10c79").unwrap()), + Address(H160::from_str("fe24cdd8648121a43a7c86d289be4dd2951ed49f").unwrap()), + Address(H160::from_str("17802f43a0137c506ba92291391a8a8f207f487d").unwrap()), + Address(H160::from_str("b136707642a4ea12fb4bae820f03d2562ebff487").unwrap()), + Address(H160::from_str("dbe9b615a3ae8709af8b93336ce9b477e4ac0940").unwrap()), + Address(H160::from_str("f14c14075d6c4ed84b86798af0956deef67365b5").unwrap()), + Address(H160::from_str("ca544e5c4687d109611d0f8f928b53a25af72448").unwrap()), + Address(H160::from_str("aeeb8ff27288bdabc0fa5ebb731b6f409507516c").unwrap()), + Address(H160::from_str("cbb9d3703e651b0d496cdefb8b92c25aeb2171f7").unwrap()), + Address(H160::from_str("accc230e8a6e5be9160b8cdf2864dd2a001c28b6").unwrap()), + Address(H160::from_str("2b3455ec7fedf16e646268bf88846bd7a2319bb2").unwrap()), + Address(H160::from_str("4613f3bca5c44ea06337a9e439fbc6d42e501d0a").unwrap()), + Address(H160::from_str("d343b217de44030afaa275f54d31a9317c7f441e").unwrap()), + Address(H160::from_str("84ef4b2357079cd7a7c69fd7a37cd0609a679106").unwrap()), + Address(H160::from_str("da2fef9e4a3230988ff17df2165440f37e8b1708").unwrap()), + Address(H160::from_str("f4c64518ea10f995918a454158c6b61407ea345c").unwrap()), + Address(H160::from_str("7602b46df5390e432ef1c307d4f2c9ff6d65cc97").unwrap()), + Address(H160::from_str("bb9bc244d798123fde783fcc1c72d3bb8c189413").unwrap()), + Address(H160::from_str("807640a13483f8ac783c557fcdf27be11ea4ac7a").unwrap()), ]), difficulty_hardfork_transition: Some(Uint(U256::from(0x59d9))), difficulty_hardfork_bound_divisor: Some(Uint(U256::from(0x0200))), diff --git a/json/src/spec/genesis.rs b/json/src/spec/genesis.rs index 1452bea0c..6c6def199 100644 --- a/json/src/spec/genesis.rs +++ b/json/src/spec/genesis.rs @@ -82,19 +82,19 @@ mod tests { let deserialized: Genesis = serde_json::from_str(s).unwrap(); assert_eq!(deserialized, Genesis { seal: Seal::Ethereum(Ethereum { - nonce: H64(Eth64::from("0x00006d6f7264656e")), - mix_hash: H256(Eth256::from("0x0000000000000000000000000000000000000000000000000000000000000000")) + nonce: H64(Eth64::from_str("00006d6f7264656e").unwrap()), + mix_hash: H256(Eth256::from_str("0000000000000000000000000000000000000000000000000000000000000000").unwrap()) }), difficulty: Uint(U256::from(0x400000000u64)), - author: Some(Address(H160::from("0x1000000000000000000000000000000000000001"))), + author: Some(Address(H160::from_str("1000000000000000000000000000000000000001").unwrap())), timestamp: Some(Uint(U256::from(0x07))), - parent_hash: Some(H256(Eth256::from("0x9000000000000000000000000000000000000000000000000000000000000000"))), + parent_hash: Some(H256(Eth256::from_str("9000000000000000000000000000000000000000000000000000000000000000").unwrap())), gas_limit: Uint(U256::from(0x1388)), transactions_root: None, receipts_root: None, - state_root: Some(H256(Eth256::from("0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544"))), + state_root: Some(H256(Eth256::from_str("d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544").unwrap())), gas_used: None, - extra_data: Some(Bytes::from_str("0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa").unwrap()), + extra_data: Some(Bytes::from_str("11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa").unwrap()), }); } } diff --git a/json/src/spec/hardcoded_sync.rs b/json/src/spec/hardcoded_sync.rs index 381cd1f1a..262d54312 100644 --- a/json/src/spec/hardcoded_sync.rs +++ b/json/src/spec/hardcoded_sync.rs @@ -40,6 +40,7 @@ mod tests { use ethereum_types::{U256, H256 as Eth256}; use hash::H256; use spec::hardcoded_sync::HardcodedSync; + use std::str::FromStr; #[test] fn hardcoded_sync_deserialization() { @@ -56,8 +57,8 @@ mod tests { header: String::from("f901f9a0d405da4e66f1445d455195229624e133f5baafe72b5cf7b3c36c12c8146e98b7a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a05fb2b4bfdef7b314451cb138a534d225c922fc0e5fbe25e451142732c3e25c25a088d2ec6b9860aae1a2c3b299f72b6a5d70d7f7ba4722c78f2c49ba96273c2158a007c6fdfa8eea7e86b81f5b0fc0f78f90cc19f4aa60d323151e0cac660199e9a1b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302008003832fefba82524d84568e932a80a0a0349d8c3df71f1a48a9df7d03fd5f14aeee7d91332c009ecaff0a71ead405bd88ab4e252a7e8c2a23"), total_difficulty: Uint(U256::from(0x400000000u64)), chts: vec![ - H256(Eth256::from("0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa")), - H256(Eth256::from("0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544")), + H256(Eth256::from_str("11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa").unwrap()), + H256(Eth256::from_str("d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544").unwrap()), ] }); } diff --git a/json/src/spec/seal.rs b/json/src/spec/seal.rs index e716a05bc..67238a5f5 100644 --- a/json/src/spec/seal.rs +++ b/json/src/spec/seal.rs @@ -76,6 +76,7 @@ mod tests { use uint::Uint; use ethereum_types::{U256, H64 as Eth64, H256 as Eth256, H520 as Eth520}; use spec::{Ethereum, AuthorityRoundSeal, TendermintSeal, Seal}; + use std::str::FromStr; #[test] fn seal_deserialization() { @@ -106,8 +107,8 @@ mod tests { // [0] assert_eq!(deserialized[0], Seal::Ethereum(Ethereum { - nonce: H64(Eth64::from("0x0000000000000042")), - mix_hash: H256(Eth256::from("0x1000000000000000000000000000000000000000000000000000000000000001")) + nonce: H64(Eth64::from_str("0000000000000042").unwrap()), + mix_hash: H256(Eth256::from_str("1000000000000000000000000000000000000000000000000000000000000001").unwrap()) })); // [1] @@ -118,14 +119,14 @@ mod tests { // [2] assert_eq!(deserialized[2], Seal::AuthorityRound(AuthorityRoundSeal { step: Uint(U256::from(0x0)), - signature: H520(Eth520::from("0x2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002")) + signature: H520(Eth520::from_str("2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002").unwrap()) })); // [3] assert_eq!(deserialized[3], Seal::Tendermint(TendermintSeal { round: Uint(U256::from(0x3)), - proposal: H520(Eth520::from("0x3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003")), - precommits: vec![H520(Eth520::from("0x4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004"))] + proposal: H520(Eth520::from_str("3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003").unwrap()), + precommits: vec![H520(Eth520::from_str("4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004").unwrap())] })); } } diff --git a/json/src/spec/validator_set.rs b/json/src/spec/validator_set.rs index e7e82282c..4de1d3aa0 100644 --- a/json/src/spec/validator_set.rs +++ b/json/src/spec/validator_set.rs @@ -42,6 +42,7 @@ mod tests { use ethereum_types::{H160, U256}; use hash::Address; use spec::validator_set::ValidatorSet; + use std::str::FromStr; #[test] fn validator_set_deserialization() { @@ -62,9 +63,9 @@ mod tests { let deserialized: Vec = serde_json::from_str(s).unwrap(); assert_eq!(deserialized.len(), 4); - assert_eq!(deserialized[0], ValidatorSet::List(vec![Address(H160::from("0xc6d9d2cd449a754c494264e1809c50e34d64562b"))])); - assert_eq!(deserialized[1], ValidatorSet::SafeContract(Address(H160::from("0xc6d9d2cd449a754c494264e1809c50e34d64562b")))); - assert_eq!(deserialized[2], ValidatorSet::Contract(Address(H160::from("0xc6d9d2cd449a754c494264e1809c50e34d64562b")))); + assert_eq!(deserialized[0], ValidatorSet::List(vec![Address(H160::from_str("c6d9d2cd449a754c494264e1809c50e34d64562b").unwrap())])); + assert_eq!(deserialized[1], ValidatorSet::SafeContract(Address(H160::from_str("c6d9d2cd449a754c494264e1809c50e34d64562b").unwrap()))); + assert_eq!(deserialized[2], ValidatorSet::Contract(Address(H160::from_str("c6d9d2cd449a754c494264e1809c50e34d64562b").unwrap()))); match deserialized[3] { ValidatorSet::Multi(ref map) => { assert_eq!(map.len(), 3); diff --git a/json/src/uint.rs b/json/src/uint.rs index 3f1d02f03..3428fd56c 100644 --- a/json/src/uint.rs +++ b/json/src/uint.rs @@ -34,22 +34,17 @@ impl Into for Uint { impl Into for Uint { fn into(self) -> u64 { - u64::from(self.0) + self.0.low_u64() } } impl Into for Uint { fn into(self) -> usize { - // TODO: clean it after util conversions refactored. - u64::from(self.0) as usize - } -} -impl Into for Uint { - fn into(self) -> u8 { - u64::from(self.0) as u8 + self.0.low_u64() as usize } } + impl Serialize for Uint { fn serialize(&self, serializer: S) -> Result where S: Serializer { @@ -101,7 +96,7 @@ pub fn validate_non_zero<'de, D>(d: D) -> Result where D: Deseri let value = Uint::deserialize(d)?; if value == Uint(U256::from(0)) { - return Err(Error::invalid_value(Unexpected::Unsigned(value.into()), &"a non-zero value")) + return Err(Error::invalid_value(Unexpected::Unsigned(0), &"a non-zero value")) } Ok(value) @@ -112,7 +107,7 @@ pub fn validate_optional_non_zero<'de, D>(d: D) -> Result, D::Error if let Some(value) = value { if value == Uint(U256::from(0)) { - return Err(Error::invalid_value(Unexpected::Unsigned(value.into()), &"a non-zero value")) + return Err(Error::invalid_value(Unexpected::Unsigned(0), &"a non-zero value")) } } diff --git a/miner/Cargo.toml b/miner/Cargo.toml index 4a017653b..68de893ec 100644 --- a/miner/Cargo.toml +++ b/miner/Cargo.toml @@ -17,20 +17,20 @@ url = { version = "1", optional = true } ansi_term = "0.10" common-types = { path = "../ethcore/types" } error-chain = "0.12" -ethabi = "6.0" -ethabi-derive = "6.0" -ethabi-contract = "6.0" +ethabi = "8.0" +ethabi-derive = "8.0" +ethabi-contract = "8.0" ethcore-call-contract = { path = "../ethcore/call-contract" } -ethereum-types = "0.4" +ethereum-types = "0.6.0" futures = "0.1" heapsize = "0.4" -keccak-hash = "0.1" +keccak-hash = "0.2.0" linked-hash-map = "0.5" log = "0.4" parity-runtime = { path = "../util/runtime" } parking_lot = "0.7" price-info = { path = "./price-info", optional = true } -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" diff --git a/miner/local-store/Cargo.toml b/miner/local-store/Cargo.toml index d16c64407..3d8030851 100644 --- a/miner/local-store/Cargo.toml +++ b/miner/local-store/Cargo.toml @@ -9,7 +9,7 @@ common-types = { path = "../../ethcore/types" } ethcore-io = { path = "../../util/io" } kvdb = "0.1" log = "0.4" -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" diff --git a/miner/src/external.rs b/miner/src/external.rs index f68e065ab..6355e5a2b 100644 --- a/miner/src/external.rs +++ b/miner/src/external.rs @@ -84,7 +84,7 @@ mod tests { // given let m = miner(); assert_eq!(m.hashrate(), U256::from(0)); - m.submit_hashrate(U256::from(10), H256::from(1)); + m.submit_hashrate(U256::from(10), H256::from_low_u64_be(1)); assert_eq!(m.hashrate(), U256::from(10)); // when @@ -99,12 +99,12 @@ mod tests { // given let m = miner(); assert_eq!(m.hashrate(), U256::from(0)); - m.submit_hashrate(U256::from(10), H256::from(1)); + m.submit_hashrate(U256::from(10), H256::from_low_u64_be(1)); assert_eq!(m.hashrate(), U256::from(10)); // when - m.submit_hashrate(U256::from(15), H256::from(1)); - m.submit_hashrate(U256::from(20), H256::from(2)); + m.submit_hashrate(U256::from(15), H256::from_low_u64_be(1)); + m.submit_hashrate(U256::from(20), H256::from_low_u64_be(2)); // then assert_eq!(m.hashrate(), U256::from(35)); diff --git a/miner/src/pool/listener.rs b/miner/src/pool/listener.rs index 0f53afb83..464f73be1 100644 --- a/miner/src/pool/listener.rs +++ b/miner/src/pool/listener.rs @@ -183,6 +183,7 @@ mod tests { use parking_lot::Mutex; use types::transaction; use txpool::Listener; + use ethereum_types::Address; #[test] fn should_notify_listeners() { @@ -217,7 +218,7 @@ mod tests { gas: 21_000.into(), gas_price: 5.into(), value: 0.into(), - }.fake_sign(5.into()); + }.fake_sign(Address::from_low_u64_be(5)); Arc::new(Transaction::from_pending_block_transaction(signed)) } diff --git a/miner/stratum/Cargo.toml b/miner/stratum/Cargo.toml index a7e13ef68..8ae35ca8c 100644 --- a/miner/stratum/Cargo.toml +++ b/miner/stratum/Cargo.toml @@ -6,8 +6,8 @@ license = "GPL-3.0" authors = ["Parity Technologies "] [dependencies] -ethereum-types = "0.4" -keccak-hash = "0.1" +ethereum-types = "0.6.0" +keccak-hash = "0.2.0" jsonrpc-core = "10.0.1" jsonrpc-tcp-server = "10.0.1" log = "0.4" diff --git a/parity/account_utils.rs b/parity/account_utils.rs index 29661978c..88a8dcfd4 100644 --- a/parity/account_utils.rs +++ b/parity/account_utils.rs @@ -61,6 +61,8 @@ mod accounts { mod accounts { use super::*; use upgrade::upgrade_key_location; + use ethereum_types::H160; + use std::str::FromStr; pub use accounts::AccountProvider; @@ -81,7 +83,7 @@ mod accounts { blacklisted_accounts: match *spec { SpecType::Morden | SpecType::Ropsten | SpecType::Kovan | SpecType::Sokol | SpecType::Dev => vec![], _ => vec![ - "00a329c0648769a73afac7f9381e08fb43dbea72".into() + H160::from_str("00a329c0648769a73afac7f9381e08fb43dbea72").expect("the string is valid hex; qed"), ], }, }; @@ -239,4 +241,3 @@ pub use self::accounts::{ private_tx_signer, accounts_list, }; - diff --git a/parity/configuration.rs b/parity/configuration.rs index 2b9832b8e..28bc08c90 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -742,7 +742,7 @@ impl Configuration { ret.listen_address = Some(format!("{}", listen)); ret.public_address = public.map(|p| format!("{}", p)); ret.use_secret = match self.args.arg_node_key.as_ref() - .map(|s| s.parse::().or_else(|_| Secret::from_unsafe_slice(&keccak(s))).map_err(|e| format!("Invalid key: {:?}", e)) + .map(|s| s.parse::().or_else(|_| Secret::from_unsafe_slice(keccak(s).as_bytes())).map_err(|e| format!("Invalid key: {:?}", e)) ) { None => None, Some(Ok(key)) => Some(key), diff --git a/parity/helpers.rs b/parity/helpers.rs index b68d854d1..2f0046f22 100644 --- a/parity/helpers.rs +++ b/parity/helpers.rs @@ -19,7 +19,7 @@ use std::io::{Write, BufReader, BufRead}; use std::time::Duration; use std::fs::File; use std::collections::HashSet; -use ethereum_types::{U256, clean_0x, Address}; +use ethereum_types::{U256, Address}; use journaldb::Algorithm; use ethcore::client::{Mode, BlockId, VMType, DatabaseCompactionProfile, ClientConfig, VerifierType}; use ethcore::miner::{PendingSet, Penalization}; @@ -37,6 +37,15 @@ pub fn to_duration(s: &str) -> Result { to_seconds(s).map(Duration::from_secs) } +// TODO: should we bring it back to ethereum-types? +fn clean_0x(s: &str) -> &str { + if s.starts_with("0x") { + &s[2..] + } else { + s + } +} + fn to_seconds(s: &str) -> Result { let bad = |_| { format!("{}: Invalid duration given. See parity --help for more information.", s) @@ -117,7 +126,7 @@ pub fn to_queue_penalization(time: Option) -> Result pub fn to_address(s: Option) -> Result { match s { Some(ref a) => clean_0x(a).parse().map_err(|_| format!("Invalid address: {:?}", a)), - None => Ok(Address::default()) + None => Ok(Address::zero()) } } diff --git a/parity/lib.rs b/parity/lib.rs index 9141bdcad..7d1bf108b 100644 --- a/parity/lib.rs +++ b/parity/lib.rs @@ -89,10 +89,6 @@ extern crate pretty_assertions; #[cfg(test)] extern crate tempdir; -#[cfg(test)] -#[macro_use] -extern crate lazy_static; - mod account; mod account_utils; mod blockchain; diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index f529a0bcb..bd71c81e6 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -15,7 +15,8 @@ log = "0.4" multihash = "0.8" order-stat = "0.1" parking_lot = "0.7" -rand = "0.4" +rand = "0.6" +rand_xorshift = "0.1.1" rustc-hex = "1.0" semver = "0.9" serde = "1.0" @@ -44,7 +45,7 @@ ethcore-miner = { path = "../miner" } ethcore-network = { path = "../util/network" } ethcore-private-tx = { path = "../ethcore/private-tx" } ethcore-sync = { path = "../ethcore/sync" } -ethereum-types = "0.4" +ethereum-types = "0.6.0" fastmap = { path = "../util/fastmap" } parity-bytes = "0.1" parity-crypto = "0.4.0" @@ -54,11 +55,11 @@ ethjson = { path = "../json" } ethkey = { path = "../accounts/ethkey" } ethstore = { path = "../accounts/ethstore" } fetch = { path = "../util/fetch" } -keccak-hash = "0.1.2" +keccak-hash = "0.2.0" parity-runtime = { path = "../util/runtime" } parity-updater = { path = "../updater" } parity-version = { path = "../util/version" } -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" stats = { path = "../util/stats" } vm = { path = "../ethcore/vm" } diff --git a/rpc/src/authcodes.rs b/rpc/src/authcodes.rs index b348dfd72..a4f440a71 100644 --- a/rpc/src/authcodes.rs +++ b/rpc/src/authcodes.rs @@ -19,8 +19,7 @@ use std::path::Path; use std::{fs, time, mem}; use itertools::Itertools; -use rand::Rng; -use rand::os::OsRng; +use rand::{Rng, rngs::OsRng, distributions::Alphanumeric}; use hash::keccak; use ethereum_types::H256; @@ -175,7 +174,7 @@ impl AuthCodes { /// Generates and returns a new code that can be used by `SignerUIs` pub fn generate_new(&mut self) -> io::Result { let mut rng = OsRng::new()?; - let code = rng.gen_ascii_chars().take(TOKEN_LENGTH).collect::(); + let code = rng.sample_iter(&Alphanumeric).take(TOKEN_LENGTH).collect::(); let readable_code = code.as_bytes() .chunks(4) .filter_map(|f| String::from_utf8(f.to_vec()).ok()) diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index e34aab673..324aea1d2 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -97,6 +97,9 @@ extern crate log; #[macro_use] extern crate serde_derive; +#[cfg(test)] +extern crate rand_xorshift; + #[cfg(test)] extern crate ethjson; #[cfg(test)] diff --git a/rpc/src/v1/extractors.rs b/rpc/src/v1/extractors.rs index d3384c2c1..6b880b754 100644 --- a/rpc/src/v1/extractors.rs +++ b/rpc/src/v1/extractors.rs @@ -52,7 +52,7 @@ impl HttpMetaExtractor for RpcExtractor { impl ipc::MetaExtractor for RpcExtractor { fn extract(&self, req: &ipc::RequestContext) -> Metadata { Metadata { - origin: Origin::Ipc(req.session_id.into()), + origin: Origin::Ipc(H256::from_low_u64_be(req.session_id)), session: Some(Arc::new(Session::new(req.sender.clone()))), } } @@ -81,10 +81,10 @@ impl ws::MetaExtractor for WsExtractor { let authorization = req.protocols.get(0).and_then(|p| auth_token_hash(&path, p, true)); match authorization { Some(id) => Origin::Signer { session: id }, - None => Origin::Ws { session: id.into() }, + None => Origin::Ws { session: H256::from_low_u64_be(id) }, } }, - None => Origin::Ws { session: id.into() }, + None => Origin::Ws { session: H256::from_low_u64_be(id) }, }; let session = Some(Arc::new(Session::new(req.sender()))); Metadata { diff --git a/rpc/src/v1/helpers/external_signer/signing_queue.rs b/rpc/src/v1/helpers/external_signer/signing_queue.rs index 00a459a86..6f3435076 100644 --- a/rpc/src/v1/helpers/external_signer/signing_queue.rs +++ b/rpc/src/v1/helpers/external_signer/signing_queue.rs @@ -213,7 +213,7 @@ impl SigningQueue for ConfirmationsQueue { #[cfg(test)] mod test { use std::sync::Arc; - use ethereum_types::{U256, Address}; + use ethereum_types::{U256, Address, H256}; use parking_lot::Mutex; use jsonrpc_core::futures::Future; use v1::helpers::external_signer::{SigningQueue, ConfirmationsQueue, QueueEvent}; @@ -222,9 +222,9 @@ mod test { fn request() -> ConfirmationPayload { ConfirmationPayload::SendTransaction(FilledTransactionRequest { - from: Address::from(1), + from: Address::from_low_u64_be(1), used_default_from: false, - to: Some(Address::from(2)), + to: Some(Address::from_low_u64_be(2)), gas_price: 0.into(), gas: 10_000.into(), value: 10_000_000.into(), @@ -243,11 +243,11 @@ mod test { // when let (id, future) = queue.add_request(request, Default::default()).unwrap(); let sender = queue.take(&id).unwrap(); - queue.request_confirmed(sender, Ok(ConfirmationResponse::SendTransaction(1.into()))); + queue.request_confirmed(sender, Ok(ConfirmationResponse::SendTransaction(H256::from_low_u64_be(1)))); // then let confirmation = future.wait().unwrap(); - assert_eq!(confirmation, Ok(ConfirmationResponse::SendTransaction(1.into()))); + assert_eq!(confirmation, Ok(ConfirmationResponse::SendTransaction(H256::from_low_u64_be(1)))); } #[test] @@ -289,4 +289,3 @@ mod test { assert_eq!(el.payload, request); } } - diff --git a/rpc/src/v1/helpers/secretstore.rs b/rpc/src/v1/helpers/secretstore.rs index 6e1cbca45..6b90246cd 100644 --- a/rpc/src/v1/helpers/secretstore.rs +++ b/rpc/src/v1/helpers/secretstore.rs @@ -15,7 +15,7 @@ // along with Parity Ethereum. If not, see . use std::collections::BTreeSet; -use rand::{Rng, OsRng}; +use rand::{RngCore, rngs::OsRng}; use ethereum_types::{H256, H512}; use ethkey::{self, Public, Secret, Random, Generator, math}; use crypto; @@ -37,8 +37,11 @@ pub fn generate_document_key(account_public: Public, server_key_public: Public) let (common_point, encrypted_point) = encrypt_secret(document_key.public(), &server_key_public)?; // ..and now encrypt document key with account public - let encrypted_key = ethkey::crypto::ecies::encrypt(&account_public, &crypto::DEFAULT_MAC, document_key.public()) - .map_err(errors::encryption)?; + let encrypted_key = ethkey::crypto::ecies::encrypt( + &account_public, + &crypto::DEFAULT_MAC, + document_key.public().as_bytes(), + ).map_err(errors::encryption)?; Ok(EncryptedDocumentKey { common_point: common_point.into(), @@ -87,7 +90,7 @@ pub fn decrypt_document(key: Bytes, mut encrypted_document: Bytes) -> Result, encrypted_document: Bytes) -> Result { let key = decrypt_with_shadow_coefficients(decrypted_secret, common_point, shadows)?; - decrypt_document(key.to_vec(), encrypted_document) + decrypt_document(key.as_bytes().to_vec(), encrypted_document) } /// Calculate Keccak(ordered servers set) diff --git a/rpc/src/v1/helpers/subscribers.rs b/rpc/src/v1/helpers/subscribers.rs index 9483d8e32..157abb58d 100644 --- a/rpc/src/v1/helpers/subscribers.rs +++ b/rpc/src/v1/helpers/subscribers.rs @@ -20,7 +20,6 @@ use std::{ops, str}; use std::collections::HashMap; use jsonrpc_pubsub::{typed::{Subscriber, Sink}, SubscriptionId}; use ethereum_types::H64; -use rand::{Rng, StdRng}; #[derive(Debug, Clone, Hash, Eq, PartialEq)] pub struct Id(H64); @@ -42,34 +41,44 @@ impl Id { } } -#[derive(Clone)] +#[cfg(not(test))] +mod random { + use rand; + + pub type Rng = rand::rngs::OsRng; + + pub fn new() -> Rng { Rng::new().expect("Valid random source is required.") } +} + +#[cfg(test)] +mod random { + use rand::SeedableRng; + use rand_xorshift::XorShiftRng; + + const RNG_SEED: [u8; 16] = [0u8; 16]; + + pub type Rng = XorShiftRng; + + pub fn new() -> Rng { Rng::from_seed(RNG_SEED) } +} + pub struct Subscribers { - rand: StdRng, + rand: random::Rng, subscriptions: HashMap, } impl Default for Subscribers { fn default() -> Self { Subscribers { - rand: StdRng::new().expect("Valid random source is required."), + rand: random::new(), subscriptions: HashMap::new(), } } } impl Subscribers { - /// Create a new Subscribers with given random source. - #[cfg(test)] - pub fn new_test() -> Self { - Subscribers { - rand: ::rand::SeedableRng::from_seed([0usize].as_ref()), - subscriptions: HashMap::new(), - } - } - fn next_id(&mut self) -> Id { - let mut data = H64::default(); - self.rand.fill_bytes(&mut data.0); + let data = H64::random_using(&mut self.rand); Id(data) } diff --git a/rpc/src/v1/helpers/subscription_manager.rs b/rpc/src/v1/helpers/subscription_manager.rs index d83beb397..8323060b7 100644 --- a/rpc/src/v1/helpers/subscription_manager.rs +++ b/rpc/src/v1/helpers/subscription_manager.rs @@ -60,7 +60,7 @@ impl> GenericPollManager { #[cfg(test)] pub fn new_test(rpc: MetaIoHandler) -> Self { let mut manager = Self::new(rpc); - manager.subscribers = Subscribers::new_test(); + manager.subscribers = Subscribers::default(); manager } @@ -165,7 +165,7 @@ mod tests { let mut el = Runtime::new().unwrap(); let mut poll_manager = poll_manager(); let (id, rx) = poll_manager.subscribe(Default::default(), "hello".into(), Params::None); - assert_eq!(id, SubscriptionId::String("0x416d77337e24399d".into())); + assert_eq!(id, SubscriptionId::String("0x43ca64edf03768e1".into())); // then poll_manager.tick().wait().unwrap(); diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index a24d49d50..f630a8fc4 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -21,7 +21,7 @@ use std::time::{Instant, Duration, SystemTime, UNIX_EPOCH}; use std::sync::Arc; use rlp::Rlp; -use ethereum_types::{Address, H64, H160, H256, U64, U256}; +use ethereum_types::{Address, H64, H160, H256, U64, U256, BigEndianHash}; use parking_lot::Mutex; use ethash::{self, SeedHashCompute}; @@ -533,7 +533,7 @@ impl Eth for EthClient< fn author(&self) -> Result { let miner = self.miner.authoring_params().author; - if miner == 0.into() { + if miner.is_zero() { (self.accounts)() .first() .cloned() @@ -611,8 +611,8 @@ impl Eth for EthClient< let key2: H256 = storage_index; self.client.prove_storage(key1, keccak(key2), id) .map(|(storage_proof, storage_value)| StorageProof { - key: key2.into(), - value: storage_value.into(), + key: key2.into_uint(), + value: storage_value.into_uint(), proof: storage_proof.into_iter().map(Bytes::new).collect() }) }) @@ -628,7 +628,7 @@ impl Eth for EthClient< let num = num.unwrap_or_default(); try_bf!(check_known(&*self.client, num.clone())); - let res = match self.client.storage_at(&address, &H256::from(position), self.get_state(num)) { + let res = match self.client.storage_at(&address, &BigEndianHash::from_uint(&position), self.get_state(num)) { Some(s) => Ok(s), None => Err(errors::state_pruned()), }; diff --git a/rpc/src/v1/impls/eth_pubsub.rs b/rpc/src/v1/impls/eth_pubsub.rs index 39ae8754d..019cbd39f 100644 --- a/rpc/src/v1/impls/eth_pubsub.rs +++ b/rpc/src/v1/impls/eth_pubsub.rs @@ -104,17 +104,6 @@ impl EthPubSubClient { } } - /// Creates new `EthPubSubCient` with deterministic subscription ids. - #[cfg(test)] - pub fn new_test(client: Arc, executor: Executor) -> Self { - let client = Self::new(client, executor); - *client.heads_subscribers.write() = Subscribers::new_test(); - *client.logs_subscribers.write() = Subscribers::new_test(); - *client.transactions_subscribers.write() = Subscribers::new_test(); - *client.sync_subscribers.write() = Subscribers::new_test(); - client - } - /// Returns a chain notification handler. pub fn handler(&self) -> Weak> { Arc::downgrade(&self.handler) diff --git a/rpc/src/v1/impls/personal.rs b/rpc/src/v1/impls/personal.rs index b6af1f81e..e0d6a97fe 100644 --- a/rpc/src/v1/impls/personal.rs +++ b/rpc/src/v1/impls/personal.rs @@ -223,7 +223,7 @@ impl Personal for PersonalClient { fn ec_recover(&self, data: RpcBytes, signature: H520) -> BoxFuture { let signature: H520 = signature.into(); - let signature = Signature::from_electrum(&signature); + let signature = Signature::from_electrum(signature.as_bytes()); let data: Bytes = data.into(); let hash = eth_data_hash(data); diff --git a/rpc/src/v1/impls/signer.rs b/rpc/src/v1/impls/signer.rs index 4edac1144..3672f3c4c 100644 --- a/rpc/src/v1/impls/signer.rs +++ b/rpc/src/v1/impls/signer.rs @@ -18,7 +18,7 @@ use std::sync::Arc; -use ethereum_types::U256; +use ethereum_types::{U256, H520}; use ethkey; use parity_runtime::Executor; use parking_lot::Mutex; @@ -218,7 +218,7 @@ impl Signer for SignerClient { let expected_hash = eth_data_hash(data); let signature = ethkey::Signature::from_electrum(&bytes.0); match ethkey::verify_address(&address, &signature, &expected_hash) { - Ok(true) => Ok(ConfirmationResponse::Signature(bytes.0.as_slice().into())), + Ok(true) => Ok(ConfirmationResponse::Signature(H520::from_slice(bytes.0.as_slice()))), Ok(false) => Err(errors::invalid_params("Sender address does not match the signature.", ())), Err(err) => Err(errors::invalid_params("Invalid signature received.", err)), } @@ -226,7 +226,7 @@ impl Signer for SignerClient { ConfirmationPayload::SignMessage(address, hash) => { let signature = ethkey::Signature::from_electrum(&bytes.0); match ethkey::verify_address(&address, &signature, &hash) { - Ok(true) => Ok(ConfirmationResponse::Signature(bytes.0.as_slice().into())), + Ok(true) => Ok(ConfirmationResponse::Signature(H520::from_slice(bytes.0.as_slice()))), Ok(false) => Err(errors::invalid_params("Sender address does not match the signature.", ())), Err(err) => Err(errors::invalid_params("Invalid signature received.", err)), } diff --git a/rpc/src/v1/tests/eth.rs b/rpc/src/v1/tests/eth.rs index 9c2273746..ea9f5b722 100644 --- a/rpc/src/v1/tests/eth.rs +++ b/rpc/src/v1/tests/eth.rs @@ -495,7 +495,7 @@ fn verify_transaction_counts(name: String, chain: BlockChain) { #[test] fn starting_nonce_test() { let tester = EthTester::from_spec(Spec::load(&env::temp_dir(), POSITIVE_NONCE_SPEC).expect("invalid chain spec")); - let address = Address::from(10); + let address = Address::from_low_u64_be(10); let sample = tester.handler.handle_request_sync(&(r#" { diff --git a/rpc/src/v1/tests/helpers/sync_provider.rs b/rpc/src/v1/tests/helpers/sync_provider.rs index d044fd564..4c2ec6b88 100644 --- a/rpc/src/v1/tests/helpers/sync_provider.rs +++ b/rpc/src/v1/tests/helpers/sync_provider.rs @@ -17,7 +17,7 @@ //! Test implementation of SyncProvider. use std::collections::BTreeMap; -use ethereum_types::H256; +use ethereum_types::{H256, H512}; use parking_lot::RwLock; use network::client_version::ClientVersion; use futures::sync::mpsc; @@ -88,7 +88,7 @@ impl SyncProvider for TestSyncProvider { eth_info: Some(EthProtocolInfo { version: 62, difficulty: Some(40.into()), - head: 50.into(), + head: H256::from_low_u64_be(50), }), pip_info: None, }, @@ -101,7 +101,7 @@ impl SyncProvider for TestSyncProvider { eth_info: Some(EthProtocolInfo { version: 64, difficulty: None, - head: 60.into() + head: H256::from_low_u64_be(60), }), pip_info: None, } @@ -114,16 +114,16 @@ impl SyncProvider for TestSyncProvider { fn transactions_stats(&self) -> BTreeMap { map![ - 1.into() => TransactionStats { + H256::from_low_u64_be(1) => TransactionStats { first_seen: 10, propagated_to: map![ - 128.into() => 16 + H512::from_low_u64_be(128) => 16 ], }, - 5.into() => TransactionStats { + H256::from_low_u64_be(5) => TransactionStats { first_seen: 16, propagated_to: map![ - 16.into() => 1 + H512::from_low_u64_be(16) => 1 ], } ] diff --git a/rpc/src/v1/tests/helpers/update_service.rs b/rpc/src/v1/tests/helpers/update_service.rs index ccf3315c4..91db02fae 100644 --- a/rpc/src/v1/tests/helpers/update_service.rs +++ b/rpc/src/v1/tests/helpers/update_service.rs @@ -19,6 +19,7 @@ use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use semver::Version; use updater::{Service as UpdateService, CapState, ReleaseInfo, VersionInfo, OperationsInfo, ReleaseTrack}; +use ethereum_types::{H160, H256}; /// Test implementation of fetcher. Will always return the same file. #[derive(Default)] @@ -73,7 +74,7 @@ impl UpdateService for TestUpdater { VersionInfo { track: ReleaseTrack::Beta, version: Version{major: 1, minor: 5, patch: 0, build: vec![], pre: vec![]}, - hash: 150.into(), + hash: H160::from_low_u64_be(150), } } @@ -85,11 +86,11 @@ impl UpdateService for TestUpdater { version: VersionInfo { track: ReleaseTrack::Beta, version: Version{major: 1, minor: 5, patch: 1, build: vec![], pre: vec![]}, - hash: 151.into(), + hash: H160::from_low_u64_be(151), }, is_critical: true, fork: 15100, - binary: Some(1510.into()), + binary: Some(H256::from_low_u64_be(1510)), }, minor: None, }) diff --git a/rpc/src/v1/tests/mocked/eth.rs b/rpc/src/v1/tests/mocked/eth.rs index 75e05ce46..e9af200f7 100644 --- a/rpc/src/v1/tests/mocked/eth.rs +++ b/rpc/src/v1/tests/mocked/eth.rs @@ -22,7 +22,7 @@ use std::time::{Instant, Duration, SystemTime, UNIX_EPOCH}; use accounts::AccountProvider; use ethcore::client::{BlockChainClient, BlockId, EachBlockWith, Executed, TestBlockChainClient, TransactionId}; use ethcore::miner::{self, MinerService}; -use ethereum_types::{H160, H256, U256, Address}; +use ethereum_types::{H160, H256, U256, Address, Bloom}; use miner::external::ExternalMiner; use parity_runtime::Runtime; use parking_lot::Mutex; @@ -186,9 +186,9 @@ fn rpc_eth_chain_id() { #[test] fn rpc_eth_hashrate() { let tester = EthTester::default(); - tester.hashrates.lock().insert(H256::from(0), (Instant::now() + Duration::from_secs(2), U256::from(0xfffa))); - tester.hashrates.lock().insert(H256::from(0), (Instant::now() + Duration::from_secs(2), U256::from(0xfffb))); - tester.hashrates.lock().insert(H256::from(1), (Instant::now() + Duration::from_secs(2), U256::from(0x1))); + tester.hashrates.lock().insert(H256::from_low_u64_be(0), (Instant::now() + Duration::from_secs(2), U256::from(0xfffa))); + tester.hashrates.lock().insert(H256::from_low_u64_be(0), (Instant::now() + Duration::from_secs(2), U256::from(0xfffb))); + tester.hashrates.lock().insert(H256::from_low_u64_be(1), (Instant::now() + Duration::from_secs(2), U256::from(0x1))); let request = r#"{"jsonrpc": "2.0", "method": "eth_hashrate", "params": [], "id": 1}"#; let response = r#"{"jsonrpc":"2.0","result":"0xfffc","id":1}"#; @@ -201,27 +201,27 @@ fn rpc_eth_logs() { let tester = EthTester::default(); tester.client.set_logs(vec![LocalizedLogEntry { block_number: 1, - block_hash: H256::default(), + block_hash: H256::zero(), entry: LogEntry { - address: Address::default(), + address: Address::zero(), topics: vec![], data: vec![1,2,3], }, transaction_index: 0, transaction_log_index: 0, - transaction_hash: H256::default(), + transaction_hash: H256::zero(), log_index: 0, }, LocalizedLogEntry { block_number: 1, - block_hash: H256::default(), + block_hash: H256::zero(), entry: LogEntry { - address: Address::default(), + address: Address::zero(), topics: vec![], data: vec![1,2,3], }, transaction_index: 0, transaction_log_index: 1, - transaction_hash: H256::default(), + transaction_hash: H256::zero(), log_index: 1, }]); @@ -240,8 +240,14 @@ fn rpc_eth_logs() { #[test] fn rpc_eth_logs_error() { + fn h256_from_digit_be(d: u8) -> H256 { + let mut bytes = [0u8; 32]; + bytes[0] = d; + H256(bytes) + } + let tester = EthTester::default(); - tester.client.set_error_on_logs(Some(BlockId::Hash(H256::from([5u8].as_ref())))); + tester.client.set_error_on_logs(Some(BlockId::Hash(h256_from_digit_be(5)))); let request = r#"{"jsonrpc": "2.0", "method": "eth_getLogs", "params": [{"limit":1,"blockHash":"0x0000000000000000000000000000000000000000000000000000000000000000"}], "id": 1}"#; let response = r#"{"jsonrpc":"2.0","error":{"code":-32000,"message":"One of the blocks specified in filter (fromBlock, toBlock or blockHash) cannot be found","data":"0x0500000000000000000000000000000000000000000000000000000000000000"},"id":1}"#; assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned())); @@ -253,27 +259,27 @@ fn rpc_logs_filter() { // Set some logs tester.client.set_logs(vec![LocalizedLogEntry { block_number: 1, - block_hash: H256::default(), + block_hash: H256::zero(), entry: LogEntry { - address: Address::default(), + address: Address::zero(), topics: vec![], data: vec![1,2,3], }, transaction_index: 0, transaction_log_index: 0, - transaction_hash: H256::default(), + transaction_hash: H256::zero(), log_index: 0, }, LocalizedLogEntry { block_number: 1, - block_hash: H256::default(), + block_hash: H256::zero(), entry: LogEntry { - address: Address::default(), + address: Address::zero(), topics: vec![], data: vec![1,2,3], }, transaction_index: 0, transaction_log_index: 1, - transaction_hash: H256::default(), + transaction_hash: H256::zero(), log_index: 1, }]); @@ -349,7 +355,7 @@ fn rpc_eth_submit_hashrate() { let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; assert_eq!(tester.io.handle_request_sync(request), Some(response.to_owned())); - assert_eq!(tester.hashrates.lock().get(&H256::from("0x59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c")).cloned().unwrap().1, + assert_eq!(tester.hashrates.lock().get(&H256::from_str("59daa26581d0acd1fce254fb7e85952f4c09d0915afd33d3886cd914bc7d283c").unwrap()).cloned().unwrap().1, U256::from(0x500_000)); } @@ -404,8 +410,8 @@ fn rpc_eth_gas_price() { fn rpc_eth_accounts() { let tester = EthTester::default(); let address = tester.accounts_provider.new_account(&"".into()).unwrap(); - tester.accounts_provider.set_address_name(1.into(), "1".into()); - tester.accounts_provider.set_address_name(10.into(), "10".into()); + tester.accounts_provider.set_address_name(Address::from_low_u64_be(1), "1".into()); + tester.accounts_provider.set_address_name(Address::from_low_u64_be(10), "10".into()); // with current policy it should return the account let request = r#"{"jsonrpc": "2.0", "method": "eth_accounts", "params": [], "id": 1}"#; @@ -427,7 +433,7 @@ fn rpc_eth_block_number() { #[test] fn rpc_eth_balance() { let tester = EthTester::default(); - tester.client.set_balance(Address::from(1), U256::from(5)); + tester.client.set_balance(Address::from_low_u64_be(1), U256::from(5)); let request = r#"{ "jsonrpc": "2.0", @@ -443,7 +449,7 @@ fn rpc_eth_balance() { #[test] fn rpc_eth_balance_pending() { let tester = EthTester::default(); - tester.client.set_balance(Address::from(1), U256::from(5)); + tester.client.set_balance(Address::from_low_u64_be(1), U256::from(5)); let request = r#"{ "jsonrpc": "2.0", @@ -460,7 +466,7 @@ fn rpc_eth_balance_pending() { #[test] fn rpc_eth_storage_at() { let tester = EthTester::default(); - tester.client.set_storage(Address::from(1), H256::from(4), H256::from(7)); + tester.client.set_storage(Address::from_low_u64_be(1), H256::from_low_u64_be(4), H256::from_low_u64_be(7)); let request = r#"{ "jsonrpc": "2.0", @@ -491,7 +497,7 @@ fn rpc_eth_transaction_count_next_nonce() { let tester = EthTester::new_with_options(EthClientOptions::with(|options| { options.pending_nonce_from_queue = true; })); - tester.miner.increment_nonce(&1.into()); + tester.miner.increment_nonce(&H160::from_low_u64_be(1)); let request1 = r#"{ "jsonrpc": "2.0", @@ -604,7 +610,7 @@ fn rpc_eth_uncle_count_by_block_number() { #[test] fn rpc_eth_code() { let tester = EthTester::default(); - tester.client.set_code(Address::from(1), vec![0xff, 0x21]); + tester.client.set_code(Address::from_low_u64_be(1), vec![0xff, 0x21]); let request = r#"{ "jsonrpc": "2.0", @@ -868,13 +874,13 @@ fn rpc_eth_transaction_receipt() { }, block_hash: H256::from_str("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5").unwrap(), block_number: 0x4510c, - transaction_hash: H256::new(), + transaction_hash: H256::zero(), transaction_index: 0, transaction_log_index: 0, log_index: 1, }], - log_bloom: 0.into(), - outcome: TransactionOutcome::StateRoot(0.into()), + log_bloom: Bloom::zero(), + outcome: TransactionOutcome::StateRoot(H256::zero()), }; let hash = H256::from_str("b903239f8543d04b5dc1ba6579132b143087c68db1b2168786408fcbce568238").unwrap(); diff --git a/rpc/src/v1/tests/mocked/eth_pubsub.rs b/rpc/src/v1/tests/mocked/eth_pubsub.rs index 21f413530..071e0eace 100644 --- a/rpc/src/v1/tests/mocked/eth_pubsub.rs +++ b/rpc/src/v1/tests/mocked/eth_pubsub.rs @@ -25,6 +25,7 @@ use std::time::Duration; use v1::{EthPubSub, EthPubSubClient, Metadata}; use ethcore::client::{TestBlockChainClient, EachBlockWith, ChainNotify, NewBlocks, ChainRoute, ChainRouteType}; use parity_runtime::Runtime; +use ethereum_types::{Address, H256}; const DURATION_ZERO: Duration = Duration::from_millis(0); @@ -39,7 +40,7 @@ fn should_subscribe_to_new_heads() { let h2 = client.block_hash_delta_minus(2); let h1 = client.block_hash_delta_minus(3); - let pubsub = EthPubSubClient::new_test(Arc::new(client), el.executor()); + let pubsub = EthPubSubClient::new(Arc::new(client), el.executor()); let handler = pubsub.handler().upgrade().unwrap(); let pubsub = pubsub.to_delegate(); @@ -52,13 +53,13 @@ fn should_subscribe_to_new_heads() { // Subscribe let request = r#"{"jsonrpc": "2.0", "method": "eth_subscribe", "params": ["newHeads"], "id": 1}"#; - let response = r#"{"jsonrpc":"2.0","result":"0x416d77337e24399d","id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":"0x43ca64edf03768e1","id":1}"#; assert_eq!(io.handle_request_sync(request, metadata.clone()), Some(response.to_owned())); // Check notifications handler.new_blocks(NewBlocks::new(vec![], vec![], ChainRoute::new(vec![(h1, ChainRouteType::Enacted)]), vec![], vec![], DURATION_ZERO, true)); let (res, receiver) = receiver.into_future().wait().unwrap(); - let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x1","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x1","parentHash":"0x0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x416d77337e24399d"}}"#; + let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x1","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x1","parentHash":"0x0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); // Notify about two blocks @@ -66,14 +67,14 @@ fn should_subscribe_to_new_heads() { // Receive both let (res, receiver) = receiver.into_future().wait().unwrap(); - let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x2","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0x44e5ecf454ea99af9d8a8f2ca0daba96964c90de05db7a78f59b84ae9e749706","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x2","parentHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x416d77337e24399d"}}"#; + let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x2","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0x44e5ecf454ea99af9d8a8f2ca0daba96964c90de05db7a78f59b84ae9e749706","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x2","parentHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); let (res, receiver) = receiver.into_future().wait().unwrap(); - let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x3","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0xdf04a98bb0c6fa8441bd429822f65a46d0cb553f6bcef602b973e65c81497f8e","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x3","parentHash":"0x44e5ecf454ea99af9d8a8f2ca0daba96964c90de05db7a78f59b84ae9e749706","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x416d77337e24399d"}}"#; + let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x3","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0xdf04a98bb0c6fa8441bd429822f65a46d0cb553f6bcef602b973e65c81497f8e","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x3","parentHash":"0x44e5ecf454ea99af9d8a8f2ca0daba96964c90de05db7a78f59b84ae9e749706","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); // And unsubscribe - let request = r#"{"jsonrpc": "2.0", "method": "eth_unsubscribe", "params": ["0x416d77337e24399d"], "id": 1}"#; + let request = r#"{"jsonrpc": "2.0", "method": "eth_unsubscribe", "params": ["0x43ca64edf03768e1"], "id": 1}"#; let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; assert_eq!(io.handle_request_sync(request, metadata), Some(response.to_owned())); @@ -98,8 +99,8 @@ fn should_subscribe_to_logs() { client.set_logs(vec![ LocalizedLogEntry { entry: LogEntry { - address: 5.into(), - topics: vec![1.into(), 2.into(), 0.into(), 0.into()], + address: Address::from_low_u64_be(5), + topics: vec![H256::from_low_u64_be(1), H256::from_low_u64_be(2), H256::from_low_u64_be(0), H256::from_low_u64_be(0)], data: vec![], }, block_hash: h1, @@ -111,7 +112,7 @@ fn should_subscribe_to_logs() { } ]); - let pubsub = EthPubSubClient::new_test(Arc::new(client), el.executor()); + let pubsub = EthPubSubClient::new(Arc::new(client), el.executor()); let handler = pubsub.handler().upgrade().unwrap(); let pubsub = pubsub.to_delegate(); @@ -124,7 +125,7 @@ fn should_subscribe_to_logs() { // Subscribe let request = r#"{"jsonrpc": "2.0", "method": "eth_subscribe", "params": ["logs", {}], "id": 1}"#; - let response = r#"{"jsonrpc":"2.0","result":"0x416d77337e24399d","id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":"0x43ca64edf03768e1","id":1}"#; assert_eq!(io.handle_request_sync(request, metadata.clone()), Some(response.to_owned())); // Check notifications (enacted) @@ -132,7 +133,7 @@ fn should_subscribe_to_logs() { let (res, receiver) = receiver.into_future().wait().unwrap(); let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"address":"0x0000000000000000000000000000000000000005","blockHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","blockNumber":"0x1","data":"0x","logIndex":"0x0","removed":false,"topics":["0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"],"transactionHash":""#.to_owned() + &format!("0x{:x}", tx_hash) - + r#"","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"},"subscription":"0x416d77337e24399d"}}"#; + + r#"","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"},"subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); // Check notifications (retracted) @@ -140,11 +141,11 @@ fn should_subscribe_to_logs() { let (res, receiver) = receiver.into_future().wait().unwrap(); let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"address":"0x0000000000000000000000000000000000000005","blockHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","blockNumber":"0x1","data":"0x","logIndex":"0x0","removed":true,"topics":["0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"],"transactionHash":""#.to_owned() + &format!("0x{:x}", tx_hash) - + r#"","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"removed"},"subscription":"0x416d77337e24399d"}}"#; + + r#"","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"removed"},"subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); // And unsubscribe - let request = r#"{"jsonrpc": "2.0", "method": "eth_unsubscribe", "params": ["0x416d77337e24399d"], "id": 1}"#; + let request = r#"{"jsonrpc": "2.0", "method": "eth_unsubscribe", "params": ["0x43ca64edf03768e1"], "id": 1}"#; let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; assert_eq!(io.handle_request_sync(request, metadata), Some(response.to_owned())); @@ -158,7 +159,7 @@ fn should_subscribe_to_pending_transactions() { let el = Runtime::with_thread_count(1); let client = TestBlockChainClient::new(); - let pubsub = EthPubSubClient::new_test(Arc::new(client), el.executor()); + let pubsub = EthPubSubClient::new(Arc::new(client), el.executor()); let handler = pubsub.handler().upgrade().unwrap(); let pubsub = pubsub.to_delegate(); @@ -176,22 +177,22 @@ fn should_subscribe_to_pending_transactions() { // Subscribe let request = r#"{"jsonrpc": "2.0", "method": "eth_subscribe", "params": ["newPendingTransactions"], "id": 1}"#; - let response = r#"{"jsonrpc":"2.0","result":"0x416d77337e24399d","id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":"0x43ca64edf03768e1","id":1}"#; assert_eq!(io.handle_request_sync(request, metadata.clone()), Some(response.to_owned())); // Send new transactions - handler.notify_new_transactions(&[5.into(), 7.into()]); + handler.notify_new_transactions(&[H256::from_low_u64_be(5), H256::from_low_u64_be(7)]); let (res, receiver) = receiver.into_future().wait().unwrap(); - let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":"0x0000000000000000000000000000000000000000000000000000000000000005","subscription":"0x416d77337e24399d"}}"#; + let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":"0x0000000000000000000000000000000000000000000000000000000000000005","subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); let (res, receiver) = receiver.into_future().wait().unwrap(); - let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":"0x0000000000000000000000000000000000000000000000000000000000000007","subscription":"0x416d77337e24399d"}}"#; + let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":"0x0000000000000000000000000000000000000000000000000000000000000007","subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); // And unsubscribe - let request = r#"{"jsonrpc": "2.0", "method": "eth_unsubscribe", "params": ["0x416d77337e24399d"], "id": 1}"#; + let request = r#"{"jsonrpc": "2.0", "method": "eth_unsubscribe", "params": ["0x43ca64edf03768e1"], "id": 1}"#; let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; assert_eq!(io.handle_request_sync(request, metadata), Some(response.to_owned())); @@ -204,7 +205,7 @@ fn eth_subscribe_syncing() { // given let el = Runtime::with_thread_count(1); let client = TestBlockChainClient::new(); - let pubsub = EthPubSubClient::new_test(Arc::new(client), el.executor()); + let pubsub = EthPubSubClient::new(Arc::new(client), el.executor()); let pubsub = pubsub.to_delegate(); let mut io = MetaIoHandler::default(); @@ -215,7 +216,7 @@ fn eth_subscribe_syncing() { metadata.session = Some(Arc::new(Session::new(sender))); // Subscribe - let response = r#"{"jsonrpc":"2.0","result":"0x416d77337e24399d","id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":"0x43ca64edf03768e1","id":1}"#; let request = r#"{"jsonrpc": "2.0", "method": "eth_subscribe", "params": ["syncing"], "id": 1}"#; assert_eq!(io.handle_request_sync(request, metadata.clone()), Some(response.to_owned())); } diff --git a/rpc/src/v1/tests/mocked/parity.rs b/rpc/src/v1/tests/mocked/parity.rs index 6608589f5..913e181e4 100644 --- a/rpc/src/v1/tests/mocked/parity.rs +++ b/rpc/src/v1/tests/mocked/parity.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use ethcore::client::{TestBlockChainClient, Executed, TransactionId}; use ethcore_logger::RotatingLogger; -use ethereum_types::{Address, U256, H256}; +use ethereum_types::{Address, U256, H256, BigEndianHash, Bloom}; use ethstore::ethkey::{Generator, Random}; use miner::pool::local_transactions::Status as LocalTransactionStatus; use sync::ManageNetwork; @@ -353,7 +353,7 @@ fn rpc_parity_ws_address() { #[test] fn rpc_parity_next_nonce() { let deps = Dependencies::new(); - let address = Address::default(); + let address = Address::zero(); let io1 = deps.default_client(); let deps = Dependencies::new(); deps.miner.increment_nonce(&address); @@ -396,10 +396,10 @@ fn rpc_parity_local_transactions() { action: ::types::transaction::Action::Create, data: vec![1, 2, 3], nonce: 0.into(), - }.fake_sign(3.into()); + }.fake_sign(Address::from_low_u64_be(3)); let tx = Arc::new(::miner::pool::VerifiedTransaction::from_pending_block_transaction(tx)); - deps.miner.local_transactions.lock().insert(10.into(), LocalTransactionStatus::Pending(tx.clone())); - deps.miner.local_transactions.lock().insert(15.into(), LocalTransactionStatus::Pending(tx.clone())); + deps.miner.local_transactions.lock().insert(H256::from_low_u64_be(10), LocalTransactionStatus::Pending(tx.clone())); + deps.miner.local_transactions.lock().insert(H256::from_low_u64_be(15), LocalTransactionStatus::Pending(tx.clone())); let request = r#"{"jsonrpc": "2.0", "method": "parity_localTransactions", "params":[], "id": 1}"#; let response = r#"{"jsonrpc":"2.0","result":{"0x000000000000000000000000000000000000000000000000000000000000000a":{"status":"pending"},"0x000000000000000000000000000000000000000000000000000000000000000f":{"status":"pending"}},"id":1}"#; @@ -412,8 +412,8 @@ fn rpc_parity_chain_status() { let deps = Dependencies::new(); let io = deps.default_client(); - *deps.client.ancient_block.write() = Some((H256::default(), 5)); - *deps.client.first_block.write() = Some((H256::from(U256::from(1234)), 3333)); + *deps.client.ancient_block.write() = Some((H256::zero(), 5)); + *deps.client.first_block.write() = Some((BigEndianHash::from_uint(&U256::from(1234)), 3333)); let request = r#"{"jsonrpc": "2.0", "method": "parity_chainStatus", "params":[], "id": 1}"#; let response = r#"{"jsonrpc":"2.0","result":{"blockGap":["0x6","0xd05"]},"id":1}"#; @@ -484,19 +484,19 @@ fn rpc_parity_call() { fn rpc_parity_block_receipts() { let deps = Dependencies::new(); deps.client.receipts.write() - .insert(TransactionId::Hash(1.into()), LocalizedReceipt { - transaction_hash: 1.into(), + .insert(TransactionId::Hash(H256::from_low_u64_be(1)), LocalizedReceipt { + transaction_hash: H256::from_low_u64_be(1), transaction_index: 0, - block_hash: 3.into(), + block_hash: H256::from_low_u64_be(3), block_number: 0, cumulative_gas_used: 21_000.into(), gas_used: 21_000.into(), contract_address: None, logs: vec![], - log_bloom: 1.into(), + log_bloom: Bloom::from_low_u64_be(1), outcome: TransactionOutcome::Unknown, to: None, - from: 9.into(), + from: Address::from_low_u64_be(9), }); let io = deps.default_client(); diff --git a/rpc/src/v1/tests/mocked/parity_accounts.rs b/rpc/src/v1/tests/mocked/parity_accounts.rs index 5b2e0762b..5d1e191d7 100644 --- a/rpc/src/v1/tests/mocked/parity_accounts.rs +++ b/rpc/src/v1/tests/mocked/parity_accounts.rs @@ -15,6 +15,7 @@ // along with Parity Ethereum. If not, see . use std::sync::Arc; +use std::str::FromStr; use accounts::{AccountProvider, AccountProviderSettings}; use ethereum_types::Address; @@ -74,7 +75,7 @@ fn rpc_parity_accounts_info() { assert_eq!(accounts.len(), 1); let address = accounts[0]; - tester.accounts.set_address_name(1.into(), "XX".into()); + tester.accounts.set_address_name(Address::from_low_u64_be(1), "XX".into()); tester.accounts.set_account_name(address.clone(), "Test".into()).unwrap(); tester.accounts.set_account_meta(address.clone(), "{foo: 69}".into()).unwrap(); @@ -89,7 +90,7 @@ fn rpc_parity_default_account() { let io = tester.io; // Check empty - let address = Address::default(); + let address = Address::zero(); let request = r#"{"jsonrpc": "2.0", "method": "parity_defaultAccount", "params": [], "id": 1}"#; let response = format!("{{\"jsonrpc\":\"2.0\",\"result\":\"0x{:x}\",\"id\":1}}", address); assert_eq!(io.handle_request_sync(request), Some(response)); @@ -456,7 +457,7 @@ fn should_import_wallet() { assert_eq!(res, response); - let account_meta = tester.accounts.account_meta("0x00bac56a8a27232baa044c03f43bf3648c961735".into()).unwrap(); + let account_meta = tester.accounts.account_meta(Address::from_str("00bac56a8a27232baa044c03f43bf3648c961735").unwrap()).unwrap(); let account_uuid: String = account_meta.uuid.unwrap().into(); // the RPC should import the account with a new id diff --git a/rpc/src/v1/tests/mocked/parity_set.rs b/rpc/src/v1/tests/mocked/parity_set.rs index 25c13fb1c..683f681e4 100644 --- a/rpc/src/v1/tests/mocked/parity_set.rs +++ b/rpc/src/v1/tests/mocked/parity_set.rs @@ -230,11 +230,11 @@ fn rpc_parity_remove_transaction() { nonce: 1.into(), gas_price: 0x9184e72a000u64.into(), gas: 0x76c0.into(), - action: Action::Call(5.into()), + action: Action::Call(Address::from_low_u64_be(5)), value: 0x9184e72au64.into(), data: vec![] }; - let signed = tx.fake_sign(2.into()); + let signed = tx.fake_sign(Address::from_low_u64_be(2)); let hash = signed.hash(); let request = r#"{"jsonrpc": "2.0", "method": "parity_removeTransaction", "params":[""#.to_owned() + &format!("0x{:x}", hash) + r#""], "id": 1}"#; @@ -268,4 +268,3 @@ fn rpc_parity_set_engine_signer() { let signature = miner.signer.read().as_ref().unwrap().sign(::hash::keccak("x")).unwrap().to_vec(); assert_eq!(&format!("{}", signature.pretty()), "6f46069ded2154af6e806706e4f7f6fd310ac45f3c6dccb85f11c0059ee20a09245df0a0008bb84a10882b1298284bc93058e7bc5938ea728e77620061687a6401"); } - diff --git a/rpc/src/v1/tests/mocked/personal.rs b/rpc/src/v1/tests/mocked/personal.rs index a2d6b87ce..5a339bc18 100644 --- a/rpc/src/v1/tests/mocked/personal.rs +++ b/rpc/src/v1/tests/mocked/personal.rs @@ -363,7 +363,7 @@ fn sign_eip191_with_validator() { }"#; let with_validator = to_value(PresignedTransaction { validator: address.into(), - data: keccak("hello world").to_vec().into() + data: keccak("hello world").as_bytes().to_vec().into() }).unwrap(); let result = eip191::hash_message(EIP191Version::PresignedTransaction, with_validator).unwrap(); let result = tester.accounts.sign(address, Some("password123".into()), result).unwrap().into_electrum(); diff --git a/rpc/src/v1/tests/mocked/pubsub.rs b/rpc/src/v1/tests/mocked/pubsub.rs index c0f664d5f..a0fafa4ba 100644 --- a/rpc/src/v1/tests/mocked/pubsub.rs +++ b/rpc/src/v1/tests/mocked/pubsub.rs @@ -53,22 +53,22 @@ fn should_subscribe_to_a_method() { // Subscribe let request = r#"{"jsonrpc": "2.0", "method": "parity_subscribe", "params": ["hello", []], "id": 1}"#; - let response = r#"{"jsonrpc":"2.0","result":"0x416d77337e24399d","id":1}"#; + let response = r#"{"jsonrpc":"2.0","result":"0x43ca64edf03768e1","id":1}"#; assert_eq!(io.handle_request_sync(request, metadata.clone()), Some(response.to_owned())); // Check notifications let (res, receiver) = receiver.into_future().wait().unwrap(); let response = - r#"{"jsonrpc":"2.0","method":"parity_subscription","params":{"result":"hello","subscription":"0x416d77337e24399d"}}"#; + r#"{"jsonrpc":"2.0","method":"parity_subscription","params":{"result":"hello","subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); let (res, receiver) = receiver.into_future().wait().unwrap(); let response = - r#"{"jsonrpc":"2.0","method":"parity_subscription","params":{"result":"world","subscription":"0x416d77337e24399d"}}"#; + r#"{"jsonrpc":"2.0","method":"parity_subscription","params":{"result":"world","subscription":"0x43ca64edf03768e1"}}"#; assert_eq!(res, Some(response.into())); // And unsubscribe - let request = r#"{"jsonrpc": "2.0", "method": "parity_unsubscribe", "params": ["0x416d77337e24399d"], "id": 1}"#; + let request = r#"{"jsonrpc": "2.0", "method": "parity_unsubscribe", "params": ["0x43ca64edf03768e1"], "id": 1}"#; let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#; assert_eq!(io.handle_request_sync(request, metadata), Some(response.to_owned())); diff --git a/rpc/src/v1/tests/mocked/signer.rs b/rpc/src/v1/tests/mocked/signer.rs index e22c5b8d2..4000f16e5 100644 --- a/rpc/src/v1/tests/mocked/signer.rs +++ b/rpc/src/v1/tests/mocked/signer.rs @@ -84,7 +84,7 @@ fn should_return_list_of_items_to_confirm() { // given let tester = signer_tester(); let _send_future = tester.signer.add_request(ConfirmationPayload::SendTransaction(FilledTransactionRequest { - from: Address::from(1), + from: Address::from_low_u64_be(1), used_default_from: false, to: Some(Address::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap()), gas_price: U256::from(10_000), @@ -94,7 +94,7 @@ fn should_return_list_of_items_to_confirm() { nonce: None, condition: None, }), Origin::Unknown).unwrap(); - let _sign_future = tester.signer.add_request(ConfirmationPayload::EthSignMessage(1.into(), vec![5].into()), Origin::Unknown).unwrap(); + let _sign_future = tester.signer.add_request(ConfirmationPayload::EthSignMessage(Address::from_low_u64_be(1), vec![5].into()), Origin::Unknown).unwrap(); // when let request = r#"{"jsonrpc":"2.0","method":"signer_requestsToConfirm","params":[],"id":1}"#; @@ -114,7 +114,7 @@ fn should_reject_transaction_from_queue_without_dispatching() { // given let tester = signer_tester(); let _confirmation_future = tester.signer.add_request(ConfirmationPayload::SendTransaction(FilledTransactionRequest { - from: Address::from(1), + from: Address::from_low_u64_be(1), used_default_from: false, to: Some(Address::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap()), gas_price: U256::from(10_000), @@ -141,7 +141,7 @@ fn should_not_remove_transaction_if_password_is_invalid() { // given let tester = signer_tester(); let _confirmation_future = tester.signer.add_request(ConfirmationPayload::SendTransaction(FilledTransactionRequest { - from: Address::from(1), + from: Address::from_low_u64_be(1), used_default_from: false, to: Some(Address::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap()), gas_price: U256::from(10_000), @@ -166,7 +166,7 @@ fn should_not_remove_transaction_if_password_is_invalid() { fn should_not_remove_sign_if_password_is_invalid() { // given let tester = signer_tester(); - let _confirmation_future = tester.signer.add_request(ConfirmationPayload::EthSignMessage(0.into(), vec![5].into()), Origin::Unknown).unwrap(); + let _confirmation_future = tester.signer.add_request(ConfirmationPayload::EthSignMessage(Address::zero(), vec![5].into()), Origin::Unknown).unwrap(); assert_eq!(tester.signer.requests().len(), 1); // when @@ -231,7 +231,7 @@ fn should_alter_the_sender_and_nonce() { let tester = signer_tester(); let recipient = Address::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap(); let _confirmation_future = tester.signer.add_request(ConfirmationPayload::SendTransaction(FilledTransactionRequest { - from: 0.into(), + from: Address::zero(), used_default_from: false, to: Some(recipient), gas_price: U256::from(10_000), @@ -377,7 +377,7 @@ fn should_return_error_when_sender_does_not_match() { let address = tester.accounts.new_account(&"test".into()).unwrap(); let recipient = Address::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap(); let _confirmation_future = tester.signer.add_request(ConfirmationPayload::SendTransaction(FilledTransactionRequest { - from: Address::default(), + from: Address::zero(), used_default_from: false, to: Some(recipient), gas_price: U256::from(10_000), diff --git a/rpc/src/v1/tests/mocked/signing.rs b/rpc/src/v1/tests/mocked/signing.rs index 39385d19b..febf002d8 100644 --- a/rpc/src/v1/tests/mocked/signing.rs +++ b/rpc/src/v1/tests/mocked/signing.rs @@ -33,7 +33,7 @@ use v1::tests::mocked::parity; use accounts::AccountProvider; use bytes::ToPretty; -use ethereum_types::{U256, Address}; +use ethereum_types::{U256, Address, Signature, H256}; use ethcore::client::TestBlockChainClient; use ethkey::Secret; use ethstore::ethkey::{Generator, Random}; @@ -138,7 +138,7 @@ fn should_add_sign_to_queue() { if signer.requests().len() == 1 { // respond let sender = signer.take(&1.into()).unwrap(); - signer.request_confirmed(sender, Ok(ConfirmationResponse::Signature(0.into()))); + signer.request_confirmed(sender, Ok(ConfirmationResponse::Signature(Signature::zero()))); break } ::std::thread::sleep(Duration::from_millis(100)) @@ -217,7 +217,7 @@ fn should_check_status_of_request_when_its_resolved() { }"#; tester.io.handle_request_sync(&request).expect("Sent"); let sender = tester.signer.take(&1.into()).unwrap(); - tester.signer.request_confirmed(sender, Ok(ConfirmationResponse::Signature(1.into()))); + tester.signer.request_confirmed(sender, Ok(ConfirmationResponse::Signature(Signature::from_low_u64_be(1)))); // This is not ideal, but we need to give futures some time to be executed, and they need to run in a separate thread thread::sleep(Duration::from_millis(20)); @@ -289,7 +289,7 @@ fn should_add_transaction_to_queue() { if signer.requests().len() == 1 { // respond let sender = signer.take(&1.into()).unwrap(); - signer.request_confirmed(sender, Ok(ConfirmationResponse::SendTransaction(0.into()))); + signer.request_confirmed(sender, Ok(ConfirmationResponse::SendTransaction(H256::zero()))); break } ::std::thread::sleep(Duration::from_millis(100)) diff --git a/rpc/src/v1/tests/mocked/traces.rs b/rpc/src/v1/tests/mocked/traces.rs index 89cf198aa..8f0f0eaa0 100644 --- a/rpc/src/v1/tests/mocked/traces.rs +++ b/rpc/src/v1/tests/mocked/traces.rs @@ -20,6 +20,7 @@ use ethcore::executed::{Executed, CallError}; use ethcore::trace::trace::{Action, Res, Call}; use ethcore::trace::LocalizedTrace; use ethcore::client::TestBlockChainClient; +use ethereum_types::{Address, H256}; use vm::CallType; @@ -37,8 +38,8 @@ fn io() -> Tester { let client = Arc::new(TestBlockChainClient::new()); *client.traces.write() = Some(vec![LocalizedTrace { action: Action::Call(Call { - from: 0xf.into(), - to: 0x10.into(), + from: Address::from_low_u64_be(0xf), + to: Address::from_low_u64_be(0x10), value: 0x1.into(), gas: 0x100.into(), input: vec![1, 2, 3], @@ -48,9 +49,9 @@ fn io() -> Tester { subtraces: 0, trace_address: vec![0], transaction_number: Some(0), - transaction_hash: Some(5.into()), + transaction_hash: Some(H256::from_low_u64_be(5)), block_number: 10, - block_hash: 10.into(), + block_hash: H256::from_low_u64_be(10), }]); *client.execution_result.write() = Some(Ok(Executed { exception: None, diff --git a/rpc/src/v1/types/block.rs b/rpc/src/v1/types/block.rs index 61f4402af..23129395b 100644 --- a/rpc/src/v1/types/block.rs +++ b/rpc/src/v1/types/block.rs @@ -216,7 +216,7 @@ mod tests { let serialized = serde_json::to_string(&t).unwrap(); assert_eq!(serialized, r#"[{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x0","gasPrice":"0x0","gas":"0x0","input":"0x","creates":null,"raw":"0x","publicKey":null,"chainId":null,"standardV":"0x0","v":"0x0","r":"0x0","s":"0x0","condition":null}]"#); - let t = BlockTransactions::Hashes(vec![H256::default().into()]); + let t = BlockTransactions::Hashes(vec![H256::zero().into()]); let serialized = serde_json::to_string(&t).unwrap(); assert_eq!(serialized, r#"["0x0000000000000000000000000000000000000000000000000000000000000000"]"#); } @@ -224,14 +224,14 @@ mod tests { #[test] fn test_serialize_block() { let block = Block { - hash: Some(H256::default()), - parent_hash: H256::default(), - uncles_hash: H256::default(), + hash: Some(H256::zero()), + parent_hash: H256::zero(), + uncles_hash: H256::zero(), author: H160::default(), miner: H160::default(), - state_root: H256::default(), - transactions_root: H256::default(), - receipts_root: H256::default(), + state_root: H256::zero(), + transactions_root: H256::zero(), + receipts_root: H256::zero(), number: Some(U256::default()), gas_used: U256::default(), gas_limit: U256::default(), @@ -249,7 +249,7 @@ mod tests { let rich_block = RichBlock { inner: block, extra_info: map![ - "mixHash".into() => format!("{:?}", H256::default()), + "mixHash".into() => format!("{:?}", H256::zero()), "nonce".into() => format!("{:?}", H64::default()) ], }; @@ -262,14 +262,14 @@ mod tests { #[test] fn none_size_null() { let block = Block { - hash: Some(H256::default()), - parent_hash: H256::default(), - uncles_hash: H256::default(), + hash: Some(H256::zero()), + parent_hash: H256::zero(), + uncles_hash: H256::zero(), author: H160::default(), miner: H160::default(), - state_root: H256::default(), - transactions_root: H256::default(), - receipts_root: H256::default(), + state_root: H256::zero(), + transactions_root: H256::zero(), + receipts_root: H256::zero(), number: Some(U256::default()), gas_used: U256::default(), gas_limit: U256::default(), @@ -287,7 +287,7 @@ mod tests { let rich_block = RichBlock { inner: block, extra_info: map![ - "mixHash".into() => format!("{:?}", H256::default()), + "mixHash".into() => format!("{:?}", H256::zero()), "nonce".into() => format!("{:?}", H64::default()) ], }; @@ -300,14 +300,14 @@ mod tests { #[test] fn test_serialize_header() { let header = Header { - hash: Some(H256::default()), - parent_hash: H256::default(), - uncles_hash: H256::default(), + hash: Some(H256::zero()), + parent_hash: H256::zero(), + uncles_hash: H256::zero(), author: H160::default(), miner: H160::default(), - state_root: H256::default(), - transactions_root: H256::default(), - receipts_root: H256::default(), + state_root: H256::zero(), + transactions_root: H256::zero(), + receipts_root: H256::zero(), number: Some(U256::default()), gas_used: U256::default(), gas_limit: U256::default(), @@ -322,7 +322,7 @@ mod tests { let rich_header = RichHeader { inner: header, extra_info: map![ - "mixHash".into() => format!("{:?}", H256::default()), + "mixHash".into() => format!("{:?}", H256::zero()), "nonce".into() => format!("{:?}", H64::default()) ], }; diff --git a/rpc/src/v1/types/call_request.rs b/rpc/src/v1/types/call_request.rs index d75e4b1a2..14a94de9b 100644 --- a/rpc/src/v1/types/call_request.rs +++ b/rpc/src/v1/types/call_request.rs @@ -75,8 +75,8 @@ mod tests { let deserialized: CallRequest = serde_json::from_str(s).unwrap(); assert_eq!(deserialized, CallRequest { - from: Some(H160::from(1)), - to: Some(H160::from(2)), + from: Some(H160::from_low_u64_be(1)), + to: Some(H160::from_low_u64_be(2)), gas_price: Some(U256::from(1)), gas: Some(U256::from(2)), value: Some(U256::from(3)), @@ -114,7 +114,7 @@ mod tests { let deserialized: CallRequest = serde_json::from_str(s).unwrap(); assert_eq!(deserialized, CallRequest { - from: Some(H160::from(1)), + from: Some(H160::from_low_u64_be(1)), to: None, gas_price: None, gas: None, diff --git a/rpc/src/v1/types/confirmations.rs b/rpc/src/v1/types/confirmations.rs index dedd0ba25..de54d0dec 100644 --- a/rpc/src/v1/types/confirmations.rs +++ b/rpc/src/v1/types/confirmations.rs @@ -282,7 +282,7 @@ impl Serialize for Either where #[cfg(test)] mod tests { use std::str::FromStr; - use ethereum_types::{H256, U256}; + use ethereum_types::{H256, U256, Address}; use serde_json; use v1::types::TransactionCondition; use v1::helpers; @@ -293,7 +293,7 @@ mod tests { // given let request = helpers::ConfirmationRequest { id: 15.into(), - payload: helpers::ConfirmationPayload::EthSignMessage(1.into(), vec![5].into()), + payload: helpers::ConfirmationPayload::EthSignMessage(Address::from_low_u64_be(1), vec![5].into()), origin: Origin::Rpc("test service".into()), }; @@ -311,7 +311,7 @@ mod tests { let request = helpers::ConfirmationRequest { id: 15.into(), payload: helpers::ConfirmationPayload::SendTransaction(helpers::FilledTransactionRequest { - from: 0.into(), + from: Address::zero(), used_default_from: false, to: None, gas: 15_000.into(), @@ -322,7 +322,7 @@ mod tests { condition: None, }), origin: Origin::Signer { - session: 5.into(), + session: H256::from_low_u64_be(5), } }; @@ -340,7 +340,7 @@ mod tests { let request = helpers::ConfirmationRequest { id: 15.into(), payload: helpers::ConfirmationPayload::SignTransaction(helpers::FilledTransactionRequest { - from: 0.into(), + from: Address::zero(), used_default_from: false, to: None, gas: 15_000.into(), @@ -367,7 +367,7 @@ mod tests { let request = helpers::ConfirmationRequest { id: 15.into(), payload: helpers::ConfirmationPayload::Decrypt( - 10.into(), vec![1, 2, 3].into(), + Address::from_low_u64_be(10), vec![1, 2, 3].into(), ), origin: Default::default(), }; @@ -398,7 +398,7 @@ mod tests { // then assert_eq!(res1, TransactionModification { - sender: Some(10.into()), + sender: Some(Address::from_low_u64_be(10)), gas_price: Some(U256::from_str("0ba43b7400").unwrap()), gas: None, condition: Some(Some(TransactionCondition::Number(0x42))), @@ -421,7 +421,7 @@ mod tests { fn should_serialize_confirmation_response_with_token() { // given let response = ConfirmationResponseWithToken { - result: ConfirmationResponse::SendTransaction(H256::default()), + result: ConfirmationResponse::SendTransaction(H256::zero()), token: "test-token".into(), }; diff --git a/rpc/src/v1/types/eth_types.rs b/rpc/src/v1/types/eth_types.rs index 606e75924..baa56fc1e 100644 --- a/rpc/src/v1/types/eth_types.rs +++ b/rpc/src/v1/types/eth_types.rs @@ -18,10 +18,10 @@ fn should_serialize_u256() { #[test] fn should_serialize_h256() { - let serialized1 = serde_json::to_string(&H256::from(0)).unwrap(); - let serialized2 = serde_json::to_string(&H256::from(1)).unwrap(); - let serialized3 = serde_json::to_string(&H256::from(16)).unwrap(); - let serialized4 = serde_json::to_string(&H256::from(256)).unwrap(); + let serialized1 = serde_json::to_string(&H256::from_low_u64_be(0)).unwrap(); + let serialized2 = serde_json::to_string(&H256::from_low_u64_be(1)).unwrap(); + let serialized3 = serde_json::to_string(&H256::from_low_u64_be(16)).unwrap(); + let serialized4 = serde_json::to_string(&H256::from_low_u64_be(256)).unwrap(); assert_eq!(serialized1, r#""0x0000000000000000000000000000000000000000000000000000000000000000""#); assert_eq!(serialized2, r#""0x0000000000000000000000000000000000000000000000000000000000000001""#); @@ -78,7 +78,7 @@ fn should_deserialize_h256() { let deserialized2: H256 = serde_json::from_str(r#""0x0000000000000000000000000000000000000000000000000000000000000001""#).unwrap(); let deserialized3: H256 = serde_json::from_str(r#""0x0000000000000000000000000000000000000000000000000000000000000100""#).unwrap(); - assert_eq!(deserialized1, 0.into()); - assert_eq!(deserialized2, 1.into()); - assert_eq!(deserialized3, 256.into()); + assert_eq!(deserialized1, H256::from_low_u64_be(0)); + assert_eq!(deserialized2, H256::from_low_u64_be(1)); + assert_eq!(deserialized3, H256::from_low_u64_be(256)); } diff --git a/rpc/src/v1/types/filter.rs b/rpc/src/v1/types/filter.rs index ec9f54179..bd1edd270 100644 --- a/rpc/src/v1/types/filter.rs +++ b/rpc/src/v1/types/filter.rs @@ -188,7 +188,7 @@ mod tests { address: Some(VariadicValue::Multiple(vec![])), topics: Some(vec![ VariadicValue::Null, - VariadicValue::Single("000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b".into()), + VariadicValue::Single(H256::from_str("000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap()), VariadicValue::Null, ]), limit: None, @@ -201,7 +201,7 @@ mod tests { address: Some(vec![]), topics: vec![ None, - Some(vec!["000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b".into()]), + Some(vec![H256::from_str("000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap()]), None, None, ], diff --git a/rpc/src/v1/types/log.rs b/rpc/src/v1/types/log.rs index 57b2cdd5d..fb24d155c 100644 --- a/rpc/src/v1/types/log.rs +++ b/rpc/src/v1/types/log.rs @@ -104,7 +104,7 @@ mod tests { data: vec![].into(), block_hash: Some(H256::from_str("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5").unwrap()), block_number: Some(U256::from(0x4510c)), - transaction_hash: Some(H256::default()), + transaction_hash: Some(H256::zero()), transaction_index: Some(U256::default()), transaction_log_index: Some(1.into()), log_index: Some(U256::from(1)), diff --git a/rpc/src/v1/types/provenance.rs b/rpc/src/v1/types/provenance.rs index dcdd2408f..41a115060 100644 --- a/rpc/src/v1/types/provenance.rs +++ b/rpc/src/v1/types/provenance.rs @@ -67,18 +67,19 @@ impl fmt::Display for Origin { mod tests { use serde_json; use super::Origin; + use ethereum_types::H256; #[test] fn should_serialize_origin() { // given let o1 = Origin::Rpc("test service".into()); - let o3 = Origin::Ipc(5.into()); + let o3 = Origin::Ipc(H256::from_low_u64_be(5)); let o4 = Origin::Signer { - session: 10.into(), + session: H256::from_low_u64_be(10), }; let o5 = Origin::Unknown; let o6 = Origin::Ws { - session: 5.into(), + session: H256::from_low_u64_be(5), }; // when diff --git a/rpc/src/v1/types/receipt.rs b/rpc/src/v1/types/receipt.rs index f492ca98c..9e5b5e3a6 100644 --- a/rpc/src/v1/types/receipt.rs +++ b/rpc/src/v1/types/receipt.rs @@ -132,6 +132,7 @@ impl From for Receipt { mod tests { use serde_json; use v1::types::{Log, Receipt}; + use ethereum_types::{H256, Bloom}; #[test] fn receipt_serialization() { @@ -140,7 +141,7 @@ mod tests { let receipt = Receipt { from: None, to: None, - transaction_hash: Some(0.into()), + transaction_hash: Some(H256::zero()), transaction_index: Some(0.into()), block_hash: Some("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5".parse().unwrap()), block_number: Some(0x4510c.into()), @@ -156,15 +157,15 @@ mod tests { data: vec![].into(), block_hash: Some("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5".parse().unwrap()), block_number: Some(0x4510c.into()), - transaction_hash: Some(0.into()), + transaction_hash: Some(H256::zero()), transaction_index: Some(0.into()), transaction_log_index: None, log_index: Some(1.into()), log_type: "mined".into(), removed: false, }], - logs_bloom: 15.into(), - state_root: Some(10.into()), + logs_bloom: Bloom::from_low_u64_be(15), + state_root: Some(H256::from_low_u64_be(10)), status_code: Some(1u64.into()), }; diff --git a/rpc/src/v1/types/secretstore.rs b/rpc/src/v1/types/secretstore.rs index ef76ec5b4..5e94328b9 100644 --- a/rpc/src/v1/types/secretstore.rs +++ b/rpc/src/v1/types/secretstore.rs @@ -32,13 +32,13 @@ pub struct EncryptedDocumentKey { #[cfg(test)] mod tests { use serde_json; - use super::EncryptedDocumentKey; + use super::{EncryptedDocumentKey, H512}; #[test] fn test_serialize_encrypted_document_key() { let initial = EncryptedDocumentKey { - common_point: 1.into(), - encrypted_point: 2.into(), + common_point: H512::from_low_u64_be(1), + encrypted_point: H512::from_low_u64_be(2), encrypted_key: vec![3].into(), }; @@ -46,8 +46,8 @@ mod tests { assert_eq!(serialized, r#"{"common_point":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001","encrypted_point":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002","encrypted_key":"0x03"}"#); let deserialized: EncryptedDocumentKey = serde_json::from_str(&serialized).unwrap(); - assert_eq!(deserialized.common_point, 1.into()); - assert_eq!(deserialized.encrypted_point, 2.into()); + assert_eq!(deserialized.common_point, H512::from_low_u64_be(1)); + assert_eq!(deserialized.encrypted_point, H512::from_low_u64_be(2)); assert_eq!(deserialized.encrypted_key, vec![3].into()); } } diff --git a/rpc/src/v1/types/sync.rs b/rpc/src/v1/types/sync.rs index 901611fea..812eaa1a8 100644 --- a/rpc/src/v1/types/sync.rs +++ b/rpc/src/v1/types/sync.rs @@ -197,7 +197,7 @@ pub struct ChainStatus { mod tests { use serde_json; use std::collections::BTreeMap; - use super::{SyncInfo, SyncStatus, Peers, TransactionStats, ChainStatus}; + use super::{SyncInfo, SyncStatus, Peers, TransactionStats, ChainStatus, H512}; #[test] fn test_serialize_sync_info() { @@ -241,7 +241,7 @@ mod tests { let stats = TransactionStats { first_seen: 100, propagated_to: map![ - 10.into() => 50 + H512::from_low_u64_be(10) => 50 ], }; diff --git a/rpc/src/v1/types/trace.rs b/rpc/src/v1/types/trace.rs index 58a5ee596..b8fc2c001 100644 --- a/rpc/src/v1/types/trace.rs +++ b/rpc/src/v1/types/trace.rs @@ -657,6 +657,7 @@ mod tests { use std::collections::BTreeMap; use v1::types::Bytes; use ethcore::trace::TraceError; + use ethereum_types::Address; use super::*; #[test] @@ -675,8 +676,8 @@ mod tests { fn test_trace_call_serialize() { let t = LocalizedTrace { action: Action::Call(Call { - from: 4.into(), - to: 5.into(), + from: Address::from_low_u64_be(4), + to: Address::from_low_u64_be(5), value: 6.into(), gas: 7.into(), input: Bytes::new(vec![0x12, 0x34]), @@ -689,9 +690,9 @@ mod tests { trace_address: vec![10], subtraces: 1, transaction_position: Some(11), - transaction_hash: Some(12.into()), + transaction_hash: Some(H256::from_low_u64_be(12)), block_number: 13, - block_hash: 14.into(), + block_hash: H256::from_low_u64_be(14), }; let serialized = serde_json::to_string(&t).unwrap(); assert_eq!(serialized, r#"{"type":"call","action":{"from":"0x0000000000000000000000000000000000000004","to":"0x0000000000000000000000000000000000000005","value":"0x6","gas":"0x7","input":"0x1234","callType":"call"},"result":{"gasUsed":"0x8","output":"0x5678"},"traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#); @@ -701,8 +702,8 @@ mod tests { fn test_trace_failed_call_serialize() { let t = LocalizedTrace { action: Action::Call(Call { - from: 4.into(), - to: 5.into(), + from: Address::from_low_u64_be(4), + to: Address::from_low_u64_be(5), value: 6.into(), gas: 7.into(), input: Bytes::new(vec![0x12, 0x34]), @@ -712,9 +713,9 @@ mod tests { trace_address: vec![10], subtraces: 1, transaction_position: Some(11), - transaction_hash: Some(12.into()), + transaction_hash: Some(H256::from_low_u64_be(12)), block_number: 13, - block_hash: 14.into(), + block_hash: H256::from_low_u64_be(14), }; let serialized = serde_json::to_string(&t).unwrap(); assert_eq!(serialized, r#"{"type":"call","action":{"from":"0x0000000000000000000000000000000000000004","to":"0x0000000000000000000000000000000000000005","value":"0x6","gas":"0x7","input":"0x1234","callType":"call"},"error":"Out of gas","traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#); @@ -724,7 +725,7 @@ mod tests { fn test_trace_create_serialize() { let t = LocalizedTrace { action: Action::Create(Create { - from: 4.into(), + from: Address::from_low_u64_be(4), value: 6.into(), gas: 7.into(), init: Bytes::new(vec![0x12, 0x34]), @@ -732,14 +733,14 @@ mod tests { result: Res::Create(CreateResult { gas_used: 8.into(), code: vec![0x56, 0x78].into(), - address: 0xff.into(), + address: Address::from_low_u64_be(0xff), }), trace_address: vec![10], subtraces: 1, transaction_position: Some(11), - transaction_hash: Some(12.into()), + transaction_hash: Some(H256::from_low_u64_be(12)), block_number: 13, - block_hash: 14.into(), + block_hash: H256::from_low_u64_be(14), }; let serialized = serde_json::to_string(&t).unwrap(); assert_eq!(serialized, r#"{"type":"create","action":{"from":"0x0000000000000000000000000000000000000004","value":"0x6","gas":"0x7","init":"0x1234"},"result":{"gasUsed":"0x8","code":"0x5678","address":"0x00000000000000000000000000000000000000ff"},"traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#); @@ -749,7 +750,7 @@ mod tests { fn test_trace_failed_create_serialize() { let t = LocalizedTrace { action: Action::Create(Create { - from: 4.into(), + from: Address::from_low_u64_be(4), value: 6.into(), gas: 7.into(), init: Bytes::new(vec![0x12, 0x34]), @@ -758,9 +759,9 @@ mod tests { trace_address: vec![10], subtraces: 1, transaction_position: Some(11), - transaction_hash: Some(12.into()), + transaction_hash: Some(H256::from_low_u64_be(12)), block_number: 13, - block_hash: 14.into(), + block_hash: H256::from_low_u64_be(14), }; let serialized = serde_json::to_string(&t).unwrap(); assert_eq!(serialized, r#"{"type":"create","action":{"from":"0x0000000000000000000000000000000000000004","value":"0x6","gas":"0x7","init":"0x1234"},"error":"Out of gas","traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#); @@ -770,17 +771,17 @@ mod tests { fn test_trace_suicide_serialize() { let t = LocalizedTrace { action: Action::Suicide(Suicide { - address: 4.into(), - refund_address: 6.into(), + address: Address::from_low_u64_be(4), + refund_address: Address::from_low_u64_be(6), balance: 7.into(), }), result: Res::None, trace_address: vec![10], subtraces: 1, transaction_position: Some(11), - transaction_hash: Some(12.into()), + transaction_hash: Some(H256::from_low_u64_be(12)), block_number: 13, - block_hash: 14.into(), + block_hash: H256::from_low_u64_be(14), }; let serialized = serde_json::to_string(&t).unwrap(); assert_eq!(serialized, r#"{"type":"suicide","action":{"address":"0x0000000000000000000000000000000000000004","refundAddress":"0x0000000000000000000000000000000000000006","balance":"0x7"},"result":null,"traceAddress":[10],"subtraces":1,"transactionPosition":11,"transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#); @@ -790,7 +791,7 @@ mod tests { fn test_trace_reward_serialize() { let t = LocalizedTrace { action: Action::Reward(Reward { - author: 4.into(), + author: Address::from_low_u64_be(4), value: 6.into(), reward_type: RewardType::Block, }), @@ -800,7 +801,7 @@ mod tests { transaction_position: None, transaction_hash: None, block_number: 13, - block_hash: 14.into(), + block_hash: H256::from_low_u64_be(14), }; let serialized = serde_json::to_string(&t).unwrap(); assert_eq!(serialized, r#"{"type":"reward","action":{"author":"0x0000000000000000000000000000000000000004","value":"0x6","rewardType":"block"},"result":null,"traceAddress":[10],"subtraces":1,"transactionPosition":null,"transactionHash":null,"blockNumber":13,"blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#); @@ -852,15 +853,15 @@ mod tests { #[test] fn test_statediff_serialize() { let t = StateDiff(map![ - 42.into() => AccountDiff { + Address::from_low_u64_be(42) => AccountDiff { balance: Diff::Same, nonce: Diff::Born(1.into()), code: Diff::Same, storage: map![ - 42.into() => Diff::Same + H256::from_low_u64_be(42) => Diff::Same ] }, - 69.into() => AccountDiff { + Address::from_low_u64_be(69) => AccountDiff { balance: Diff::Same, nonce: Diff::Changed(ChangedType { from: 1.into(), to: 0.into() }), code: Diff::Died(vec![96].into()), diff --git a/rpc/src/v1/types/trace_filter.rs b/rpc/src/v1/types/trace_filter.rs index a455c3d1c..60c770195 100644 --- a/rpc/src/v1/types/trace_filter.rs +++ b/rpc/src/v1/types/trace_filter.rs @@ -97,8 +97,8 @@ mod tests { assert_eq!(deserialized, TraceFilter { from_block: Some(BlockNumber::Latest), to_block: Some(BlockNumber::Latest), - from_address: Some(vec![Address::from(3).into()]), - to_address: Some(vec![Address::from(5).into()]), + from_address: Some(vec![Address::from_low_u64_be(3).into()]), + to_address: Some(vec![Address::from_low_u64_be(5).into()]), after: 50.into(), count: 100.into(), }); diff --git a/rpc/src/v1/types/transaction.rs b/rpc/src/v1/types/transaction.rs index 931e03866..9d75aca3c 100644 --- a/rpc/src/v1/types/transaction.rs +++ b/rpc/src/v1/types/transaction.rs @@ -286,6 +286,8 @@ mod tests { #[test] fn test_local_transaction_status_serialize() { + use ethereum_types::H256; + let tx_ser = serde_json::to_string(&Transaction::default()).unwrap(); let status1 = LocalTransactionStatus::Pending; let status2 = LocalTransactionStatus::Future; @@ -293,7 +295,7 @@ mod tests { let status4 = LocalTransactionStatus::Dropped(Transaction::default()); let status5 = LocalTransactionStatus::Invalid(Transaction::default()); let status6 = LocalTransactionStatus::Rejected(Transaction::default(), "Just because".into()); - let status7 = LocalTransactionStatus::Replaced(Transaction::default(), 5.into(), 10.into()); + let status7 = LocalTransactionStatus::Replaced(Transaction::default(), 5.into(), H256::from_low_u64_be(10)); assert_eq!( serde_json::to_string(&status1).unwrap(), diff --git a/rpc/src/v1/types/transaction_request.rs b/rpc/src/v1/types/transaction_request.rs index 944ee1114..0f1463931 100644 --- a/rpc/src/v1/types/transaction_request.rs +++ b/rpc/src/v1/types/transaction_request.rs @@ -157,8 +157,8 @@ mod tests { let deserialized: TransactionRequest = serde_json::from_str(s).unwrap(); assert_eq!(deserialized, TransactionRequest { - from: Some(H160::from(1)), - to: Some(H160::from(2)), + from: Some(H160::from_low_u64_be(1)), + to: Some(H160::from_low_u64_be(2)), gas_price: Some(U256::from(1)), gas: Some(U256::from(2)), value: Some(U256::from(3)), @@ -198,7 +198,7 @@ mod tests { let deserialized: TransactionRequest = serde_json::from_str(s).unwrap(); assert_eq!(deserialized, TransactionRequest { - from: Some(H160::from(1).into()), + from: Some(H160::from_low_u64_be(1)), to: None, gas_price: None, gas: None, diff --git a/secret-store/Cargo.toml b/secret-store/Cargo.toml index 5b5f25034..5139d1b7f 100644 --- a/secret-store/Cargo.toml +++ b/secret-store/Cargo.toml @@ -8,18 +8,18 @@ authors = ["Parity Technologies "] [dependencies] byteorder = "1.0" common-types = { path = "../ethcore/types" } -ethabi = "6.0" -ethabi-contract = "6.0" -ethabi-derive = "6.0" +ethabi = "8.0" +ethabi-contract = "8.0" +ethabi-derive = "8.0" ethcore = { path = "../ethcore" } ethcore-accounts = { path = "../accounts", optional = true} ethcore-call-contract = { path = "../ethcore/call-contract" } ethcore-sync = { path = "../ethcore/sync" } -ethereum-types = "0.4" +ethereum-types = "0.6.0" ethkey = { path = "../accounts/ethkey" } futures = "0.1" hyper = { version = "0.12", default-features = false } -keccak-hash = "0.1" +keccak-hash = "0.2.0" kvdb = "0.1" lazy_static = "1.0" log = "0.4" diff --git a/secret-store/src/key_server.rs b/secret-store/src/key_server.rs index 3f03e7e25..77b32d623 100644 --- a/secret-store/src/key_server.rs +++ b/secret-store/src/key_server.rs @@ -103,7 +103,7 @@ impl DocumentKeyServer for KeyServerImpl { self.store_document_key(key_id, author, encrypted_document_key.common_point, encrypted_document_key.encrypted_point)?; // encrypt document key with requestor public key - let document_key = crypto::ecies::encrypt(&public, &DEFAULT_MAC, &document_key) + let document_key = crypto::ecies::encrypt(&public, &DEFAULT_MAC, document_key.as_bytes()) .map_err(|err| Error::Internal(format!("Error encrypting document key: {}", err)))?; Ok(document_key) } @@ -120,7 +120,7 @@ impl DocumentKeyServer for KeyServerImpl { .decrypted_secret; // encrypt document key with requestor public key - let document_key = crypto::ecies::encrypt(&public, &DEFAULT_MAC, &document_key) + let document_key = crypto::ecies::encrypt(&public, &DEFAULT_MAC, document_key.as_bytes()) .map_err(|err| Error::Internal(format!("Error encrypting document key: {}", err)))?; Ok(document_key) } @@ -146,8 +146,8 @@ impl MessageSigner for KeyServerImpl { // compose two message signature components into single one let mut combined_signature = [0; 64]; - combined_signature[..32].clone_from_slice(&**message_signature.0); - combined_signature[32..].clone_from_slice(&**message_signature.1); + combined_signature[..32].clone_from_slice(message_signature.0.as_bytes()); + combined_signature[32..].clone_from_slice(message_signature.1.as_bytes()); // encrypt combined signature with requestor public key let message_signature = crypto::ecies::encrypt(&public, &DEFAULT_MAC, &combined_signature) @@ -422,7 +422,7 @@ pub mod tests { let server_public = key_servers[0].generate_key(&server_key_id, &signature.clone().into(), *threshold).unwrap(); // sign message - let message_hash = H256::from(42); + let message_hash = H256::from_low_u64_be(42); let combined_signature = key_servers[0].sign_message_schnorr(&server_key_id, &signature.into(), message_hash.clone()).unwrap(); let combined_signature = crypto::ecies::decrypt(&requestor_secret, &DEFAULT_MAC, &combined_signature).unwrap(); let signature_c = Secret::from_slice(&combined_signature[..32]).unwrap(); @@ -473,7 +473,7 @@ pub mod tests { key_storages[0].remove(&server_key_id).unwrap(); // sign message - let message_hash = H256::from(42); + let message_hash = H256::from_low_u64_be(42); let combined_signature = key_servers[0].sign_message_schnorr(&server_key_id, &signature.into(), message_hash.clone()).unwrap(); let combined_signature = crypto::ecies::decrypt(&requestor_secret, &DEFAULT_MAC, &combined_signature).unwrap(); let signature_c = Secret::from_slice(&combined_signature[..32]).unwrap(); @@ -503,7 +503,7 @@ pub mod tests { let message_hash = H256::random(); let signature = key_servers[0].sign_message_ecdsa(&server_key_id, &signature.into(), message_hash.clone()).unwrap(); let signature = crypto::ecies::decrypt(&requestor_secret, &DEFAULT_MAC, &signature).unwrap(); - let signature: H520 = signature[0..65].into(); + let signature = H520::from_slice(&signature[0..65]); // check signature assert!(verify_public(&server_public, &signature.into(), &message_hash).unwrap()); diff --git a/secret-store/src/key_server_cluster/admin_sessions/key_version_negotiation_session.rs b/secret-store/src/key_server_cluster/admin_sessions/key_version_negotiation_session.rs index 588019486..34d7bde71 100644 --- a/secret-store/src/key_server_cluster/admin_sessions/key_version_negotiation_session.rs +++ b/secret-store/src/key_server_cluster/admin_sessions/key_version_negotiation_session.rs @@ -590,6 +590,7 @@ impl SessionResultComputer for LargestSupportResultComputer { mod tests { use std::sync::Arc; use std::collections::{VecDeque, BTreeMap, BTreeSet}; + use ethereum_types::{H512, Address}; use ethkey::public_to_address; use key_server_cluster::{NodeId, SessionId, Error, KeyStorage, DummyKeyStorage, DocumentKeyShare, DocumentKeyShareVersion}; @@ -600,8 +601,10 @@ mod tests { use key_server_cluster::admin_sessions::ShareChangeSessionMeta; use key_server_cluster::decryption_session::create_default_decryption_session; use key_server_cluster::message::{Message, KeyVersionNegotiationMessage, RequestKeyVersions, KeyVersions}; - use super::{SessionImpl, SessionTransport, SessionParams, FastestResultComputer, LargestSupportResultComputer, - SessionResultComputer, SessionState, ContinueAction, FailedContinueAction}; + use super::{ + SessionImpl, SessionTransport, SessionParams, FastestResultComputer, LargestSupportResultComputer, + SessionResultComputer, SessionState, ContinueAction, FailedContinueAction, + }; struct DummyTransport { cluster: Arc, @@ -880,7 +883,7 @@ mod tests { #[test] fn fatal_error_is_broadcasted_if_started_with_origin() { let mut ml = MessageLoop::empty(3); - ml.session(0).set_continue_action(ContinueAction::Decrypt(create_default_decryption_session(), Some(1.into()), true, true)); + ml.session(0).set_continue_action(ContinueAction::Decrypt(create_default_decryption_session(), Some(Address::from_low_u64_be(1)), true, true)); ml.session(0).initialize(ml.nodes.keys().cloned().collect()).unwrap(); ml.run(); @@ -889,6 +892,6 @@ mod tests { // slave nodes have non-empty failed continue action assert!(ml.nodes.values().skip(1).all(|n| n.session.take_failed_continue_action() - == Some(FailedContinueAction::Decrypt(Some(1.into()), public_to_address(&2.into()))))); + == Some(FailedContinueAction::Decrypt(Some(Address::from_low_u64_be(1)), public_to_address(&H512::from_low_u64_be(2)))))); } } diff --git a/secret-store/src/key_server_cluster/client_sessions/decryption_session.rs b/secret-store/src/key_server_cluster/client_sessions/decryption_session.rs index ccb34e982..b47c81b98 100644 --- a/secret-store/src/key_server_cluster/client_sessions/decryption_session.rs +++ b/secret-store/src/key_server_cluster/client_sessions/decryption_session.rs @@ -816,6 +816,7 @@ impl JobTransport for DecryptionJobTransport { pub fn create_default_decryption_session() -> Arc { use acl_storage::DummyAclStorage; use key_server_cluster::cluster::tests::DummyCluster; + use ethereum_types::H512; Arc::new(SessionImpl::new(SessionParams { meta: SessionMeta { @@ -831,7 +832,7 @@ pub fn create_default_decryption_session() -> Arc { acl_storage: Arc::new(DummyAclStorage::default()), cluster: Arc::new(DummyCluster::new(Default::default())), nonce: 0, - }, Some(Requester::Public(2.into()))).unwrap()) + }, Some(Requester::Public(H512::from_low_u64_be(2)))).unwrap()) } #[cfg(test)] @@ -848,6 +849,8 @@ mod tests { use key_server_cluster::message::{self, Message, DecryptionMessage}; use key_server_cluster::math; use key_server_cluster::jobs::consensus_session::ConsensusSessionState; + use ethereum_types::{H512, Address}; + use std::str::FromStr; const SECRET_PLAIN: &'static str = "d2b57ae7619e070af0af6bc8c703c0cd27814c54d5d6a999cacac0da34ede279ca0d9216e85991029e54e2f0c92ee0bd30237725fa765cbdbfc4529489864c5f"; @@ -863,19 +866,19 @@ mod tests { "c06546b5669877ba579ca437a5602e89425c53808c708d44ccd6afcaa4610fad".parse().unwrap(), ]; let id_numbers: Vec<(NodeId, Secret)> = vec![ - ("b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8".into(), + (H512::from_str("b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8").unwrap(), "281b6bf43cb86d0dc7b98e1b7def4a80f3ce16d28d2308f934f116767306f06c".parse().unwrap()), - ("1395568277679f7f583ab7c0992da35f26cde57149ee70e524e49bdae62db3e18eb96122501e7cbb798b784395d7bb5a499edead0706638ad056d886e56cf8fb".into(), + (H512::from_str("1395568277679f7f583ab7c0992da35f26cde57149ee70e524e49bdae62db3e18eb96122501e7cbb798b784395d7bb5a499edead0706638ad056d886e56cf8fb").unwrap(), "00125d85a05e5e63e214cb60fe63f132eec8a103aa29266b7e6e6c5b7597230b".parse().unwrap()), - ("99e82b163b062d55a64085bacfd407bb55f194ba5fb7a1af9c34b84435455520f1372e0e650a4f91aed0058cb823f62146ccb5599c8d13372c300dea866b69fc".into(), + (H512::from_str("99e82b163b062d55a64085bacfd407bb55f194ba5fb7a1af9c34b84435455520f1372e0e650a4f91aed0058cb823f62146ccb5599c8d13372c300dea866b69fc").unwrap(), "f43ac0fba42a5b6ed95707d2244659e89ba877b1c9b82c0d0a9dcf834e80fc62".parse().unwrap()), - ("7e05df9dd077ec21ed4bc45c9fe9e0a43d65fa4be540630de615ced5e95cf5c3003035eb713317237d7667feeeb64335525158f5f7411f67aca9645169ea554c".into(), + (H512::from_str("7e05df9dd077ec21ed4bc45c9fe9e0a43d65fa4be540630de615ced5e95cf5c3003035eb713317237d7667feeeb64335525158f5f7411f67aca9645169ea554c").unwrap(), "5a324938dfb2516800487d25ab7289ba8ec38811f77c3df602e4e65e3c9acd9f".parse().unwrap()), - ("321977760d1d8e15b047a309e4c7fe6f355c10bb5a06c68472b676926427f69f229024fa2692c10da167d14cdc77eb95d0fce68af0a0f704f0d3db36baa83bb2".into(), + (H512::from_str("321977760d1d8e15b047a309e4c7fe6f355c10bb5a06c68472b676926427f69f229024fa2692c10da167d14cdc77eb95d0fce68af0a0f704f0d3db36baa83bb2").unwrap(), "12cf422d50002d04e52bd4906fd7f5f235f051ca36abfe37e061f8da248008d8".parse().unwrap()), ]; - let common_point: Public = "6962be696e1bcbba8e64cc7fddf140f854835354b5804f3bb95ae5a2799130371b589a131bd39699ac7174ccb35fc4342dab05331202209582fc8f3a40916ab0".into(); - let encrypted_point: Public = "b07031982bde9890e12eff154765f03c56c3ab646ad47431db5dd2d742a9297679c4c65b998557f8008469afd0c43d40b6c5f6c6a1c7354875da4115237ed87a".into(); + let common_point: Public = H512::from_str("6962be696e1bcbba8e64cc7fddf140f854835354b5804f3bb95ae5a2799130371b589a131bd39699ac7174ccb35fc4342dab05331202209582fc8f3a40916ab0").unwrap(); + let encrypted_point: Public = H512::from_str("b07031982bde9890e12eff154765f03c56c3ab646ad47431db5dd2d742a9297679c4c65b998557f8008469afd0c43d40b6c5f6c6a1c7354875da4115237ed87a").unwrap(); let encrypted_datas: Vec<_> = (0..5).map(|i| DocumentKeyShare { author: Default::default(), threshold: 3, @@ -1272,7 +1275,7 @@ mod tests { assert!(sessions.iter().skip(1).all(|s| s.decrypted_secret().is_none())); assert_eq!(sessions[0].decrypted_secret().unwrap().unwrap(), EncryptedDocumentKeyShadow { - decrypted_secret: SECRET_PLAIN.into(), + decrypted_secret: H512::from_str(SECRET_PLAIN).unwrap(), common_point: None, decrypt_shadows: None, }); @@ -1295,7 +1298,7 @@ mod tests { let decrypted_secret = sessions[0].decrypted_secret().unwrap().unwrap(); // check that decrypted_secret != SECRET_PLAIN - assert!(decrypted_secret.decrypted_secret != SECRET_PLAIN.into()); + assert!(decrypted_secret.decrypted_secret != H512::from_str(SECRET_PLAIN).unwrap()); // check that common point && shadow coefficients are returned assert!(decrypted_secret.common_point.is_some()); assert!(decrypted_secret.decrypt_shadows.is_some()); @@ -1306,7 +1309,7 @@ mod tests { .map(|c| Secret::from_slice(&decrypt(key_pair.secret(), &DEFAULT_MAC, &c).unwrap()).unwrap()) .collect(); let decrypted_secret = math::decrypt_with_shadow_coefficients(decrypted_secret.decrypted_secret, decrypted_secret.common_point.unwrap(), decrypt_shadows).unwrap(); - assert_eq!(decrypted_secret, SECRET_PLAIN.into()); + assert_eq!(decrypted_secret, H512::from_str(SECRET_PLAIN).unwrap()); } #[test] @@ -1347,7 +1350,7 @@ mod tests { // 2) 1 session has decrypted key value assert!(sessions.iter().skip(1).all(|s| s.decrypted_secret().is_none())); assert_eq!(sessions[0].decrypted_secret().unwrap().unwrap(), EncryptedDocumentKeyShadow { - decrypted_secret: SECRET_PLAIN.into(), + decrypted_secret: H512::from_str(SECRET_PLAIN).unwrap(), common_point: None, decrypt_shadows: None, }); @@ -1385,7 +1388,7 @@ mod tests { assert_eq!(sessions.iter().filter(|s| s.state() == ConsensusSessionState::Finished).count(), 4); // 2) 1 session has decrypted key value assert_eq!(sessions[1].decrypted_secret().unwrap().unwrap(), EncryptedDocumentKeyShadow { - decrypted_secret: SECRET_PLAIN.into(), + decrypted_secret: H512::from_str(SECRET_PLAIN).unwrap(), common_point: None, decrypt_shadows: None, }); @@ -1407,7 +1410,7 @@ mod tests { do_messages_exchange(&clusters, &sessions).unwrap(); assert_eq!(sessions[0].decrypted_secret().unwrap().unwrap(), EncryptedDocumentKeyShadow { - decrypted_secret: SECRET_PLAIN.into(), + decrypted_secret: H512::from_str(SECRET_PLAIN).unwrap(), common_point: None, decrypt_shadows: None, }); @@ -1423,7 +1426,7 @@ mod tests { let result = sessions[0].decrypted_secret(); assert!(result.clone().unwrap().is_ok()); assert_eq!(result.clone().unwrap().unwrap(), EncryptedDocumentKeyShadow { - decrypted_secret: SECRET_PLAIN.into(), + decrypted_secret: H512::from_str(SECRET_PLAIN).unwrap(), common_point: None, decrypt_shadows: None, }); @@ -1452,16 +1455,16 @@ mod tests { .map(|c| Secret::from_slice(&decrypt(key_pair.secret(), &DEFAULT_MAC, &c).unwrap()).unwrap()) .collect(); let decrypted_secret = math::decrypt_with_shadow_coefficients(result.decrypted_secret, result.common_point.unwrap(), decrypt_shadows).unwrap(); - assert_eq!(decrypted_secret, SECRET_PLAIN.into()); + assert_eq!(decrypted_secret, H512::from_str(SECRET_PLAIN).unwrap()); } #[test] fn decryption_session_origin_is_known_to_all_initialized_nodes() { let (_, clusters, _, sessions) = prepare_decryption_sessions(); - sessions[0].initialize(Some(1.into()), Default::default(), true, true).unwrap(); + sessions[0].initialize(Some(Address::from_low_u64_be(1)), Default::default(), true, true).unwrap(); do_messages_exchange(&clusters, &sessions).unwrap(); // all session must have origin set - assert_eq!(5, sessions.iter().filter(|s| s.origin() == Some(1.into())).count()); + assert_eq!(5, sessions.iter().filter(|s| s.origin() == Some(Address::from_low_u64_be(1))).count()); } } diff --git a/secret-store/src/key_server_cluster/client_sessions/signing_session_schnorr.rs b/secret-store/src/key_server_cluster/client_sessions/signing_session_schnorr.rs index 0b0619f96..b0881dfff 100644 --- a/secret-store/src/key_server_cluster/client_sessions/signing_session_schnorr.rs +++ b/secret-store/src/key_server_cluster/client_sessions/signing_session_schnorr.rs @@ -933,7 +933,7 @@ mod tests { #[test] fn schnorr_fails_to_initialize_when_already_initialized() { let (ml, _, _) = MessageLoop::new(1, 0).unwrap().init().unwrap(); - assert_eq!(ml.session_at(0).initialize(ml.key_version(), 777.into()), + assert_eq!(ml.session_at(0).initialize(ml.key_version(), H256::from_low_u64_be(777)), Err(Error::InvalidStateForRequest)); } @@ -1005,7 +1005,7 @@ mod tests { session: SessionId::default().into(), session_nonce: 0, origin: None, - author: Address::default().into(), + author: Address::zero().into(), nodes: BTreeMap::new(), is_zero: false, threshold: 1, @@ -1023,7 +1023,7 @@ mod tests { sub_session: session.core.access_key.clone().into(), session_nonce: 0, request_id: Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap().into(), - message_hash: H256::default().into(), + message_hash: H256::zero().into(), nodes: Default::default(), }), Err(Error::InvalidStateForRequest)); } @@ -1037,7 +1037,7 @@ mod tests { sub_session: session.core.access_key.clone().into(), session_nonce: 0, request_id: Secret::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap().into(), - message_hash: H256::default().into(), + message_hash: H256::zero().into(), nodes: Default::default(), }), Err(Error::InvalidMessage)); } diff --git a/secret-store/src/key_server_cluster/connection_trigger_with_migration.rs b/secret-store/src/key_server_cluster/connection_trigger_with_migration.rs index 559bab18c..ba11ea60c 100644 --- a/secret-store/src/key_server_cluster/connection_trigger_with_migration.rs +++ b/secret-store/src/key_server_cluster/connection_trigger_with_migration.rs @@ -142,7 +142,7 @@ impl ConnectionTriggerWithMigration { session_action: None, } } - + /// Actually do mainteinance. fn do_maintain(&mut self) -> Option { loop { @@ -452,58 +452,59 @@ mod tests { use key_server_cluster::connection_trigger::ConnectionsAction; use super::{MigrationState, SessionState, SessionAction, migration_state, maintain_session, maintain_connections, select_master_node}; + use ethereum_types::{H256, H512}; #[test] fn migration_state_is_idle_when_required_but_this_node_is_not_on_the_list() { - assert_eq!(migration_state(&1.into(), &KeyServerSetSnapshot { - current_set: vec![(2.into(), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(), - new_set: vec![(3.into(), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(), + assert_eq!(migration_state(&H512::from_low_u64_be(1), &KeyServerSetSnapshot { + current_set: vec![(H512::from_low_u64_be(2), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(3), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(), migration: None, }), MigrationState::Idle); } #[test] fn migration_state_is_idle_when_sets_are_equal() { - assert_eq!(migration_state(&1.into(), &KeyServerSetSnapshot { - current_set: vec![(1.into(), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(), - new_set: vec![(1.into(), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(), + assert_eq!(migration_state(&H512::from_low_u64_be(1), &KeyServerSetSnapshot { + current_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(), migration: None, }), MigrationState::Idle); } #[test] fn migration_state_is_idle_when_only_address_changes() { - assert_eq!(migration_state(&1.into(), &KeyServerSetSnapshot { - current_set: vec![(1.into(), "127.0.0.1:8080".parse().unwrap())].into_iter().collect(), - new_set: vec![(1.into(), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(), + assert_eq!(migration_state(&H512::from_low_u64_be(1), &KeyServerSetSnapshot { + current_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8080".parse().unwrap())].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(), migration: None, }), MigrationState::Idle); } #[test] fn migration_state_is_required_when_node_is_added() { - assert_eq!(migration_state(&1.into(), &KeyServerSetSnapshot { - current_set: vec![(1.into(), "127.0.0.1:8080".parse().unwrap())].into_iter().collect(), - new_set: vec![(1.into(), "127.0.0.1:8080".parse().unwrap()), - (2.into(), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(), + assert_eq!(migration_state(&H512::from_low_u64_be(1), &KeyServerSetSnapshot { + current_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8080".parse().unwrap())].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8080".parse().unwrap()), + (H512::from_low_u64_be(2), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(), migration: None, }), MigrationState::Required); } #[test] fn migration_state_is_required_when_node_is_removed() { - assert_eq!(migration_state(&1.into(), &KeyServerSetSnapshot { - current_set: vec![(1.into(), "127.0.0.1:8080".parse().unwrap()), - (2.into(), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(), - new_set: vec![(1.into(), "127.0.0.1:8080".parse().unwrap())].into_iter().collect(), + assert_eq!(migration_state(&H512::from_low_u64_be(1), &KeyServerSetSnapshot { + current_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8080".parse().unwrap()), + (H512::from_low_u64_be(2), "127.0.0.1:8081".parse().unwrap())].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8080".parse().unwrap())].into_iter().collect(), migration: None, }), MigrationState::Required); } #[test] fn migration_state_is_started_when_migration_is_some() { - assert_eq!(migration_state(&1.into(), &KeyServerSetSnapshot { - current_set: vec![(1.into(), "127.0.0.1:8080".parse().unwrap())].into_iter().collect(), + assert_eq!(migration_state(&H512::from_low_u64_be(1), &KeyServerSetSnapshot { + current_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8080".parse().unwrap())].into_iter().collect(), new_set: Default::default(), migration: Some(KeyServerSetMigration { id: Default::default(), @@ -517,35 +518,35 @@ mod tests { #[test] fn existing_master_is_selected_when_migration_has_started() { assert_eq!(select_master_node(&KeyServerSetSnapshot { - current_set: vec![(1.into(), "127.0.0.1:8180".parse().unwrap())].into_iter().collect(), - new_set: vec![(2.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + current_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8180".parse().unwrap())].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(2), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), migration: Some(KeyServerSetMigration { - master: 3.into(), + master: H512::from_low_u64_be(3), ..Default::default() }), - }), &3.into()); + }), &H512::from_low_u64_be(3)); } #[test] fn persistent_master_is_selected_when_migration_has_not_started_yet() { assert_eq!(select_master_node(&KeyServerSetSnapshot { - current_set: vec![(1.into(), "127.0.0.1:8180".parse().unwrap()), - (2.into(), "127.0.0.1:8180".parse().unwrap())].into_iter().collect(), - new_set: vec![(2.into(), "127.0.0.1:8181".parse().unwrap()), - (4.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + current_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8180".parse().unwrap()), + (H512::from_low_u64_be(2), "127.0.0.1:8180".parse().unwrap())].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(2), "127.0.0.1:8181".parse().unwrap()), + (H512::from_low_u64_be(4), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), migration: None, - }), &2.into()); + }), &H512::from_low_u64_be(2)); } #[test] fn new_master_is_selected_in_worst_case() { assert_eq!(select_master_node(&KeyServerSetSnapshot { - current_set: vec![(1.into(), "127.0.0.1:8180".parse().unwrap()), - (2.into(), "127.0.0.1:8180".parse().unwrap())].into_iter().collect(), - new_set: vec![(3.into(), "127.0.0.1:8181".parse().unwrap()), - (4.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + current_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8180".parse().unwrap()), + (H512::from_low_u64_be(2), "127.0.0.1:8180".parse().unwrap())].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(3), "127.0.0.1:8181".parse().unwrap()), + (H512::from_low_u64_be(4), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), migration: None, - }), &3.into()); + }), &H512::from_low_u64_be(3)); } #[test] @@ -574,29 +575,29 @@ mod tests { #[test] fn maintain_sessions_does_nothing_if_no_session_and_no_migration() { - assert_eq!(maintain_session(&1.into(), &Default::default(), &Default::default(), + assert_eq!(maintain_session(&H512::from_low_u64_be(1), &Default::default(), &Default::default(), MigrationState::Idle, SessionState::Idle), None); } #[test] fn maintain_session_does_nothing_when_migration_required_on_slave_node_and_no_session() { - assert_eq!(maintain_session(&2.into(), &vec![2.into()].into_iter().collect(), &KeyServerSetSnapshot { - current_set: vec![(1.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), - new_set: vec![(1.into(), "127.0.0.1:8181".parse().unwrap()), - (2.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + assert_eq!(maintain_session(&H512::from_low_u64_be(2), &vec![H512::from_low_u64_be(2)].into_iter().collect(), &KeyServerSetSnapshot { + current_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8181".parse().unwrap()), + (H512::from_low_u64_be(2), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), migration: None, }, MigrationState::Required, SessionState::Idle), None); } #[test] fn maintain_session_does_nothing_when_migration_started_on_slave_node_and_no_session() { - assert_eq!(maintain_session(&2.into(), &vec![2.into()].into_iter().collect(), &KeyServerSetSnapshot { - current_set: vec![(1.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + assert_eq!(maintain_session(&H512::from_low_u64_be(2), &vec![H512::from_low_u64_be(2)].into_iter().collect(), &KeyServerSetSnapshot { + current_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), new_set: Default::default(), migration: Some(KeyServerSetMigration { - master: 1.into(), - set: vec![(1.into(), "127.0.0.1:8181".parse().unwrap()), - (2.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + master: H512::from_low_u64_be(1), + set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8181".parse().unwrap()), + (H512::from_low_u64_be(2), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), ..Default::default() }), }, MigrationState::Started, SessionState::Idle), None); @@ -604,13 +605,13 @@ mod tests { #[test] fn maintain_session_does_nothing_when_migration_started_on_master_node_and_no_session_and_not_connected_to_migration_nodes() { - assert_eq!(maintain_session(&1.into(), &Default::default(), &KeyServerSetSnapshot { - current_set: vec![(1.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + assert_eq!(maintain_session(&H512::from_low_u64_be(1), &Default::default(), &KeyServerSetSnapshot { + current_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), new_set: Default::default(), migration: Some(KeyServerSetMigration { - master: 1.into(), - set: vec![(1.into(), "127.0.0.1:8181".parse().unwrap()), - (2.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + master: H512::from_low_u64_be(1), + set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8181".parse().unwrap()), + (H512::from_low_u64_be(2), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), ..Default::default() }), }, MigrationState::Started, SessionState::Idle), None); @@ -618,13 +619,13 @@ mod tests { #[test] fn maintain_session_starts_session_when_migration_started_on_master_node_and_no_session() { - assert_eq!(maintain_session(&1.into(), &vec![2.into()].into_iter().collect(), &KeyServerSetSnapshot { - current_set: vec![(1.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + assert_eq!(maintain_session(&H512::from_low_u64_be(1), &vec![H512::from_low_u64_be(2)].into_iter().collect(), &KeyServerSetSnapshot { + current_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), new_set: Default::default(), migration: Some(KeyServerSetMigration { - master: 1.into(), - set: vec![(1.into(), "127.0.0.1:8181".parse().unwrap()), - (2.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + master: H512::from_low_u64_be(1), + set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8181".parse().unwrap()), + (H512::from_low_u64_be(2), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), ..Default::default() }), }, MigrationState::Started, SessionState::Idle), Some(SessionAction::Start)); @@ -632,13 +633,13 @@ mod tests { #[test] fn maintain_session_does_nothing_when_both_migration_and_session_are_started() { - assert_eq!(maintain_session(&1.into(), &vec![2.into()].into_iter().collect(), &KeyServerSetSnapshot { - current_set: vec![(1.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + assert_eq!(maintain_session(&H512::from_low_u64_be(1), &vec![H512::from_low_u64_be(2)].into_iter().collect(), &KeyServerSetSnapshot { + current_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), new_set: Default::default(), migration: Some(KeyServerSetMigration { - master: 1.into(), - set: vec![(1.into(), "127.0.0.1:8181".parse().unwrap()), - (2.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + master: H512::from_low_u64_be(1), + set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8181".parse().unwrap()), + (H512::from_low_u64_be(2), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), ..Default::default() }), }, MigrationState::Started, SessionState::Active(Default::default())), None); @@ -646,13 +647,13 @@ mod tests { #[test] fn maintain_session_confirms_migration_when_active_and_session_has_finished_on_new_node() { - assert_eq!(maintain_session(&1.into(), &vec![2.into()].into_iter().collect(), &KeyServerSetSnapshot { - current_set: vec![(1.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + assert_eq!(maintain_session(&H512::from_low_u64_be(1), &vec![H512::from_low_u64_be(2)].into_iter().collect(), &KeyServerSetSnapshot { + current_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), new_set: Default::default(), migration: Some(KeyServerSetMigration { - master: 1.into(), - set: vec![(1.into(), "127.0.0.1:8181".parse().unwrap()), - (2.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + master: H512::from_low_u64_be(1), + set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8181".parse().unwrap()), + (H512::from_low_u64_be(2), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), ..Default::default() }), }, MigrationState::Started, SessionState::Finished(Default::default())), Some(SessionAction::ConfirmAndDrop(Default::default()))); @@ -660,13 +661,13 @@ mod tests { #[test] fn maintain_session_drops_session_when_active_and_session_has_finished_on_removed_node() { - assert_eq!(maintain_session(&1.into(), &vec![2.into()].into_iter().collect(), &KeyServerSetSnapshot { - current_set: vec![(1.into(), "127.0.0.1:8181".parse().unwrap()), - (2.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + assert_eq!(maintain_session(&H512::from_low_u64_be(1), &vec![H512::from_low_u64_be(2)].into_iter().collect(), &KeyServerSetSnapshot { + current_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8181".parse().unwrap()), + (H512::from_low_u64_be(2), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), new_set: Default::default(), migration: Some(KeyServerSetMigration { - master: 2.into(), - set: vec![(2.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + master: H512::from_low_u64_be(2), + set: vec![(H512::from_low_u64_be(2), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), ..Default::default() }), }, MigrationState::Started, SessionState::Finished(Default::default())), Some(SessionAction::Drop)); @@ -674,13 +675,13 @@ mod tests { #[test] fn maintain_session_drops_session_when_active_and_session_has_failed() { - assert_eq!(maintain_session(&1.into(), &vec![2.into()].into_iter().collect(), &KeyServerSetSnapshot { - current_set: vec![(1.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + assert_eq!(maintain_session(&H512::from_low_u64_be(1), &vec![H512::from_low_u64_be(2)].into_iter().collect(), &KeyServerSetSnapshot { + current_set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), new_set: Default::default(), migration: Some(KeyServerSetMigration { - master: 1.into(), - set: vec![(1.into(), "127.0.0.1:8181".parse().unwrap()), - (2.into(), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), + master: H512::from_low_u64_be(1), + set: vec![(H512::from_low_u64_be(1), "127.0.0.1:8181".parse().unwrap()), + (H512::from_low_u64_be(2), "127.0.0.1:8181".parse().unwrap())].into_iter().collect(), ..Default::default() }), }, MigrationState::Started, SessionState::Failed(Default::default())), Some(SessionAction::Drop)); @@ -726,32 +727,32 @@ mod tests { fn maintain_session_detects_abnormal_when_active_migration_and_active_session_with_different_id() { assert_eq!(maintain_session(&Default::default(), &Default::default(), &KeyServerSetSnapshot { migration: Some(KeyServerSetMigration { - id: 0.into(), + id: H256::zero(), ..Default::default() }), ..Default::default() - }, MigrationState::Started, SessionState::Active(Some(1.into()))), Some(SessionAction::DropAndRetry)); + }, MigrationState::Started, SessionState::Active(Some(H256::from_low_u64_be(1)))), Some(SessionAction::DropAndRetry)); } #[test] fn maintain_session_detects_abnormal_when_active_migration_and_finished_session_with_different_id() { assert_eq!(maintain_session(&Default::default(), &Default::default(), &KeyServerSetSnapshot { migration: Some(KeyServerSetMigration { - id: 0.into(), + id: H256::zero(), ..Default::default() }), ..Default::default() - }, MigrationState::Started, SessionState::Finished(Some(1.into()))), Some(SessionAction::DropAndRetry)); + }, MigrationState::Started, SessionState::Finished(Some(H256::from_low_u64_be(1)))), Some(SessionAction::DropAndRetry)); } #[test] fn maintain_session_detects_abnormal_when_active_migration_and_failed_session_with_different_id() { assert_eq!(maintain_session(&Default::default(), &Default::default(), &KeyServerSetSnapshot { migration: Some(KeyServerSetMigration { - id: 0.into(), + id: H256::zero(), ..Default::default() }), ..Default::default() - }, MigrationState::Started, SessionState::Failed(Some(1.into()))), Some(SessionAction::DropAndRetry)); + }, MigrationState::Started, SessionState::Failed(Some(H256::from_low_u64_be(1)))), Some(SessionAction::DropAndRetry)); } } diff --git a/secret-store/src/key_server_cluster/io/message.rs b/secret-store/src/key_server_cluster/io/message.rs index 0ce2b7c01..5707bd809 100644 --- a/secret-store/src/key_server_cluster/io/message.rs +++ b/secret-store/src/key_server_cluster/io/message.rs @@ -22,7 +22,7 @@ use serde_json; use ethkey::crypto::ecies; use ethkey::{Secret, KeyPair}; use ethkey::math::curve_order; -use ethereum_types::{H256, U256}; +use ethereum_types::{H256, U256, BigEndianHash}; use key_server_cluster::Error; use key_server_cluster::message::{Message, ClusterMessage, GenerationMessage, EncryptionMessage, DecryptionMessage, SchnorrSigningMessage, EcdsaSigningMessage, ServersSetChangeMessage, ShareAddMessage, KeyVersionNegotiationMessage}; @@ -257,9 +257,9 @@ pub fn fix_shared_key(shared_secret: &Secret) -> Result { // secret key created in agree function is invalid, as it is not calculated mod EC.field.n // => let's do it manually let shared_secret: H256 = (**shared_secret).into(); - let shared_secret: U256 = shared_secret.into(); - let shared_secret: H256 = (shared_secret % curve_order()).into(); - let shared_key_pair = KeyPair::from_secret_slice(&*shared_secret)?; + let shared_secret: U256 = shared_secret.into_uint(); + let shared_secret: H256 = BigEndianHash::from_uint(&(shared_secret % curve_order())); + let shared_key_pair = KeyPair::from_secret_slice(shared_secret.as_bytes())?; Ok(shared_key_pair) } diff --git a/secret-store/src/key_server_cluster/jobs/consensus_session.rs b/secret-store/src/key_server_cluster/jobs/consensus_session.rs index 7daf05d3b..7f2933870 100644 --- a/secret-store/src/key_server_cluster/jobs/consensus_session.rs +++ b/secret-store/src/key_server_cluster/jobs/consensus_session.rs @@ -354,7 +354,7 @@ impl Result<(), Error> { let consensus_result = match message { - + &ConsensusMessage::InitializeConsensusSession(ref message) => self.consensus_job.on_partial_request(sender, message.requester.clone().into()).map(|_| ()), &ConsensusMessage::ConfirmConsensusInitialization(ref message) => @@ -397,9 +397,9 @@ mod tests { #[test] fn consensus_session_consensus_is_not_reached_when_initializes_with_non_zero_threshold() { let mut session = make_master_consensus_session(1, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2)].into_iter().collect()).unwrap(); + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2)].into_iter().collect()).unwrap(); assert_eq!(session.state(), ConsensusSessionState::EstablishingConsensus); - session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); @@ -408,9 +408,9 @@ mod tests { #[test] fn consensus_session_consensus_is_reached_when_initializes_with_zero_threshold() { let mut session = make_master_consensus_session(0, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2)].into_iter().collect()).unwrap(); + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2)].into_iter().collect()).unwrap(); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); - session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); @@ -423,9 +423,9 @@ mod tests { acl_storage.prohibit(public_to_address(requester.public()), SessionId::default()); let mut session = make_master_consensus_session(0, Some(requester), Some(acl_storage)); - session.initialize(vec![NodeId::from(1), NodeId::from(2)].into_iter().collect()).unwrap(); + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2)].into_iter().collect()).unwrap(); assert_eq!(session.state(), ConsensusSessionState::EstablishingConsensus); - session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); @@ -438,16 +438,16 @@ mod tests { acl_storage.prohibit(public_to_address(requester.public()), SessionId::default()); let mut session = make_master_consensus_session(1, Some(requester), Some(acl_storage)); - assert_eq!(session.initialize(vec![NodeId::from(1), NodeId::from(2)].into_iter().collect()).unwrap_err(), Error::ConsensusUnreachable); + assert_eq!(session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2)].into_iter().collect()).unwrap_err(), Error::ConsensusUnreachable); assert_eq!(session.state(), ConsensusSessionState::Failed); } #[test] fn consensus_session_consensus_is_failed_by_slave_node() { let mut session = make_master_consensus_session(1, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2)].into_iter().collect()).unwrap(); + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2)].into_iter().collect()).unwrap(); assert_eq!(session.state(), ConsensusSessionState::EstablishingConsensus); - assert_eq!(session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + assert_eq!(session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: false, })).unwrap_err(), Error::ConsensusUnreachable); assert_eq!(session.state(), ConsensusSessionState::Failed); @@ -462,15 +462,15 @@ mod tests { #[test] fn consensus_session_job_dissemination_selects_master_node_if_agreed() { let mut session = make_master_consensus_session(0, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2)].into_iter().collect()).unwrap(); + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2)].into_iter().collect()).unwrap(); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); - session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); session.disseminate_jobs(SquaredSumJobExecutor, DummyJobTransport::default(), false).unwrap(); assert_eq!(session.state(), ConsensusSessionState::Finished); - assert!(session.computation_job().responses().contains_key(&NodeId::from(1))); + assert!(session.computation_job().responses().contains_key(&NodeId::from_low_u64_be(1))); } #[test] @@ -480,39 +480,39 @@ mod tests { acl_storage.prohibit(public_to_address(requester.public()), SessionId::default()); let mut session = make_master_consensus_session(0, Some(requester), Some(acl_storage)); - session.initialize(vec![NodeId::from(1), NodeId::from(2)].into_iter().collect()).unwrap(); + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2)].into_iter().collect()).unwrap(); assert_eq!(session.state(), ConsensusSessionState::EstablishingConsensus); - session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); session.disseminate_jobs(SquaredSumJobExecutor, DummyJobTransport::default(), false).unwrap(); assert_eq!(session.state(), ConsensusSessionState::WaitingForPartialResults); - assert!(!session.computation_job().responses().contains_key(&NodeId::from(1))); + assert!(!session.computation_job().responses().contains_key(&NodeId::from_low_u64_be(1))); } #[test] fn consensus_session_computation_request_is_rejected_when_received_by_master_node() { let mut session = make_master_consensus_session(0, None, None); - assert_eq!(session.on_job_request(&NodeId::from(2), 2, SquaredSumJobExecutor, DummyJobTransport::default()).unwrap_err(), Error::InvalidMessage); + assert_eq!(session.on_job_request(&NodeId::from_low_u64_be(2), 2, SquaredSumJobExecutor, DummyJobTransport::default()).unwrap_err(), Error::InvalidMessage); } #[test] fn consensus_session_computation_request_is_rejected_when_received_before_consensus_is_established() { let mut session = make_slave_consensus_session(0, None); - assert_eq!(session.on_job_request(&NodeId::from(1), 2, SquaredSumJobExecutor, DummyJobTransport::default()).unwrap_err(), Error::InvalidStateForRequest); + assert_eq!(session.on_job_request(&NodeId::from_low_u64_be(1), 2, SquaredSumJobExecutor, DummyJobTransport::default()).unwrap_err(), Error::InvalidStateForRequest); } #[test] fn consensus_session_computation_request_is_ignored_when_wrong() { let mut session = make_slave_consensus_session(0, None); assert_eq!(session.state(), ConsensusSessionState::WaitingForInitialization); - session.on_consensus_message(&NodeId::from(1), &ConsensusMessage::InitializeConsensusSession(InitializeConsensusSession { + session.on_consensus_message(&NodeId::from_low_u64_be(1), &ConsensusMessage::InitializeConsensusSession(InitializeConsensusSession { requester: Requester::Signature(sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap()).into(), version: Default::default(), })).unwrap(); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); - assert_eq!(session.on_job_request(&NodeId::from(1), 20, SquaredSumJobExecutor, DummyJobTransport::default()).unwrap_err(), Error::InvalidMessage); + assert_eq!(session.on_job_request(&NodeId::from_low_u64_be(1), 20, SquaredSumJobExecutor, DummyJobTransport::default()).unwrap_err(), Error::InvalidMessage); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); } @@ -520,159 +520,159 @@ mod tests { fn consensus_session_computation_request_is_processed_when_correct() { let mut session = make_slave_consensus_session(0, None); assert_eq!(session.state(), ConsensusSessionState::WaitingForInitialization); - session.on_consensus_message(&NodeId::from(1), &ConsensusMessage::InitializeConsensusSession(InitializeConsensusSession { + session.on_consensus_message(&NodeId::from_low_u64_be(1), &ConsensusMessage::InitializeConsensusSession(InitializeConsensusSession { requester: Requester::Signature(sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap()).into(), version: Default::default(), })).unwrap(); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); - session.on_job_request(&NodeId::from(1), 2, SquaredSumJobExecutor, DummyJobTransport::default()).unwrap(); + session.on_job_request(&NodeId::from_low_u64_be(1), 2, SquaredSumJobExecutor, DummyJobTransport::default()).unwrap(); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); } #[test] fn consensus_session_computation_response_is_ignored_when_consensus_is_not_reached() { let mut session = make_master_consensus_session(1, None, None); - assert_eq!(session.on_job_response(&NodeId::from(2), 4).unwrap_err(), Error::InvalidStateForRequest); + assert_eq!(session.on_job_response(&NodeId::from_low_u64_be(2), 4).unwrap_err(), Error::InvalidStateForRequest); } #[test] fn consessus_session_completion_is_ignored_when_received_from_non_master_node() { let mut session = make_slave_consensus_session(0, None); - assert_eq!(session.on_session_completed(&NodeId::from(3)).unwrap_err(), Error::InvalidMessage); + assert_eq!(session.on_session_completed(&NodeId::from_low_u64_be(3)).unwrap_err(), Error::InvalidMessage); } #[test] fn consessus_session_completion_is_ignored_when_consensus_is_not_established() { let mut session = make_slave_consensus_session(0, None); - assert_eq!(session.on_session_completed(&NodeId::from(1)).unwrap_err(), Error::InvalidStateForRequest); + assert_eq!(session.on_session_completed(&NodeId::from_low_u64_be(1)).unwrap_err(), Error::InvalidStateForRequest); } #[test] fn consessus_session_completion_is_accepted() { let mut session = make_slave_consensus_session(0, None); - session.on_consensus_message(&NodeId::from(1), &ConsensusMessage::InitializeConsensusSession(InitializeConsensusSession { + session.on_consensus_message(&NodeId::from_low_u64_be(1), &ConsensusMessage::InitializeConsensusSession(InitializeConsensusSession { requester: Requester::Signature(sign(Random.generate().unwrap().secret(), &SessionId::default()).unwrap()).into(), version: Default::default(), })).unwrap(); - session.on_session_completed(&NodeId::from(1)).unwrap(); + session.on_session_completed(&NodeId::from_low_u64_be(1)).unwrap(); assert_eq!(session.state(), ConsensusSessionState::Finished); } #[test] fn consensus_session_fails_if_node_error_received_by_uninitialized_master() { let mut session = make_master_consensus_session(0, None, None); - assert_eq!(session.on_node_error(&NodeId::from(2), Error::AccessDenied), Err(Error::ConsensusUnreachable)); + assert_eq!(session.on_node_error(&NodeId::from_low_u64_be(2), Error::AccessDenied), Err(Error::ConsensusUnreachable)); assert_eq!(session.state(), ConsensusSessionState::Failed); } #[test] fn consensus_session_fails_if_node_error_received_by_uninitialized_slave_from_master() { let mut session = make_slave_consensus_session(0, None); - assert_eq!(session.on_node_error(&NodeId::from(1), Error::AccessDenied), Err(Error::ConsensusUnreachable)); + assert_eq!(session.on_node_error(&NodeId::from_low_u64_be(1), Error::AccessDenied), Err(Error::ConsensusUnreachable)); assert_eq!(session.state(), ConsensusSessionState::Failed); } #[test] fn consensus_sessions_fails_with_temp_error_if_node_error_received_by_uninitialized_slave_from_master() { let mut session = make_slave_consensus_session(0, None); - assert_eq!(session.on_node_error(&NodeId::from(1), Error::NodeDisconnected).unwrap_err(), Error::ConsensusTemporaryUnreachable); + assert_eq!(session.on_node_error(&NodeId::from_low_u64_be(1), Error::NodeDisconnected).unwrap_err(), Error::ConsensusTemporaryUnreachable); } #[test] fn consensus_session_continues_if_node_error_received_by_master_during_establish_and_enough_nodes_left() { let mut session = make_master_consensus_session(1, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2), NodeId::from(3)].into_iter().collect()).unwrap(); - assert_eq!(session.on_node_error(&NodeId::from(2), Error::AccessDenied), Ok(false)); + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2), NodeId::from_low_u64_be(3)].into_iter().collect()).unwrap(); + assert_eq!(session.on_node_error(&NodeId::from_low_u64_be(2), Error::AccessDenied), Ok(false)); } #[test] fn consensus_session_fails_if_node_error_received_by_master_during_establish_and_not_enough_nodes_left() { let mut session = make_master_consensus_session(1, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2)].into_iter().collect()).unwrap(); - assert_eq!(session.on_node_error(&NodeId::from(2), Error::AccessDenied), Err(Error::ConsensusUnreachable)); + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2)].into_iter().collect()).unwrap(); + assert_eq!(session.on_node_error(&NodeId::from_low_u64_be(2), Error::AccessDenied), Err(Error::ConsensusUnreachable)); assert_eq!(session.state(), ConsensusSessionState::Failed); } #[test] fn consensus_session_continues_if_node2_error_received_by_master_after_consensus_established_and_enough_nodes_left() { let mut session = make_master_consensus_session(1, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2), NodeId::from(3)].into_iter().collect()).unwrap(); - session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2), NodeId::from_low_u64_be(3)].into_iter().collect()).unwrap(); + session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); - assert_eq!(session.on_node_error(&NodeId::from(2), Error::AccessDenied), Ok(false)); + assert_eq!(session.on_node_error(&NodeId::from_low_u64_be(2), Error::AccessDenied), Ok(false)); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); } #[test] fn consensus_session_continues_if_node3_error_received_by_master_after_consensus_established_and_enough_nodes_left() { let mut session = make_master_consensus_session(1, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2), NodeId::from(3)].into_iter().collect()).unwrap(); - session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2), NodeId::from_low_u64_be(3)].into_iter().collect()).unwrap(); + session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); - assert_eq!(session.on_node_error(&NodeId::from(3), Error::AccessDenied), Ok(false)); + assert_eq!(session.on_node_error(&NodeId::from_low_u64_be(3), Error::AccessDenied), Ok(false)); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); } #[test] fn consensus_session_fails_if_node_error_received_by_master_after_consensus_established_and_not_enough_nodes_left() { let mut session = make_master_consensus_session(1, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2)].into_iter().collect()).unwrap(); - session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2)].into_iter().collect()).unwrap(); + session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); - assert_eq!(session.on_node_error(&NodeId::from(2), Error::AccessDenied), Err(Error::ConsensusUnreachable)); + assert_eq!(session.on_node_error(&NodeId::from_low_u64_be(2), Error::AccessDenied), Err(Error::ConsensusUnreachable)); assert_eq!(session.state(), ConsensusSessionState::Failed); } #[test] fn consensus_session_continues_if_node_error_received_from_slave_not_participating_in_computation() { let mut session = make_master_consensus_session(1, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2), NodeId::from(3), NodeId::from(4)].into_iter().collect()).unwrap(); - session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2), NodeId::from_low_u64_be(3), NodeId::from_low_u64_be(4)].into_iter().collect()).unwrap(); + session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); - session.on_consensus_message(&NodeId::from(3), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.on_consensus_message(&NodeId::from_low_u64_be(3), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); session.disseminate_jobs(SquaredSumJobExecutor, DummyJobTransport::default(), false).unwrap(); - assert_eq!(session.on_node_error(&NodeId::from(3), Error::AccessDenied), Ok(false)); - assert_eq!(session.on_node_error(&NodeId::from(4), Error::AccessDenied), Ok(false)); + assert_eq!(session.on_node_error(&NodeId::from_low_u64_be(3), Error::AccessDenied), Ok(false)); + assert_eq!(session.on_node_error(&NodeId::from_low_u64_be(4), Error::AccessDenied), Ok(false)); assert_eq!(session.state(), ConsensusSessionState::WaitingForPartialResults); } #[test] fn consensus_session_restarts_if_node_error_received_from_slave_participating_in_computation_and_enough_nodes_left() { let mut session = make_master_consensus_session(1, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2), NodeId::from(3), NodeId::from(4)].into_iter().collect()).unwrap(); - session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2), NodeId::from_low_u64_be(3), NodeId::from_low_u64_be(4)].into_iter().collect()).unwrap(); + session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); session.disseminate_jobs(SquaredSumJobExecutor, DummyJobTransport::default(), false).unwrap(); assert_eq!(session.state(), ConsensusSessionState::WaitingForPartialResults); - session.on_consensus_message(&NodeId::from(3), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.on_consensus_message(&NodeId::from_low_u64_be(3), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); - assert_eq!(session.on_node_error(&NodeId::from(2), Error::AccessDenied), Ok(true)); + assert_eq!(session.on_node_error(&NodeId::from_low_u64_be(2), Error::AccessDenied), Ok(true)); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); session.disseminate_jobs(SquaredSumJobExecutor, DummyJobTransport::default(), false).unwrap(); assert_eq!(session.state(), ConsensusSessionState::WaitingForPartialResults); - assert_eq!(session.on_node_error(&NodeId::from(3), Error::AccessDenied), Ok(false)); + assert_eq!(session.on_node_error(&NodeId::from_low_u64_be(3), Error::AccessDenied), Ok(false)); assert_eq!(session.state(), ConsensusSessionState::EstablishingConsensus); } #[test] fn consensus_session_fails_if_node_error_received_from_slave_participating_in_computation_and_not_enough_nodes_left() { let mut session = make_master_consensus_session(1, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2)].into_iter().collect()).unwrap(); - session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2)].into_iter().collect()).unwrap(); + session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); session.disseminate_jobs(SquaredSumJobExecutor, DummyJobTransport::default(), false).unwrap(); - assert_eq!(session.on_node_error(&NodeId::from(2), Error::AccessDenied), Err(Error::ConsensusUnreachable)); + assert_eq!(session.on_node_error(&NodeId::from_low_u64_be(2), Error::AccessDenied), Err(Error::ConsensusUnreachable)); assert_eq!(session.state(), ConsensusSessionState::Failed); } @@ -685,15 +685,15 @@ mod tests { #[test] fn consensus_session_continues_if_session_timeouts_and_enough_nodes_left_for_computation() { let mut session = make_master_consensus_session(1, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2), NodeId::from(3), NodeId::from(4)].into_iter().collect()).unwrap(); - session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2), NodeId::from_low_u64_be(3), NodeId::from_low_u64_be(4)].into_iter().collect()).unwrap(); + session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); session.disseminate_jobs(SquaredSumJobExecutor, DummyJobTransport::default(), false).unwrap(); assert_eq!(session.state(), ConsensusSessionState::WaitingForPartialResults); - session.on_consensus_message(&NodeId::from(3), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.on_consensus_message(&NodeId::from_low_u64_be(3), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); assert_eq!(session.on_session_timeout(), Ok(true)); @@ -709,8 +709,8 @@ mod tests { #[test] fn consensus_session_continues_if_session_timeouts_and_not_enough_nodes_left_for_computation() { let mut session = make_master_consensus_session(1, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2)].into_iter().collect()).unwrap(); - session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2)].into_iter().collect()).unwrap(); + session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); session.disseminate_jobs(SquaredSumJobExecutor, DummyJobTransport::default(), false).unwrap(); @@ -723,11 +723,11 @@ mod tests { #[test] fn same_consensus_group_returned_after_second_selection() { let mut session = make_master_consensus_session(1, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2), NodeId::from(3)].into_iter().collect()).unwrap(); - session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2), NodeId::from_low_u64_be(3)].into_iter().collect()).unwrap(); + session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); - session.on_consensus_message(&NodeId::from(3), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.on_consensus_message(&NodeId::from_low_u64_be(3), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); @@ -739,15 +739,15 @@ mod tests { #[test] fn consensus_session_complete_2_of_4() { let mut session = make_master_consensus_session(1, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2), NodeId::from(3), NodeId::from(3)].into_iter().collect()).unwrap(); + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2), NodeId::from_low_u64_be(3), NodeId::from_low_u64_be(3)].into_iter().collect()).unwrap(); assert_eq!(session.state(), ConsensusSessionState::EstablishingConsensus); - session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); session.disseminate_jobs(SquaredSumJobExecutor, DummyJobTransport::default(), false).unwrap(); assert_eq!(session.state(), ConsensusSessionState::WaitingForPartialResults); - session.on_job_response(&NodeId::from(2), 16).unwrap(); + session.on_job_response(&NodeId::from_low_u64_be(2), 16).unwrap(); assert_eq!(session.state(), ConsensusSessionState::Finished); assert_eq!(session.result(), Ok(20)); } @@ -755,9 +755,9 @@ mod tests { #[test] fn consensus_session_complete_2_of_4_after_restart() { let mut session = make_master_consensus_session(1, None, None); - session.initialize(vec![NodeId::from(1), NodeId::from(2), NodeId::from(3), NodeId::from(4)].into_iter().collect()).unwrap(); + session.initialize(vec![NodeId::from_low_u64_be(1), NodeId::from_low_u64_be(2), NodeId::from_low_u64_be(3), NodeId::from_low_u64_be(4)].into_iter().collect()).unwrap(); assert_eq!(session.state(), ConsensusSessionState::EstablishingConsensus); - session.on_consensus_message(&NodeId::from(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.on_consensus_message(&NodeId::from_low_u64_be(2), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); @@ -765,20 +765,20 @@ mod tests { session.disseminate_jobs(SquaredSumJobExecutor, DummyJobTransport::default(), false).unwrap(); assert_eq!(session.state(), ConsensusSessionState::WaitingForPartialResults); - session.on_consensus_message(&NodeId::from(3), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.on_consensus_message(&NodeId::from_low_u64_be(3), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); - assert_eq!(session.on_node_error(&NodeId::from(2), Error::AccessDenied).unwrap(), true); + assert_eq!(session.on_node_error(&NodeId::from_low_u64_be(2), Error::AccessDenied).unwrap(), true); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); session.disseminate_jobs(SquaredSumJobExecutor, DummyJobTransport::default(), false).unwrap(); assert_eq!(session.state(), ConsensusSessionState::WaitingForPartialResults); - assert_eq!(session.on_node_error(&NodeId::from(3), Error::AccessDenied).unwrap(), false); + assert_eq!(session.on_node_error(&NodeId::from_low_u64_be(3), Error::AccessDenied).unwrap(), false); assert_eq!(session.state(), ConsensusSessionState::EstablishingConsensus); - session.on_consensus_message(&NodeId::from(4), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { + session.on_consensus_message(&NodeId::from_low_u64_be(4), &ConsensusMessage::ConfirmConsensusInitialization(ConfirmConsensusInitialization { is_confirmed: true, })).unwrap(); assert_eq!(session.state(), ConsensusSessionState::ConsensusEstablished); @@ -786,7 +786,7 @@ mod tests { session.disseminate_jobs(SquaredSumJobExecutor, DummyJobTransport::default(), false).unwrap(); assert_eq!(session.state(), ConsensusSessionState::WaitingForPartialResults); - session.on_job_response(&NodeId::from(4), 16).unwrap(); + session.on_job_response(&NodeId::from_low_u64_be(4), 16).unwrap(); assert_eq!(session.state(), ConsensusSessionState::Finished); assert_eq!(session.result(), Ok(20)); } diff --git a/secret-store/src/key_server_cluster/jobs/decryption_job.rs b/secret-store/src/key_server_cluster/jobs/decryption_job.rs index ca3df29b2..e57255f85 100644 --- a/secret-store/src/key_server_cluster/jobs/decryption_job.rs +++ b/secret-store/src/key_server_cluster/jobs/decryption_job.rs @@ -150,7 +150,7 @@ impl JobExecutor for DecryptionJob { shadow_point: shadow_point, decrypt_shadow: match decrypt_shadow.clone() { None => None, - Some(decrypt_shadow) => Some(encrypt(&self.requester, &DEFAULT_MAC, &**decrypt_shadow)?), + Some(decrypt_shadow) => Some(encrypt(&self.requester, &DEFAULT_MAC, decrypt_shadow.as_bytes())?), }, })) } diff --git a/secret-store/src/key_server_cluster/jobs/job_session.rs b/secret-store/src/key_server_cluster/jobs/job_session.rs index d76f8adda..0af8ea2d0 100644 --- a/secret-store/src/key_server_cluster/jobs/job_session.rs +++ b/secret-store/src/key_server_cluster/jobs/job_session.rs @@ -434,12 +434,12 @@ pub mod tests { } pub fn make_master_session_meta(threshold: usize) -> SessionMeta { - SessionMeta { id: SessionId::default(), master_node_id: NodeId::from(1), self_node_id: NodeId::from(1), threshold: threshold, + SessionMeta { id: SessionId::default(), master_node_id: NodeId::from_low_u64_be(1), self_node_id: NodeId::from_low_u64_be(1), threshold: threshold, configured_nodes_count: 5, connected_nodes_count: 5 } } pub fn make_slave_session_meta(threshold: usize) -> SessionMeta { - SessionMeta { id: SessionId::default(), master_node_id: NodeId::from(1), self_node_id: NodeId::from(2), threshold: threshold, + SessionMeta { id: SessionId::default(), master_node_id: NodeId::from_low_u64_be(1), self_node_id: NodeId::from_low_u64_be(2), threshold: threshold, configured_nodes_count: 5, connected_nodes_count: 5 } } @@ -447,27 +447,27 @@ pub mod tests { fn job_initialize_fails_if_not_enough_nodes_for_threshold_total() { let mut job = JobSession::new(make_master_session_meta(1), SquaredSumJobExecutor, DummyJobTransport::default()); job.meta.configured_nodes_count = 1; - assert_eq!(job.initialize(vec![Public::from(1)].into_iter().collect(), None, false).unwrap_err(), Error::ConsensusUnreachable); + assert_eq!(job.initialize(vec![Public::from_low_u64_be(1)].into_iter().collect(), None, false).unwrap_err(), Error::ConsensusUnreachable); } #[test] fn job_initialize_fails_if_not_enough_nodes_for_threshold_connected() { let mut job = JobSession::new(make_master_session_meta(1), SquaredSumJobExecutor, DummyJobTransport::default()); job.meta.connected_nodes_count = 3; - assert_eq!(job.initialize(vec![Public::from(1)].into_iter().collect(), None, false).unwrap_err(), Error::ConsensusTemporaryUnreachable); + assert_eq!(job.initialize(vec![Public::from_low_u64_be(1)].into_iter().collect(), None, false).unwrap_err(), Error::ConsensusTemporaryUnreachable); } #[test] fn job_initialize_fails_if_not_inactive() { let mut job = JobSession::new(make_master_session_meta(0), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(1)].into_iter().collect(), None, false).unwrap(); - assert_eq!(job.initialize(vec![Public::from(1)].into_iter().collect(), None, false).unwrap_err(), Error::InvalidStateForRequest); + job.initialize(vec![Public::from_low_u64_be(1)].into_iter().collect(), None, false).unwrap(); + assert_eq!(job.initialize(vec![Public::from_low_u64_be(1)].into_iter().collect(), None, false).unwrap_err(), Error::InvalidStateForRequest); } #[test] fn job_initialization_leads_to_finish_if_single_node_is_required() { let mut job = JobSession::new(make_master_session_meta(0), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(1)].into_iter().collect(), None, false).unwrap(); + job.initialize(vec![Public::from_low_u64_be(1)].into_iter().collect(), None, false).unwrap(); assert_eq!(job.state(), JobSessionState::Finished); assert!(job.is_result_ready()); assert_eq!(job.result(), Ok(4)); @@ -476,77 +476,77 @@ pub mod tests { #[test] fn job_initialization_does_not_leads_to_finish_if_single_other_node_is_required() { let mut job = JobSession::new(make_master_session_meta(0), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(2)].into_iter().collect(), None, false).unwrap(); + job.initialize(vec![Public::from_low_u64_be(2)].into_iter().collect(), None, false).unwrap(); assert_eq!(job.state(), JobSessionState::Active); } #[test] fn job_request_fails_if_comes_from_non_master_node() { let mut job = JobSession::new(make_slave_session_meta(0), SquaredSumJobExecutor, DummyJobTransport::default()); - assert_eq!(job.on_partial_request(&NodeId::from(3), 2).unwrap_err(), Error::InvalidMessage); + assert_eq!(job.on_partial_request(&NodeId::from_low_u64_be(3), 2).unwrap_err(), Error::InvalidMessage); } #[test] fn job_request_fails_if_comes_to_master_node() { let mut job = JobSession::new(make_master_session_meta(0), SquaredSumJobExecutor, DummyJobTransport::default()); - assert_eq!(job.on_partial_request(&NodeId::from(1), 2).unwrap_err(), Error::InvalidMessage); + assert_eq!(job.on_partial_request(&NodeId::from_low_u64_be(1), 2).unwrap_err(), Error::InvalidMessage); } #[test] fn job_request_fails_if_comes_to_failed_state() { let mut job = JobSession::new(make_slave_session_meta(0), SquaredSumJobExecutor, DummyJobTransport::default()); job.on_session_timeout().unwrap_err(); - assert_eq!(job.on_partial_request(&NodeId::from(1), 2).unwrap_err(), Error::InvalidStateForRequest); + assert_eq!(job.on_partial_request(&NodeId::from_low_u64_be(1), 2).unwrap_err(), Error::InvalidStateForRequest); } #[test] fn job_request_succeeds_if_comes_to_finished_state() { let mut job = JobSession::new(make_slave_session_meta(0), SquaredSumJobExecutor, DummyJobTransport::default()); - job.on_partial_request(&NodeId::from(1), 2).unwrap(); - assert_eq!(job.transport().response(), (NodeId::from(1), 4)); + job.on_partial_request(&NodeId::from_low_u64_be(1), 2).unwrap(); + assert_eq!(job.transport().response(), (NodeId::from_low_u64_be(1), 4)); assert_eq!(job.state(), JobSessionState::Finished); - job.on_partial_request(&NodeId::from(1), 3).unwrap(); - assert_eq!(job.transport().response(), (NodeId::from(1), 9)); + job.on_partial_request(&NodeId::from_low_u64_be(1), 3).unwrap(); + assert_eq!(job.transport().response(), (NodeId::from_low_u64_be(1), 9)); assert_eq!(job.state(), JobSessionState::Finished); } #[test] fn job_response_fails_if_comes_to_slave_node() { let mut job = JobSession::new(make_slave_session_meta(0), SquaredSumJobExecutor, DummyJobTransport::default()); - assert_eq!(job.on_partial_response(&NodeId::from(1), 2).unwrap_err(), Error::InvalidMessage); + assert_eq!(job.on_partial_response(&NodeId::from_low_u64_be(1), 2).unwrap_err(), Error::InvalidMessage); } #[test] fn job_response_fails_if_comes_to_failed_state() { let mut job = JobSession::new(make_master_session_meta(0), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(2)].into_iter().collect(), None, false).unwrap(); + job.initialize(vec![Public::from_low_u64_be(2)].into_iter().collect(), None, false).unwrap(); job.on_session_timeout().unwrap_err(); - assert_eq!(job.on_partial_response(&NodeId::from(2), 2).unwrap_err(), Error::InvalidStateForRequest); + assert_eq!(job.on_partial_response(&NodeId::from_low_u64_be(2), 2).unwrap_err(), Error::InvalidStateForRequest); } #[test] fn job_response_fails_if_comes_from_unknown_node() { let mut job = JobSession::new(make_master_session_meta(0), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(2)].into_iter().collect(), None, false).unwrap(); - assert_eq!(job.on_partial_response(&NodeId::from(3), 2).unwrap_err(), Error::InvalidNodeForRequest); + job.initialize(vec![Public::from_low_u64_be(2)].into_iter().collect(), None, false).unwrap(); + assert_eq!(job.on_partial_response(&NodeId::from_low_u64_be(3), 2).unwrap_err(), Error::InvalidNodeForRequest); } #[test] fn job_response_leads_to_failure_if_too_few_nodes_left() { let mut job = JobSession::new(make_master_session_meta(1), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(1), Public::from(2)].into_iter().collect(), None, false).unwrap(); + job.initialize(vec![Public::from_low_u64_be(1), Public::from_low_u64_be(2)].into_iter().collect(), None, false).unwrap(); assert_eq!(job.state(), JobSessionState::Active); - assert_eq!(job.on_partial_response(&NodeId::from(2), 3).unwrap_err(), Error::ConsensusUnreachable); + assert_eq!(job.on_partial_response(&NodeId::from_low_u64_be(2), 3).unwrap_err(), Error::ConsensusUnreachable); assert_eq!(job.state(), JobSessionState::Failed); } #[test] fn job_response_succeeds() { let mut job = JobSession::new(make_master_session_meta(2), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(1), Public::from(2), Public::from(3)].into_iter().collect(), None, false).unwrap(); + job.initialize(vec![Public::from_low_u64_be(1), Public::from_low_u64_be(2), Public::from_low_u64_be(3)].into_iter().collect(), None, false).unwrap(); assert_eq!(job.state(), JobSessionState::Active); assert!(!job.is_result_ready()); - job.on_partial_response(&NodeId::from(2), 2).unwrap(); + job.on_partial_response(&NodeId::from_low_u64_be(2), 2).unwrap(); assert_eq!(job.state(), JobSessionState::Active); assert!(!job.is_result_ready()); } @@ -554,9 +554,9 @@ pub mod tests { #[test] fn job_response_leads_to_finish() { let mut job = JobSession::new(make_master_session_meta(1), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(1), Public::from(2)].into_iter().collect(), None, false).unwrap(); + job.initialize(vec![Public::from_low_u64_be(1), Public::from_low_u64_be(2)].into_iter().collect(), None, false).unwrap(); assert_eq!(job.state(), JobSessionState::Active); - job.on_partial_response(&NodeId::from(2), 2).unwrap(); + job.on_partial_response(&NodeId::from_low_u64_be(2), 2).unwrap(); assert_eq!(job.state(), JobSessionState::Finished); } @@ -564,7 +564,7 @@ pub mod tests { fn job_node_error_ignored_when_slave_disconnects_from_slave() { let mut job = JobSession::new(make_slave_session_meta(1), SquaredSumJobExecutor, DummyJobTransport::default()); assert_eq!(job.state(), JobSessionState::Inactive); - job.on_node_error(&NodeId::from(3), Error::AccessDenied).unwrap(); + job.on_node_error(&NodeId::from_low_u64_be(3), Error::AccessDenied).unwrap(); assert_eq!(job.state(), JobSessionState::Inactive); } @@ -572,59 +572,59 @@ pub mod tests { fn job_node_error_leads_to_fail_when_slave_disconnects_from_master() { let mut job = JobSession::new(make_slave_session_meta(1), SquaredSumJobExecutor, DummyJobTransport::default()); assert_eq!(job.state(), JobSessionState::Inactive); - assert_eq!(job.on_node_error(&NodeId::from(1), Error::AccessDenied).unwrap_err(), Error::ConsensusUnreachable); + assert_eq!(job.on_node_error(&NodeId::from_low_u64_be(1), Error::AccessDenied).unwrap_err(), Error::ConsensusUnreachable); assert_eq!(job.state(), JobSessionState::Failed); } #[test] fn job_node_error_ignored_when_disconnects_from_rejected() { let mut job = JobSession::new(make_master_session_meta(1), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(1), Public::from(2), Public::from(3)].into_iter().collect(), None, false).unwrap(); + job.initialize(vec![Public::from_low_u64_be(1), Public::from_low_u64_be(2), Public::from_low_u64_be(3)].into_iter().collect(), None, false).unwrap(); assert_eq!(job.state(), JobSessionState::Active); - job.on_partial_response(&NodeId::from(2), 3).unwrap(); - job.on_node_error(&NodeId::from(2), Error::AccessDenied).unwrap(); + job.on_partial_response(&NodeId::from_low_u64_be(2), 3).unwrap(); + job.on_node_error(&NodeId::from_low_u64_be(2), Error::AccessDenied).unwrap(); assert_eq!(job.state(), JobSessionState::Active); } #[test] fn job_node_error_ignored_when_disconnects_from_unknown() { let mut job = JobSession::new(make_master_session_meta(1), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(1), Public::from(2)].into_iter().collect(), None, false).unwrap(); + job.initialize(vec![Public::from_low_u64_be(1), Public::from_low_u64_be(2)].into_iter().collect(), None, false).unwrap(); assert_eq!(job.state(), JobSessionState::Active); - job.on_node_error(&NodeId::from(3), Error::AccessDenied).unwrap(); + job.on_node_error(&NodeId::from_low_u64_be(3), Error::AccessDenied).unwrap(); assert_eq!(job.state(), JobSessionState::Active); } #[test] fn job_node_error_ignored_when_disconnects_from_requested_and_enough_nodes_left() { let mut job = JobSession::new(make_master_session_meta(1), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(1), Public::from(2), Public::from(3)].into_iter().collect(), None, false).unwrap(); + job.initialize(vec![Public::from_low_u64_be(1), Public::from_low_u64_be(2), Public::from_low_u64_be(3)].into_iter().collect(), None, false).unwrap(); assert_eq!(job.state(), JobSessionState::Active); - job.on_node_error(&NodeId::from(3), Error::AccessDenied).unwrap(); + job.on_node_error(&NodeId::from_low_u64_be(3), Error::AccessDenied).unwrap(); assert_eq!(job.state(), JobSessionState::Active); } #[test] fn job_node_error_leads_to_fail_when_disconnects_from_requested_and_not_enough_nodes_left() { let mut job = JobSession::new(make_master_session_meta(1), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(1), Public::from(2)].into_iter().collect(), None, false).unwrap(); + job.initialize(vec![Public::from_low_u64_be(1), Public::from_low_u64_be(2)].into_iter().collect(), None, false).unwrap(); assert_eq!(job.state(), JobSessionState::Active); - assert_eq!(job.on_node_error(&NodeId::from(2), Error::AccessDenied).unwrap_err(), Error::ConsensusUnreachable); + assert_eq!(job.on_node_error(&NodeId::from_low_u64_be(2), Error::AccessDenied).unwrap_err(), Error::ConsensusUnreachable); assert_eq!(job.state(), JobSessionState::Failed); } #[test] fn job_broadcasts_self_response() { let mut job = JobSession::new(make_master_session_meta(1), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(1), Public::from(2)].into_iter().collect(), None, true).unwrap(); + job.initialize(vec![Public::from_low_u64_be(1), Public::from_low_u64_be(2)].into_iter().collect(), None, true).unwrap(); assert_eq!(job.state(), JobSessionState::Active); - assert_eq!(job.transport().response(), (NodeId::from(2), 4)); + assert_eq!(job.transport().response(), (NodeId::from_low_u64_be(2), 4)); } #[test] fn job_does_not_broadcasts_self_response() { let mut job = JobSession::new(make_master_session_meta(1), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(1), Public::from(2)].into_iter().collect(), None, false).unwrap(); + job.initialize(vec![Public::from_low_u64_be(1), Public::from_low_u64_be(2)].into_iter().collect(), None, false).unwrap(); assert_eq!(job.state(), JobSessionState::Active); assert!(job.transport().is_empty_response()); } @@ -632,30 +632,30 @@ pub mod tests { #[test] fn job_fails_with_temp_error_if_more_than_half_nodes_respond_with_temp_error() { let mut job = JobSession::new(make_master_session_meta(2), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(1), Public::from(2), Public::from(3), Public::from(4)].into_iter().collect(), None, false).unwrap(); - job.on_node_error(&NodeId::from(2), Error::NodeDisconnected).unwrap(); - assert_eq!(job.on_node_error(&NodeId::from(3), Error::NodeDisconnected).unwrap_err(), Error::ConsensusTemporaryUnreachable); + job.initialize(vec![Public::from_low_u64_be(1), Public::from_low_u64_be(2), Public::from_low_u64_be(3), Public::from_low_u64_be(4)].into_iter().collect(), None, false).unwrap(); + job.on_node_error(&NodeId::from_low_u64_be(2), Error::NodeDisconnected).unwrap(); + assert_eq!(job.on_node_error(&NodeId::from_low_u64_be(3), Error::NodeDisconnected).unwrap_err(), Error::ConsensusTemporaryUnreachable); } #[test] fn job_fails_with_temp_error_if_more_than_half_rejects_are_temp() { let mut job = JobSession::new(make_master_session_meta(2), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(1), Public::from(2), Public::from(3), Public::from(4)].into_iter().collect(), None, false).unwrap(); - job.on_node_error(&NodeId::from(2), Error::NodeDisconnected).unwrap(); - assert_eq!(job.on_node_error(&NodeId::from(3), Error::NodeDisconnected).unwrap_err(), Error::ConsensusTemporaryUnreachable); + job.initialize(vec![Public::from_low_u64_be(1), Public::from_low_u64_be(2), Public::from_low_u64_be(3), Public::from_low_u64_be(4)].into_iter().collect(), None, false).unwrap(); + job.on_node_error(&NodeId::from_low_u64_be(2), Error::NodeDisconnected).unwrap(); + assert_eq!(job.on_node_error(&NodeId::from_low_u64_be(3), Error::NodeDisconnected).unwrap_err(), Error::ConsensusTemporaryUnreachable); } #[test] fn job_fails_if_more_than_half_rejects_are_non_temp() { let mut job = JobSession::new(make_master_session_meta(2), SquaredSumJobExecutor, DummyJobTransport::default()); - job.initialize(vec![Public::from(1), Public::from(2), Public::from(3), Public::from(4)].into_iter().collect(), None, false).unwrap(); - job.on_node_error(&NodeId::from(2), Error::AccessDenied).unwrap(); - assert_eq!(job.on_node_error(&NodeId::from(3), Error::AccessDenied).unwrap_err(), Error::ConsensusUnreachable); + job.initialize(vec![Public::from_low_u64_be(1), Public::from_low_u64_be(2), Public::from_low_u64_be(3), Public::from_low_u64_be(4)].into_iter().collect(), None, false).unwrap(); + job.on_node_error(&NodeId::from_low_u64_be(2), Error::AccessDenied).unwrap(); + assert_eq!(job.on_node_error(&NodeId::from_low_u64_be(3), Error::AccessDenied).unwrap_err(), Error::ConsensusUnreachable); } #[test] fn job_fails_with_temp_error_when_temp_error_is_reported_by_master_node() { let mut job = JobSession::new(make_slave_session_meta(2), SquaredSumJobExecutor, DummyJobTransport::default()); - assert_eq!(job.on_node_error(&NodeId::from(1), Error::NodeDisconnected).unwrap_err(), Error::ConsensusTemporaryUnreachable); + assert_eq!(job.on_node_error(&NodeId::from_low_u64_be(1), Error::NodeDisconnected).unwrap_err(), Error::ConsensusTemporaryUnreachable); } } diff --git a/secret-store/src/key_server_cluster/jobs/servers_set_change_access_job.rs b/secret-store/src/key_server_cluster/jobs/servers_set_change_access_job.rs index ace5021a0..a37e07499 100644 --- a/secret-store/src/key_server_cluster/jobs/servers_set_change_access_job.rs +++ b/secret-store/src/key_server_cluster/jobs/servers_set_change_access_job.rs @@ -139,7 +139,7 @@ impl JobExecutor for ServersSetChangeAccessJob { pub fn ordered_nodes_hash(nodes: &BTreeSet) -> SessionId { let mut nodes_keccak = Keccak::new_keccak256(); for node in nodes { - nodes_keccak.update(&*node); + nodes_keccak.update(node.as_bytes()); } let mut nodes_keccak_value = [0u8; 32]; diff --git a/secret-store/src/key_server_cluster/math.rs b/secret-store/src/key_server_cluster/math.rs index 60d48b7f3..99340e492 100644 --- a/secret-store/src/key_server_cluster/math.rs +++ b/secret-store/src/key_server_cluster/math.rs @@ -15,7 +15,7 @@ // along with Parity Ethereum. If not, see . use ethkey::{Public, Secret, Signature, Random, Generator, math}; -use ethereum_types::{H256, U256}; +use ethereum_types::{H256, U256, BigEndianHash}; use hash::keccak; use key_server_cluster::Error; @@ -35,8 +35,8 @@ pub fn zero_scalar() -> Secret { /// Convert hash to EC scalar (modulo curve order). pub fn to_scalar(hash: H256) -> Result { - let scalar: U256 = hash.into(); - let scalar: H256 = (scalar % math::curve_order()).into(); + let scalar: U256 = hash.into_uint(); + let scalar: H256 = BigEndianHash::from_uint(&(scalar % math::curve_order())); let scalar = Secret::from(scalar.0); scalar.check_validity()?; Ok(scalar) @@ -54,12 +54,12 @@ pub fn generate_random_point() -> Result { /// Get X coordinate of point. fn public_x(public: &Public) -> H256 { - public[0..32].into() + H256::from_slice(&public.as_bytes()[0..32]) } /// Get Y coordinate of point. fn public_y(public: &Public) -> H256 { - public[32..64].into() + H256::from_slice(&public.as_bytes()[32..64]) } /// Compute publics sum. @@ -478,7 +478,7 @@ pub fn serialize_ecdsa_signature(nonce_public: &Public, signature_r: Secret, mut // compute recovery param let mut signature_v = { let nonce_public_x = public_x(nonce_public); - let nonce_public_y: U256 = public_y(nonce_public).into(); + let nonce_public_y: U256 = public_y(nonce_public).into_uint(); let nonce_public_y_is_odd = !(nonce_public_y % 2).is_zero(); let bit0 = if nonce_public_y_is_odd { 1u8 } else { 0u8 }; let bit1 = if nonce_public_x != *signature_r { 2u8 } else { 0u8 }; @@ -488,17 +488,17 @@ pub fn serialize_ecdsa_signature(nonce_public: &Public, signature_r: Secret, mut // fix high S let curve_order = math::curve_order(); let curve_order_half = curve_order / 2; - let s_numeric: U256 = (*signature_s).into(); + let s_numeric: U256 = (*signature_s).into_uint(); if s_numeric > curve_order_half { - let signature_s_hash: H256 = (curve_order - s_numeric).into(); + let signature_s_hash: H256 = BigEndianHash::from_uint(&(curve_order - s_numeric)); signature_s = signature_s_hash.into(); signature_v ^= 1; } // serialize as [r][s]v let mut signature = [0u8; 65]; - signature[..32].copy_from_slice(&**signature_r); - signature[32..64].copy_from_slice(&**signature_s); + signature[..32].copy_from_slice(signature_r.as_bytes()); + signature[32..64].copy_from_slice(signature_s.as_bytes()); signature[64] = signature_v; signature.into() diff --git a/secret-store/src/key_server_set.rs b/secret-store/src/key_server_set.rs index 5b25641ae..3002a3c12 100644 --- a/secret-store/src/key_server_set.rs +++ b/secret-store/src/key_server_set.rs @@ -583,7 +583,7 @@ fn block_confirmations(client: &BlockChainClient, block: H256) -> Option { pub mod tests { use std::collections::BTreeMap; use std::net::SocketAddr; - use ethereum_types::H256; + use ethereum_types::{H256, H512}; use ethkey::Public; use super::{update_future_set, update_number_of_confirmations, FutureNewSet, KeyServerSet, KeyServerSetSnapshot, MIGRATION_CONFIRMATIONS_REQUIRED}; @@ -675,18 +675,18 @@ pub mod tests { let mut future_new_set = None; let mut new_snapshot = KeyServerSetSnapshot { - current_set: vec![(1.into(), address)].into_iter().collect(), - new_set: vec![(2.into(), address)].into_iter().collect(), + current_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(2), address)].into_iter().collect(), ..Default::default() }; update_future_set(&mut future_new_set, &mut new_snapshot, Default::default()); assert_eq!(future_new_set, Some(FutureNewSet { - new_set: vec![(2.into(), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(2), address)].into_iter().collect(), block: Default::default(), })); assert_eq!(new_snapshot, KeyServerSetSnapshot { - current_set: vec![(1.into(), address)].into_iter().collect(), - new_set: vec![(1.into(), address)].into_iter().collect(), + current_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), ..Default::default() }); } @@ -696,22 +696,22 @@ pub mod tests { let address = "127.0.0.1:12000".parse().unwrap(); let mut future_new_set = Some(FutureNewSet { - new_set: vec![(2.into(), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(2), address)].into_iter().collect(), block: Default::default(), }); let mut new_snapshot = KeyServerSetSnapshot { - current_set: vec![(1.into(), address)].into_iter().collect(), - new_set: vec![(3.into(), address)].into_iter().collect(), + current_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(3), address)].into_iter().collect(), ..Default::default() }; - update_future_set(&mut future_new_set, &mut new_snapshot, 1.into()); + update_future_set(&mut future_new_set, &mut new_snapshot, H256::from_low_u64_be(1)); assert_eq!(future_new_set, Some(FutureNewSet { - new_set: vec![(3.into(), address)].into_iter().collect(), - block: 1.into(), + new_set: vec![(H512::from_low_u64_be(3), address)].into_iter().collect(), + block: H256::from_low_u64_be(1), })); assert_eq!(new_snapshot, KeyServerSetSnapshot { - current_set: vec![(1.into(), address)].into_iter().collect(), - new_set: vec![(1.into(), address)].into_iter().collect(), + current_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), ..Default::default() }); } @@ -721,22 +721,22 @@ pub mod tests { let address = "127.0.0.1:12000".parse().unwrap(); let mut future_new_set = Some(FutureNewSet { - new_set: vec![(2.into(), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(2), address)].into_iter().collect(), block: Default::default(), }); let mut new_snapshot = KeyServerSetSnapshot { - current_set: vec![(1.into(), address)].into_iter().collect(), - new_set: vec![(2.into(), address)].into_iter().collect(), + current_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(2), address)].into_iter().collect(), ..Default::default() }; - update_future_set(&mut future_new_set, &mut new_snapshot, 1.into()); + update_future_set(&mut future_new_set, &mut new_snapshot, H256::from_low_u64_be(1)); assert_eq!(future_new_set, Some(FutureNewSet { - new_set: vec![(2.into(), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(2), address)].into_iter().collect(), block: Default::default(), })); assert_eq!(new_snapshot, KeyServerSetSnapshot { - current_set: vec![(1.into(), address)].into_iter().collect(), - new_set: vec![(1.into(), address)].into_iter().collect(), + current_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), ..Default::default() }); } @@ -747,13 +747,13 @@ pub mod tests { let mut future_new_set = None; let mut snapshot = KeyServerSetSnapshot { - current_set: vec![(1.into(), address)].into_iter().collect(), - new_set: vec![(1.into(), address)].into_iter().collect(), + current_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), ..Default::default() }; let snapshot_copy = snapshot.clone(); update_number_of_confirmations( - &|| 1.into(), + &|| H256::from_low_u64_be(1), &|_| Some(MIGRATION_CONFIRMATIONS_REQUIRED), &mut future_new_set, &mut snapshot); assert_eq!(future_new_set, None); @@ -765,22 +765,22 @@ pub mod tests { let address = "127.0.0.1:12000".parse().unwrap(); let mut future_new_set = Some(FutureNewSet { - new_set: vec![(2.into(), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(2), address)].into_iter().collect(), block: Default::default(), }); let mut snapshot = KeyServerSetSnapshot { - current_set: vec![(1.into(), address)].into_iter().collect(), - new_set: vec![(1.into(), address)].into_iter().collect(), + current_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), ..Default::default() }; update_number_of_confirmations( - &|| 1.into(), + &|| H256::from_low_u64_be(1), &|_| Some(MIGRATION_CONFIRMATIONS_REQUIRED), &mut future_new_set, &mut snapshot); assert_eq!(future_new_set, None); assert_eq!(snapshot, KeyServerSetSnapshot { - current_set: vec![(1.into(), address)].into_iter().collect(), - new_set: vec![(2.into(), address)].into_iter().collect(), + current_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(2), address)].into_iter().collect(), ..Default::default() }); } @@ -790,18 +790,18 @@ pub mod tests { let address = "127.0.0.1:12000".parse().unwrap(); let mut future_new_set = Some(FutureNewSet { - new_set: vec![(2.into(), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(2), address)].into_iter().collect(), block: Default::default(), }); let mut snapshot = KeyServerSetSnapshot { - current_set: vec![(1.into(), address)].into_iter().collect(), - new_set: vec![(1.into(), address)].into_iter().collect(), + current_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), ..Default::default() }; let future_new_set_copy = future_new_set.clone(); let snapshot_copy = snapshot.clone(); update_number_of_confirmations( - &|| 1.into(), + &|| H256::from_low_u64_be(1), &|_| Some(MIGRATION_CONFIRMATIONS_REQUIRED - 1), &mut future_new_set, &mut snapshot); assert_eq!(future_new_set, future_new_set_copy); @@ -813,22 +813,22 @@ pub mod tests { let address = "127.0.0.1:12000".parse().unwrap(); let mut future_new_set = Some(FutureNewSet { - new_set: vec![(2.into(), address)].into_iter().collect(), - block: 1.into(), + new_set: vec![(H512::from_low_u64_be(2), address)].into_iter().collect(), + block: H256::from_low_u64_be(1), }); let mut snapshot = KeyServerSetSnapshot { - current_set: vec![(1.into(), address)].into_iter().collect(), - new_set: vec![(1.into(), address)].into_iter().collect(), + current_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), + new_set: vec![(H512::from_low_u64_be(1), address)].into_iter().collect(), ..Default::default() }; let snapshot_copy = snapshot.clone(); update_number_of_confirmations( - &|| 2.into(), + &|| H256::from_low_u64_be(2), &|_| None, &mut future_new_set, &mut snapshot); assert_eq!(future_new_set, Some(FutureNewSet { - new_set: vec![(2.into(), address)].into_iter().collect(), - block: 2.into(), + new_set: vec![(H512::from_low_u64_be(2), address)].into_iter().collect(), + block: H256::from_low_u64_be(2), })); assert_eq!(snapshot, snapshot_copy); } diff --git a/secret-store/src/key_storage.rs b/secret-store/src/key_storage.rs index 36edae43e..183235d1c 100644 --- a/secret-store/src/key_storage.rs +++ b/secret-store/src/key_storage.rs @@ -193,13 +193,13 @@ fn upgrade_db(db: Arc) -> Result, Error> { let current_key = CurrentSerializableDocumentKeyShare { // author is used in separate generation + encrypt sessions. // in v0 there have been only simultaneous GenEnc sessions. - author: Address::default().into(), // added in v1 + author: Address::zero().into(), // added in v1 threshold: v0_key.threshold, public: Public::default().into(), // addded in v2 common_point: Some(v0_key.common_point), encrypted_point: Some(v0_key.encrypted_point), versions: vec![CurrentSerializableDocumentKeyVersion { - hash: DocumentKeyShareVersion::data_hash(v0_key.id_numbers.iter().map(|(k, v)| (&***k, &****v))).into(), + hash: DocumentKeyShareVersion::data_hash(v0_key.id_numbers.iter().map(|(k, v)| (k.as_bytes(), v.as_bytes()))).into(), id_numbers: v0_key.id_numbers, secret_share: v0_key.secret_share, }], @@ -222,7 +222,7 @@ fn upgrade_db(db: Arc) -> Result, Error> { common_point: v1_key.common_point, encrypted_point: v1_key.encrypted_point, versions: vec![CurrentSerializableDocumentKeyVersion { - hash: DocumentKeyShareVersion::data_hash(v1_key.id_numbers.iter().map(|(k, v)| (&***k, &****v))).into(), + hash: DocumentKeyShareVersion::data_hash(v1_key.id_numbers.iter().map(|(k, v)| (k.as_bytes(), v.as_bytes()))).into(), id_numbers: v1_key.id_numbers, secret_share: v1_key.secret_share, }], @@ -262,7 +262,7 @@ impl KeyStorage for PersistentKeyStorage { let key: CurrentSerializableDocumentKeyShare = key.into(); let key = serde_json::to_vec(&key).map_err(|e| Error::Database(e.to_string()))?; let mut batch = self.db.transaction(); - batch.put(None, &document, &key); + batch.put(None, document.as_bytes(), &key); self.db.write(batch).map_err(Into::into) } @@ -271,7 +271,7 @@ impl KeyStorage for PersistentKeyStorage { } fn get(&self, document: &ServerKeyId) -> Result, Error> { - self.db.get(None, document) + self.db.get(None, document.as_bytes()) .map_err(|e| Error::Database(e.to_string())) .and_then(|key| match key { None => Ok(None), @@ -284,21 +284,21 @@ impl KeyStorage for PersistentKeyStorage { fn remove(&self, document: &ServerKeyId) -> Result<(), Error> { let mut batch = self.db.transaction(); - batch.delete(None, &document); + batch.delete(None, document.as_bytes()); self.db.write(batch).map_err(Into::into) } fn clear(&self) -> Result<(), Error> { let mut batch = self.db.transaction(); for (key, _) in self.iter() { - batch.delete(None, &key); + batch.delete(None, key.as_bytes()); } self.db.write(batch) .map_err(|e| Error::Database(e.to_string())) } fn contains(&self, document: &ServerKeyId) -> bool { - self.db.get(None, document) + self.db.get(None, document.as_bytes()) .map(|k| k.is_some()) .unwrap_or(false) } @@ -317,7 +317,7 @@ impl<'a> Iterator for PersistentKeyStorageIterator<'a> { self.iter.as_mut().next() .and_then(|(db_key, db_val)| serde_json::from_slice::(&db_val) .ok() - .map(|key| ((*db_key).into(), key.into()))) + .map(|key| (ServerKeyId::from_slice(&*db_key), key.into()))) } } @@ -342,7 +342,7 @@ impl DocumentKeyShareVersion { /// Create new version pub fn new(id_numbers: BTreeMap, secret_share: Secret) -> Self { DocumentKeyShareVersion { - hash: Self::data_hash(id_numbers.iter().map(|(k, v)| (&**k, &***v))), + hash: Self::data_hash(id_numbers.iter().map(|(k, v)| (k.as_bytes(), v.as_bytes()))), id_numbers: id_numbers, secret_share: secret_share, } @@ -412,10 +412,11 @@ pub mod tests { use std::collections::HashMap; use std::sync::Arc; + use std::str::FromStr; use parking_lot::RwLock; use serde_json; use self::tempdir::TempDir; - use ethereum_types::{Address, H256}; + use ethereum_types::{Address, H256, H512}; use ethkey::{Random, Generator, Public, Secret, public_to_address}; use kvdb_rocksdb::Database; use types::{Error, ServerKeyId}; @@ -466,7 +467,7 @@ pub mod tests { #[test] fn persistent_key_storage() { let tempdir = TempDir::new("").unwrap(); - let key1 = ServerKeyId::from(1); + let key1 = ServerKeyId::from_low_u64_be(1); let value1 = DocumentKeyShare { author: Default::default(), threshold: 100, @@ -481,7 +482,7 @@ pub mod tests { secret_share: Random.generate().unwrap().secret().clone(), }], }; - let key2 = ServerKeyId::from(2); + let key2 = ServerKeyId::from_low_u64_be(2); let value2 = DocumentKeyShare { author: Default::default(), threshold: 200, @@ -496,7 +497,7 @@ pub mod tests { secret_share: Random.generate().unwrap().secret().clone(), }], }; - let key3 = ServerKeyId::from(3); + let key3 = ServerKeyId::from_low_u64_be(3); let db = Database::open_default(&tempdir.path().display().to_string()).unwrap(); @@ -526,12 +527,12 @@ pub mod tests { let key = serde_json::to_vec(&SerializableDocumentKeyShareV0 { threshold: 777, id_numbers: vec![( - "b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8".into(), + H512::from_str("b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8").unwrap().into(), "281b6bf43cb86d0dc7b98e1b7def4a80f3ce16d28d2308f934f116767306f06c".parse::().unwrap().into(), )].into_iter().collect(), secret_share: "00125d85a05e5e63e214cb60fe63f132eec8a103aa29266b7e6e6c5b7597230b".parse::().unwrap().into(), - common_point: "99e82b163b062d55a64085bacfd407bb55f194ba5fb7a1af9c34b84435455520f1372e0e650a4f91aed0058cb823f62146ccb5599c8d13372c300dea866b69fc".into(), - encrypted_point: "7e05df9dd077ec21ed4bc45c9fe9e0a43d65fa4be540630de615ced5e95cf5c3003035eb713317237d7667feeeb64335525158f5f7411f67aca9645169ea554c".into(), + common_point: H512::from_str("99e82b163b062d55a64085bacfd407bb55f194ba5fb7a1af9c34b84435455520f1372e0e650a4f91aed0058cb823f62146ccb5599c8d13372c300dea866b69fc").unwrap().into(), + encrypted_point: H512::from_str("7e05df9dd077ec21ed4bc45c9fe9e0a43d65fa4be540630de615ced5e95cf5c3003035eb713317237d7667feeeb64335525158f5f7411f67aca9645169ea554c").unwrap().into(), }).unwrap(); let mut batch = db.transaction(); batch.put(None, &[7], &key); @@ -544,7 +545,7 @@ pub mod tests { // check upgrade assert_eq!(db.get(None, DB_META_KEY_VERSION).unwrap().unwrap()[0], CURRENT_VERSION); let key = serde_json::from_slice::(&db.get(None, &[7]).unwrap().map(|key| key.to_vec()).unwrap()).unwrap(); - assert_eq!(Address::default(), key.author.clone().into()); + assert_eq!(Address::zero(), key.author.clone().into()); assert_eq!(777, key.threshold); assert_eq!(Some("99e82b163b062d55a64085bacfd407bb55f194ba5fb7a1af9c34b84435455520f1372e0e650a4f91aed0058cb823f62146ccb5599c8d13372c300dea866b69fc".parse::().unwrap()), key.common_point.clone().map(Into::into)); assert_eq!(Some("7e05df9dd077ec21ed4bc45c9fe9e0a43d65fa4be540630de615ced5e95cf5c3003035eb713317237d7667feeeb64335525158f5f7411f67aca9645169ea554c".parse::().unwrap()), key.encrypted_point.clone().map(Into::into)); @@ -565,15 +566,15 @@ pub mod tests { // prepare v1 database { let key = serde_json::to_vec(&SerializableDocumentKeyShareV1 { - author: "b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8".into(), + author: H512::from_str("b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8").unwrap().into(), threshold: 777, id_numbers: vec![( - "b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8".into(), + H512::from_str("b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8").unwrap().into(), "281b6bf43cb86d0dc7b98e1b7def4a80f3ce16d28d2308f934f116767306f06c".parse::().unwrap().into(), )].into_iter().collect(), secret_share: "00125d85a05e5e63e214cb60fe63f132eec8a103aa29266b7e6e6c5b7597230b".parse::().unwrap().into(), - common_point: Some("99e82b163b062d55a64085bacfd407bb55f194ba5fb7a1af9c34b84435455520f1372e0e650a4f91aed0058cb823f62146ccb5599c8d13372c300dea866b69fc".into()), - encrypted_point: Some("7e05df9dd077ec21ed4bc45c9fe9e0a43d65fa4be540630de615ced5e95cf5c3003035eb713317237d7667feeeb64335525158f5f7411f67aca9645169ea554c".into()), + common_point: Some(H512::from_str("99e82b163b062d55a64085bacfd407bb55f194ba5fb7a1af9c34b84435455520f1372e0e650a4f91aed0058cb823f62146ccb5599c8d13372c300dea866b69fc").unwrap().into()), + encrypted_point: Some(H512::from_str("7e05df9dd077ec21ed4bc45c9fe9e0a43d65fa4be540630de615ced5e95cf5c3003035eb713317237d7667feeeb64335525158f5f7411f67aca9645169ea554c").unwrap().into()), }).unwrap(); let mut batch = db.transaction(); batch.put(None, DB_META_KEY_VERSION, &[1]); @@ -590,7 +591,7 @@ pub mod tests { assert_eq!(777, key.threshold); assert_eq!(Some("99e82b163b062d55a64085bacfd407bb55f194ba5fb7a1af9c34b84435455520f1372e0e650a4f91aed0058cb823f62146ccb5599c8d13372c300dea866b69fc".parse::().unwrap()), key.common_point.clone().map(Into::into)); assert_eq!(Some("7e05df9dd077ec21ed4bc45c9fe9e0a43d65fa4be540630de615ced5e95cf5c3003035eb713317237d7667feeeb64335525158f5f7411f67aca9645169ea554c".parse::().unwrap()), key.encrypted_point.clone().map(Into::into)); - assert_eq!(key.author.0, public_to_address(&"b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8".into())); + assert_eq!(key.author.0, public_to_address(&H512::from_str("b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8").unwrap())); assert_eq!(key.versions.len(), 1); assert_eq!(vec![( @@ -609,15 +610,15 @@ pub mod tests { // prepare v2 database { let key = serde_json::to_vec(&SerializableDocumentKeyShareV2 { - author: "b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8".into(), + author: H512::from_str("b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8").unwrap().into(), threshold: 777, - common_point: Some("99e82b163b062d55a64085bacfd407bb55f194ba5fb7a1af9c34b84435455520f1372e0e650a4f91aed0058cb823f62146ccb5599c8d13372c300dea866b69fc".into()), - encrypted_point: Some("7e05df9dd077ec21ed4bc45c9fe9e0a43d65fa4be540630de615ced5e95cf5c3003035eb713317237d7667feeeb64335525158f5f7411f67aca9645169ea554c".into()), - public: "b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8".into(), + common_point: Some(H512::from_str("99e82b163b062d55a64085bacfd407bb55f194ba5fb7a1af9c34b84435455520f1372e0e650a4f91aed0058cb823f62146ccb5599c8d13372c300dea866b69fc").unwrap().into()), + encrypted_point: Some(H512::from_str("7e05df9dd077ec21ed4bc45c9fe9e0a43d65fa4be540630de615ced5e95cf5c3003035eb713317237d7667feeeb64335525158f5f7411f67aca9645169ea554c").unwrap().into()), + public: H512::from_str("b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8").unwrap().into(), versions: vec![SerializableDocumentKeyShareVersionV2 { hash: "281b6bf43cb86d0dc7b98e1b7def4a80f3ce16d28d2308f934f116767306f06c".parse::().unwrap().into(), id_numbers: vec![( - "b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8".into(), + H512::from_str("b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8").unwrap().into(), "281b6bf43cb86d0dc7b98e1b7def4a80f3ce16d28d2308f934f116767306f06c".parse::().unwrap().into(), )].into_iter().collect(), secret_share: "00125d85a05e5e63e214cb60fe63f132eec8a103aa29266b7e6e6c5b7597230b".parse::().unwrap().into(), diff --git a/secret-store/src/listener/http_listener.rs b/secret-store/src/listener/http_listener.rs index d2c3e3d66..e3b0bf595 100644 --- a/secret-store/src/listener/http_listener.rs +++ b/secret-store/src/listener/http_listener.rs @@ -428,12 +428,14 @@ fn parse_admin_request(method: &HttpMethod, path: Vec, body: &[u8]) -> R #[cfg(test)] mod tests { use std::sync::Arc; + use std::str::FromStr; use hyper::Method as HttpMethod; use ethkey::Public; use traits::KeyServer; use key_server::tests::DummyKeyServer; use types::NodeAddress; use parity_runtime::Runtime; + use ethereum_types::H256; use super::{parse_request, Request, KeyServerHttpListener}; #[test] @@ -450,39 +452,39 @@ mod tests { fn parse_request_successful() { // POST /shadow/{server_key_id}/{signature}/{threshold} => generate server key assert_eq!(parse_request(&HttpMethod::POST, "/shadow/0000000000000000000000000000000000000000000000000000000000000001/a199fb39e11eefb61c78a4074a53c0d4424600a3e74aad4fb9d93a26c30d067e1d4d29936de0c73f19827394a1dd049480a0d581aee7ae7546968da7d3d1c2fd01/2", Default::default()), - Request::GenerateServerKey("0000000000000000000000000000000000000000000000000000000000000001".into(), + Request::GenerateServerKey(H256::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap(), "a199fb39e11eefb61c78a4074a53c0d4424600a3e74aad4fb9d93a26c30d067e1d4d29936de0c73f19827394a1dd049480a0d581aee7ae7546968da7d3d1c2fd01".parse().unwrap(), 2)); // POST /shadow/{server_key_id}/{signature}/{common_point}/{encrypted_key} => store encrypted document key assert_eq!(parse_request(&HttpMethod::POST, "/shadow/0000000000000000000000000000000000000000000000000000000000000001/a199fb39e11eefb61c78a4074a53c0d4424600a3e74aad4fb9d93a26c30d067e1d4d29936de0c73f19827394a1dd049480a0d581aee7ae7546968da7d3d1c2fd01/b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8/1395568277679f7f583ab7c0992da35f26cde57149ee70e524e49bdae62db3e18eb96122501e7cbb798b784395d7bb5a499edead0706638ad056d886e56cf8fb", Default::default()), - Request::StoreDocumentKey("0000000000000000000000000000000000000000000000000000000000000001".into(), + Request::StoreDocumentKey(H256::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap(), "a199fb39e11eefb61c78a4074a53c0d4424600a3e74aad4fb9d93a26c30d067e1d4d29936de0c73f19827394a1dd049480a0d581aee7ae7546968da7d3d1c2fd01".parse().unwrap(), "b486d3840218837b035c66196ecb15e6b067ca20101e11bd5e626288ab6806ecc70b8307012626bd512bad1559112d11d21025cef48cc7a1d2f3976da08f36c8".parse().unwrap(), "1395568277679f7f583ab7c0992da35f26cde57149ee70e524e49bdae62db3e18eb96122501e7cbb798b784395d7bb5a499edead0706638ad056d886e56cf8fb".parse().unwrap())); // POST /{server_key_id}/{signature}/{threshold} => generate server && document key assert_eq!(parse_request(&HttpMethod::POST, "/0000000000000000000000000000000000000000000000000000000000000001/a199fb39e11eefb61c78a4074a53c0d4424600a3e74aad4fb9d93a26c30d067e1d4d29936de0c73f19827394a1dd049480a0d581aee7ae7546968da7d3d1c2fd01/2", Default::default()), - Request::GenerateDocumentKey("0000000000000000000000000000000000000000000000000000000000000001".into(), + Request::GenerateDocumentKey(H256::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap(), "a199fb39e11eefb61c78a4074a53c0d4424600a3e74aad4fb9d93a26c30d067e1d4d29936de0c73f19827394a1dd049480a0d581aee7ae7546968da7d3d1c2fd01".parse().unwrap(), 2)); // GET /{server_key_id}/{signature} => get document key assert_eq!(parse_request(&HttpMethod::GET, "/0000000000000000000000000000000000000000000000000000000000000001/a199fb39e11eefb61c78a4074a53c0d4424600a3e74aad4fb9d93a26c30d067e1d4d29936de0c73f19827394a1dd049480a0d581aee7ae7546968da7d3d1c2fd01", Default::default()), - Request::GetDocumentKey("0000000000000000000000000000000000000000000000000000000000000001".into(), + Request::GetDocumentKey(H256::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap(), "a199fb39e11eefb61c78a4074a53c0d4424600a3e74aad4fb9d93a26c30d067e1d4d29936de0c73f19827394a1dd049480a0d581aee7ae7546968da7d3d1c2fd01".parse().unwrap())); assert_eq!(parse_request(&HttpMethod::GET, "/%30000000000000000000000000000000000000000000000000000000000000001/a199fb39e11eefb61c78a4074a53c0d4424600a3e74aad4fb9d93a26c30d067e1d4d29936de0c73f19827394a1dd049480a0d581aee7ae7546968da7d3d1c2fd01", Default::default()), - Request::GetDocumentKey("0000000000000000000000000000000000000000000000000000000000000001".into(), + Request::GetDocumentKey(H256::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap(), "a199fb39e11eefb61c78a4074a53c0d4424600a3e74aad4fb9d93a26c30d067e1d4d29936de0c73f19827394a1dd049480a0d581aee7ae7546968da7d3d1c2fd01".parse().unwrap())); // GET /shadow/{server_key_id}/{signature} => get document key shadow assert_eq!(parse_request(&HttpMethod::GET, "/shadow/0000000000000000000000000000000000000000000000000000000000000001/a199fb39e11eefb61c78a4074a53c0d4424600a3e74aad4fb9d93a26c30d067e1d4d29936de0c73f19827394a1dd049480a0d581aee7ae7546968da7d3d1c2fd01", Default::default()), - Request::GetDocumentKeyShadow("0000000000000000000000000000000000000000000000000000000000000001".into(), + Request::GetDocumentKeyShadow(H256::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap(), "a199fb39e11eefb61c78a4074a53c0d4424600a3e74aad4fb9d93a26c30d067e1d4d29936de0c73f19827394a1dd049480a0d581aee7ae7546968da7d3d1c2fd01".parse().unwrap())); // GET /schnorr/{server_key_id}/{signature}/{message_hash} => schnorr-sign message with server key assert_eq!(parse_request(&HttpMethod::GET, "/schnorr/0000000000000000000000000000000000000000000000000000000000000001/a199fb39e11eefb61c78a4074a53c0d4424600a3e74aad4fb9d93a26c30d067e1d4d29936de0c73f19827394a1dd049480a0d581aee7ae7546968da7d3d1c2fd01/281b6bf43cb86d0dc7b98e1b7def4a80f3ce16d28d2308f934f116767306f06c", Default::default()), - Request::SchnorrSignMessage("0000000000000000000000000000000000000000000000000000000000000001".into(), + Request::SchnorrSignMessage(H256::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap(), "a199fb39e11eefb61c78a4074a53c0d4424600a3e74aad4fb9d93a26c30d067e1d4d29936de0c73f19827394a1dd049480a0d581aee7ae7546968da7d3d1c2fd01".parse().unwrap(), "281b6bf43cb86d0dc7b98e1b7def4a80f3ce16d28d2308f934f116767306f06c".parse().unwrap())); // GET /ecdsa/{server_key_id}/{signature}/{message_hash} => ecdsa-sign message with server key assert_eq!(parse_request(&HttpMethod::GET, "/ecdsa/0000000000000000000000000000000000000000000000000000000000000001/a199fb39e11eefb61c78a4074a53c0d4424600a3e74aad4fb9d93a26c30d067e1d4d29936de0c73f19827394a1dd049480a0d581aee7ae7546968da7d3d1c2fd01/281b6bf43cb86d0dc7b98e1b7def4a80f3ce16d28d2308f934f116767306f06c", Default::default()), - Request::EcdsaSignMessage("0000000000000000000000000000000000000000000000000000000000000001".into(), + Request::EcdsaSignMessage(H256::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap(), "a199fb39e11eefb61c78a4074a53c0d4424600a3e74aad4fb9d93a26c30d067e1d4d29936de0c73f19827394a1dd049480a0d581aee7ae7546968da7d3d1c2fd01".parse().unwrap(), "281b6bf43cb86d0dc7b98e1b7def4a80f3ce16d28d2308f934f116767306f06c".parse().unwrap())); // POST /admin/servers_set_change/{old_set_signature}/{new_set_signature} + body diff --git a/secret-store/src/listener/service_contract.rs b/secret-store/src/listener/service_contract.rs index 795e75d2c..4fad7cf7e 100644 --- a/secret-store/src/listener/service_contract.rs +++ b/secret-store/src/listener/service_contract.rs @@ -24,7 +24,7 @@ use ethcore::client::{Client, BlockChainClient, BlockId}; use ethkey::{Public, public_to_address}; use hash::keccak; use bytes::Bytes; -use ethereum_types::{H256, U256, Address}; +use ethereum_types::{H256, U256, Address, H512}; use listener::ApiMask; use listener::service_contract_listener::ServiceTask; use trusted_client::TrustedClient; @@ -466,7 +466,7 @@ impl ServerKeyGenerationService { /// Prepare publish key transaction data. pub fn prepare_pubish_tx_data(server_key_id: &ServerKeyId, server_key_public: &Public) -> Bytes { - service::functions::server_key_generated::encode_input(*server_key_id, server_key_public.to_vec()) + service::functions::server_key_generated::encode_input(*server_key_id, server_key_public.as_bytes().to_vec()) } /// Prepare error transaction data. @@ -526,7 +526,7 @@ impl ServerKeyRetrievalService { /// Prepare publish key transaction data. pub fn prepare_pubish_tx_data(server_key_id: &ServerKeyId, server_key_public: Public, threshold: U256) -> Bytes { - service::functions::server_key_retrieved::encode_input(*server_key_id, server_key_public.to_vec(), threshold) + service::functions::server_key_retrieved::encode_input(*server_key_id, server_key_public.as_bytes().to_vec(), threshold) } /// Prepare error transaction data. @@ -566,7 +566,13 @@ impl DocumentKeyStoreService { /// Parse request log entry. pub fn parse_log(origin: &Address, raw_log: RawLog) -> Result { match service::events::document_key_store_requested::parse_log(raw_log) { - Ok(l) => Ok(ServiceTask::StoreDocumentKey(origin.clone(), l.server_key_id, l.author, (*l.common_point).into(), (*l.encrypted_point).into())), + Ok(l) => Ok(ServiceTask::StoreDocumentKey( + origin.clone(), + l.server_key_id, + l.author, + H512::from_slice(&*l.common_point), + H512::from_slice(&*l.encrypted_point), + )), Err(e) => Err(format!("{}", e)), } } @@ -633,7 +639,7 @@ impl DocumentKeyShadowRetrievalService { /// Parse personal request log entry. pub fn parse_personal_request_log(origin: &Address, raw_log: RawLog) -> Result { match service::events::document_key_personal_retrieval_requested::parse_log(raw_log) { - Ok(l) => Ok(ServiceTask::RetrieveShadowDocumentKeyPersonal(origin.clone(), l.server_key_id, (*l.requester_public).into())), + Ok(l) => Ok(ServiceTask::RetrieveShadowDocumentKeyPersonal(origin.clone(), l.server_key_id, H512::from_slice(&*l.requester_public))), Err(e) => Err(e.to_string()) } } @@ -650,7 +656,7 @@ impl DocumentKeyShadowRetrievalService { /// Prepare publish common key transaction data. pub fn prepare_pubish_common_tx_data(server_key_id: &ServerKeyId, requester: &Address, common_point: Public, threshold: U256) -> Bytes { - service::functions::document_key_common_retrieved::encode_input(*server_key_id, *requester, common_point.to_vec(), threshold) + service::functions::document_key_common_retrieved::encode_input(*server_key_id, *requester, common_point.as_bytes().to_vec(), threshold) } /// Prepare publish personal key transaction data. @@ -662,7 +668,7 @@ impl DocumentKeyShadowRetrievalService { participants_mask = participants_mask | (U256::one() << participant_index); } Ok(service::functions::document_key_personal_retrieved::encode_input( - *server_key_id, *requester, participants_mask, decrypted_secret.to_vec(), shadow + *server_key_id, *requester, participants_mask, decrypted_secret.as_bytes().to_vec(), shadow )) } @@ -718,7 +724,7 @@ impl DocumentKeyShadowRetrievalService { if index > u8::max_value().into() { Err(format!("key server index is too big: {}", index)) } else { - let index: u32 = index.into(); + let index: u32 = index.low_u32(); Ok(index as u8) } } diff --git a/secret-store/src/listener/service_contract_listener.rs b/secret-store/src/listener/service_contract_listener.rs index 61dcda176..db4253e25 100644 --- a/secret-store/src/listener/service_contract_listener.rs +++ b/secret-store/src/listener/service_contract_listener.rs @@ -22,7 +22,7 @@ use parking_lot::Mutex; use ethcore::client::{ChainNotify, NewBlocks}; use ethkey::{Public, public_to_address}; use bytes::Bytes; -use ethereum_types::{H256, U256, Address}; +use ethereum_types::{H256, U256, Address, BigEndianHash as _}; use key_server_set::KeyServerSet; use key_server_cluster::{NodeId, ClusterClient, ClusterSessionsListener, ClusterSession}; use key_server_cluster::math; @@ -574,7 +574,7 @@ fn is_processed_by_this_key_server(key_server_set: &KeyServerSet, node: &NodeId, None => return false, }; - let server_key_id_value: U256 = server_key_id.into(); + let server_key_id_value: U256 = server_key_id.into_uint(); let range_interval = U256::max_value() / total_servers_count; let range_begin = (range_interval + 1) * this_server_index as u32; let range_end = range_begin.saturating_add(range_interval); @@ -597,6 +597,7 @@ mod tests { use key_server_set::tests::MapKeyServerSet; use {NodeKeyPair, PlainNodeKeyPair, ServerKeyId}; use super::{ServiceTask, ServiceContractListener, ServiceContractListenerParams, is_processed_by_this_key_server}; + use ethereum_types::Address; fn create_non_empty_key_storage(has_doc_key: bool) -> Arc { let key_storage = Arc::new(DummyKeyStorage::default()); @@ -983,7 +984,7 @@ mod tests { let key_storage = create_non_empty_key_storage(false); let listener = make_service_contract_listener(Some(contract.clone()), None, Some(key_storage), None, None); ServiceContractListener::process_service_task(&listener.data, ServiceTask::StoreDocumentKey( - Default::default(), Default::default(), 1.into(), Default::default(), Default::default())).unwrap_err(); + Default::default(), Default::default(), Address::from_low_u64_be(1), Default::default(), Default::default())).unwrap_err(); assert_eq!(*contract.document_keys_store_failures.lock(), vec![Default::default()]); } diff --git a/secret-store/src/serialization.rs b/secret-store/src/serialization.rs index 64cc5f1ce..c75d0992f 100644 --- a/secret-store/src/serialization.rs +++ b/secret-store/src/serialization.rs @@ -16,7 +16,7 @@ use std::fmt; use std::ops::Deref; -use rustc_hex::{ToHex, FromHex}; +use rustc_hex::{self, FromHex}; use serde::{Serialize, Deserialize, Serializer, Deserializer}; use serde::de::{Visitor, Error as SerdeError}; use ethkey::{Public, Secret, Signature}; @@ -24,6 +24,38 @@ use ethereum_types::{H160, H256}; use bytes::Bytes; use types::Requester; +trait ToHex { + fn to_hex(&self) -> String; +} + +impl ToHex for Bytes { + fn to_hex(&self) -> String { + format!("0x{}", rustc_hex::ToHex::to_hex(&self[..])) + } +} + +impl ToHex for Signature { + fn to_hex(&self) -> String { + format!("0x{}", self) + } +} + +impl ToHex for Secret { + fn to_hex(&self) -> String { + format!("0x{}", rustc_hex::ToHex::to_hex(self)) + } +} + +macro_rules! impl_to_hex { + ($name: ident) => ( + impl ToHex for $name { + fn to_hex(&self) -> String { + format!("{:#x}", self) + } + } + ); +} + macro_rules! impl_bytes_deserialize { ($name: ident, $value: expr, true) => { $value[2..].from_hex().map($name).map_err(SerdeError::custom) @@ -60,9 +92,7 @@ macro_rules! impl_bytes { impl Serialize for $name { fn serialize(&self, serializer: S) -> Result where S: Serializer { - let mut serialized = "0x".to_owned(); - serialized.push_str(self.0.to_hex().as_ref()); - serializer.serialize_str(serialized.as_ref()) + serializer.serialize_str(self.0.to_hex().as_ref()) } } @@ -101,17 +131,15 @@ pub type SerializableMessageHash = SerializableH256; /// Serializable address; pub type SerializableAddress = SerializableH160; -/// Serializable Bytes. +impl_to_hex!(H256); +impl_to_hex!(H160); +impl_to_hex!(Public); + impl_bytes!(SerializableBytes, Bytes, true, (Default)); -/// Serializable H256. impl_bytes!(SerializableH256, H256, false, (Default, PartialOrd, Ord)); -/// Serializable H160. impl_bytes!(SerializableH160, H160, false, (Default)); -/// Serializable H512 (aka Public). impl_bytes!(SerializablePublic, Public, false, (Default, PartialOrd, Ord)); -/// Serializable Secret. impl_bytes!(SerializableSecret, Secret, false, ()); -/// Serializable Signature. impl_bytes!(SerializableSignature, Signature, false, ()); /// Serializable shadow decryption result. @@ -159,23 +187,59 @@ impl From for SerializableRequester { #[cfg(test)] mod tests { use serde_json; - use super::{SerializableBytes, SerializablePublic}; + use super::*; + use std::str::FromStr; + + macro_rules! do_test { + ($value: expr, $expected: expr, $expected_type: ident) => ( + let serialized = serde_json::to_string(&$value).unwrap(); + assert_eq!(serialized, $expected); + let deserialized: $expected_type = serde_json::from_str(&serialized).unwrap(); + assert_eq!(deserialized, $value); + ); + } #[test] fn serialize_and_deserialize_bytes() { - let bytes = SerializableBytes(vec![1, 2, 3, 4]); - let bytes_serialized = serde_json::to_string(&bytes).unwrap(); - assert_eq!(&bytes_serialized, r#""0x01020304""#); - let bytes_deserialized: SerializableBytes = serde_json::from_str(&bytes_serialized).unwrap(); - assert_eq!(bytes_deserialized, bytes); + do_test!(SerializableBytes(vec![1, 2, 3, 4]), "\"0x01020304\"".to_owned(), SerializableBytes); + } + + #[test] + fn serialize_and_deserialize_h256() { + let s = "5a39ed1020c04d4d84539975b893a4e7c53eab6c2965db8bc3468093a31bc5ae"; + let h256 = SerializableH256(H256::from_str(s).unwrap()); + do_test!(h256, format!("\"0x{}\"", s), SerializableH256); + } + + #[test] + fn serialize_and_deserialize_h160() { + let s = "c6d9d2cd449a754c494264e1809c50e34d64562b"; + let h160 = SerializableH160(H160::from_str(s).unwrap()); + do_test!(h160, format!("\"0x{}\"", s), SerializableH160); } #[test] fn serialize_and_deserialize_public() { - let public = SerializablePublic("cac6c205eb06c8308d65156ff6c862c62b000b8ead121a4455a8ddeff7248128d895692136f240d5d1614dc7cc4147b1bd584bd617e30560bb872064d09ea325".parse().unwrap()); - let public_serialized = serde_json::to_string(&public).unwrap(); - assert_eq!(&public_serialized, r#""0xcac6c205eb06c8308d65156ff6c862c62b000b8ead121a4455a8ddeff7248128d895692136f240d5d1614dc7cc4147b1bd584bd617e30560bb872064d09ea325""#); - let public_deserialized: SerializablePublic = serde_json::from_str(&public_serialized).unwrap(); - assert_eq!(public_deserialized, public); + let s = "cac6c205eb06c8308d65156ff6c862c62b000b8ead121a4455a8ddeff7248128d895692136f240d5d1614dc7cc4147b1bd584bd617e30560bb872064d09ea325"; + let public = SerializablePublic(s.parse().unwrap()); + do_test!(public, format!("\"0x{}\"", s), SerializablePublic); + } + + #[test] + fn serialize_and_deserialize_secret() { + let s = "5a39ed1020c04d4d84539975b893a4e7c53eab6c2965db8bc3468093a31bc5ae"; + let secret = SerializableSecret(Secret::from(s)); + do_test!(secret, format!("\"0x{}\"", s), SerializableSecret); + } + + #[test] + fn serialize_and_deserialize_signature() { + let raw_r = "afafafafafafafafafafafbcbcbcbcbcbcbcbcbcbeeeeeeeeeeeeedddddddddd"; + let raw_s = "5a39ed1020c04d4d84539975b893a4e7c53eab6c2965db8bc3468093a31bc5ae"; + let r = H256::from_str(raw_r).unwrap(); + let s = H256::from_str(raw_s).unwrap(); + let v = 42u8; + let public = SerializableSignature(Signature::from_rsv(&r, &s, v)); + do_test!(public, format!("\"0x{}{}{:x}\"", raw_r, raw_s, v), SerializableSignature); } } diff --git a/updater/Cargo.toml b/updater/Cargo.toml index dd3417f88..c4996bfd7 100644 --- a/updater/Cargo.toml +++ b/updater/Cargo.toml @@ -7,13 +7,13 @@ authors = ["Parity Technologies "] [dependencies] common-types = { path = "../ethcore/types" } -ethabi = "6.0" -ethabi-contract = "6.0" -ethabi-derive = "6.0" +ethabi = "8.0" +ethabi-contract = "8.0" +ethabi-derive = "8.0" ethcore = { path = "../ethcore" } ethcore-sync = { path = "../ethcore/sync" } -ethereum-types = "0.4" -keccak-hash = "0.1" +ethereum-types = "0.6.0" +keccak-hash = "0.2.0" lazy_static = "1.0" log = "0.4" parity-bytes = "0.1" @@ -21,7 +21,7 @@ parity-hash-fetch = { path = "hash-fetch" } parity-path = "0.1" parity-version = { path = "../util/version" } parking_lot = "0.7" -rand = "0.4" +rand = "0.6" semver = "0.9" target_info = "0.1" diff --git a/updater/hash-fetch/Cargo.toml b/updater/hash-fetch/Cargo.toml index 1c5477c06..0c98d3f67 100644 --- a/updater/hash-fetch/Cargo.toml +++ b/updater/hash-fetch/Cargo.toml @@ -11,18 +11,18 @@ futures = "0.1" log = "0.4" mime = "0.3" mime_guess = "2.0.0-alpha.2" -rand = "0.4" +rand = "0.6" rustc-hex = "1.0" fetch = { path = "../../util/fetch" } parity-bytes = "0.1" -ethereum-types = "0.4" +ethereum-types = "0.6.0" parity-runtime = { path = "../../util/runtime" } -keccak-hash = "0.1" +keccak-hash = "0.2.0" registrar = { path = "../../util/registrar" } -ethabi = "6.0" -ethabi-derive = "6.0" -ethabi-contract = "6.0" +ethabi = "8.0" +ethabi-derive = "8.0" +ethabi-contract = "8.0" [dev-dependencies] parking_lot = "0.7" diff --git a/updater/hash-fetch/src/client.rs b/updater/hash-fetch/src/client.rs index 513b02f25..a3ebdce26 100644 --- a/updater/hash-fetch/src/client.rs +++ b/updater/hash-fetch/src/client.rs @@ -176,11 +176,11 @@ impl HashFetch for Client { } fn random_temp_path() -> PathBuf { - use ::rand::Rng; + use rand::{Rng, rngs::OsRng, distributions::Alphanumeric}; use ::std::env; - let mut rng = ::rand::OsRng::new().expect("Reliable random source is required to work."); - let file: String = rng.gen_ascii_chars().take(12).collect(); + let mut rng = OsRng::new().expect("Reliable random source is required to work."); + let file: String = rng.sample_iter(&Alphanumeric).take(12).collect(); let mut path = env::temp_dir(); path.push(file); @@ -195,7 +195,8 @@ mod tests { use parking_lot::Mutex; use parity_runtime::Executor; use urlhint::tests::{FakeRegistrar, URLHINT}; - use super::{Error, Client, HashFetch, random_temp_path}; + use super::{Error, Client, HashFetch, random_temp_path, H256}; + use std::str::FromStr; fn registrar() -> FakeRegistrar { let mut registrar = FakeRegistrar::new(); @@ -215,7 +216,7 @@ mod tests { // when let (tx, rx) = mpsc::channel(); - client.fetch(2.into(), Default::default(), Box::new(move |result| { + client.fetch(H256::from_low_u64_be(2), Default::default(), Box::new(move |result| { tx.send(result).unwrap(); })); @@ -233,7 +234,7 @@ mod tests { // when let (tx, rx) = mpsc::channel(); - client.fetch(2.into(), Default::default(), Box::new(move |result| { + client.fetch(H256::from_low_u64_be(2), Default::default(), Box::new(move |result| { tx.send(result).unwrap(); })); @@ -254,14 +255,14 @@ mod tests { // when let (tx, rx) = mpsc::channel(); - client.fetch(2.into(), Default::default(), Box::new(move |result| { + client.fetch(H256::from_low_u64_be(2), Default::default(), Box::new(move |result| { tx.send(result).unwrap(); })); // then let result = rx.recv().unwrap(); - let hash = "0x2be00befcf008bc0e7d9cdefc194db9c75352e8632f48498b5a6bfce9f02c88e".into(); - assert_eq!(result.unwrap_err(), Error::HashMismatch { expected: 2.into(), got: hash }); + let hash = H256::from_str("2be00befcf008bc0e7d9cdefc194db9c75352e8632f48498b5a6bfce9f02c88e").unwrap(); + assert_eq!(result.unwrap_err(), Error::HashMismatch { expected: H256::from_low_u64_be(2), got: hash }); assert!(!path.exists(), "Temporary file should be removed."); } @@ -274,7 +275,7 @@ mod tests { // when let (tx, rx) = mpsc::channel(); - client.fetch("0x2be00befcf008bc0e7d9cdefc194db9c75352e8632f48498b5a6bfce9f02c88e".into(), + client.fetch(H256::from_str("2be00befcf008bc0e7d9cdefc194db9c75352e8632f48498b5a6bfce9f02c88e").unwrap(), Default::default(), Box::new(move |result| { tx.send(result).unwrap(); })); diff --git a/updater/hash-fetch/src/urlhint.rs b/updater/hash-fetch/src/urlhint.rs index 73520fd3b..59829d1da 100644 --- a/updater/hash-fetch/src/urlhint.rs +++ b/updater/hash-fetch/src/urlhint.rs @@ -126,7 +126,7 @@ fn get_urlhint_content(account_slash_repo: String, owner: Address) -> Content { fn decode_urlhint_output(output: (String, [u8; 20], Address)) -> Option { let (account_slash_repo, commit, owner) = output; - if owner == Address::default() { + if owner == Address::zero() { return None; } @@ -249,6 +249,12 @@ pub mod tests { } } + fn h256_from_short_str(s: &str) -> H256 { + let mut bytes = s.as_bytes().to_vec(); + bytes.resize(32usize, 0u8); + H256::from_slice(bytes.as_ref()) + } + #[test] fn should_call_registrar_and_urlhint_contracts() { // given @@ -263,7 +269,7 @@ pub mod tests { let urlhint = URLHintContract::new(Arc::new(registrar)); // when - let res = urlhint.resolve("test".as_bytes().into()).wait().unwrap(); + let res = urlhint.resolve(h256_from_short_str("test")).wait().unwrap(); let calls = calls.lock(); let call0 = calls.get(0).expect("Registrar resolve called"); let call1 = calls.get(1).expect("URLHint Resolve called"); @@ -291,7 +297,7 @@ pub mod tests { let urlhint = URLHintContract::new(Arc::new(registrar)); // when - let res = urlhint.resolve("test".as_bytes().into()).wait().unwrap(); + let res = urlhint.resolve(h256_from_short_str("test")).wait().unwrap(); // then assert_eq!(res, Some(URLHintResult::Dapp(GithubApp { @@ -313,7 +319,7 @@ pub mod tests { let urlhint = URLHintContract::new(Arc::new(registrar)); // when - let res = urlhint.resolve("test".as_bytes().into()).wait().unwrap(); + let res = urlhint.resolve(h256_from_short_str("test")).wait().unwrap(); // then assert_eq!(res, Some(URLHintResult::Content(Content { @@ -330,7 +336,7 @@ pub mod tests { account: "test".into(), repo: "xyz".into(), commit: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], - owner: Address::default(), + owner: Address::zero(), }; // when diff --git a/updater/src/updater.rs b/updater/src/updater.rs index 072d0584a..27daac4ed 100644 --- a/updater/src/updater.rs +++ b/updater/src/updater.rs @@ -28,7 +28,7 @@ use target_info::Target; use common_types::BlockNumber; use common_types::filter::Filter; use ethcore::client::{BlockId, BlockChainClient, ChainNotify, NewBlocks}; -use ethereum_types::H256; +use ethereum_types::{H256, H160}; use hash_fetch::{self as fetch, HashFetch}; use parity_path::restrict_permissions_owner; use service::Service; @@ -159,7 +159,7 @@ pub struct Updater { - let type_hash = (&type_hash(ident, &message_types)?).to_vec(); + let type_hash = (&type_hash(ident, &message_types)?).0.to_vec(); let mut tokens = encode(&[EthAbiToken::FixedBytes(type_hash)]); for field in message_types.get(ident).expect("Already checked in match guard; qed") { @@ -140,7 +140,7 @@ fn encode_data( tokens.append(&mut encoded); } - keccak(tokens).to_vec() + keccak(tokens).as_ref().to_vec() } Type::Bytes => { @@ -151,7 +151,7 @@ fn encode_data( let bytes = (&string[2..]) .from_hex::>() .map_err(|err| ErrorKind::HexParseError(format!("{}", err)))?; - let bytes = keccak(&bytes).to_vec(); + let bytes = keccak(&bytes).as_ref().to_vec(); encode(&[EthAbiToken::FixedBytes(bytes)]) } @@ -170,7 +170,7 @@ fn encode_data( Type::String => { let value = value.as_str().ok_or_else(|| serde_error("string", field_name))?; - let hash = keccak(value).to_vec(); + let hash = keccak(value).as_ref().to_vec(); encode(&[EthAbiToken::FixedBytes(hash)]) } @@ -359,9 +359,10 @@ mod tests { #[test] fn test_hash_data() { let typed_data = from_str::(JSON).expect("alas error!"); + let hash = hash_structured_data(typed_data).expect("alas error!"); assert_eq!( - hash_structured_data(typed_data).expect("alas error!").to_hex::(), - "be609aee343fb3c4b28e1df9e632fca64fcfaede20f02e86244efddf30957bd2" + &format!("{:x}", hash)[..], + "be609aee343fb3c4b28e1df9e632fca64fcfaede20f02e86244efddf30957bd2", ) } diff --git a/util/blooms-db/Cargo.toml b/util/blooms-db/Cargo.toml index c64721e6f..f4a2bb5d3 100644 --- a/util/blooms-db/Cargo.toml +++ b/util/blooms-db/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Parity Technologies "] [dependencies] byteorder = "1.2" -ethbloom = "0.5" +ethbloom = "0.6.4" parking_lot = "0.7" tiny-keccak = "1.4" diff --git a/util/blooms-db/src/db.rs b/util/blooms-db/src/db.rs index 7d003f7e2..7a423d81d 100644 --- a/util/blooms-db/src/db.rs +++ b/util/blooms-db/src/db.rs @@ -303,27 +303,32 @@ mod tests { fn test_database() { let tempdir = TempDir::new("").unwrap(); let mut database = Database::open(tempdir.path()).unwrap(); - database.insert_blooms(0, vec![Bloom::from(0), Bloom::from(0x01), Bloom::from(0x10), Bloom::from(0x11)].iter()).unwrap(); + database.insert_blooms(0, vec![ + Bloom::from_low_u64_be(0), + Bloom::from_low_u64_be(0x01), + Bloom::from_low_u64_be(0x10), + Bloom::from_low_u64_be(0x11), + ].iter()).unwrap(); - let matches = database.iterate_matching(0, 3, Some(&Bloom::from(0))).unwrap().collect::, _>>().unwrap(); + let matches = database.iterate_matching(0, 3, Some(&Bloom::zero())).unwrap().collect::, _>>().unwrap(); assert_eq!(matches, vec![0, 1, 2, 3]); - let matches = database.iterate_matching(0, 4, Some(&Bloom::from(0))).unwrap().collect::, _>>().unwrap(); + let matches = database.iterate_matching(0, 4, Some(&Bloom::zero())).unwrap().collect::, _>>().unwrap(); assert_eq!(matches, vec![0, 1, 2, 3]); - let matches = database.iterate_matching(1, 3, Some(&Bloom::from(0))).unwrap().collect::, _>>().unwrap(); + let matches = database.iterate_matching(1, 3, Some(&Bloom::zero())).unwrap().collect::, _>>().unwrap(); assert_eq!(matches, vec![1, 2, 3]); - let matches = database.iterate_matching(1, 2, Some(&Bloom::from(0))).unwrap().collect::, _>>().unwrap(); + let matches = database.iterate_matching(1, 2, Some(&Bloom::zero())).unwrap().collect::, _>>().unwrap(); assert_eq!(matches, vec![1, 2]); - let matches = database.iterate_matching(0, 3, Some(&Bloom::from(0x01))).unwrap().collect::, _>>().unwrap(); + let matches = database.iterate_matching(0, 3, Some(&Bloom::from_low_u64_be(0x01))).unwrap().collect::, _>>().unwrap(); assert_eq!(matches, vec![1, 3]); - let matches = database.iterate_matching(0, 3, Some(&Bloom::from(0x10))).unwrap().collect::, _>>().unwrap(); + let matches = database.iterate_matching(0, 3, Some(&Bloom::from_low_u64_be(0x10))).unwrap().collect::, _>>().unwrap(); assert_eq!(matches, vec![2, 3]); - let matches = database.iterate_matching(2, 2, Some(&Bloom::from(0x10))).unwrap().collect::, _>>().unwrap(); + let matches = database.iterate_matching(2, 2, Some(&Bloom::from_low_u64_be(0x10))).unwrap().collect::, _>>().unwrap(); assert_eq!(matches, vec![2]); } @@ -331,31 +336,41 @@ mod tests { fn test_database2() { let tempdir = TempDir::new("").unwrap(); let mut database = Database::open(tempdir.path()).unwrap(); - database.insert_blooms(254, vec![Bloom::from(0x100), Bloom::from(0x01), Bloom::from(0x10), Bloom::from(0x11)].iter()).unwrap(); + database.insert_blooms(254, vec![ + Bloom::from_low_u64_be(0x100), + Bloom::from_low_u64_be(0x01), + Bloom::from_low_u64_be(0x10), + Bloom::from_low_u64_be(0x11), + ].iter()).unwrap(); - let matches = database.iterate_matching(0, 257, Some(&Bloom::from(0x01))).unwrap().collect::, _>>().unwrap(); + let matches = database.iterate_matching(0, 257, Some(&Bloom::from_low_u64_be(0x01))).unwrap().collect::, _>>().unwrap(); assert_eq!(matches, vec![255, 257]); - let matches = database.iterate_matching(0, 258, Some(&Bloom::from(0x100))).unwrap().collect::, _>>().unwrap(); + let matches = database.iterate_matching(0, 258, Some(&Bloom::from_low_u64_be(0x100))).unwrap().collect::, _>>().unwrap(); assert_eq!(matches, vec![254]); - let matches = database.iterate_matching(0, 256, Some(&Bloom::from(0x01))).unwrap().collect::, _>>().unwrap(); + let matches = database.iterate_matching(0, 256, Some(&Bloom::from_low_u64_be(0x01))).unwrap().collect::, _>>().unwrap(); assert_eq!(matches, vec![255]); - let matches = database.iterate_matching(255, 255, Some(&Bloom::from(0x01))).unwrap().collect::, _>>().unwrap(); + let matches = database.iterate_matching(255, 255, Some(&Bloom::from_low_u64_be(0x01))).unwrap().collect::, _>>().unwrap(); assert_eq!(matches, vec![255]); - let matches = database.iterate_matching(256, 256, Some(&Bloom::from(0x10))).unwrap().collect::, _>>().unwrap(); + let matches = database.iterate_matching(256, 256, Some(&Bloom::from_low_u64_be(0x10))).unwrap().collect::, _>>().unwrap(); assert_eq!(matches, vec![256]); - let matches = database.iterate_matching(256, 257, Some(&Bloom::from(0x10))).unwrap().collect::, _>>().unwrap(); + let matches = database.iterate_matching(256, 257, Some(&Bloom::from_low_u64_be(0x10))).unwrap().collect::, _>>().unwrap(); assert_eq!(matches, vec![256, 257]); } #[test] fn test_db_close() { let tempdir = TempDir::new("").unwrap(); - let blooms = vec![Bloom::from(0x100), Bloom::from(0x01), Bloom::from(0x10), Bloom::from(0x11)]; + let blooms = vec![ + Bloom::from_low_u64_be(0x100), + Bloom::from_low_u64_be(0x01), + Bloom::from_low_u64_be(0x10), + Bloom::from_low_u64_be(0x11), + ]; let mut database = Database::open(tempdir.path()).unwrap(); // Close the DB and ensure inserting blooms errors diff --git a/util/blooms-db/src/file.rs b/util/blooms-db/src/file.rs index 0362ce884..656447243 100644 --- a/util/blooms-db/src/file.rs +++ b/util/blooms-db/src/file.rs @@ -65,7 +65,7 @@ impl File { let mut file_ref = &self.file; file_ref.seek(SeekFrom::Start(pos * 256))?; let mut bloom = ethbloom::Bloom::default(); - file_ref.read_exact(&mut bloom)?; + file_ref.read_exact(bloom.as_bytes_mut())?; Ok(bloom) } @@ -76,7 +76,7 @@ impl File { old_bloom.accrue_bloom(bloom); let mut file_ref = &self.file; file_ref.seek(SeekFrom::Start(pos * 256))?; - file_ref.write_all(&old_bloom) + file_ref.write_all(old_bloom.as_bytes()) } /// Replace bloom at given position with a new one. @@ -128,7 +128,7 @@ impl<'a> Iterator for FileIterator<'a> { fn next(&mut self) -> Option { let mut bloom = ethbloom::Bloom::default(); - match self.file.read_exact(&mut bloom) { + match self.file.read_exact(bloom.as_bytes_mut()) { Ok(_) => Some(Ok(bloom)), Err(ref err) if err.kind() == io::ErrorKind::UnexpectedEof => None, Err(err) => Some(Err(err)), @@ -146,9 +146,9 @@ mod tests { fn test_file() { let tempdir = TempDir::new("").unwrap(); let mut file = File::open(tempdir.path().join("file")).unwrap(); - file.accrue_bloom(0, &Bloom::from(1)).unwrap(); + file.accrue_bloom(0, &Bloom::from_low_u64_be(1)).unwrap(); file.flush().unwrap(); - assert_eq!(file.read_bloom(0).unwrap(), Bloom::from(1)); + assert_eq!(file.read_bloom(0).unwrap(), Bloom::from_low_u64_be(1)); } } diff --git a/util/dir/Cargo.toml b/util/dir/Cargo.toml index 836eb3ecc..baa9d63b9 100644 --- a/util/dir/Cargo.toml +++ b/util/dir/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] license = "GPL3" [dependencies] -ethereum-types = "0.4" +ethereum-types = "0.6.0" journaldb = { path = "../journaldb" } app_dirs = { git = "https://github.com/paritytech/app-dirs-rs" } home = "0.3" diff --git a/util/dir/src/lib.rs b/util/dir/src/lib.rs index fa7882cdd..175725312 100644 --- a/util/dir/src/lib.rs +++ b/util/dir/src/lib.rs @@ -157,7 +157,12 @@ impl DatabaseDirectories { /// Base DB directory for the given fork. // TODO: remove in 1.7 pub fn legacy_fork_path(&self) -> PathBuf { - Path::new(&self.legacy_path).join(format!("{:x}{}", H64::from(self.genesis_hash), self.fork_name.as_ref().map(|f| format!("-{}", f)).unwrap_or_default())) + let gh = H64::from_slice(&self.genesis_hash.as_bytes()[20..28]); + Path::new(&self.legacy_path).join(format!( + "{:x}{}", + gh, + self.fork_name.as_ref().map(|f| format!("-{}", f)).unwrap_or_default() + )) } /// Spec root directory for the given fork. @@ -172,7 +177,8 @@ impl DatabaseDirectories { /// DB root path, named after genesis hash pub fn db_root_path(&self) -> PathBuf { - self.spec_root_path().join("db").join(format!("{:x}", H64::from(self.genesis_hash))) + let gh = H64::from_slice(&self.genesis_hash.as_bytes()[20..28]); + self.spec_root_path().join("db").join(format!("{:x}", gh)) } /// DB path diff --git a/util/fastmap/Cargo.toml b/util/fastmap/Cargo.toml index 371eebe97..5e0a882c0 100644 --- a/util/fastmap/Cargo.toml +++ b/util/fastmap/Cargo.toml @@ -6,5 +6,5 @@ description = "Specialized version of `HashMap` with H256 keys and fast hashing license = "GPL-3.0" [dependencies] -ethereum-types = "0.4" +ethereum-types = "0.6.0" plain_hasher = "0.2" diff --git a/util/fastmap/src/lib.rs b/util/fastmap/src/lib.rs index 97f7d3b24..97c69e764 100644 --- a/util/fastmap/src/lib.rs +++ b/util/fastmap/src/lib.rs @@ -36,6 +36,6 @@ mod tests { #[test] fn test_works() { let mut h = H256FastMap::default(); - h.insert(H256::from(123), "abc"); + h.insert(H256::from_low_u64_be(123), "abc"); } } diff --git a/util/journaldb/Cargo.toml b/util/journaldb/Cargo.toml index 045b42d66..eaae94043 100644 --- a/util/journaldb/Cargo.toml +++ b/util/journaldb/Cargo.toml @@ -7,7 +7,7 @@ license = "GPL3" [dependencies] parity-bytes = "0.1" -ethereum-types = "0.4" +ethereum-types = "0.6.0" hash-db = "0.11.0" heapsize = "0.4" keccak-hasher = { path = "../keccak-hasher" } @@ -16,9 +16,9 @@ log = "0.4" memory-db = "0.11.0" parking_lot = "0.7" fastmap = { path = "../../util/fastmap" } -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" [dev-dependencies] env_logger = "0.5" -keccak-hash = "0.1" +keccak-hash = "0.2.0" kvdb-memorydb = "0.1" diff --git a/util/journaldb/src/archivedb.rs b/util/journaldb/src/archivedb.rs index a068919a7..6dd1504eb 100644 --- a/util/journaldb/src/archivedb.rs +++ b/util/journaldb/src/archivedb.rs @@ -60,7 +60,7 @@ impl ArchiveDB { } fn payload(&self, key: &H256) -> Option { - self.backing.get(self.column, key).expect("Low-level database error. Some issue with your hard disk?") + self.backing.get(self.column, key.as_bytes()).expect("Low-level database error. Some issue with your hard disk?") } } @@ -138,7 +138,7 @@ impl JournalDB for ArchiveDB { for i in self.overlay.drain() { let (key, (value, rc)) = i; if rc > 0 { - batch.put(self.column, &key, &value); + batch.put(self.column, key.as_bytes(), &value); inserts += 1; } if rc < 0 { @@ -166,18 +166,18 @@ impl JournalDB for ArchiveDB { for i in self.overlay.drain() { let (key, (value, rc)) = i; if rc > 0 { - if self.backing.get(self.column, &key)?.is_some() { + if self.backing.get(self.column, key.as_bytes())?.is_some() { return Err(error_key_already_exists(&key)); } - batch.put(self.column, &key, &value); + batch.put(self.column, key.as_bytes(), &value); inserts += 1; } if rc < 0 { assert!(rc == -1); - if self.backing.get(self.column, &key)?.is_none() { + if self.backing.get(self.column, key.as_bytes())?.is_none() { return Err(error_negatively_reference_hash(&key)); } - batch.delete(self.column, &key); + batch.delete(self.column, key.as_bytes()); deletes += 1; } } diff --git a/util/journaldb/src/earlymergedb.rs b/util/journaldb/src/earlymergedb.rs index 2a55200c4..563df751b 100644 --- a/util/journaldb/src/earlymergedb.rs +++ b/util/journaldb/src/earlymergedb.rs @@ -129,7 +129,7 @@ impl EarlyMergeDB { } fn morph_key(key: &H256, index: u8) -> Bytes { - let mut ret = (&**key).to_owned(); + let mut ret = key.as_bytes().to_owned(); ret.push(index); ret } @@ -152,7 +152,8 @@ impl EarlyMergeDB { }, Entry::Vacant(entry) => { // this is the first entry for this node in the journal. - let in_archive = backing.get(col, h).expect("Low-level database error. Some issue with your hard disk?").is_some(); + let in_archive = backing.get(col, h.as_bytes()) + .expect("Low-level database error. Some issue with your hard disk?").is_some(); if in_archive { // already in the backing DB. start counting, and remember it was already in. Self::set_already_in(batch, col, h); @@ -162,7 +163,7 @@ impl EarlyMergeDB { //Self::reset_already_in(&h); assert!(!Self::is_already_in(backing, col, h)); trace!(target: "jdb.fine", " insert({}): New to queue, not in DB: Inserting into queue and DB", h); - batch.put(col, h, d); + batch.put(col, h.as_bytes(), d); } entry.insert(RefInfo { queue_refs: 1, @@ -227,7 +228,7 @@ impl EarlyMergeDB { }, (1, false) => { entry.remove(); - batch.delete(col, h); + batch.delete(col, h.as_bytes()); trace!(target: "jdb.fine", " remove({}): Not in archive, only 1 ref in queue: Removing from queue and DB", h); }, _ => panic!("Invalid value in refs: {:?}", entry.get()), @@ -236,7 +237,7 @@ impl EarlyMergeDB { Entry::Vacant(_entry) => { // Gets removed when moving from 1 to 0 additional refs. Should never be here at 0 additional refs. //assert!(!Self::is_already_in(db, &h)); - batch.delete(col, h); + batch.delete(col, h.as_bytes()); trace!(target: "jdb.fine", " remove({}): Not in queue - MUST BE IN ARCHIVE: Removing from DB", h); }, } @@ -258,7 +259,9 @@ impl EarlyMergeDB { } fn payload(&self, key: &H256) -> Option { - self.backing.get(self.column, key).expect("Low-level database error. Some issue with your hard disk?") + self.backing + .get(self.column, key.as_bytes()) + .expect("Low-level database error. Some issue with your hard disk?") } fn read_refs(db: &KeyValueDB, col: Option) -> (Option, HashMap) { @@ -499,16 +502,16 @@ impl JournalDB for EarlyMergeDB { match rc { 0 => {} 1 => { - if self.backing.get(self.column, &key)?.is_some() { + if self.backing.get(self.column, key.as_bytes())?.is_some() { return Err(error_key_already_exists(&key)); } - batch.put(self.column, &key, &value) + batch.put(self.column, key.as_bytes(), &value) } -1 => { - if self.backing.get(self.column, &key)?.is_none() { + if self.backing.get(self.column, key.as_bytes())?.is_none() { return Err(error_negatively_reference_hash(&key)); } - batch.delete(self.column, &key) + batch.delete(self.column, key.as_bytes()) } _ => panic!("Attempted to inject invalid state."), } diff --git a/util/journaldb/src/overlaydb.rs b/util/journaldb/src/overlaydb.rs index 757a92e62..2e7dc34ca 100644 --- a/util/journaldb/src/overlaydb.rs +++ b/util/journaldb/src/overlaydb.rs @@ -138,7 +138,7 @@ impl OverlayDB { /// Get the refs and value of the given key. fn payload(&self, key: &H256) -> Option { - self.backing.get(self.column, key) + self.backing.get(self.column, key.as_bytes()) .expect("Low-level database error. Some issue with your hard disk?") .map(|ref d| decode(d).expect("decoding db value failed") ) } @@ -146,10 +146,10 @@ impl OverlayDB { /// Put the refs and value of the given key, possibly deleting it from the db. fn put_payload_in_batch(&self, batch: &mut DBTransaction, key: &H256, payload: &Payload) -> bool { if payload.count > 0 { - batch.put(self.column, key, &encode(payload)); + batch.put(self.column, key.as_bytes(), &encode(payload)); false } else { - batch.delete(self.column, key); + batch.delete(self.column, key.as_bytes()); true } } diff --git a/util/journaldb/src/overlayrecentdb.rs b/util/journaldb/src/overlayrecentdb.rs index a48e59d91..6487dffda 100644 --- a/util/journaldb/src/overlayrecentdb.rs +++ b/util/journaldb/src/overlayrecentdb.rs @@ -176,7 +176,9 @@ impl OverlayRecentDB { } fn payload(&self, key: &H256) -> Option { - self.backing.get(self.column, key).expect("Low-level database error. Some issue with your hard disk?") + self.backing + .get(self.column, key.as_bytes()) + .expect("Low-level database error. Some issue with your hard disk?") } fn read_overlay(db: &KeyValueDB, col: Option) -> JournalOverlay { @@ -238,7 +240,7 @@ impl OverlayRecentDB { #[inline] fn to_short_key(key: &H256) -> H256 { - let mut k = H256::new(); + let mut k = H256::zero(); k[0..DB_PREFIX_LEN].copy_from_slice(&key[0..DB_PREFIX_LEN]); k } @@ -403,7 +405,7 @@ impl JournalDB for OverlayRecentDB { // apply canon inserts first for (k, v) in canon_insertions { - batch.put(self.column, &k, &v); + batch.put(self.column, k.as_bytes(), &v); journal_overlay.pending_overlay.insert(to_short_key(&k), v); } // update the overlay @@ -415,7 +417,7 @@ impl JournalDB for OverlayRecentDB { // apply canon deletions for k in canon_deletions { if !journal_overlay.backing_overlay.contains(&to_short_key(&k)) { - batch.delete(self.column, &k); + batch.delete(self.column, k.as_bytes()); } } } @@ -441,13 +443,13 @@ impl JournalDB for OverlayRecentDB { match rc { 0 => {} _ if rc > 0 => { - batch.put(self.column, &key, &value) + batch.put(self.column, key.as_bytes(), &value) } -1 => { - if cfg!(debug_assertions) && self.backing.get(self.column, &key)?.is_none() { + if cfg!(debug_assertions) && self.backing.get(self.column, key.as_bytes())?.is_none() { return Err(error_negatively_reference_hash(&key)); } - batch.delete(self.column, &key) + batch.delete(self.column, key.as_bytes()) } _ => panic!("Attempted to inject invalid state ({})", rc), } diff --git a/util/keccak-hasher/Cargo.toml b/util/keccak-hasher/Cargo.toml index edeecda83..c33dab9aa 100644 --- a/util/keccak-hasher/Cargo.toml +++ b/util/keccak-hasher/Cargo.toml @@ -6,7 +6,7 @@ description = "Keccak-256 implementation of the Hasher trait" license = "GPL-3.0" [dependencies] -ethereum-types = "0.4" +ethereum-types = "0.6.0" tiny-keccak = "1.4.2" hash-db = "0.11.0" plain_hasher = "0.2" diff --git a/util/network-devp2p/Cargo.toml b/util/network-devp2p/Cargo.toml index 3059cc100..95a39831f 100644 --- a/util/network-devp2p/Cargo.toml +++ b/util/network-devp2p/Cargo.toml @@ -10,7 +10,7 @@ authors = ["Parity Technologies "] log = "0.4" mio = "0.6.8" bytes = "0.4" -rand = "0.4" +rand = "0.6" tiny-keccak = "1.4" rust-crypto = "0.2.34" slab = "0.2" @@ -23,12 +23,12 @@ ethcore-io = { path = "../io", features = ["mio"] } parity-bytes = "0.1" parity-crypto = "0.4.0" ethcore-network = { path = "../network" } -ethereum-types = "0.4" +ethereum-types = "0.6.0" ethkey = { path = "../../accounts/ethkey" } -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" parity-path = "0.1" ipnetwork = "0.12.6" -keccak-hash = "0.1" +keccak-hash = "0.2.0" parity-snappy = "0.1" serde = "1.0" serde_json = "1.0" diff --git a/util/network-devp2p/src/connection.rs b/util/network-devp2p/src/connection.rs index ae34ec44c..07b14622a 100644 --- a/util/network-devp2p/src/connection.rs +++ b/util/network-devp2p/src/connection.rs @@ -298,37 +298,40 @@ impl EncryptedConnection { /// Create an encrypted connection out of the handshake. pub fn new(handshake: &mut Handshake) -> Result { let shared = crypto::ecdh::agree(handshake.ecdhe.secret(), &handshake.remote_ephemeral)?; - let mut nonce_material = H512::new(); + let mut nonce_material = H512::default(); if handshake.originated { - handshake.remote_nonce.copy_to(&mut nonce_material[0..32]); - handshake.nonce.copy_to(&mut nonce_material[32..64]); + (&mut nonce_material[0..32]).copy_from_slice(handshake.remote_nonce.as_bytes()); + (&mut nonce_material[32..64]).copy_from_slice(handshake.nonce.as_bytes()); } else { - handshake.nonce.copy_to(&mut nonce_material[0..32]); - handshake.remote_nonce.copy_to(&mut nonce_material[32..64]); + (&mut nonce_material[0..32]).copy_from_slice(handshake.nonce.as_bytes()); + (&mut nonce_material[32..64]).copy_from_slice(handshake.remote_nonce.as_bytes()); } - let mut key_material = H512::new(); - shared.copy_to(&mut key_material[0..32]); + let mut key_material = H512::default(); + (&mut key_material[0..32]).copy_from_slice(shared.as_bytes()); write_keccak(&nonce_material, &mut key_material[32..64]); - keccak(&key_material).copy_to(&mut key_material[32..64]); - keccak(&key_material).copy_to(&mut key_material[32..64]); + let key_material_keccak = keccak(&key_material); + (&mut key_material[32..64]).copy_from_slice(key_material_keccak.as_bytes()); + let key_material_keccak = keccak(&key_material); + (&mut key_material[32..64]).copy_from_slice(key_material_keccak.as_bytes()); let iv = vec![0u8; 16]; let encoder = CtrMode::new(AesSafe256Encryptor::new(&key_material[32..64]), iv); let iv = vec![0u8; 16]; let decoder = CtrMode::new(AesSafe256Encryptor::new(&key_material[32..64]), iv); - keccak(&key_material).copy_to(&mut key_material[32..64]); + let key_material_keccak = keccak(&key_material); + (&mut key_material[32..64]).copy_from_slice(key_material_keccak.as_bytes()); let mac_encoder = EcbEncryptor::new(AesSafe256Encryptor::new(&key_material[32..64]), NoPadding); let mut egress_mac = Keccak::new_keccak256(); let mut mac_material = H256::from_slice(&key_material[32..64]) ^ handshake.remote_nonce; - egress_mac.update(&mac_material); + egress_mac.update(mac_material.as_bytes()); egress_mac.update(if handshake.originated { &handshake.auth_cipher } else { &handshake.ack_cipher }); let mut ingress_mac = Keccak::new_keccak256(); mac_material = H256::from_slice(&key_material[32..64]) ^ handshake.nonce; - ingress_mac.update(&mac_material); + ingress_mac.update(mac_material.as_bytes()); ingress_mac.update(if handshake.originated { &handshake.ack_cipher } else { &handshake.auth_cipher }); let old_connection = handshake.connection.try_clone()?; @@ -385,14 +388,18 @@ impl EncryptedConnection { } EncryptedConnection::update_mac(&mut self.ingress_mac, &mut self.mac_encoder, &header[0..16]); let mac = &header[16..]; - let mut expected = H256::new(); - self.ingress_mac.clone().finalize(&mut expected); + let mut expected = H256::zero(); + self.ingress_mac.clone().finalize(expected.as_bytes_mut()); if mac != &expected[0..16] { return Err(ErrorKind::Auth.into()); } - let mut hdec = H128::new(); - self.decoder.decrypt(&mut RefReadBuffer::new(&header[0..16]), &mut RefWriteBuffer::new(&mut hdec), false).expect("Invalid length or padding"); + let mut hdec = H128::default(); + self.decoder.decrypt( + &mut RefReadBuffer::new(&header[0..16]), + &mut RefWriteBuffer::new(hdec.as_bytes_mut()), + false, + ).expect("Invalid length or padding"); let length = ((((hdec[0] as u32) << 8) + (hdec[1] as u32)) << 8) + (hdec[2] as u32); let header_rlp = Rlp::new(&hdec[3..6]); @@ -418,8 +425,8 @@ impl EncryptedConnection { self.ingress_mac.update(&payload[0..payload.len() - 16]); EncryptedConnection::update_mac(&mut self.ingress_mac, &mut self.mac_encoder, &[0u8; 0]); let mac = &payload[(payload.len() - 16)..]; - let mut expected = H128::new(); - self.ingress_mac.clone().finalize(&mut expected); + let mut expected = H128::default(); + self.ingress_mac.clone().finalize(expected.as_bytes_mut()); if mac != &expected[..] { return Err(ErrorKind::Auth.into()); } @@ -436,14 +443,18 @@ impl EncryptedConnection { /// Update MAC after reading or writing any data. fn update_mac(mac: &mut Keccak, mac_encoder: &mut EcbEncryptor>, seed: &[u8]) { - let mut prev = H128::new(); - mac.clone().finalize(&mut prev); - let mut enc = H128::new(); - mac_encoder.encrypt(&mut RefReadBuffer::new(&prev), &mut RefWriteBuffer::new(&mut enc), true).expect("Error updating MAC"); + let mut prev = H128::default(); + mac.clone().finalize(prev.as_bytes_mut()); + let mut enc = H128::default(); + mac_encoder.encrypt( + &mut RefReadBuffer::new(prev.as_bytes()), + &mut RefWriteBuffer::new(enc.as_bytes_mut()), + true + ).expect("Error updating MAC"); mac_encoder.reset(); enc = enc ^ if seed.is_empty() { prev } else { H128::from_slice(seed) }; - mac.update(&enc); + mac.update(enc.as_bytes()); } /// Readable IO handler. Tracker receive status and returns decoded packet if available. @@ -486,14 +497,14 @@ pub fn test_encryption() { let after = H128::from_str("89464c6b04e7c99e555c81d3f7266a05").unwrap(); let after2 = H128::from_str("85c070030589ef9c7a2879b3a8489316").unwrap(); - let mut got = H128::new(); + let mut got = H128::zero(); - let mut encoder = EcbEncryptor::new(AesSafe256Encryptor::new(&key), NoPadding); - encoder.encrypt(&mut RefReadBuffer::new(&before), &mut RefWriteBuffer::new(&mut got), true).unwrap(); + let mut encoder = EcbEncryptor::new(AesSafe256Encryptor::new(key.as_bytes()), NoPadding); + encoder.encrypt(&mut RefReadBuffer::new(before.as_bytes()), &mut RefWriteBuffer::new(got.as_bytes_mut()), true).unwrap(); encoder.reset(); assert_eq!(got, after); - got = H128::new(); - encoder.encrypt(&mut RefReadBuffer::new(&before2), &mut RefWriteBuffer::new(&mut got), true).unwrap(); + got = H128::zero(); + encoder.encrypt(&mut RefReadBuffer::new(before2.as_bytes()), &mut RefWriteBuffer::new(got.as_bytes_mut()), true).unwrap(); encoder.reset(); assert_eq!(got, after2); } diff --git a/util/network-devp2p/src/discovery.rs b/util/network-devp2p/src/discovery.rs index 7bf8dc62e..262730bfd 100644 --- a/util/network-devp2p/src/discovery.rs +++ b/util/network-devp2p/src/discovery.rs @@ -197,7 +197,7 @@ impl<'a> Discovery<'a> { public_endpoint: public, discovery_initiated: false, discovery_round: None, - discovery_id: NodeId::new(), + discovery_id: NodeId::default(), discovery_nodes: HashSet::new(), node_buckets: (0..ADDRESS_BITS).map(|_| NodeBucket::new()).collect(), other_observed_nodes: LruCache::new(OBSERVED_NODES_MAX_SIZE), @@ -414,7 +414,7 @@ impl<'a> Discovery<'a> { fn send_packet(&mut self, packet_id: u8, address: &SocketAddr, payload: &[u8]) -> Result { let packet = assemble_packet(packet_id, payload, &self.secret)?; - let hash = H256::from(&packet[0..32]); + let hash = H256::from_slice(&packet[0..32]); self.send_to(packet, address.clone()); Ok(hash) } @@ -491,7 +491,7 @@ impl<'a> Discovery<'a> { let packet_id = signed[0]; let rlp = Rlp::new(&signed[1..]); match packet_id { - PACKET_PING => self.on_ping(&rlp, &node_id, &from, &hash_signed), + PACKET_PING => self.on_ping(&rlp, &node_id, &from, hash_signed.as_bytes()), PACKET_PONG => self.on_pong(&rlp, &node_id, &from), PACKET_FIND_NODE => self.on_find_node(&rlp, &node_id, &from), PACKET_NEIGHBOURS => self.on_neighbours(&rlp, &node_id, &from), @@ -860,7 +860,7 @@ fn assemble_packet(packet_id: u8, bytes: &[u8], secret: &Secret) -> Result, socket: TcpStream, nonce: &H256) -> Result { Ok(Handshake { - id: if let Some(id) = id { *id } else { NodeId::new() }, + id: if let Some(id) = id { *id } else { NodeId::default() }, connection: Connection::new(token, socket), originated: false, state: HandshakeState::New, ecdhe: Random.generate()?, nonce: *nonce, - remote_ephemeral: Public::new(), - remote_nonce: H256::new(), + remote_ephemeral: Public::default(), + remote_nonce: H256::zero(), remote_version: PROTOCOL_VERSION, auth_cipher: Bytes::new(), ack_cipher: Bytes::new(), @@ -149,8 +149,9 @@ impl Handshake { } fn set_auth(&mut self, host_secret: &Secret, sig: &[u8], remote_public: &[u8], remote_nonce: &[u8], remote_version: u64) -> Result<(), Error> { - self.id.clone_from_slice(remote_public); - self.remote_nonce.clone_from_slice(remote_nonce); + // TODO: assign_from_slice will panic if sizes differ + self.id.assign_from_slice(remote_public); + self.remote_nonce.assign_from_slice(remote_nonce); self.remote_version = remote_version; let shared = *ecdh::agree(host_secret, &self.id)?; let signature = H520::from_slice(sig); @@ -199,7 +200,7 @@ impl Handshake { let remote_public: Public = rlp.val_at(1)?; let remote_nonce: H256 = rlp.val_at(2)?; let remote_version: u64 = rlp.val_at(3)?; - self.set_auth(secret, &signature, &remote_public, &remote_nonce, remote_version)?; + self.set_auth(secret, signature.as_bytes(), remote_public.as_bytes(), remote_nonce.as_bytes(), remote_version)?; self.write_ack_eip8(io)?; Ok(()) } @@ -214,8 +215,8 @@ impl Handshake { self.ack_cipher = data.to_vec(); match ecies::decrypt(secret, &[], data) { Ok(ack) => { - self.remote_ephemeral.clone_from_slice(&ack[0..64]); - self.remote_nonce.clone_from_slice(&ack[64..(64+32)]); + self.remote_ephemeral.assign_from_slice(&ack[0..64]); + self.remote_nonce.assign_from_slice(&ack[64..(64+32)]); self.state = HandshakeState::StartSession; } Err(_) => { @@ -261,8 +262,8 @@ impl Handshake { let shared = *ecdh::agree(secret, &self.id)?; sig.copy_from_slice(&*sign(self.ecdhe.secret(), &(shared ^ self.nonce))?); write_keccak(self.ecdhe.public(), hepubk); - pubk.copy_from_slice(public); - nonce.copy_from_slice(&self.nonce); + pubk.copy_from_slice(public.as_bytes()); + nonce.copy_from_slice(self.nonce.as_bytes()); } let message = ecies::encrypt(&self.id, &[], &data)?; self.auth_cipher = message.clone(); @@ -281,8 +282,8 @@ impl Handshake { data[len - 1] = 0x0; let (epubk, rest) = data.split_at_mut(64); let (nonce, _) = rest.split_at_mut(32); - self.ecdhe.public().copy_to(epubk); - self.nonce.copy_to(nonce); + epubk.copy_from_slice(self.ecdhe.public().as_bytes()); + nonce.copy_from_slice(self.nonce.as_bytes()); } let message = ecies::encrypt(&self.id, &[], &data)?; self.ack_cipher = message.clone(); @@ -319,28 +320,38 @@ impl Handshake { mod test { use rustc_hex::FromHex; use super::*; - use ethereum_types::H256; + use ethereum_types::{H256, H512}; use io::*; use mio::tcp::TcpStream; use ethkey::Public; + use std::str::FromStr; fn check_auth(h: &Handshake, version: u64) { - assert_eq!(h.id, "fda1cff674c90c9a197539fe3dfb53086ace64f83ed7c6eabec741f7f381cc803e52ab2cd55d5569bce4347107a310dfd5f88a010cd2ffd1005ca406f1842877".into()); - assert_eq!(h.remote_nonce, "7e968bba13b6c50e2c4cd7f241cc0d64d1ac25c7f5952df231ac6a2bda8ee5d6".into()); - assert_eq!(h.remote_ephemeral, "654d1044b69c577a44e5f01a1209523adb4026e70c62d1c13a067acabc09d2667a49821a0ad4b634554d330a15a58fe61f8a8e0544b310c6de7b0c8da7528a8d".into()); + assert_eq!( + h.id, + H512::from_str("fda1cff674c90c9a197539fe3dfb53086ace64f83ed7c6eabec741f7f381cc803e52ab2cd55d5569bce4347107a310dfd5f88a010cd2ffd1005ca406f1842877").unwrap(), + ); + assert_eq!(h.remote_nonce, H256::from_str("7e968bba13b6c50e2c4cd7f241cc0d64d1ac25c7f5952df231ac6a2bda8ee5d6").unwrap()); + assert_eq!( + h.remote_ephemeral, + H512::from_str("654d1044b69c577a44e5f01a1209523adb4026e70c62d1c13a067acabc09d2667a49821a0ad4b634554d330a15a58fe61f8a8e0544b310c6de7b0c8da7528a8d").unwrap(), + ); assert_eq!(h.remote_version, version); } fn check_ack(h: &Handshake, version: u64) { - assert_eq!(h.remote_nonce, "559aead08264d5795d3909718cdd05abd49572e84fe55590eef31a88a08fdffd".into()); - assert_eq!(h.remote_ephemeral, "b6d82fa3409da933dbf9cb0140c5dde89f4e64aec88d476af648880f4a10e1e49fe35ef3e69e93dd300b4797765a747c6384a6ecf5db9c2690398607a86181e4".into()); + assert_eq!(h.remote_nonce, H256::from_str("559aead08264d5795d3909718cdd05abd49572e84fe55590eef31a88a08fdffd").unwrap()); + assert_eq!( + h.remote_ephemeral, + H512::from_str("b6d82fa3409da933dbf9cb0140c5dde89f4e64aec88d476af648880f4a10e1e49fe35ef3e69e93dd300b4797765a747c6384a6ecf5db9c2690398607a86181e4").unwrap(), + ); assert_eq!(h.remote_version, version); } fn create_handshake(to: Option<&Public>) -> Handshake { let addr = "127.0.0.1:50556".parse().unwrap(); let socket = TcpStream::connect(&addr).unwrap(); - let nonce = H256::new(); + let nonce = H256::zero(); Handshake::new(0, to, socket, &nonce).unwrap() } @@ -427,7 +438,7 @@ mod test { #[test] fn test_handshake_ack_plain() { - let remote = "fda1cff674c90c9a197539fe3dfb53086ace64f83ed7c6eabec741f7f381cc803e52ab2cd55d5569bce4347107a310dfd5f88a010cd2ffd1005ca406f1842877".into(); + let remote = H512::from_str("fda1cff674c90c9a197539fe3dfb53086ace64f83ed7c6eabec741f7f381cc803e52ab2cd55d5569bce4347107a310dfd5f88a010cd2ffd1005ca406f1842877").unwrap(); let mut h = create_handshake(Some(&remote)); let secret = "49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee".parse().unwrap(); let ack = @@ -447,7 +458,7 @@ mod test { #[test] fn test_handshake_ack_eip8() { - let remote = "fda1cff674c90c9a197539fe3dfb53086ace64f83ed7c6eabec741f7f381cc803e52ab2cd55d5569bce4347107a310dfd5f88a010cd2ffd1005ca406f1842877".into(); + let remote = H512::from_str("fda1cff674c90c9a197539fe3dfb53086ace64f83ed7c6eabec741f7f381cc803e52ab2cd55d5569bce4347107a310dfd5f88a010cd2ffd1005ca406f1842877").unwrap(); let mut h = create_handshake(Some(&remote)); let secret = "49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee".parse().unwrap(); let ack = @@ -476,7 +487,7 @@ mod test { #[test] fn test_handshake_ack_eip8_2() { - let remote = "fda1cff674c90c9a197539fe3dfb53086ace64f83ed7c6eabec741f7f381cc803e52ab2cd55d5569bce4347107a310dfd5f88a010cd2ffd1005ca406f1842877".into(); + let remote = H512::from_str("fda1cff674c90c9a197539fe3dfb53086ace64f83ed7c6eabec741f7f381cc803e52ab2cd55d5569bce4347107a310dfd5f88a010cd2ffd1005ca406f1842877").unwrap(); let mut h = create_handshake(Some(&remote)); let secret = "49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee".parse().unwrap(); let ack = diff --git a/util/network-devp2p/src/host.rs b/util/network-devp2p/src/host.rs index 5f0969751..0383aa993 100644 --- a/util/network-devp2p/src/host.rs +++ b/util/network-devp2p/src/host.rs @@ -33,6 +33,7 @@ use mio::tcp::*; use mio::udp::*; use ethereum_types::H256; use rlp::{RlpStream, Encodable}; +use rustc_hex::ToHex; use session::{Session, SessionData}; use io::*; @@ -1223,7 +1224,7 @@ fn save_key(path: &Path, key: &Secret) { if let Err(e) = restrict_permissions_owner(path, true, false) { warn!(target: "network", "Failed to modify permissions of the file ({})", e); } - if let Err(e) = file.write(&key.hex().into_bytes()[2..]) { + if let Err(e) = file.write(&key.to_hex().into_bytes()) { warn!("Error writing key file: {:?}", e); } } diff --git a/util/network-devp2p/src/node_table.rs b/util/network-devp2p/src/node_table.rs index db5189008..12f5a0b66 100644 --- a/util/network-devp2p/src/node_table.rs +++ b/util/network-devp2p/src/node_table.rs @@ -211,7 +211,7 @@ impl FromStr for Node { (s[8..136].parse().map_err(|_| ErrorKind::InvalidNodeId)?, NodeEndpoint::from_str(&s[137..])?) } else { - (NodeId::new(), NodeEndpoint::from_str(s)?) + (NodeId::default(), NodeEndpoint::from_str(s)?) }; Ok(Node { diff --git a/util/network/Cargo.toml b/util/network/Cargo.toml index ec3232926..018152c72 100644 --- a/util/network/Cargo.toml +++ b/util/network/Cargo.toml @@ -10,11 +10,11 @@ authors = ["Parity Technologies "] error-chain = { version = "0.12", default-features = false } parity-crypto = "0.4.0" ethcore-io = { path = "../io" } -ethereum-types = "0.4" +ethereum-types = "0.6.0" ethkey = { path = "../../accounts/ethkey" } ipnetwork = "0.12.6" lazy_static = "1.0" -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" libc = "0.2" parity-snappy = "0.1" semver = {version="0.9.0", features=["serde"]} diff --git a/util/patricia-trie-ethereum/Cargo.toml b/util/patricia-trie-ethereum/Cargo.toml index 8cb8664a5..f6a25b876 100644 --- a/util/patricia-trie-ethereum/Cargo.toml +++ b/util/patricia-trie-ethereum/Cargo.toml @@ -9,12 +9,12 @@ license = "GPL-3.0" trie-db = "0.11.0" keccak-hasher = { version = "0.1.1", path = "../keccak-hasher" } hash-db = "0.11.0" -rlp = "0.3.0" +rlp = "0.4.0" parity-bytes = "0.1" -ethereum-types = "0.4" +ethereum-types = "0.6.0" elastic-array = "0.10" [dev-dependencies] memory-db = "0.11.0" -keccak-hash = "0.1.2" +keccak-hash = "0.2.0" journaldb = { path = "../journaldb" } diff --git a/util/patricia-trie-ethereum/src/lib.rs b/util/patricia-trie-ethereum/src/lib.rs index ab44f4e83..ac8479fe3 100644 --- a/util/patricia-trie-ethereum/src/lib.rs +++ b/util/patricia-trie-ethereum/src/lib.rs @@ -63,7 +63,7 @@ pub type RlpCodec = RlpNodeCodec; /// /// fn main() { /// let mut memdb = journaldb::new_memory_db(); -/// let mut root = H256::new(); +/// let mut root = H256::zero(); /// TrieDBMut::new(&mut memdb, &mut root).insert(b"foo", b"bar").unwrap(); /// let t = TrieDB::new(&memdb, &root).unwrap(); /// assert!(t.contains(b"foo").unwrap()); @@ -107,7 +107,7 @@ pub type FatDB<'db> = trie::FatDB<'db, KeccakHasher, RlpCodec>; /// /// fn main() { /// let mut memdb = journaldb::new_memory_db(); -/// let mut root = H256::new(); +/// let mut root = H256::zero(); /// let mut t = TrieDBMut::new(&mut memdb, &mut root); /// assert!(t.is_empty()); /// assert_eq!(*t.root(), KECCAK_NULL_RLP); diff --git a/util/registrar/Cargo.toml b/util/registrar/Cargo.toml index 6f526af28..44904028b 100644 --- a/util/registrar/Cargo.toml +++ b/util/registrar/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Parity Technologies "] [dependencies] futures = "0.1" -ethabi = "6.0" -ethabi-derive = "6.0" -ethabi-contract = "6.0" -keccak-hash = "0.1" +ethabi = "8.0" +ethabi-derive = "8.0" +ethabi-contract = "8.0" +keccak-hash = "0.2.0" diff --git a/util/rlp-compress/Cargo.toml b/util/rlp-compress/Cargo.toml index 4bd34bce1..0bcb092a1 100644 --- a/util/rlp-compress/Cargo.toml +++ b/util/rlp-compress/Cargo.toml @@ -4,6 +4,6 @@ version = "0.1.0" authors = ["Parity Technologies "] [dependencies] -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" elastic-array = "0.10" lazy_static = "1.0" diff --git a/util/rlp-derive/Cargo.toml b/util/rlp-derive/Cargo.toml index 2087f7524..ba5fb984f 100644 --- a/util/rlp-derive/Cargo.toml +++ b/util/rlp-derive/Cargo.toml @@ -13,4 +13,4 @@ quote = "0.6" proc-macro2 = "0.4" [dev-dependencies] -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" diff --git a/util/triehash-ethereum/Cargo.toml b/util/triehash-ethereum/Cargo.toml index 5b6364297..b1f7b1216 100644 --- a/util/triehash-ethereum/Cargo.toml +++ b/util/triehash-ethereum/Cargo.toml @@ -6,6 +6,6 @@ description = "Trie-root helpers, ethereum style" license = "GPL-3.0" [dependencies] -triehash = { version = "0.4.0", features = ["ethereum"] } -ethereum-types = "0.4" +triehash = "0.5.0" +ethereum-types = "0.6.0" keccak-hasher = { path = "../keccak-hasher" } diff --git a/util/triehash-ethereum/src/lib.rs b/util/triehash-ethereum/src/lib.rs index 696ed61ab..27cc2b323 100644 --- a/util/triehash-ethereum/src/lib.rs +++ b/util/triehash-ethereum/src/lib.rs @@ -54,15 +54,16 @@ where #[cfg(test)] mod tests { - use super::{trie_root, sec_trie_root, ordered_trie_root}; + use super::{trie_root, sec_trie_root, ordered_trie_root, H256}; use triehash; use keccak_hasher::KeccakHasher; + use std::str::FromStr; #[test] fn simple_test() { assert_eq!(trie_root(vec![ (b"A", b"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" as &[u8]) - ]), "d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab".into()); + ]), H256::from_str("d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab").unwrap()); } #[test] diff --git a/util/version/Cargo.toml b/util/version/Cargo.toml index 192ff906a..238c02db7 100644 --- a/util/version/Cargo.toml +++ b/util/version/Cargo.toml @@ -23,7 +23,7 @@ goerli = { forkBlock = 0, critical = false } [dependencies] parity-bytes = "0.1" -rlp = { version = "0.3.0", features = ["ethereum"] } +rlp = "0.4.0" target_info = "0.1" [build-dependencies] diff --git a/whisper/Cargo.toml b/whisper/Cargo.toml index c23df60cd..1998de55a 100644 --- a/whisper/Cargo.toml +++ b/whisper/Cargo.toml @@ -7,7 +7,7 @@ description = "Whisper Protocol implementation for Parity" [dependencies] bitflags = "0.9" byteorder = "1.0.0" -ethereum-types = "0.4" +ethereum-types = "0.6.0" ethcore-network = { path = "../util/network" } ring = "0.14.6" ethkey = { path = "../accounts/ethkey" } @@ -16,8 +16,9 @@ log = "0.4" memzero = { path = "../util/memzero" } ordered-float = "0.5" parking_lot = "0.7" -rand = "0.4" -rlp = { version = "0.3.0", features = ["ethereum"] } +rand = "0.6" +rand_xorshift = "0.1.1" +rlp = "0.4.0" serde = "1.0" serde_derive = "1.0" serde_json = "1.0" diff --git a/whisper/src/lib.rs b/whisper/src/lib.rs index 80447ef11..62a44ac93 100644 --- a/whisper/src/lib.rs +++ b/whisper/src/lib.rs @@ -28,6 +28,7 @@ extern crate memzero; extern crate ordered_float; extern crate parking_lot; extern crate rand; +extern crate rand_xorshift; extern crate ring; extern crate rlp; extern crate serde; diff --git a/whisper/src/message.rs b/whisper/src/message.rs index c10d39700..ad50e3d9b 100644 --- a/whisper/src/message.rs +++ b/whisper/src/message.rs @@ -35,8 +35,8 @@ pub fn work_factor_proved(size: u64, ttl: u64, hash: H256) -> f64 { assert!(size != 0 && ttl != 0); let leading_zeros = { - let leading_bytes = hash.iter().take_while(|&&x| x == 0).count(); - let remaining_leading_bits = hash.get(leading_bytes).map_or(0, |byte| byte.leading_zeros() as usize); + let leading_bytes = hash.as_ref().iter().take_while(|&&x| x == 0).count(); + let remaining_leading_bits = hash.as_ref().get(leading_bytes).map_or(0, |byte| byte.leading_zeros() as usize); (leading_bytes * 8) + remaining_leading_bits }; let spacetime = size as f64 * ttl as f64; @@ -70,7 +70,7 @@ impl Topic { } debug_assert!(idx <= 511); - bloom[idx / 8] |= 1 << (7 - idx % 8); + bloom.as_bytes_mut()[idx / 8] |= 1 << (7 - idx % 8); } } @@ -258,13 +258,14 @@ impl Message { /// Panics if TTL is 0. pub fn create(params: CreateParams) -> Result { use byteorder::{BigEndian, ByteOrder}; - use rand::{Rng, SeedableRng, XorShiftRng}; + use rand::{Rng, SeedableRng}; + use rand_xorshift::XorShiftRng; if params.topics.is_empty() { return Err(Error::EmptyTopics) } let mut rng = { let mut thread_rng = ::rand::thread_rng(); - XorShiftRng::from_seed(thread_rng.gen::<[u32; 4]>()) + XorShiftRng::from_seed(thread_rng.gen()) }; assert!(params.ttl > 0); @@ -529,9 +530,9 @@ mod tests { #[test] fn work_factor() { // 256 leading zeros -> 2^256 / 1 - assert_eq!(work_factor_proved(1, 1, H256::from(0)), 115792089237316200000000000000000000000000000000000000000000000000000000000000.0); + assert_eq!(work_factor_proved(1, 1, H256::zero()), 115792089237316200000000000000000000000000000000000000000000000000000000000000.0); // 255 leading zeros -> 2^255 / 1 - assert_eq!(work_factor_proved(1, 1, H256::from(1)), 57896044618658100000000000000000000000000000000000000000000000000000000000000.0); + assert_eq!(work_factor_proved(1, 1, H256::from_low_u64_be(1)), 57896044618658100000000000000000000000000000000000000000000000000000000000000.0); // 0 leading zeros -> 2^0 / 1 assert_eq!(work_factor_proved(1, 1, serde_json::from_str::("\"0xff00000000000000000000000000000000000000000000000000000000000000\"").unwrap()), 1.0); } diff --git a/whisper/src/net/tests.rs b/whisper/src/net/tests.rs index 7af0cb8d3..fc4534dcc 100644 --- a/whisper/src/net/tests.rs +++ b/whisper/src/net/tests.rs @@ -114,7 +114,7 @@ impl<'a> Context for TestContext<'a> { fn node_key(&self, peer: PeerId) -> Option { let mut id = NodeId::default(); - id[0] = peer as _; + id.as_bytes_mut()[0] = peer as _; Some(id) } diff --git a/whisper/src/rpc/crypto.rs b/whisper/src/rpc/crypto.rs index ba4435e7c..418f40374 100644 --- a/whisper/src/rpc/crypto.rs +++ b/whisper/src/rpc/crypto.rs @@ -165,8 +165,8 @@ impl DecryptionInstance { if ciphertext.len() < num_topics * 32 { return None } - let mut salted_topic = H256::new(); - salted_topic.copy_from_slice(&ciphertext[(known_index * 32)..][..32]); + let mut salted_topic = H256::zero(); + salted_topic.as_bytes_mut().copy_from_slice(&ciphertext[(known_index * 32)..][..32]); let key = Memzero::from((salted_topic ^ known_topic).0); let offset = num_topics * 32; Decryptor::aes_256_gcm(&*key).ok()? @@ -186,6 +186,8 @@ impl DecryptionInstance { #[cfg(test)] mod tests { use super::*; + use rand::{Rng, rngs::OsRng}; + #[test] fn encrypt_asymmetric() { @@ -213,8 +215,6 @@ mod tests { #[test] fn encrypt_symmetric() { - use rand::{Rng, OsRng}; - let mut rng = OsRng::new().unwrap(); let mut test_message = move |message: &[u8]| { let key = Memzero::from(rng.gen::<[u8; 32]>()); @@ -239,12 +239,10 @@ mod tests { #[test] fn encrypt_broadcast() { - use rand::{Rng, OsRng}; - let mut rng = OsRng::new().unwrap(); let mut test_message = move |message: &[u8]| { - let all_topics = (0..5).map(|_| rng.gen()).collect::>(); + let all_topics = (0..5).map(|_| H256::random_using(&mut rng)).collect::>(); let known_idx = 2; let known_topic = all_topics[2]; let key = Memzero::from(rng.gen::<[u8; 32]>()); diff --git a/whisper/src/rpc/filter.rs b/whisper/src/rpc/filter.rs index 46cefd61e..a58f16f9c 100644 --- a/whisper/src/rpc/filter.rs +++ b/whisper/src/rpc/filter.rs @@ -23,7 +23,6 @@ use ethereum_types::{H256, H512}; use ethkey::Public; use jsonrpc_pubsub::typed::{Subscriber, Sink}; use parking_lot::{Mutex, RwLock}; -use rand::{Rng, OsRng}; use message::{Message, Topic}; use super::{key_store::KeyStore, types::{self, FilterItem, HexEncode}}; @@ -107,10 +106,7 @@ impl Manager { pub fn insert_polled(&self, filter: Filter) -> Result { let buffer = Arc::new(Mutex::new(Vec::new())); let entry = FilterEntry::Poll(Arc::new(filter), buffer); - let id = OsRng::new() - .map_err(|_| "unable to acquire secure randomness")? - .gen(); - + let id = H256::random(); self.filters.write().insert(id, entry); Ok(id) } @@ -120,9 +116,7 @@ impl Manager { pub fn insert_subscription(&self, filter: Filter, sub: Subscriber) -> Result<(), &'static str> { - let id: H256 = OsRng::new() - .map_err(|_| "unable to acquire secure randomness")? - .gen(); + let id = H256::random(); sub.assign_id(::jsonrpc_pubsub::SubscriptionId::String(format!("{:x}", id))) .map(move |sink| { diff --git a/whisper/src/rpc/key_store.rs b/whisper/src/rpc/key_store.rs index 081a8b374..687eab48a 100644 --- a/whisper/src/rpc/key_store.rs +++ b/whisper/src/rpc/key_store.rs @@ -24,7 +24,7 @@ use std::collections::HashMap; use ethereum_types::H256; use ethkey::{KeyPair, Public, Secret}; use memzero::Memzero; -use rand::{Rng, OsRng}; +use rand::{Rng, rngs::OsRng}; use rpc::crypto::{AES_KEY_LEN, EncryptionInstance, DecryptionInstance}; @@ -105,7 +105,7 @@ impl KeyStore { /// Import a key, generating a random identity for it. pub fn insert(&mut self, key: Key) -> H256 { - let id = self.rng().gen(); + let id = H256::random_using(self.rng()); self.identities.insert(id, key); id diff --git a/whisper/src/rpc/mod.rs b/whisper/src/rpc/mod.rs index 03d98b51f..a5ed05da7 100644 --- a/whisper/src/rpc/mod.rs +++ b/whisper/src/rpc/mod.rs @@ -277,7 +277,7 @@ impl Whisper for WhisperClien Some(types::Receiver::Identity(id)) => self.store.read().encryption_instance(&id.into_inner()) .map_err(whisper_error)?, None => { - use rand::{Rng, OsRng}; + use rand::{Rng, rngs::OsRng}; // broadcast mode: use fixed nonce and fresh key each time. diff --git a/whisper/src/rpc/types.rs b/whisper/src/rpc/types.rs index 40e440bf5..b5550dbff 100644 --- a/whisper/src/rpc/types.rs +++ b/whisper/src/rpc/types.rs @@ -17,6 +17,7 @@ //! Types for Whisper RPC. use std::fmt; +use std::convert::AsRef; use std::ops::Deref; use ethereum_types::{H32, H64, H128, H256, H264, H512}; @@ -26,7 +27,7 @@ use serde::{Serialize, Serializer, Deserialize, Deserializer}; use serde::de::{Error, Visitor}; /// Helper trait for generic hex bytes encoding. -pub trait HexEncodable: Sized + ::std::ops::Deref { +pub trait HexEncodable: Sized + AsRef<[u8]> { fn from_bytes(bytes: Vec) -> Option; } @@ -39,7 +40,7 @@ macro_rules! impl_hex_for_hash { $( impl HexEncodable for $t { fn from_bytes(bytes: Vec) -> Option { - if bytes.len() != $t::len() { + if bytes.len() != $t::len_bytes() { None } else { Some($t::from_slice(&bytes)) @@ -100,7 +101,7 @@ pub type Symmetric = HexEncode; impl Serialize for HexEncode { fn serialize(&self, serializer: S) -> Result { - let data = &self.0[..]; + let data = self.0.as_ref(); let serialized = "0x".to_owned() + &data.to_hex(); serializer.serialize_str(serialized.as_ref())