Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5708 from ethereum/chainin-opcode-interpreter
Browse files Browse the repository at this point in the history
Implement EIP-1344: CHAINID opcode in aleth-interpreter
gumb0 authored Aug 22, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 91e9883 + d9002e0 commit 67ceda4
Showing 6 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
- Added: [#5634](https://github.com/ethereum/aleth/pull/5634) Bootnodes for Rinkeby and Goerli.
- Added: [#5640](https://github.com/ethereum/aleth/pull/5640) Support EIP-1702 Generalized Account Versioning Scheme (active only in Experimental fork.)
- Added: [#5691](https://github.com/ethereum/aleth/pull/5691) Istanbul support: EIP-2028 Transaction data gas cost reduction.
- Added: [#5696](https://github.com/ethereum/aleth/pull/5696) Istanbul support: EIP-1344 ChainID opcode.
- Added: [#5696](https://github.com/ethereum/aleth/pull/5708) [#5696](https://github.com/ethereum/aleth/pull/5708) Istanbul support: EIP-1344 ChainID opcode.
- Added: [#5701](https://github.com/ethereum/aleth/issues/5701) Outputs ENR text representation in admin.nodeInfo RPC.
- Added: [#5707](https://github.com/ethereum/aleth/pull/5707) Aleth waits for 2 seconds after sending disconnect to peer before closing socket.
- Changed: [#5532](https://github.com/ethereum/aleth/pull/5532) The leveldb is upgraded to 1.22. This is breaking change on Windows and the old databases are not compatible.
14 changes: 14 additions & 0 deletions libaleth-interpreter/VM.cpp
Original file line number Diff line number Diff line change
@@ -1154,6 +1154,20 @@ void VM::interpretCases()
}
NEXT


CASE(CHAINID)
{
ON_OP();

if (m_rev < EVMC_ISTANBUL)
throwBadInstruction();

updateIOGas();

m_SPP[0] = fromEvmC(getTxContext().chain_id);
}
NEXT

CASE(POP)
{
ON_OP();
2 changes: 1 addition & 1 deletion libaleth-interpreter/VMConfig.h
Original file line number Diff line number Diff line change
@@ -222,7 +222,7 @@ namespace eth
&&NUMBER, \
&&DIFFICULTY, \
&&GASLIMIT, \
&&INVALID, \
&&CHAINID, \
&&INVALID, \
&&INVALID, \
&&INVALID, \
13 changes: 8 additions & 5 deletions libevm/ExtVMFace.cpp
Original file line number Diff line number Diff line change
@@ -142,11 +142,14 @@ evmc_tx_context EvmCHost::get_tx_context() noexcept
evmc_tx_context result = {};
result.tx_gas_price = toEvmC(m_extVM.gasPrice);
result.tx_origin = toEvmC(m_extVM.origin);
result.block_coinbase = toEvmC(m_extVM.envInfo().author());
result.block_number = m_extVM.envInfo().number();
result.block_timestamp = m_extVM.envInfo().timestamp();
result.block_gas_limit = static_cast<int64_t>(m_extVM.envInfo().gasLimit());
result.block_difficulty = toEvmC(m_extVM.envInfo().difficulty());

auto const& envInfo = m_extVM.envInfo();
result.block_coinbase = toEvmC(envInfo.author());
result.block_number = envInfo.number();
result.block_timestamp = envInfo.timestamp();
result.block_gas_limit = static_cast<int64_t>(envInfo.gasLimit());
result.block_difficulty = toEvmC(envInfo.difficulty());
result.chain_id = toEvmC(envInfo.chainID());
return result;
}

20 changes: 20 additions & 0 deletions test/unittests/libevm/VMTest.cpp
Original file line number Diff line number Diff line change
@@ -570,6 +570,13 @@ class LegacyVMChainIDTestFixture : public ChainIDTestFixture
LegacyVMChainIDTestFixture() : ChainIDTestFixture{new LegacyVM} {}
};

class AlethInterpreterChainIDTestFixture : public ChainIDTestFixture
{
public:
AlethInterpreterChainIDTestFixture() : ChainIDTestFixture{new EVMC{evmc_create_interpreter()}}
{}
};

} // namespace

BOOST_FIXTURE_TEST_SUITE(LegacyVMSuite, TestOutputHelperFixture)
@@ -937,4 +944,17 @@ BOOST_AUTO_TEST_CASE(AlethInterpreterSstoreEip1283Case17)

BOOST_AUTO_TEST_SUITE_END()

BOOST_FIXTURE_TEST_SUITE(AlethInterpreterChainIDSuite, AlethInterpreterChainIDTestFixture)

BOOST_AUTO_TEST_CASE(AlethInterpreterChainIDworksInIstanbul)
{
testChainIDWorksInIstanbul();
}

BOOST_AUTO_TEST_CASE(AlethInterpreterChainIDisInvalidBeforeIstanbul)
{
testChainIDisInvalidBeforeIstanbul();
}
BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 67ceda4

Please sign in to comment.