@@ -140,28 +140,29 @@ address compute_new_account_address(const address& sender, uint64_t sender_nonce
140
140
141
141
std::optional<evmc_message> Host::prepare_message (evmc_message msg)
142
142
{
143
- auto & sender_acc = m_state.get (msg.sender );
144
- const auto sender_nonce = sender_acc.nonce ;
145
-
146
- // Bump sender nonce.
147
143
if (msg.depth == 0 || msg.kind == EVMC_CREATE || msg.kind == EVMC_CREATE2)
148
144
{
149
- if (sender_nonce == Account::NonceMax)
150
- return {}; // Light early exception, cannot happen for depth == 0.
151
- ++sender_acc.nonce ;
152
- }
145
+ auto & sender_acc = m_state.get (msg.sender );
146
+ const auto sender_nonce = sender_acc.nonce ;
153
147
154
- if (msg.kind == EVMC_CREATE || msg.kind == EVMC_CREATE2)
155
- {
156
- // Compute and fill create address.
157
- assert (msg.recipient == address{});
158
- assert (msg.code_address == address{});
159
- msg.recipient = compute_new_account_address (msg.sender , sender_nonce,
160
- (msg.kind == EVMC_CREATE2) ? std::optional{msg.create2_salt } : std::nullopt,
161
- {msg.input_data , msg.input_size });
162
-
163
- // By EIP-2929, the access to new created address is never reverted.
164
- access_account (msg.recipient );
148
+ // EIP-2681 (already checked for depth 0 during transaction validation).
149
+ if (sender_nonce == Account::NonceMax)
150
+ return {}; // Light early exception.
151
+
152
+ ++sender_acc.nonce ; // Bump sender nonce.
153
+
154
+ if (msg.kind == EVMC_CREATE || msg.kind == EVMC_CREATE2)
155
+ {
156
+ // Compute and set the address of the account being created.
157
+ assert (msg.recipient == address{});
158
+ assert (msg.code_address == address{});
159
+ msg.recipient = compute_new_account_address (msg.sender , sender_nonce,
160
+ (msg.kind == EVMC_CREATE2) ? std::optional{msg.create2_salt } : std::nullopt,
161
+ {msg.input_data , msg.input_size });
162
+
163
+ // By EIP-2929, the access to new created address is never reverted.
164
+ access_account (msg.recipient );
165
+ }
165
166
}
166
167
167
168
return msg;
@@ -252,9 +253,10 @@ evmc::Result Host::execute_message(const evmc_message& msg) noexcept
252
253
auto * const dst_acc =
253
254
(msg.kind == EVMC_CALL) ? &m_state.touch (msg.recipient ) : m_state.find (msg.code_address );
254
255
255
- if (msg.kind == EVMC_CALL)
256
+ if (msg.kind == EVMC_CALL && ! evmc::is_zero (msg. value ) )
256
257
{
257
- // Transfer value.
258
+ // Transfer value: sender → recipient.
259
+ // The sender's balance is already checked therefore the sender account must exist.
258
260
const auto value = intx::be::load<intx::uint256>(msg.value );
259
261
assert (m_state.get (msg.sender ).balance >= value);
260
262
m_state.get (msg.sender ).balance -= value;
0 commit comments