New evmone API: StateView & StateDiff#802
Conversation
0f92b8a to
af88125
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #802 +/- ##
==========================================
+ Coverage 94.21% 94.23% +0.01%
==========================================
Files 153 155 +2
Lines 15934 15968 +34
==========================================
+ Hits 15012 15047 +35
+ Misses 922 921 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
1ea121a to
3f608b1
Compare
d77ecd8 to
83342e2
Compare
0028573 to
1bab196
Compare
e4e3eb4 to
838a5cf
Compare
| // TODO: Cache code hash. It will be needed also to compute the MPT hash. | ||
| const auto raw_code = m_state.get_code(addr); | ||
| if (is_eof_container(raw_code)) | ||
| return keccak256(raw_code.substr(0, 2)); |
There was a problem hiding this comment.
It is probably good idea to handle EOF ext code and possible code hash caching up front.
pdobacz
left a comment
There was a problem hiding this comment.
I still need to wrap head around this, but here some early comments
| [[nodiscard]] bool is_create_collision(const Account& acc) noexcept | ||
| { | ||
| if (acc.nonce != 0 || !acc.code.empty()) | ||
| // TODO: This requires much more testing: |
| std::variant<JournalBalanceChange, JournalTouched, JournalStorageChange, JournalNonceBump, | ||
| JournalCreate, JournalTransientStorageChange, JournalDestruct, JournalAccessAccount>; | ||
|
|
||
| const StateView* m_cold = nullptr; |
There was a problem hiding this comment.
comment pls what this means, making sure to answer its relation to the notion of cold/warm storage (access lists and whatnot). I kinda know but would appreciate the comment to make sure and make it easier to digest.
There was a problem hiding this comment.
I would maybe rename this and m_accounts: m_initial_state and m_modified_accounts maybe.
There was a problem hiding this comment.
The "initial" and "modified" sounds nice. How about just m_initial and m_modified?
Wrap the usage of the state transition API from the `evmone::state` for tests so that the new API in `evmone::test` only exposes `TestState` and hides `state::State`. This isolates usage of the `evmone::state` to lower the disturbance caused by API modifications, e.g. in #802.
28caf35 to
a7cac6e
Compare
Wrap the usage of the state transition API from the `evmone::state` for tests so that the new API in `evmone::test` only exposes `TestState` and hides `state::State`. This isolates usage of the `evmone::state` to lower the disturbance caused by API modifications, e.g. in #802.
a7cac6e to
5ef5009
Compare
Wrap the usage of the state transition API from the `evmone::state` for tests so that the new API in `evmone::test` only exposes `TestState` and hides `state::State`. This isolates usage of the `evmone::state` to lower the disturbance caused by API modifications, e.g. in #802.
5ef5009 to
65c7d8e
Compare
4c5c323 to
d69bc4c
Compare
| if (std::ranges::any_of( | ||
| acc.storage, [](auto& e) noexcept { return !is_zero(e.second.current); })) | ||
| if (acc.code_hash != Account::EMPTY_CODE_HASH) | ||
| return true; |
There was a problem hiding this comment.
This is not covered by any tests, so more work for #1037. Should I remove/shorten the TODO comments here?
8a8e576 to
da4cd30
Compare
| // TODO(clang): In old Clang emplace_back without Account doesn't compile. | ||
| // NOLINTNEXTLINE(modernize-use-emplace) | ||
| auto& a = diff.modified_accounts.emplace_back(StateDiff::Entry{addr, m.nonce, m.balance}); | ||
| if (m.just_created && !m.code.empty()) |
There was a problem hiding this comment.
Note for the future: in 7702 the code may change 😱 (when resetting existing delegation to another account)
|
Why |
Introduce the type `StateDiff` to represent a set of modifications to the State. Implement the procedure to collect the set of changes out of an intra state object.
Implement `TestState::appy(StateDiff)` procedure to apply state changes back to the state.
da4cd30 to
bd366dc
Compare
This is the interface a user of the API has to implement (similarly to EVMC's Host). In evmone the user is |
Return `StateDiff` out of: - `state::transition()` (as a subobject of `TransactionReceipt`) - `state::system_call()` - `state::finalize()`
Introduce `StateView` interface as a way to read the initial/cold State.
Implement `StateView` interface in `TestState`. This will be used later.
| if (is_precompile(m_rev, msg.code_address)) | ||
| return call_precompile(m_rev, msg); | ||
|
|
||
| // In case msg.recipient == msg.code_address, this is the second lookup of the same address. |
There was a problem hiding this comment.
Kind of true, but now this is the State::get_code() API issue: how to combine local account lookup with code lookup.
bd366dc to
889d23f
Compare
Modify the `State` to require `StateView` interface as a parameter and use it to read the initial state values. This drops `TestState` dependency on `State`.
889d23f to
3350cd7
Compare
Wrap the usage of the state transition API from the `evmone::state` for tests so that the new API in `evmone::test` only exposes `TestState` and hides `state::State`. This isolates usage of the `evmone::state` to lower the disturbance caused by API modifications, e.g. in ipsilon/evmone#802.
A step towards of the new API for evmone. It uses the test runners as users and modifies the
StateAPI fromstate.h.StateViewinterface with (simpler thanState) representation of the State.transition()) takes theStateViewand producesStateDiff.StateDiffto itsStateViewimplementation.The current state diff building is based on visiting the intra state cache of accounts loaded from initial state. This approach is relatively simple but has some false positives and may not be efficient.