Skip to content

Commit

Permalink
fix nonce back to U256 ref: rust-ethereum/evm#166
Browse files Browse the repository at this point in the history
  • Loading branch information
zjb0807 committed Jan 17, 2024
1 parent 47cb26f commit 8d17aa8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions modules/evm-utility/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ sha3 = { workspace = true }

sp-std = { workspace = true }

evm = { git = "https://github.com/rust-blockchain/evm", rev = "0e035609b0ac5f54cf77b6bb7a1cbc17e2ad6e2e", default-features = false, features = ["with-codec"] }
evm-gasometer = { git = "https://github.com/rust-blockchain/evm", rev = "0e035609b0ac5f54cf77b6bb7a1cbc17e2ad6e2e", default-features = false }
evm-runtime = { git = "https://github.com/rust-blockchain/evm", rev = "0e035609b0ac5f54cf77b6bb7a1cbc17e2ad6e2e", default-features = false }
evm = { git = "https://github.com/rust-blockchain/evm", rev = "adfa174ca6e021e9b0f530bd87e20989eaab31ca", default-features = false, features = ["with-codec"] }
evm-gasometer = { git = "https://github.com/rust-blockchain/evm", rev = "adfa174ca6e021e9b0f530bd87e20989eaab31ca", default-features = false }
evm-runtime = { git = "https://github.com/rust-blockchain/evm", rev = "adfa174ca6e021e9b0f530bd87e20989eaab31ca", default-features = false }
#evm = { version = "0.41.1", default-features = false, features = ["with-codec"] }
#evm-gasometer = { version = "0.41.0", default-features = false }
#evm-runtime = { version = "0.41.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion modules/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ impl<T: Config> Pallet<T> {
let balance = T::Currency::free_balance(&account_id);

Account {
nonce: UniqueSaturatedInto::<u64>::unique_saturated_into(nonce),
nonce: U256::from(UniqueSaturatedInto::<u128>::unique_saturated_into(nonce)),
balance: U256::from(UniqueSaturatedInto::<u128>::unique_saturated_into(
convert_decimals_to_evm(balance),
)),
Expand Down
4 changes: 2 additions & 2 deletions modules/evm/src/runner/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu
}

/// 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 @@ -910,7 +910,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu
}

// We will keep the nonce until the storages are cleared.
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
4 changes: 2 additions & 2 deletions modules/evm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ fn should_calculate_contract_address() {
Ok(H160::from_str("d654cB21c05cb14895baae28159b1107e9DbD6E4").unwrap())
);

executor.state_mut().inc_nonce(addr);
assert_ok!(executor.state_mut().inc_nonce(addr));
assert_eq!(
executor.create_address(evm::CreateScheme::Legacy { caller: addr }),
Ok(H160::from_str("97784910F057B07bFE317b0552AE23eF34644Aed").unwrap())
);

executor.state_mut().inc_nonce(addr);
assert_ok!(executor.state_mut().inc_nonce(addr));
assert_eq!(
executor.create_address(evm::CreateScheme::Legacy { caller: addr }),
Ok(H160::from_str("82155a21E0Ccaee9D4239a582EB2fDAC1D9237c5").unwrap())
Expand Down

0 comments on commit 8d17aa8

Please sign in to comment.