diff --git a/silkworm/core/execution/evm.cpp b/silkworm/core/execution/evm.cpp index 90a7e0db..af059071 100644 --- a/silkworm/core/execution/evm.cpp +++ b/silkworm/core/execution/evm.cpp @@ -367,6 +367,10 @@ void EVM::add_tracer(EvmTracer& tracer) noexcept { bool EVM::account_exists(const evmc::address& address) const noexcept { const evmc_revision rev{revision()}; + if(get_eos_evm_version() >= 1 && is_reserved_address(address)) { + return true; + } + if (rev >= EVMC_SPURIOUS_DRAGON) { return !state_.is_dead(address); } else { diff --git a/silkworm/core/execution/evm.hpp b/silkworm/core/execution/evm.hpp index e7eda46a..8fa681e0 100644 --- a/silkworm/core/execution/evm.hpp +++ b/silkworm/core/execution/evm.hpp @@ -113,7 +113,7 @@ class EVM { return gas_params_; } - uint64_t get_eos_evm_version() { + uint64_t get_eos_evm_version()const { return eos_evm_version_; } diff --git a/silkworm/core/execution/evm_test.cpp b/silkworm/core/execution/evm_test.cpp index ec80ca2e..6ccb0e15 100644 --- a/silkworm/core/execution/evm_test.cpp +++ b/silkworm/core/execution/evm_test.cpp @@ -789,4 +789,46 @@ TEST_CASE("EOS EVM G_txnewaccount") { } +TEST_CASE("EOS EVM send value to reserved address (tx)") { + + auto send_tx_to_reserved_address = [&](uint64_t version, const evmone::gas_parameters& gas_params, uint64_t gas_limit) { + + Block block{}; + block.header.number = 1; + block.header.nonce = eosevm::version_to_nonce(version); + + evmc::address sender{0x0a6bb546b9208cfab9e8fa2b9b2c042b18df7030_address}; + evmc::address receiver1{make_reserved_address(0x3ab3400000000000)}; //beto + + InMemoryState db; + IntraBlockState state{db}; + state.set_balance(sender, intx::uint256{1e18}); + EVM evm{block, state, test::kIstanbulTrustConfig, gas_params}; + + Transaction txn{}; + txn.from = sender; + txn.to = receiver1; + txn.value = intx::uint256{1}; + + CallResult res = evm.execute(txn, gas_limit); + return res; + }; + + evmone::gas_parameters gas_params; + + //version = 1, G_txnewaccount = 0, gas_limit = 1000 + gas_params.G_txnewaccount = 0; + auto res1 = send_tx_to_reserved_address(1, gas_params, 1000); + CHECK(res1.status == EVMC_SUCCESS); + CHECK(res1.gas_left == 1000); + CHECK(res1.gas_refund == 0); + + //version = 2, G_txnewaccount = 5000, gas_limit = 4999 + gas_params.G_txnewaccount = 5000; + auto res2 = send_tx_to_reserved_address(1, gas_params, 4999); + CHECK(res2.status == EVMC_SUCCESS); + CHECK(res2.gas_left == 4999); + CHECK(res2.gas_refund == 0); +} + } // namespace silkworm diff --git a/silkworm/core/execution/processor_test.cpp b/silkworm/core/execution/processor_test.cpp index 5feb5ac0..c785e2a0 100644 --- a/silkworm/core/execution/processor_test.cpp +++ b/silkworm/core/execution/processor_test.cpp @@ -126,7 +126,7 @@ TEST_CASE("No refund on error") { TEST_CASE("refund eosevm v2") { - auto deploy_and_execute = [&](uint64_t v) { + auto deploy_and_execute = [&](uint64_t v, uint64_t times=10) { Block block{}; block.header.number = 10'050'107; block.header.gas_limit = 10'000'000; @@ -176,7 +176,7 @@ TEST_CASE("refund eosevm v2") { // Call run(10) on the newly created contract //a444f5e9 = run, 00..0a = 10 txn.nonce = nonce + 1; txn.to = create_address(caller, nonce); - txn.data = *from_hex("a444f5e9000000000000000000000000000000000000000000000000000000000000000a"); + txn.data = *from_hex("a444f5e9" + to_hex(evmc::bytes32{times})); txn.gas_limit = 800'000; Receipt receipt2; @@ -193,6 +193,9 @@ TEST_CASE("refund eosevm v2") { auto gas_used_v2 = deploy_and_execute(2); CHECK(gas_used_v2 == 27760); + + auto gas_used_v2_0_times = deploy_and_execute(2, 0); + CHECK(gas_used_v2_0_times == 21608); } diff --git a/third_party/evmone b/third_party/evmone index 2eb456db..ffa70aa4 160000 --- a/third_party/evmone +++ b/third_party/evmone @@ -1 +1 @@ -Subproject commit 2eb456db439c28592131623e491b21990cabc867 +Subproject commit ffa70aa4fcd7a5f8b7af3df8e5a61277ebc6b0aa