Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change nonce type back to U256 #166

Merged
merged 3 commits into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/backend/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Basic {
/// Account balance.
pub balance: U256,
/// Account nonce.
pub nonce: u64,
pub nonce: U256,
}

pub use ethereum::Log;
Expand Down
4 changes: 2 additions & 2 deletions src/executor/stack/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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()));
}
Expand Down
11 changes: 7 additions & 4 deletions src/executor/stack/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}
Expand Down Expand Up @@ -303,7 +303,10 @@ impl<'config> MemoryStackSubstate<'config> {

pub fn inc_nonce<B: Backend>(&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(())
}

Expand Down Expand Up @@ -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
}

Expand Down