diff --git a/src/backend/memory.rs b/src/backend/memory.rs index 4910e628e..37e7718b1 100644 --- a/src/backend/memory.rs +++ b/src/backend/memory.rs @@ -47,7 +47,7 @@ pub struct MemoryVicinity { #[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))] pub struct MemoryAccount { /// Account nonce. - pub nonce: u64, + pub nonce: U256, /// Account balance. pub balance: U256, /// Full account storage. @@ -210,7 +210,8 @@ impl<'vicinity> ApplyBackend for MemoryBackend<'vicinity> { } account.balance == U256::zero() - && account.nonce == 0 && account.code.is_empty() + && account.nonce == U256::zero() + && account.code.is_empty() }; if is_empty && delete_empty { diff --git a/src/backend/mod.rs b/src/backend/mod.rs index c442958c1..7cda7fd1d 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -20,7 +20,7 @@ pub struct Basic { /// Account balance. pub balance: U256, /// Account nonce. - pub nonce: u64, + pub nonce: U256, } pub use ethereum::Log; diff --git a/src/executor/stack/executor.rs b/src/executor/stack/executor.rs index 4f6f52cd2..4d30981d5 100644 --- a/src/executor/stack/executor.rs +++ b/src/executor/stack/executor.rs @@ -618,7 +618,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> } /// Get account nonce. - pub fn nonce(&self, address: H160) -> u64 { + pub fn nonce(&self, address: H160) -> U256 { self.state.basic(address).nonce } @@ -734,7 +734,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> return Capture::Exit((ExitError::CreateCollision.into(), None, Vec::new())); } - if self.nonce(address) > 0 { + if self.nonce(address) > U256::zero() { let _ = self.exit_substate(StackExitKind::Failed); return Capture::Exit((ExitError::CreateCollision.into(), None, Vec::new())); } diff --git a/src/executor/stack/memory.rs b/src/executor/stack/memory.rs index d66c10335..957b2b3d5 100644 --- a/src/executor/stack/memory.rs +++ b/src/executor/stack/memory.rs @@ -198,14 +198,14 @@ impl<'config> MemoryStackSubstate<'config> { return Some(false); } - if account.basic.nonce != 0 { + if account.basic.nonce != U256::zero() { return Some(false); } if let Some(code) = &account.code { return Some( account.basic.balance == U256::zero() - && account.basic.nonce == 0 + && account.basic.nonce == U256::zero() && code.is_empty(), ); } @@ -303,7 +303,10 @@ impl<'config> MemoryStackSubstate<'config> { pub fn inc_nonce(&mut self, address: H160, backend: &B) -> Result<(), ExitError> { let nonce = &mut self.account_mut(address, backend).basic.nonce; - *nonce = nonce.checked_add(1).ok_or(ExitError::MaxNonce)?; + if *nonce >= U256::from(u64::MAX) { + return Err(ExitError::MaxNonce); + } + *nonce += U256::one(); Ok(()) } @@ -499,7 +502,7 @@ impl<'backend, 'config, B: Backend> StackState<'config> for MemoryStackState<'ba } self.backend.basic(address).balance == U256::zero() - && self.backend.basic(address).nonce == 0 + && self.backend.basic(address).nonce == U256::zero() && self.backend.code(address).len() == 0 }