Skip to content

Commit

Permalink
fix eip-2618 ref: rust-ethereum/evm#163
Browse files Browse the repository at this point in the history
  • Loading branch information
zjb0807 committed Jan 17, 2024
1 parent 05f6418 commit 47cb26f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
8 changes: 4 additions & 4 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 = "21972c2392af3381bbfcd2139664ba3fff0ee287", default-features = false, features = ["with-codec"] }
evm-gasometer = { git = "https://github.com/rust-blockchain/evm", rev = "21972c2392af3381bbfcd2139664ba3fff0ee287", default-features = false }
evm-runtime = { git = "https://github.com/rust-blockchain/evm", rev = "21972c2392af3381bbfcd2139664ba3fff0ee287", default-features = false }
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 = { 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: U256::from(UniqueSaturatedInto::<u128>::unique_saturated_into(nonce)),
nonce: UniqueSaturatedInto::<u64>::unique_saturated_into(nonce),
balance: U256::from(UniqueSaturatedInto::<u128>::unique_saturated_into(
convert_decimals_to_evm(balance),
)),
Expand Down
3 changes: 2 additions & 1 deletion modules/evm/src/runner/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,9 @@ impl<'vicinity, 'config, T: Config> StackStateT<'config> for SubstrateStackState
self.substate.deleted(address)
}

fn inc_nonce(&mut self, address: H160) {
fn inc_nonce(&mut self, address: H160) -> Result<(), ExitError> {
Pallet::<T>::inc_nonce(&address);
Ok(())
}

fn set_storage(&mut self, address: H160, index: H256, value: H256) {
Expand Down
18 changes: 12 additions & 6 deletions modules/evm/src/runner/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ pub trait StackState<'config>: Backend {
fn is_cold(&self, address: H160) -> bool;
fn is_storage_cold(&self, address: H160, key: H256) -> bool;

fn inc_nonce(&mut self, address: H160);
fn inc_nonce(&mut self, address: H160) -> Result<(), ExitError>;
fn set_storage(&mut self, address: H160, key: H256, value: H256);
fn reset_storage(&mut self, address: H160);
fn log(&mut self, address: H160, topics: Vec<H256>, data: Vec<u8>);
Expand Down Expand Up @@ -691,7 +691,9 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu
gas_limit: u64,
access_list: Vec<(H160, Vec<H256>)>,
) -> (ExitReason, Vec<u8>) {
self.state.inc_nonce(caller);
if let Err(e) = self.state.inc_nonce(caller) {
return (e.into(), Vec::new());
}

event!(TransactCall {
caller,
Expand Down Expand Up @@ -772,7 +774,7 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu
}

/// Get account nonce.
pub fn nonce(&self, address: H160) -> U256 {
pub fn nonce(&self, address: H160) -> u64 {
self.state.basic(address).nonce
}

Expand Down Expand Up @@ -877,7 +879,9 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu
return Capture::Exit((ExitError::OutOfFund.into(), None, Vec::new()));
}

self.state.inc_nonce(caller);
if let Err(e) = self.state.inc_nonce(caller) {
return Capture::Exit((e.into(), None, Vec::new()));
}

let after_gas = if take_l64 && self.config.call_l64_after_gas {
if self.config.estimate {
Expand Down Expand Up @@ -906,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) > U256::zero() {
if self.nonce(address) > 0 {
let _ = self.exit_substate(StackExitKind::Failed);
return Capture::Exit((ExitError::CreateCollision.into(), None, Vec::new()));
}
Expand Down Expand Up @@ -934,7 +938,9 @@ impl<'config, 'precompiles, S: StackState<'config>, P: PrecompileSet> StackExecu
}

if self.config.create_increase_nonce {
self.state.inc_nonce(address);
if let Err(e) = self.state.inc_nonce(address) {
return Capture::Exit((e.into(), None, Vec::new()));
}
}

let runtime = Runtime::new(
Expand Down

0 comments on commit 47cb26f

Please sign in to comment.