Skip to content

Commit 126d592

Browse files
committed
EIP-2935: Serve historical block hashes from state
1 parent d02e518 commit 126d592

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

test/state/state.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,39 @@ void system_call(State& state, const BlockInfo& block, evmc_revision rev, evmc::
412412
}
413413
}
414414
}
415+
416+
static constexpr auto HISTORY_STORAGE_ADDRESS =
417+
0x0aae40965e6800cd9b1f4b05ff21581047e3f91e_address;
418+
if (rev >= EVMC_PRAGUE)
419+
{
420+
if (const auto acc = state.find(HISTORY_STORAGE_ADDRESS);
421+
acc != nullptr && !block.known_block_hashes.empty())
422+
{
423+
const auto parent_block_hash = block.known_block_hashes.at(block.number - 1);
424+
const evmc_message msg{
425+
.kind = EVMC_CALL,
426+
.gas = 30'000'000,
427+
.recipient = HISTORY_STORAGE_ADDRESS,
428+
.sender = SystemAddress,
429+
.input_data = parent_block_hash.bytes,
430+
.input_size = sizeof(parent_block_hash),
431+
};
432+
433+
const Transaction empty_tx{};
434+
Host host{rev, vm, state, block, empty_tx};
435+
const auto& code = acc->code;
436+
[[maybe_unused]] const auto res = vm.execute(host, rev, msg, code.data(), code.size());
437+
assert(res.status_code == EVMC_SUCCESS);
438+
assert(acc->access_status == EVMC_ACCESS_COLD);
439+
440+
// Reset storage status.
441+
for (auto& [_, val] : acc->storage)
442+
{
443+
val.access_status = EVMC_ACCESS_COLD;
444+
val.original = val.current;
445+
}
446+
}
447+
}
415448
}
416449

417450
void finalize(State& state, evmc_revision rev, const address& coinbase,

test/utils/utils.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ RevisionSchedule to_rev_schedule(std::string_view s)
4646
{
4747
if (s == "ShanghaiToCancunAtTime15k")
4848
return {EVMC_SHANGHAI, EVMC_CANCUN, 15'000};
49+
if (s == "CancunToPragueAtTime15k")
50+
return {EVMC_CANCUN, EVMC_PRAGUE, 15'000};
4951

5052
const auto single_rev = to_rev(s);
5153
return {single_rev, single_rev, 0};

0 commit comments

Comments
 (0)