Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHAINID opcode - 256 bit version #190

Merged
merged 2 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/
Expand Down
8 changes: 7 additions & 1 deletion lib/evmone/instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint256>(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<uint256>(state.host.get_tx_context().tx_origin));
Expand Down Expand Up @@ -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};
Expand Down
20 changes: 11 additions & 9 deletions test/unittests/evm_state_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down