diff --git a/CHANGELOG.md b/CHANGELOG.md index d60760cf1e..b2a83446aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ Documentation of all notable changes to the **evmone** project. The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning]. + +## [0.3.0] - unreleased + +### Added + +- **Istanbul** EVM revision support with new costs for some instructions ([EIP-1884]). + [#191](https://github.com/ethereum/evmone/pull/191) +- Implementation of CHAINID instruction from the **Istanbul** EVM revision ([EIP-1344]). + [#190](https://github.com/ethereum/evmone/pull/190) + + ## [0.2.0] - 2019-09-24 This release of evmone is binary compatible with 0.1 and delivers big performance improvements @@ -106,11 +117,14 @@ It delivers fully-compatible and high-speed EVM implementation. - The [intx 0.2.0](https://github.com/chfast/intx/releases/tag/v0.2.0) library is used for 256-bit precision arithmetic. +[0.3.0]: https://github.com/ethereum/evmone/compare/v0.2.0..master [0.2.0]: https://github.com/ethereum/evmone/releases/tag/v0.2.0 [0.1.1]: https://github.com/ethereum/evmone/releases/tag/v0.1.1 [0.1.0]: https://github.com/ethereum/evmone/releases/tag/v0.1.0 [Aleth]: https://github.com/ethereum/aleth +[EIP-1884]: https://eips.ethereum.org/EIPS/eip-1884 +[EIP-1344]: https://eips.ethereum.org/EIPS/eip-1344 [EVMC]: https://github.com/ethereum/evmc [intx]: https://github.com/chfast/intx [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/ diff --git a/lib/evmone/instructions.cpp b/lib/evmone/instructions.cpp index 5a33b1dec8..3e90958ac9 100644 --- a/lib/evmone/instructions.cpp +++ b/lib/evmone/instructions.cpp @@ -330,6 +330,12 @@ const instruction* op_balance(const instruction* instr, execution_state& state) return ++instr; } +const instruction* op_chainid(const instruction* instr, execution_state& state) noexcept +{ + state.stack.push(intx::be::load(state.host.get_tx_context().chain_id)); + return ++instr; +} + const instruction* op_origin(const instruction* instr, execution_state& state) noexcept { state.stack.push(intx::be::load(state.host.get_tx_context().tx_origin)); @@ -1378,7 +1384,7 @@ constexpr op_table create_op_table_istanbul() noexcept { auto table = create_op_table_constantinople(); table[OP_BALANCE] = {op_balance, 700, 1, 0}; - table[OP_CHAINID] = {op_undefined, 2, 0, 1}; + table[OP_CHAINID] = {op_chainid, 2, 0, 1}; table[OP_EXTCODEHASH] = {op_extcodehash, 700, 1, 0}; table[OP_SELFBALANCE] = {op_undefined, 5, 0, 1}; table[OP_SLOAD] = {op_sload, 800, 1, 0}; diff --git a/test/unittests/evm_state_test.cpp b/test/unittests/evm_state_test.cpp index 86e9f08897..579072eb2e 100644 --- a/test/unittests/evm_state_test.cpp +++ b/test/unittests/evm_state_test.cpp @@ -171,26 +171,28 @@ TEST_F(evm_state, sstore_cost) TEST_F(evm_state, tx_context) { + rev = EVMC_ISTANBUL; + host.tx_context.block_timestamp = 0xdd; - host.tx_context.block_coinbase.bytes[1] = 0xcc; host.tx_context.block_number = 0x1100; - host.tx_context.block_difficulty.bytes[1] = 0xdd; host.tx_context.block_gas_limit = 0x990000; - host.tx_context.tx_gas_price.bytes[2] = 0x66; + host.tx_context.chain_id.bytes[28] = 0xaa; + host.tx_context.block_coinbase.bytes[1] = 0xcc; host.tx_context.tx_origin.bytes[2] = 0x55; + host.tx_context.block_difficulty.bytes[1] = 0xdd; + host.tx_context.tx_gas_price.bytes[2] = 0x66; - std::string s; - s += "4241173a17"; // TIMESTAMP COINBASE OR GASPRICE OR - s += "4317441745173217"; // NUMBER OR DIFFICULTY OR GASLIMIT OR ORIGIN OR - s += "600052"; // m[0..] = - s += "60206000f3"; // RETURN(0,32) - execute(47, s); + auto const code = bytecode{} + OP_TIMESTAMP + OP_COINBASE + OP_OR + OP_GASPRICE + OP_OR + + OP_NUMBER + OP_OR + OP_DIFFICULTY + OP_OR + OP_GASLIMIT + OP_OR + OP_ORIGIN + + OP_OR + OP_CHAINID + OP_OR + ret_top(); + execute(52, code); EXPECT_EQ(result.status_code, EVMC_SUCCESS); EXPECT_EQ(result.gas_left, 0); ASSERT_EQ(result.output_size, 32); EXPECT_EQ(result.output_data[31], 0xdd); EXPECT_EQ(result.output_data[30], 0x11); EXPECT_EQ(result.output_data[29], 0x99); + EXPECT_EQ(result.output_data[28], 0xaa); EXPECT_EQ(result.output_data[14], 0x55); EXPECT_EQ(result.output_data[13], 0xcc); EXPECT_EQ(result.output_data[2], 0x66);