Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ Documentation of all notable changes to the **EVMC** project.
The format is based on [Keep a Changelog],
and this project adheres to [Semantic Versioning].

## [7.0.0] - unreleased

### Added

- Support for Istanbul CHAINID opcode. `chain_id` added to `evmc_tx_context` struct.
[[#375](https://github.com/ethereum/evmc/pull/375)]

## [6.3.1] - 2019-08-19

### Added
Expand Down Expand Up @@ -340,6 +347,7 @@ and this project adheres to [Semantic Versioning].
[[#52](https://github.com/ethereum/evmc/pull/52)]


[7.0.0]: https://github.com/ethereum/evmc/compare/v6.3.1...master
[6.3.1]: https://github.com/ethereum/evmc/releases/tag/v6.3.1
[6.3.0]: https://github.com/ethereum/evmc/releases/tag/v6.3.0
[6.2.2]: https://github.com/ethereum/evmc/releases/tag/v6.2.2
Expand Down
2 changes: 2 additions & 0 deletions bindings/go/evmc/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type TxContext struct {
Timestamp int64
GasLimit int64
Difficulty common.Hash
ChainID common.Hash
}

type HostContext interface {
Expand Down Expand Up @@ -181,6 +182,7 @@ func getTxContext(pCtx unsafe.Pointer) C.struct_evmc_tx_context {
C.int64_t(txContext.Timestamp),
C.int64_t(txContext.GasLimit),
evmcBytes32(txContext.Difficulty),
evmcBytes32(txContext.ChainID),
}
}

Expand Down
1 change: 1 addition & 0 deletions bindings/rust/evmc-vm/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ mod tests {
block_timestamp: 0,
block_gas_limit: 0,
block_difficulty: Uint256::default(),
chain_id: Uint256::default(),
}
}

Expand Down
1 change: 1 addition & 0 deletions bindings/rust/evmc-vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ mod tests {
block_timestamp: 235117,
block_gas_limit: 105023,
block_difficulty: Uint256 { bytes: [0xaa; 32] },
chain_id: Uint256::default(),
}
}

Expand Down
1 change: 1 addition & 0 deletions include/evmc/evmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ struct evmc_tx_context
int64_t block_timestamp; /**< The block timestamp. */
int64_t block_gas_limit; /**< The block gas limit. */
evmc_uint256be block_difficulty; /**< The block difficulty. */
evmc_uint256be chain_id; /**< The blockchain's ChainID. */
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is contentious. There is a long discussion on https://ethereum-magicians.org/t/eip-1344-add-chain-id-opcode/1131/56

However many say it should be a hash, e.g. bytes32, however the calculation done the transaction format requires it to be a number.

Geth uses 256-bit, Parity 64-bit and Pantheon 32-bit numbers for chain id.

};

struct evmc_context;
Expand Down
3 changes: 1 addition & 2 deletions include/evmc/evmc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,7 @@ inline void emit_log(evmc_context* h,

constexpr evmc_host_interface interface{
account_exists, get_storage, set_storage, get_balance, get_code_size, get_code_hash,
copy_code, selfdestruct, call, get_tx_context, get_block_hash, emit_log,
};
copy_code, selfdestruct, call, get_tx_context, get_block_hash, emit_log};
} // namespace internal

inline Host::Host() noexcept : evmc_context{&evmc::internal::interface} {}
Expand Down
1 change: 1 addition & 0 deletions include/evmc/instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ enum evmc_opcode
OP_NUMBER = 0x43,
OP_DIFFICULTY = 0x44,
OP_GASLIMIT = 0x45,
OP_CHAINID = 0x46,

OP_POP = 0x50,
OP_MLOAD = 0x51,
Expand Down
2 changes: 1 addition & 1 deletion lib/instructions/instruction_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static struct evmc_instruction_metrics istanbul_metrics[256] = {
/* NUMBER = 0x43 */ {BASE, 0, 1},
/* DIFFICULTY = 0x44 */ {BASE, 0, 1},
/* GASLIMIT = 0x45 */ {BASE, 0, 1},
/* = 0x46 */ {UNDEFINED, 0, 0},
/* CHAINID = 0x46 */ {BASE, 0, 1},
/* = 0x47 */ {UNDEFINED, 0, 0},
/* = 0x48 */ {UNDEFINED, 0, 0},
/* = 0x49 */ {UNDEFINED, 0, 0},
Expand Down
2 changes: 1 addition & 1 deletion lib/instructions/instruction_names.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static const char* istanbul_names[256] = {
/* 0x43 */ "NUMBER",
/* 0x44 */ "DIFFICULTY",
/* 0x45 */ "GASLIMIT",
/* 0x46 */ NULL,
/* 0x46 */ "CHAINID",
/* 0x47 */ NULL,
/* 0x48 */ NULL,
/* 0x49 */ NULL,
Expand Down
18 changes: 16 additions & 2 deletions test/unittests/test_instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,21 @@ TEST(instructions, istanbul_hard_fork)

for (int op{OP_STOP}; op <= OP_SELFDESTRUCT; ++op)
{
EXPECT_EQ(i[op], p[op]) << op;
EXPECT_STREQ(in[op], pn[op]) << op;
switch (op)
{
case OP_CHAINID:
continue;
default:
EXPECT_EQ(i[op], p[op]) << op;
EXPECT_STREQ(in[op], pn[op]) << op;
break;
}
}

EXPECT_EQ(i[OP_CHAINID].gas_cost, 2);
EXPECT_EQ(i[OP_CHAINID].num_stack_arguments, 0);
EXPECT_EQ(i[OP_CHAINID].num_stack_returned_items, 1);
EXPECT_EQ(p[OP_CHAINID].gas_cost, -1);
EXPECT_EQ(in[OP_CHAINID], std::string{"CHAINID"});
EXPECT_TRUE(pn[OP_CHAINID] == nullptr);
}