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

[1.0] Change EVM::account_exists to return true for reserved addresses if eos_evm_version >= 1 #167

Merged
merged 1 commit into from
Jun 26, 2024
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
4 changes: 4 additions & 0 deletions silkworm/core/execution/evm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion silkworm/core/execution/evm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
}

Expand Down
42 changes: 42 additions & 0 deletions silkworm/core/execution/evm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 5 additions & 2 deletions silkworm/core/execution/processor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}


Expand Down
2 changes: 1 addition & 1 deletion third_party/evmone
Loading