Skip to content

Commit

Permalink
Update evm create to v0.39.0 (polkadot-evm#1058)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgmichel committed May 23, 2023
1 parent 2d1791f commit ba18cb2
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 24 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.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ bn = { package = "substrate-bn", version = "0.6", default-features = false }
environmental = { version = "1.1.4", default-features = false }
ethereum = { version = "0.14.0", default-features = false }
ethereum-types = { version = "0.14.1", default-features = false }
evm = { version = "0.37.0", default-features = false }
evm = { version = "0.39.0", default-features = false }
hex-literal = { version = "0.3.4" }
impl-serde = { version = "0.4.0", default-features = false }
jsonrpsee = "0.16.2"
kvdb-rocksdb = "0.17.0"
Expand Down
4 changes: 2 additions & 2 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ use fp_account::AccountId20;
use fp_evm::GenesisAccount;
pub use fp_evm::{
Account, CallInfo, CreateInfo, ExecutionInfo, FeeCalculator, InvalidEvmTransactionError,
LinearCostPrecompile, Log, Precompile, PrecompileFailure, PrecompileHandle, PrecompileOutput,
PrecompileResult, PrecompileSet, Vicinity,
IsPrecompileResult, LinearCostPrecompile, Log, Precompile, PrecompileFailure, PrecompileHandle,
PrecompileOutput, PrecompileResult, PrecompileSet, Vicinity,
};

pub use self::{
Expand Down
9 changes: 6 additions & 3 deletions frame/evm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

//! Test mock for unit tests and benchmarking
use fp_evm::Precompile;
use fp_evm::{IsPrecompileResult, Precompile};
use frame_support::{
parameter_types,
traits::{ConstU32, FindAuthor},
Expand Down Expand Up @@ -173,7 +173,10 @@ impl PrecompileSet for MockPrecompileSet {
/// Check if the given address is a precompile. Should only be called to
/// perform the check while not executing the precompile afterward, since
/// `execute` already performs a check internally.
fn is_precompile(&self, address: H160) -> bool {
address == H160::from_low_u64_be(1)
fn is_precompile(&self, address: H160, _gas: u64) -> IsPrecompileResult {
IsPrecompileResult::Answer {
is_precompile: address == H160::from_low_u64_be(1),
extra_cost: 0,
}
}
}
41 changes: 34 additions & 7 deletions frame/evm/src/runner/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ use evm::{
executor::stack::{Accessed, StackExecutor, StackState as StackStateT, StackSubstateMetadata},
ExitError, ExitReason, Transfer,
};
use fp_evm::{CallInfo, CreateInfo, ExecutionInfo, Log, PrecompileSet, Vicinity};
use frame_support::traits::{Currency, ExistenceRequirement, Get};
use fp_evm::{
CallInfo, CreateInfo, ExecutionInfo, IsPrecompileResult, Log, PrecompileSet, Vicinity,
};
use frame_support::traits::{Currency, ExistenceRequirement, Get,};
use sp_core::{H160, H256, U256};
use sp_runtime::traits::UniqueSaturatedInto;
use sp_std::{
Expand Down Expand Up @@ -73,6 +75,7 @@ where
T::PrecompilesType,
>,
) -> (ExitReason, R),
R: Default,
{
let (base_fee, weight) = T::FeeCalculator::min_gas_price();

Expand Down Expand Up @@ -110,7 +113,7 @@ where
fn execute_inner<'config, 'precompiles, F, R>(
source: H160,
value: U256,
gas_limit: u64,
mut gas_limit: u64,
max_fee_per_gas: Option<U256>,
max_priority_fee_per_gas: Option<U256>,
config: &'config evm::Config,
Expand All @@ -129,7 +132,28 @@ where
T::PrecompilesType,
>,
) -> (ExitReason, R),
R: Default,
{
// The precompile check is only used for transactional invocations. However, here we always
// execute the check, because the check has side effects.
let is_precompile = match precompiles.is_precompile(source, gas_limit) {
IsPrecompileResult::Answer {
is_precompile,
extra_cost,
} => {
gas_limit = gas_limit.saturating_sub(extra_cost);
is_precompile
}
IsPrecompileResult::OutOfGas => {
return Ok(ExecutionInfo {
exit_reason: ExitError::OutOfGas.into(),
value: Default::default(),
used_gas: gas_limit.into(),
logs: Default::default(),
})
}
};

// Only check the restrictions of EIP-3607 if the source of the EVM operation is from an external transaction.
// If the source of this EVM operation is from an internal call, like from `eth_call` or `eth_estimateGas` RPC,
// we will skip the checks for the EIP-3607.
Expand All @@ -141,9 +165,7 @@ where
// of a precompile. While mainnet Ethereum currently only has stateless precompiles,
// projects using Frontier can have stateful precompiles that can manage funds or
// which calls other contracts that expects this precompile address to be trustworthy.
if is_transactional
&& (!<AccountCodes<T>>::get(source).is_empty() || precompiles.is_precompile(source))
{
if is_transactional && (!<AccountCodes<T>>::get(source).is_empty() || is_precompile) {
return Err(RunnerError {
error: Error::<T>::TransactionMustComeFromEOA,
weight,
Expand Down Expand Up @@ -616,6 +638,10 @@ impl<'vicinity, 'config, T: Config> BackendT for SubstrateStackState<'vicinity,
self.vicinity.origin
}

fn block_randomness(&self) -> Option<H256> {
None
}

fn block_hash(&self, number: U256) -> H256 {
if number > U256::from(u32::MAX) {
H256::default()
Expand Down Expand Up @@ -725,9 +751,10 @@ where
self.substate.deleted(address)
}

fn inc_nonce(&mut self, address: H160) {
fn inc_nonce(&mut self, address: H160) -> Result<(), ExitError> {
let account_id = T::AddressMapping::into_account_id(address);
frame_system::Pallet::<T>::inc_account_nonce(&account_id);
Ok(())
}

fn set_storage(&mut self, address: H160, index: H256, value: H256) {
Expand Down
1 change: 1 addition & 0 deletions primitives/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use sp_std::vec::Vec;

pub use evm::{
backend::{Basic as Account, Log},
executor::stack::IsPrecompileResult,
Config, ExitReason,
};

Expand Down
11 changes: 8 additions & 3 deletions template/runtime/src/precompiles.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use pallet_evm::{Precompile, PrecompileHandle, PrecompileResult, PrecompileSet};
use pallet_evm::{
IsPrecompileResult, Precompile, PrecompileHandle, PrecompileResult, PrecompileSet,
};
use sp_core::H160;
use sp_std::marker::PhantomData;

Expand Down Expand Up @@ -46,8 +48,11 @@ where
}
}

fn is_precompile(&self, address: H160) -> bool {
Self::used_addresses().contains(&address)
fn is_precompile(&self, address: H160, _gas: u64) -> IsPrecompileResult {
IsPrecompileResult::Answer {
is_precompile: Self::used_addresses().contains(&address),
extra_cost: 0,
}
}
}

Expand Down

0 comments on commit ba18cb2

Please sign in to comment.