Skip to content

Commit

Permalink
fix: create high nonce (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat authored Sep 26, 2024
1 parent 489c2bf commit 00a16db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion crates/evm/src/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ pub enum EVMError {
OutOfGas,
Assertion,
DepthLimit,
MemoryLimitOOG
MemoryLimitOOG,
NonceOverflow
}

#[generate_trait]
Expand All @@ -83,6 +84,7 @@ pub impl EVMErrorImpl of EVMErrorTrait {
EVMError::Assertion => 'assertion failed'.into(),
EVMError::DepthLimit => 'max call depth exceeded'.into(),
EVMError::MemoryLimitOOG => 'memory limit out of gas'.into(),
EVMError::NonceOverflow => 'nonce overflow'.into(),
}
}

Expand Down
9 changes: 7 additions & 2 deletions crates/evm/src/interpreter.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use contracts::account_contract::{IAccountDispatcher, IAccountDispatcherTrait};
use contracts::kakarot_core::KakarotCore;
use contracts::kakarot_core::interface::IKakarotCore;
use core::num::traits::Zero;
use core::num::traits::{Bounded, Zero};
use core::ops::SnapshotDeref;
use core::starknet::EthAddress;
use core::starknet::get_tx_info;
Expand All @@ -21,7 +21,7 @@ use evm::model::account::{Account, AccountTrait};
use evm::model::vm::{VM, VMTrait};
use evm::model::{
Message, Environment, Transfer, ExecutionSummary, ExecutionResult, ExecutionResultTrait,
ExecutionResultStatus, AddressTrait, TransactionResult, Address
ExecutionResultStatus, AddressTrait, TransactionResult, TransactionResultTrait, Address
};
use evm::precompiles::Precompiles;
use evm::precompiles::eth_precompile_addresses;
Expand Down Expand Up @@ -117,6 +117,11 @@ pub impl EVMImpl of EVMTrait {
.prepare_message(@tx, @sender_account, ref env, gas_left);

// Increment nonce of sender AFTER computing eventual created address
if sender_account.nonce() == Bounded::<u64>::MAX {
return TransactionResultTrait::exceptional_failure(
EVMError::NonceOverflow.to_bytes(), tx.gas_limit()
);
}
sender_account.set_nonce(sender_account.nonce() + 1);

env.state.set_account(sender_account);
Expand Down

0 comments on commit 00a16db

Please sign in to comment.