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

evm: apply state diff from evmone APIv2 if enabled #2590

Merged
merged 1 commit into from
Dec 13, 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
2 changes: 1 addition & 1 deletion silkworm/core/execution/execution_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ TEST_CASE("Execute block with tracing") {
std::vector<Receipt> receipts;
const auto rule_set{protocol::rule_set_factory(chain_config)};
REQUIRE(rule_set);
ExecutionProcessor processor{block, *rule_set, state, chain_config, false};
ExecutionProcessor processor{block, *rule_set, state, chain_config, true};

BlockTracer block_tracer{};
processor.evm().add_tracer(block_tracer);
Expand Down
25 changes: 25 additions & 0 deletions silkworm/core/execution/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,31 @@ void ExecutionProcessor::execute_transaction(const Transaction& txn, Receipt& re
receipt.logs.emplace_back(Log{addr, std::move(topics), std::move(data)});
receipt.bloom = logs_bloom(receipt.logs);

if (evm1_v2_) {
// Apply the state diff produced by evmone APIv2 to the state and skip the Silkworm execution.
const auto& state_diff = evm1_receipt.state_diff;
for (const auto& m : state_diff.modified_accounts) {
if (!m.code.empty()) {
state_.create_contract(m.addr);
state_.set_code(m.addr, m.code);
}

auto& acc = state_.get_or_create_object(m.addr);
acc.current->nonce = m.nonce;
acc.current->balance = m.balance;

auto& storage = state_.storage_[m.addr];
for (const auto& [k, v] : m.modified_storage) {
storage.committed[k].original = v;
}
}

for (const auto& a : state_diff.deleted_accounts) {
state_.destruct(a);
}
return;
}

state_.clear_journal_and_substate();

const std::optional<evmc::address> sender{txn.sender()};
Expand Down
10 changes: 5 additions & 5 deletions silkworm/core/execution/processor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ TEST_CASE("Zero gas price") {

InMemoryState state;
auto rule_set{protocol::rule_set_factory(kMainnetConfig)};
ExecutionProcessor processor{block, *rule_set, state, kMainnetConfig, false};
ExecutionProcessor processor{block, *rule_set, state, kMainnetConfig, true};

Receipt receipt;
processor.execute_transaction(txn, receipt);
Expand Down Expand Up @@ -85,7 +85,7 @@ TEST_CASE("No refund on error") {

InMemoryState state;
auto rule_set{protocol::rule_set_factory(kMainnetConfig)};
ExecutionProcessor processor{block, *rule_set, state, kMainnetConfig, false};
ExecutionProcessor processor{block, *rule_set, state, kMainnetConfig, true};

Transaction txn{};
txn.nonce = nonce;
Expand Down Expand Up @@ -179,7 +179,7 @@ TEST_CASE("Self-destruct") {

InMemoryState state;
auto rule_set{protocol::rule_set_factory(kMainnetConfig)};
ExecutionProcessor processor{block, *rule_set, state, kMainnetConfig, false};
ExecutionProcessor processor{block, *rule_set, state, kMainnetConfig, true};

processor.evm().state().add_to_balance(originator, kEther);
processor.evm().state().set_code(caller_address, caller_code);
Expand Down Expand Up @@ -327,7 +327,7 @@ TEST_CASE("Out of Gas during account re-creation") {
txn.set_sender(caller);

auto rule_set{protocol::rule_set_factory(kMainnetConfig)};
ExecutionProcessor processor{block, *rule_set, state, kMainnetConfig, false};
ExecutionProcessor processor{block, *rule_set, state, kMainnetConfig, true};
processor.evm().state().add_to_balance(caller, kEther);

Receipt receipt;
Expand Down Expand Up @@ -370,7 +370,7 @@ TEST_CASE("Empty suicide beneficiary") {
InMemoryState state;

auto rule_set{protocol::rule_set_factory(kMainnetConfig)};
ExecutionProcessor processor{block, *rule_set, state, kMainnetConfig, false};
ExecutionProcessor processor{block, *rule_set, state, kMainnetConfig, true};
processor.evm().state().add_to_balance(caller, kEther);

Receipt receipt;
Expand Down
1 change: 1 addition & 0 deletions silkworm/core/state/intra_block_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class IntraBlockState {
friend class state::AccountAccessDelta;
friend class state::TransientStorageChangeDelta;
friend class StateView;
friend class ExecutionProcessor;

evmc::bytes32 get_storage(const evmc::address& address, const evmc::bytes32& key, bool original) const noexcept;

Expand Down
Loading