diff --git a/Cargo.lock b/Cargo.lock index 8f866209a..98940990f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1631,6 +1631,7 @@ 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.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.2.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.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1956,6 +1957,23 @@ dependencies = [ "unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "hex-literal" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "hex-literal-impl 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hex-literal-impl" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro-hack 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "hmac" version = "0.7.0" @@ -3563,6 +3581,16 @@ dependencies = [ "toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "proc-macro-hack" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "proc-macro2" version = "0.4.20" @@ -3571,6 +3599,14 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "proc-macro2" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "pulldown-cmark" version = "0.0.3" @@ -3623,6 +3659,14 @@ dependencies = [ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "quote" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rand" version = "0.3.22" @@ -4302,6 +4346,16 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "syn" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "synom" version = "0.11.3" @@ -4840,6 +4894,11 @@ name = "unicode-xid" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "unicode-xid" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "unreachable" version = "1.0.0" @@ -5288,6 +5347,8 @@ dependencies = [ "checksum hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8e04cb7a5051270ef3fa79f8c7604d581ecfa73d520e74f554e45541c4b5881a" "checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" "checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82" +"checksum hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c3da68162fdd2147e66682e78e729bd77f93b4c99656db058c5782d8c6b6225a" +"checksum hex-literal-impl 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "06095d08c7c05760f11a071b3e1d4c5b723761c01bd8d7201c30a9536668a612" "checksum hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f127a908633569f208325f86f71255d3363c79721d7f9fe31cd5569908819771" "checksum home 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "80dff82fb58cfbbc617fb9a9184b010be0529201553cda50ad04372bc2333aff" "checksum http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "eed324f0f0daf6ec10c474f150505af2c143f251722bf9dbd1261bd1f2ee2c1a" @@ -5410,12 +5471,15 @@ dependencies = [ "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-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e10d4b51f154c8a7fb96fd6dad097cb74b863943ec010ac94b9fd1be8861fe1e" +"checksum proc-macro-hack 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e688f31d92ffd7c1ddc57a1b4e6d773c0f2a14ee437a4b0a4f5a69c80eb221c8" "checksum proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "3d7b7eaaa90b4a90a932a9ea6666c95a389e424eff347f0f793979289429feee" +"checksum proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4c5c2380ae88876faae57698be9e9775e3544decad214599c3a6266cca6ac802" "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" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dd636425967c33af890042c483632d33fa7a18f19ad1d7ea72e8998c6ef8dea5" +"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" "checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1" "checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd" "checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c" @@ -5489,6 +5553,7 @@ dependencies = [ "checksum subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "01dca13cf6c3b179864ab3292bd794e757618d35a7766b7c46050c614ba00829" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" "checksum syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)" = "f92e629aa1d9c827b2bb8297046c1ccffc57c99b947a680d3ccff1f136a3bee9" +"checksum syn 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "158521e6f544e7e3dcfc370ac180794aa38cb34a1b1e07609376d4adcf429b93" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "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" @@ -5543,6 +5608,7 @@ dependencies = [ "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" +"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" "checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" "checksum url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2a321979c09843d272956e73700d12c4e7d3d92b2ee112b31548aef0d4efc5a6" diff --git a/ethcore/engines/validator-set/src/safe_contract.rs b/ethcore/engines/validator-set/src/safe_contract.rs index d023802f0..666d43eac 100644 --- a/ethcore/engines/validator-set/src/safe_contract.rs +++ b/ethcore/engines/validator-set/src/safe_contract.rs @@ -115,7 +115,7 @@ fn check_first_proof(machine: &Machine, contract_address: Address, old_header: H gas_limit: PROVIDED_GAS.into(), timestamp: old_header.timestamp(), last_hashes: { - // this will break if we don't inclue all 256 last hashes. + // this will break if we don't include all 256 last hashes. let mut last_hashes: Vec<_> = (0..256).map(|_| H256::zero()).collect(); last_hashes[255] = *old_header.parent_hash(); Arc::new(last_hashes) diff --git a/ethcore/evm/Cargo.toml b/ethcore/evm/Cargo.toml index 094d22f84..7c098654d 100644 --- a/ethcore/evm/Cargo.toml +++ b/ethcore/evm/Cargo.toml @@ -19,6 +19,7 @@ memory-cache = { path = "../../util/memory-cache" } [dev-dependencies] rustc-hex = "1.0" criterion = "0.2" +hex-literal = "0.2.0" [features] evm-debug = [] diff --git a/ethcore/evm/src/factory.rs b/ethcore/evm/src/factory.rs index 7f441df01..2b107e5a6 100644 --- a/ethcore/evm/src/factory.rs +++ b/ethcore/evm/src/factory.rs @@ -47,7 +47,7 @@ impl Factory { /// for caching jump destinations. pub fn new(evm: VMType, cache_size: usize) -> Self { Factory { - evm: evm, + evm, evm_cache: Arc::new(SharedCache::new(cache_size)), } } diff --git a/ethcore/evm/src/instructions.rs b/ethcore/evm/src/instructions.rs index 0cdbb5687..1580f7b59 100644 --- a/ethcore/evm/src/instructions.rs +++ b/ethcore/evm/src/instructions.rs @@ -149,6 +149,8 @@ enum_with_from_u8! { DIFFICULTY = 0x44, #[doc = "get the block's gas limit"] GASLIMIT = 0x45, + #[doc = "get chain ID"] + CHAINID = 0x46, #[doc = "remove item from stack"] POP = 0x50, @@ -442,12 +444,7 @@ pub struct InstructionInfo { impl InstructionInfo { /// Create new instruction info. pub fn new(name: &'static str, args: usize, ret: usize, tier: GasPriceTier) -> Self { - InstructionInfo { - name: name, - args: args, - ret: ret, - tier: tier - } + InstructionInfo { name, args, ret, tier } } } @@ -504,6 +501,7 @@ lazy_static! { arr[NUMBER as usize] = Some(InstructionInfo::new("NUMBER", 0, 1, GasPriceTier::Base)); arr[DIFFICULTY as usize] = Some(InstructionInfo::new("DIFFICULTY", 0, 1, GasPriceTier::Base)); arr[GASLIMIT as usize] = Some(InstructionInfo::new("GASLIMIT", 0, 1, GasPriceTier::Base)); + arr[CHAINID as usize] = Some(InstructionInfo::new("CHAINID", 0, 1, GasPriceTier::Base)); arr[POP as usize] = Some(InstructionInfo::new("POP", 1, 0, GasPriceTier::Base)); arr[MLOAD as usize] = Some(InstructionInfo::new("MLOAD", 1, 1, GasPriceTier::VeryLow)); arr[MSTORE as usize] = Some(InstructionInfo::new("MSTORE", 2, 0, GasPriceTier::VeryLow)); diff --git a/ethcore/evm/src/interpreter/mod.rs b/ethcore/evm/src/interpreter/mod.rs index e8a318020..855643855 100644 --- a/ethcore/evm/src/interpreter/mod.rs +++ b/ethcore/evm/src/interpreter/mod.rs @@ -428,7 +428,8 @@ impl Interpreter { ((instruction == instructions::RETURNDATACOPY || instruction == instructions::RETURNDATASIZE) && !schedule.have_return_data) || (instruction == instructions::REVERT && !schedule.have_revert) || ((instruction == instructions::SHL || instruction == instructions::SHR || instruction == instructions::SAR) && !schedule.have_bitwise_shifting) || - (instruction == instructions::EXTCODEHASH && !schedule.have_extcodehash) + (instruction == instructions::EXTCODEHASH && !schedule.have_extcodehash) || + (instruction == instructions::CHAINID && !schedule.have_chain_id) { return Err(vm::Error::BadInstruction { instruction: instruction as u8 @@ -843,6 +844,9 @@ impl Interpreter { instructions::GASLIMIT => { self.stack.push(ext.env_info().gas_limit.clone()); }, + instructions::CHAINID => { + self.stack.push(ext.chain_id().into()) + }, // Stack instructions diff --git a/ethcore/evm/src/lib.rs b/ethcore/evm/src/lib.rs index 7cfa5a69e..db029d15f 100644 --- a/ethcore/evm/src/lib.rs +++ b/ethcore/evm/src/lib.rs @@ -33,6 +33,8 @@ extern crate log; #[cfg(test)] extern crate rustc_hex; +#[cfg(test)] +extern crate hex_literal; pub mod evm; pub mod interpreter; diff --git a/ethcore/evm/src/tests.rs b/ethcore/evm/src/tests.rs index 15749b926..05a39e1b5 100644 --- a/ethcore/evm/src/tests.rs +++ b/ethcore/evm/src/tests.rs @@ -19,17 +19,22 @@ use std::str::FromStr; use std::hash::Hash; use std::sync::Arc; use std::collections::{HashMap, HashSet}; -use rustc_hex::FromHex; use ethereum_types::{U256, H256, Address}; use vm::{self, ActionParams, ActionValue, Ext}; use vm::tests::{FakeExt, FakeCall, FakeCallType, test_finalize}; use factory::Factory; use vmtype::VMType; +use hex_literal::hex; evm_test!{test_add: test_add_int} fn test_add(factory: super::Factory) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); - let code = "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055".from_hex().unwrap(); + // 7f PUSH32 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff + // 7f PUSH32 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff + // 01 ADD + // 60 00 PUSH 0 + // 55 SSTORE + let code = hex!("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600055").to_vec(); let mut params = ActionParams::default(); params.address = address.clone(); @@ -49,7 +54,12 @@ fn test_add(factory: super::Factory) { evm_test!{test_sha3: test_sha3_int} fn test_sha3(factory: super::Factory) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); - let code = "6000600020600055".from_hex().unwrap(); + // 60 00 PUSH 0 + // 60 00 PUSH 0 + // 20 SHA3 + // 60 00 PUSH 0 + // 55 SSTORE + let code = hex!("6000600020600055").to_vec(); let mut params = ActionParams::default(); params.address = address.clone(); @@ -69,7 +79,10 @@ fn test_sha3(factory: super::Factory) { evm_test!{test_address: test_address_int} fn test_address(factory: super::Factory) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); - let code = "30600055".from_hex().unwrap(); + // 30 ADDRESS + // 60 00 PUSH 0 + // 55 SSTORE + let code = hex!("30600055").to_vec(); let mut params = ActionParams::default(); params.address = address.clone(); @@ -90,7 +103,10 @@ evm_test!{test_origin: test_origin_int} fn test_origin(factory: super::Factory) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let origin = Address::from_str("cd1722f2947def4cf144679da39c4c32bdc35681").unwrap(); - let code = "32600055".from_hex().unwrap(); + // 32 ORIGIN + // 60 00 PUSH 0 + // 55 SSTORE + let code = hex!("32600055").to_vec(); let mut params = ActionParams::default(); params.address = address.clone(); @@ -112,7 +128,10 @@ evm_test!{test_sender: test_sender_int} fn test_sender(factory: super::Factory) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let sender = Address::from_str("cd1722f2947def4cf144679da39c4c32bdc35681").unwrap(); - let code = "33600055".from_hex().unwrap(); + // 33 CALLER + // 60 00 PUSH 0 + // 55 SSTORE + let code = hex!("33600055").to_vec(); let mut params = ActionParams::default(); params.address = address.clone(); @@ -130,6 +149,27 @@ fn test_sender(factory: super::Factory) { assert_store(&ext, 0, "000000000000000000000000cd1722f2947def4cf144679da39c4c32bdc35681"); } +evm_test!{test_chain_id: test_chain_id_int} +fn test_chain_id(factory: super::Factory) { + // 46 CHAINID + // 60 00 PUSH 0 + // 55 SSTORE + let code = hex!("46 60 00 55").to_vec(); + + let mut params = ActionParams::default(); + params.gas = U256::from(100_000); + params.code = Some(Arc::new(code)); + let mut ext = FakeExt::new_istanbul().with_chain_id(9); + + let gas_left = { + let vm = factory.create(params, ext.schedule(), ext.depth()); + test_finalize(vm.exec(&mut ext).ok().unwrap()).unwrap() + }; + + assert_eq!(gas_left, U256::from(79_995)); + assert_store(&ext, 0, "0000000000000000000000000000000000000000000000000000000000000009"); +} + evm_test!{test_extcodecopy: test_extcodecopy_int} fn test_extcodecopy(factory: super::Factory) { // 33 - sender @@ -145,8 +185,8 @@ fn test_extcodecopy(factory: super::Factory) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let sender = Address::from_str("cd1722f2947def4cf144679da39c4c32bdc35681").unwrap(); - let code = "333b60006000333c600051600055".from_hex().unwrap(); - let sender_code = "6005600055".from_hex().unwrap(); + let code = hex!("333b60006000333c600051600055").to_vec(); + let sender_code = hex!("6005600055").to_vec(); let mut params = ActionParams::default(); params.address = address.clone(); @@ -168,7 +208,7 @@ fn test_extcodecopy(factory: super::Factory) { evm_test!{test_log_empty: test_log_empty_int} fn test_log_empty(factory: super::Factory) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); - let code = "60006000a0".from_hex().unwrap(); + let code = hex!("60006000a0").to_vec(); let mut params = ActionParams::default(); params.address = address.clone(); @@ -199,7 +239,7 @@ fn test_log_sender(factory: super::Factory) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); let sender = Address::from_str("cd1722f3947def4cf144679da39c4c32bdc35681").unwrap(); - let code = "60ff6000533360206000a1".from_hex().unwrap(); + let code = hex!("60ff6000533360206000a1").to_vec(); let mut params = ActionParams::default(); params.address = address.clone(); @@ -217,13 +257,13 @@ fn test_log_sender(factory: super::Factory) { assert_eq!(ext.logs.len(), 1); assert_eq!(ext.logs[0].topics.len(), 1); assert_eq!(ext.logs[0].topics[0], H256::from_str("000000000000000000000000cd1722f3947def4cf144679da39c4c32bdc35681").unwrap()); - assert_eq!(ext.logs[0].data, "ff00000000000000000000000000000000000000000000000000000000000000".from_hex().unwrap()); + assert_eq!(ext.logs[0].data, hex!("ff00000000000000000000000000000000000000000000000000000000000000").to_vec()); } evm_test!{test_blockhash: test_blockhash_int} fn test_blockhash(factory: super::Factory) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); - let code = "600040600055".from_hex().unwrap(); + let code = hex!("600040600055").to_vec(); let blockhash = H256::from_str("123400000000000000000000cd1722f2947def4cf144679da39c4c32bdc35681").unwrap(); let mut params = ActionParams::default(); @@ -245,8 +285,8 @@ fn test_blockhash(factory: super::Factory) { evm_test!{test_calldataload: test_calldataload_int} fn test_calldataload(factory: super::Factory) { let address = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); - let code = "600135600055".from_hex().unwrap(); - let data = "0123ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff23".from_hex().unwrap(); + let code = hex!("600135600055").to_vec(); + let data = hex!("0123ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff23").to_vec(); let mut params = ActionParams::default(); params.address = address.clone(); @@ -267,7 +307,7 @@ fn test_calldataload(factory: super::Factory) { evm_test!{test_author: test_author_int} fn test_author(factory: super::Factory) { let author = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap(); - let code = "41600055".from_hex().unwrap(); + let code = hex!("41600055").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -287,7 +327,7 @@ fn test_author(factory: super::Factory) { evm_test!{test_timestamp: test_timestamp_int} fn test_timestamp(factory: super::Factory) { let timestamp = 0x1234; - let code = "42600055".from_hex().unwrap(); + let code = hex!("42600055").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -307,7 +347,7 @@ fn test_timestamp(factory: super::Factory) { evm_test!{test_number: test_number_int} fn test_number(factory: super::Factory) { let number = 0x1234; - let code = "43600055".from_hex().unwrap(); + let code = hex!("43600055").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -327,7 +367,7 @@ fn test_number(factory: super::Factory) { evm_test!{test_difficulty: test_difficulty_int} fn test_difficulty(factory: super::Factory) { let difficulty = U256::from(0x1234); - let code = "44600055".from_hex().unwrap(); + let code = hex!("44600055").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -347,7 +387,7 @@ fn test_difficulty(factory: super::Factory) { evm_test!{test_gas_limit: test_gas_limit_int} fn test_gas_limit(factory: super::Factory) { let gas_limit = U256::from(0x1234); - let code = "45600055".from_hex().unwrap(); + let code = hex!("45600055").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -366,7 +406,7 @@ fn test_gas_limit(factory: super::Factory) { evm_test!{test_mul: test_mul_int} fn test_mul(factory: super::Factory) { - let code = "65012365124623626543219002600055".from_hex().unwrap(); + let code = hex!("65012365124623626543219002600055").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -384,7 +424,7 @@ fn test_mul(factory: super::Factory) { evm_test!{test_sub: test_sub_int} fn test_sub(factory: super::Factory) { - let code = "65012365124623626543219003600055".from_hex().unwrap(); + let code = hex!("65012365124623626543219003600055").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -402,7 +442,7 @@ fn test_sub(factory: super::Factory) { evm_test!{test_div: test_div_int} fn test_div(factory: super::Factory) { - let code = "65012365124623626543219004600055".from_hex().unwrap(); + let code = hex!("65012365124623626543219004600055").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -420,7 +460,7 @@ fn test_div(factory: super::Factory) { evm_test!{test_div_zero: test_div_zero_int} fn test_div_zero(factory: super::Factory) { - let code = "6501236512462360009004600055".from_hex().unwrap(); + let code = hex!("6501236512462360009004600055").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -438,7 +478,7 @@ fn test_div_zero(factory: super::Factory) { evm_test!{test_mod: test_mod_int} fn test_mod(factory: super::Factory) { - let code = "650123651246236265432290066000556501236512462360009006600155".from_hex().unwrap(); + let code = hex!("650123651246236265432290066000556501236512462360009006600155").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -457,7 +497,7 @@ fn test_mod(factory: super::Factory) { evm_test!{test_smod: test_smod_int} fn test_smod(factory: super::Factory) { - let code = "650123651246236265432290076000556501236512462360009007600155".from_hex().unwrap(); + let code = hex!("650123651246236265432290076000556501236512462360009007600155").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -476,7 +516,7 @@ fn test_smod(factory: super::Factory) { evm_test!{test_sdiv: test_sdiv_int} fn test_sdiv(factory: super::Factory) { - let code = "650123651246236265432290056000556501236512462360009005600155".from_hex().unwrap(); + let code = hex!("650123651246236265432290056000556501236512462360009005600155").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -495,7 +535,7 @@ fn test_sdiv(factory: super::Factory) { evm_test!{test_exp: test_exp_int} fn test_exp(factory: super::Factory) { - let code = "6016650123651246230a6000556001650123651246230a6001556000650123651246230a600255".from_hex().unwrap(); + let code = hex!("6016650123651246230a6000556001650123651246230a6001556000650123651246230a600255").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -515,7 +555,7 @@ fn test_exp(factory: super::Factory) { evm_test!{test_comparison: test_comparison_int} fn test_comparison(factory: super::Factory) { - let code = "601665012365124623818181811060005511600155146002556415235412358014600355".from_hex().unwrap(); + let code = hex!("601665012365124623818181811060005511600155146002556415235412358014600355").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -536,7 +576,7 @@ fn test_comparison(factory: super::Factory) { evm_test!{test_signed_comparison: test_signed_comparison_int} fn test_signed_comparison(factory: super::Factory) { - let code = "60106000036010818112600055136001556010601060000381811260025513600355".from_hex().unwrap(); + let code = hex!("60106000036010818112600055136001556010601060000381811260025513600355").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -557,7 +597,7 @@ fn test_signed_comparison(factory: super::Factory) { evm_test!{test_bitops: test_bitops_int} fn test_bitops(factory: super::Factory) { - let code = "60ff610ff08181818116600055176001551860025560008015600355198015600455600555".from_hex().unwrap(); + let code = hex!("60ff610ff08181818116600055176001551860025560008015600355198015600455600555").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(150_000); @@ -580,7 +620,7 @@ fn test_bitops(factory: super::Factory) { evm_test!{test_addmod_mulmod: test_addmod_mulmod_int} fn test_addmod_mulmod(factory: super::Factory) { - let code = "60ff60f060108282820860005509600155600060f0601082828208196002550919600355".from_hex().unwrap(); + let code = hex!("60ff60f060108282820860005509600155600060f0601082828208196002550919600355").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -601,7 +641,7 @@ fn test_addmod_mulmod(factory: super::Factory) { evm_test!{test_byte: test_byte_int} fn test_byte(factory: super::Factory) { - let code = "60f061ffff1a600055610fff601f1a600155".from_hex().unwrap(); + let code = hex!("60f061ffff1a600055610fff601f1a600155").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -620,7 +660,7 @@ fn test_byte(factory: super::Factory) { evm_test!{test_signextend: test_signextend_int} fn test_signextend(factory: super::Factory) { - let code = "610fff60020b60005560ff60200b600155".from_hex().unwrap(); + let code = hex!("610fff60020b60005560ff60200b600155").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -640,7 +680,7 @@ fn test_signextend(factory: super::Factory) { #[test] // JIT just returns out of gas fn test_badinstruction_int() { let factory = super::Factory::new(VMType::Interpreter, 1024 * 32); - let code = "af".from_hex().unwrap(); + let code = hex!("af").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -660,7 +700,7 @@ fn test_badinstruction_int() { evm_test!{test_pop: test_pop_int} fn test_pop(factory: super::Factory) { - let code = "60f060aa50600055".from_hex().unwrap(); + let code = hex!("60f060aa50600055").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(100_000); @@ -678,7 +718,7 @@ fn test_pop(factory: super::Factory) { evm_test!{test_extops: test_extops_int} fn test_extops(factory: super::Factory) { - let code = "5a6001555836553a600255386003553460045560016001526016590454600555".from_hex().unwrap(); + let code = hex!("5a6001555836553a600255386003553460045560016001526016590454600555").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(150_000); @@ -703,7 +743,7 @@ fn test_extops(factory: super::Factory) { evm_test!{test_jumps: test_jumps_int} fn test_jumps(factory: super::Factory) { - let code = "600160015560066000555b60016000540380806000551560245760015402600155600a565b".from_hex().unwrap(); + let code = hex!("600160015560066000555b60016000540380806000551560245760015402600155600a565b").to_vec(); let mut params = ActionParams::default(); params.gas = U256::from(150_000); @@ -723,7 +763,7 @@ fn test_jumps(factory: super::Factory) { evm_test!{test_calls: test_calls_int} fn test_calls(factory: super::Factory) { - let code = "600054602d57600160005560006000600060006050610998610100f160006000600060006050610998610100f25b".from_hex().unwrap(); + let code = hex!("600054602d57600160005560006000600060006050610998610100f160006000600060006050610998610100f25b").to_vec(); let address = Address::from_low_u64_be(0x155); let code_address = Address::from_low_u64_be(0x998); @@ -769,7 +809,7 @@ fn test_calls(factory: super::Factory) { 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 code = hex!("600060006064f000").to_vec(); let address = Address::from_low_u64_be(0x155); let mut params = ActionParams::default(); @@ -793,68 +833,68 @@ fn test_shl(factory: super::Factory) { push_two_pop_one_constantinople_test( &factory, 0x1b, - "0000000000000000000000000000000000000000000000000000000000000001", - "00", + hex!("0000000000000000000000000000000000000000000000000000000000000001").to_vec(), + hex!("00").to_vec(), "0000000000000000000000000000000000000000000000000000000000000001"); push_two_pop_one_constantinople_test( &factory, 0x1b, - "0000000000000000000000000000000000000000000000000000000000000001", - "01", + hex!("0000000000000000000000000000000000000000000000000000000000000001").to_vec(), + hex!("01").to_vec(), "0000000000000000000000000000000000000000000000000000000000000002"); push_two_pop_one_constantinople_test( &factory, 0x1b, - "0000000000000000000000000000000000000000000000000000000000000001", - "ff", + hex!("0000000000000000000000000000000000000000000000000000000000000001").to_vec(), + hex!("ff").to_vec(), "8000000000000000000000000000000000000000000000000000000000000000"); push_two_pop_one_constantinople_test( &factory, 0x1b, - "0000000000000000000000000000000000000000000000000000000000000001", - "0100", + hex!("0000000000000000000000000000000000000000000000000000000000000001").to_vec(), + hex!("0100").to_vec(), "0000000000000000000000000000000000000000000000000000000000000000"); push_two_pop_one_constantinople_test( &factory, 0x1b, - "0000000000000000000000000000000000000000000000000000000000000001", - "0101", + hex!("0000000000000000000000000000000000000000000000000000000000000001").to_vec(), + hex!("0101").to_vec(), "0000000000000000000000000000000000000000000000000000000000000000"); push_two_pop_one_constantinople_test( &factory, 0x1b, - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "00", + hex!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("00").to_vec(), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); push_two_pop_one_constantinople_test( &factory, 0x1b, - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "01", + hex!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("01").to_vec(), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"); push_two_pop_one_constantinople_test( &factory, 0x1b, - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "ff", + hex!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("ff").to_vec(), "8000000000000000000000000000000000000000000000000000000000000000"); push_two_pop_one_constantinople_test( &factory, 0x1b, - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "0100", + hex!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("0100").to_vec(), "0000000000000000000000000000000000000000000000000000000000000000"); push_two_pop_one_constantinople_test( &factory, 0x1b, - "0000000000000000000000000000000000000000000000000000000000000000", - "01", + hex!("0000000000000000000000000000000000000000000000000000000000000000").to_vec(), + hex!("01").to_vec(), "0000000000000000000000000000000000000000000000000000000000000000"); push_two_pop_one_constantinople_test( &factory, 0x1b, - "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "01", + hex!("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("01").to_vec(), "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"); } @@ -863,68 +903,68 @@ fn test_shr(factory: super::Factory) { push_two_pop_one_constantinople_test( &factory, 0x1c, - "0000000000000000000000000000000000000000000000000000000000000001", - "00", + hex!("0000000000000000000000000000000000000000000000000000000000000001").to_vec(), + hex!("00").to_vec(), "0000000000000000000000000000000000000000000000000000000000000001"); push_two_pop_one_constantinople_test( &factory, 0x1c, - "0000000000000000000000000000000000000000000000000000000000000001", - "01", + hex!("0000000000000000000000000000000000000000000000000000000000000001").to_vec(), + hex!("01").to_vec(), "0000000000000000000000000000000000000000000000000000000000000000"); push_two_pop_one_constantinople_test( &factory, 0x1c, - "8000000000000000000000000000000000000000000000000000000000000000", - "01", + hex!("8000000000000000000000000000000000000000000000000000000000000000").to_vec(), + hex!("01").to_vec(), "4000000000000000000000000000000000000000000000000000000000000000"); push_two_pop_one_constantinople_test( &factory, 0x1c, - "8000000000000000000000000000000000000000000000000000000000000000", - "ff", + hex!("8000000000000000000000000000000000000000000000000000000000000000").to_vec(), + hex!("ff").to_vec(), "0000000000000000000000000000000000000000000000000000000000000001"); push_two_pop_one_constantinople_test( &factory, 0x1c, - "8000000000000000000000000000000000000000000000000000000000000000", - "0100", + hex!("8000000000000000000000000000000000000000000000000000000000000000").to_vec(), + hex!("0100").to_vec(), "0000000000000000000000000000000000000000000000000000000000000000"); push_two_pop_one_constantinople_test( &factory, 0x1c, - "8000000000000000000000000000000000000000000000000000000000000000", - "0101", + hex!("8000000000000000000000000000000000000000000000000000000000000000").to_vec(), + hex!("0101").to_vec(), "0000000000000000000000000000000000000000000000000000000000000000"); push_two_pop_one_constantinople_test( &factory, 0x1c, - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "00", + hex!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("00").to_vec(), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); push_two_pop_one_constantinople_test( &factory, 0x1c, - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "01", + hex!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("01").to_vec(), "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); push_two_pop_one_constantinople_test( &factory, 0x1c, - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "ff", + hex!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("ff").to_vec(), "0000000000000000000000000000000000000000000000000000000000000001"); push_two_pop_one_constantinople_test( &factory, 0x1c, - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "0100", + hex!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("0100").to_vec(), "0000000000000000000000000000000000000000000000000000000000000000"); push_two_pop_one_constantinople_test( &factory, 0x1c, - "0000000000000000000000000000000000000000000000000000000000000000", - "01", + hex!("0000000000000000000000000000000000000000000000000000000000000000").to_vec(), + hex!("01").to_vec(), "0000000000000000000000000000000000000000000000000000000000000000"); } @@ -933,104 +973,102 @@ fn test_sar(factory: super::Factory) { push_two_pop_one_constantinople_test( &factory, 0x1d, - "0000000000000000000000000000000000000000000000000000000000000001", - "00", + hex!("0000000000000000000000000000000000000000000000000000000000000001").to_vec(), + hex!("00").to_vec(), "0000000000000000000000000000000000000000000000000000000000000001"); push_two_pop_one_constantinople_test( &factory, 0x1d, - "0000000000000000000000000000000000000000000000000000000000000001", - "01", + hex!("0000000000000000000000000000000000000000000000000000000000000001").to_vec(), + hex!("01").to_vec(), "0000000000000000000000000000000000000000000000000000000000000000"); push_two_pop_one_constantinople_test( &factory, 0x1d, - "8000000000000000000000000000000000000000000000000000000000000000", - "01", + hex!("8000000000000000000000000000000000000000000000000000000000000000").to_vec(), + hex!("01").to_vec(), "c000000000000000000000000000000000000000000000000000000000000000"); push_two_pop_one_constantinople_test( &factory, 0x1d, - "8000000000000000000000000000000000000000000000000000000000000000", - "ff", + hex!("8000000000000000000000000000000000000000000000000000000000000000").to_vec(), + hex!("ff").to_vec(), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); push_two_pop_one_constantinople_test( &factory, 0x1d, - "8000000000000000000000000000000000000000000000000000000000000000", - "0100", + hex!("8000000000000000000000000000000000000000000000000000000000000000").to_vec(), + hex!("0100").to_vec(), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); push_two_pop_one_constantinople_test( &factory, 0x1d, - "8000000000000000000000000000000000000000000000000000000000000000", - "0101", + hex!("8000000000000000000000000000000000000000000000000000000000000000").to_vec(), + hex!("0101").to_vec(), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); push_two_pop_one_constantinople_test( &factory, 0x1d, - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "00", + hex!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("00").to_vec(), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); push_two_pop_one_constantinople_test( &factory, 0x1d, - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "01", + hex!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("01").to_vec(), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); push_two_pop_one_constantinople_test( &factory, 0x1d, - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "ff", + hex!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("ff").to_vec(), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); push_two_pop_one_constantinople_test( &factory, 0x1d, - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "0100", + hex!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("0100").to_vec(), "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); push_two_pop_one_constantinople_test( &factory, 0x1d, - "0000000000000000000000000000000000000000000000000000000000000000", - "01", + hex!("0000000000000000000000000000000000000000000000000000000000000000").to_vec(), + hex!("01").to_vec(), "0000000000000000000000000000000000000000000000000000000000000000"); push_two_pop_one_constantinople_test( &factory, 0x1d, - "4000000000000000000000000000000000000000000000000000000000000000", - "fe", + hex!("4000000000000000000000000000000000000000000000000000000000000000").to_vec(), + hex!("fe").to_vec(), "0000000000000000000000000000000000000000000000000000000000000001"); push_two_pop_one_constantinople_test( &factory, 0x1d, - "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "f8", + hex!("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("f8").to_vec(), "000000000000000000000000000000000000000000000000000000000000007f"); push_two_pop_one_constantinople_test( &factory, 0x1d, - "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "fe", + hex!("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("fe").to_vec(), "0000000000000000000000000000000000000000000000000000000000000001"); push_two_pop_one_constantinople_test( &factory, 0x1d, - "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "ff", + hex!("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("ff").to_vec(), "0000000000000000000000000000000000000000000000000000000000000000"); push_two_pop_one_constantinople_test( &factory, 0x1d, - "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "0100", + hex!("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), + hex!("0100").to_vec(), "0000000000000000000000000000000000000000000000000000000000000000"); } -fn push_two_pop_one_constantinople_test(factory: &super::Factory, opcode: u8, push1: &str, push2: &str, result: &str) { - let mut push1 = push1.from_hex().unwrap(); - let mut push2 = push2.from_hex().unwrap(); +fn push_two_pop_one_constantinople_test(factory: &super::Factory, opcode: u8, mut push1: Vec, mut push2: Vec, result: &str) { assert!(push1.len() <= 32 && push1.len() != 0); assert!(push2.len() <= 32 && push2.len() != 0); diff --git a/ethcore/machine/src/externalities.rs b/ethcore/machine/src/externalities.rs index d002f07be..b951eba16 100644 --- a/ethcore/machine/src/externalities.rs +++ b/ethcore/machine/src/externalities.rs @@ -416,6 +416,10 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B> self.env_info } + fn chain_id(&self) -> u64 { + self.machine.params().chain_id + } + fn depth(&self) -> usize { self.depth } diff --git a/ethcore/src/json_tests/executive.rs b/ethcore/src/json_tests/executive.rs index 514206fdd..2ce13f6f0 100644 --- a/ethcore/src/json_tests/executive.rs +++ b/ethcore/src/json_tests/executive.rs @@ -216,6 +216,8 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for TestExt<'a, T, V, B> self.ext.env_info() } + fn chain_id(&self) -> u64 { 0 } + fn depth(&self) -> usize { 0 } diff --git a/ethcore/types/src/engines/params.rs b/ethcore/types/src/engines/params.rs index 4b6fba31d..fc8eb9667 100644 --- a/ethcore/types/src/engines/params.rs +++ b/ethcore/types/src/engines/params.rs @@ -90,6 +90,8 @@ pub struct CommonParams { pub eip1283_disable_transition: BlockNumber, /// Number of first block where EIP-1014 rules begin. pub eip1014_transition: BlockNumber, + /// Number of first block where EIP-1344 rules begin: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1344.md + pub eip1344_transition: BlockNumber, /// Number of first block where EIP-2028 rules begin. pub eip2028_transition: BlockNumber, /// Number of first block where dust cleanup rules (EIP-168 and EIP169) begin. @@ -161,6 +163,7 @@ impl CommonParams { schedule.have_return_data = block_number >= self.eip211_transition; schedule.have_bitwise_shifting = block_number >= self.eip145_transition; schedule.have_extcodehash = block_number >= self.eip1052_transition; + schedule.have_chain_id = block_number >= self.eip1344_transition; schedule.eip1283 = block_number >= self.eip1283_transition && !(block_number >= self.eip1283_disable_transition); if block_number >= self.eip2028_transition { schedule.tx_data_non_zero_gas = 16; @@ -282,6 +285,10 @@ impl From for CommonParams { BlockNumber::max_value, Into::into, ), + eip1344_transition: p.eip1344_transition.map_or_else( + BlockNumber::max_value, + Into::into, + ), eip2028_transition: p.eip2028_transition.map_or_else( BlockNumber::max_value, Into::into, diff --git a/ethcore/vm/src/env_info.rs b/ethcore/vm/src/env_info.rs index 6c602d80f..6dc742938 100644 --- a/ethcore/vm/src/env_info.rs +++ b/ethcore/vm/src/env_info.rs @@ -65,7 +65,7 @@ impl From for EnvInfo { fn from(e: ethjson::vm::Env) -> Self { let number = e.number.into(); EnvInfo { - number: number, + number, author: e.author.into(), difficulty: e.difficulty.into(), gas_limit: e.gas_limit.into(), diff --git a/ethcore/vm/src/ext.rs b/ethcore/vm/src/ext.rs index ba6849589..63d9595fb 100644 --- a/ethcore/vm/src/ext.rs +++ b/ethcore/vm/src/ext.rs @@ -145,6 +145,9 @@ pub trait Ext { /// Returns environment info. fn env_info(&self) -> &EnvInfo; + /// Returns the chain ID of the blockchain + fn chain_id(&self) -> u64; + /// Returns current depth of execution. /// /// If contract A calls contract B, and contract B calls C, diff --git a/ethcore/vm/src/schedule.rs b/ethcore/vm/src/schedule.rs index 66c2391ac..e11603ecd 100644 --- a/ethcore/vm/src/schedule.rs +++ b/ethcore/vm/src/schedule.rs @@ -122,6 +122,8 @@ pub struct Schedule { pub have_return_data: bool, /// SHL, SHR, SAR opcodes enabled. pub have_bitwise_shifting: bool, + /// CHAINID opcode enabled. + pub have_chain_id: bool, /// Kill basic accounts below this balance if touched. pub kill_dust: CleanDustMode, /// Enable EIP-1283 rules @@ -220,6 +222,7 @@ impl Schedule { have_revert: false, have_return_data: false, have_bitwise_shifting: false, + have_chain_id: false, have_extcodehash: false, stack_limit: 1024, max_depth: 1024, @@ -291,6 +294,7 @@ impl Schedule { /// Schedule for the Istanbul fork of the Ethereum main net. pub fn new_istanbul() -> Schedule { let mut schedule = Self::new_constantinople(); + schedule.have_chain_id = true; schedule.tx_data_non_zero_gas = 16; schedule } @@ -303,6 +307,7 @@ impl Schedule { have_revert: false, have_return_data: false, have_bitwise_shifting: false, + have_chain_id: false, have_extcodehash: false, stack_limit: 1024, max_depth: 1024, diff --git a/ethcore/vm/src/tests.rs b/ethcore/vm/src/tests.rs index b6709d6ef..40ae0dac4 100644 --- a/ethcore/vm/src/tests.rs +++ b/ethcore/vm/src/tests.rs @@ -67,6 +67,8 @@ pub struct FakeExt { pub balances: HashMap, pub tracing: bool, pub is_static: bool, + + chain_id: u64, } // similar to the normal `finalize` function, but ignoring NeedsReturn. @@ -98,7 +100,7 @@ impl FakeExt { ext } - /// New fake externalities with constantinople schedule rules + /// New fake externalities with Istanbul schedule rules pub fn new_istanbul() -> Self { let mut ext = FakeExt::default(); ext.schedule = Schedule::new_istanbul(); @@ -110,6 +112,12 @@ impl FakeExt { self.schedule.wasm = Some(Default::default()); self } + + /// Set chain ID + pub fn with_chain_id(mut self, chain_id: u64) -> Self { + self.chain_id = chain_id; + self + } } impl Ext for FakeExt { @@ -208,7 +216,7 @@ impl Ext for FakeExt { fn log(&mut self, topics: Vec, data: &[u8]) -> Result<()> { self.logs.push(FakeLogEntry { - topics: topics, + topics, data: data.to_vec() }); Ok(()) @@ -231,6 +239,10 @@ impl Ext for FakeExt { &self.info } + fn chain_id(&self) -> u64 { + self.chain_id + } + fn depth(&self) -> usize { self.depth } diff --git a/json/src/spec/params.rs b/json/src/spec/params.rs index 68093db20..29c842b87 100644 --- a/json/src/spec/params.rs +++ b/json/src/spec/params.rs @@ -94,6 +94,8 @@ pub struct Params { /// See `CommonParams` docs. pub eip1014_transition: Option, /// See `CommonParams` docs. + pub eip1344_transition: Option, + /// See `CommonParams` docs. pub eip2028_transition: Option, /// See `CommonParams` docs. pub dust_protection_transition: Option, diff --git a/parity/informant.rs b/parity/informant.rs index 60ba59f7b..e4511aff4 100644 --- a/parity/informant.rs +++ b/parity/informant.rs @@ -24,7 +24,7 @@ use std::time::{Instant, Duration}; use atty; use ethcore::client::{ChainNotify, NewBlocks, Client}; -use client_traits::{BlockInfo, ChainInfo, BlockChainClient, IoClient}; +use client_traits::{BlockInfo, ChainInfo, BlockChainClient}; use types::{ BlockNumber, client_types::ClientReport, diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index ff8fa9325..27b2b6fda 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -67,7 +67,6 @@ account-state = { path = "../ethcore/account-state" } stats = { path = "../util/stats" } trace = { path = "../ethcore/trace" } vm = { path = "../ethcore/vm" } -verification = { path = "../ethcore/verification" } [dev-dependencies] client-traits = { path = "../ethcore/client-traits" } @@ -80,6 +79,7 @@ macros = { path = "../util/macros" } spec = { path = "../ethcore/spec" } pretty_assertions = "0.1" transaction-pool = "2.0" +verification = { path = "../ethcore/verification" } [features] accounts = ["ethcore-accounts"] diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 5bff93582..5cb96fa1f 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -89,7 +89,6 @@ extern crate account_state; extern crate stats; extern crate tempdir; extern crate trace; -extern crate verification; extern crate vm; #[cfg(any(test, feature = "ethcore-accounts"))] @@ -130,6 +129,8 @@ extern crate ethcore_io as io; #[cfg(test)] extern crate spec; +#[cfg(test)] +extern crate verification; pub extern crate jsonrpc_ws_server as ws;