From 00a16dbd5d236df7f9fdf031e3bb5fcdd7aaf643 Mon Sep 17 00:00:00 2001 From: Mathieu <60658558+enitrat@users.noreply.github.com> Date: Thu, 26 Sep 2024 10:19:02 +0200 Subject: [PATCH] fix: create high nonce (#974) --- crates/evm/src/errors.cairo | 4 +++- crates/evm/src/interpreter.cairo | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/evm/src/errors.cairo b/crates/evm/src/errors.cairo index 06543f313..fa4587ca7 100644 --- a/crates/evm/src/errors.cairo +++ b/crates/evm/src/errors.cairo @@ -58,7 +58,8 @@ pub enum EVMError { OutOfGas, Assertion, DepthLimit, - MemoryLimitOOG + MemoryLimitOOG, + NonceOverflow } #[generate_trait] @@ -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(), } } diff --git a/crates/evm/src/interpreter.cairo b/crates/evm/src/interpreter.cairo index 82b39a40a..59d11b6bb 100644 --- a/crates/evm/src/interpreter.cairo +++ b/crates/evm/src/interpreter.cairo @@ -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; @@ -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; @@ -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::::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);