Skip to content

Commit 08cc098

Browse files
committed
fix: nonce changed is not reverted in journal if fail due to insufficient balance
1 parent ccdbcc0 commit 08cc098

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

crates/handler/src/pre_execution.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,6 @@ pub fn validate_against_state_and_deduct_caller<
138138
is_nonce_check_disabled,
139139
)?;
140140

141-
// Bump the nonce for calls. Nonce for CREATE will be bumped in `make_create_frame`.
142-
if tx.kind().is_call() {
143-
// Nonce is already checked
144-
caller_account.info.nonce = caller_account.info.nonce.saturating_add(1);
145-
}
146-
147141
let max_balance_spending = tx.max_balance_spending()?;
148142

149143
// Check if account has enough balance for `gas_limit * max_fee`` and value transfer.
@@ -178,6 +172,12 @@ pub fn validate_against_state_and_deduct_caller<
178172
caller_account.mark_touch();
179173
caller_account.info.balance = new_balance;
180174

175+
// Bump the nonce for calls. Nonce for CREATE will be bumped in `make_create_frame`.
176+
if tx.kind().is_call() {
177+
// Nonce is already checked
178+
caller_account.info.nonce = caller_account.info.nonce.saturating_add(1);
179+
}
180+
181181
journal.caller_accounting_journal_entry(tx.caller(), old_balance, tx.kind().is_call());
182182
Ok(())
183183
}

crates/op-revm/src/handler.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,6 @@ where
157157
)?;
158158
}
159159

160-
// Bump the nonce for calls. Nonce for CREATE will be bumped in `handle_create`.
161-
if tx.kind().is_call() {
162-
caller_account.info.nonce = caller_account.info.nonce.saturating_add(1);
163-
}
164-
165160
let max_balance_spending = tx.max_balance_spending()?.saturating_add(additional_cost);
166161

167162
// old balance is journaled before mint is incremented.
@@ -210,6 +205,11 @@ where
210205
caller_account.mark_touch();
211206
caller_account.info.balance = new_balance;
212207

208+
// Bump the nonce for calls. Nonce for CREATE will be bumped in `handle_create`.
209+
if tx.kind().is_call() {
210+
caller_account.info.nonce = caller_account.info.nonce.saturating_add(1);
211+
}
212+
213213
// NOTE: all changes to the caller account should journaled so in case of error
214214
// we can revert the changes.
215215
journal.caller_accounting_journal_entry(tx.caller(), old_balance, tx.kind().is_call());

0 commit comments

Comments
 (0)