TLA Line data Source code
1 : // evmone: Fast Ethereum Virtual Machine implementation
2 : // Copyright 2021 The evmone Authors.
3 : // SPDX-License-Identifier: Apache-2.0
4 : #pragma once
5 :
6 : #include <evmc/evmc.hpp>
7 : #include <intx/intx.hpp>
8 : #include <unordered_map>
9 :
10 : namespace evmone::state
11 : {
12 : using evmc::address;
13 : using evmc::bytes;
14 : using evmc::bytes32;
15 :
16 : /// The representation of the account storage value.
17 : struct StorageValue
18 : {
19 : /// The current value.
20 : bytes32 current = {};
21 :
22 : /// The original value.
23 : bytes32 original = {};
24 :
25 : evmc_access_status access_status = EVMC_ACCESS_COLD;
26 : };
27 :
28 : /// The state account.
29 : struct Account
30 : {
31 : /// The maximum allowed nonce value.
32 : static constexpr auto NonceMax = std::numeric_limits<uint64_t>::max();
33 :
34 : /// The account nonce.
35 : uint64_t nonce = 0;
36 :
37 : /// The account balance.
38 : intx::uint256 balance;
39 :
40 : /// The account storage map.
41 : std::unordered_map<bytes32, StorageValue> storage;
42 :
43 : std::unordered_map<bytes32, bytes32> transient_storage;
44 :
45 : /// The account code.
46 : bytes code;
47 :
48 : /// The account has been destructed and should be erased at the end of of a transaction.
49 : bool destructed = false;
50 :
51 : /// The account should be erased if it is empty at the end of a transaction.
52 : /// This flag means the account has been "touched" as defined in EIP-161
53 : /// or it is a newly created temporary account.
54 : ///
55 : /// Yellow Paper uses term "delete" but it is a keyword in C++ while
56 : /// the term "erase" is used for deleting objects from C++ collections.
57 : bool erase_if_empty = false;
58 :
59 : /// The account has been created in the current transaction.
60 : bool just_created = false;
61 :
62 : evmc_access_status access_status = EVMC_ACCESS_COLD;
63 :
64 CBC 185 : [[nodiscard]] bool is_empty() const noexcept
65 : {
66 185 : return code.empty() && nonce == 0 && balance == 0;
67 : }
68 : };
69 : } // namespace evmone::state
|