Skip to content

Commit

Permalink
Use new version evm 2
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Apr 11, 2024
1 parent 9de79d4 commit 0de823a
Show file tree
Hide file tree
Showing 6 changed files with 368 additions and 373 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions frame/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ sp-std = { workspace = true }
fp-account = { workspace = true }
fp-evm = { workspace = true, features = ["serde"] }

evm-precompile ={ path = "../../../evm/precompile", default-features = false }

[dev-dependencies]
hex = { workspace = true }
# Substrate
Expand Down Expand Up @@ -63,6 +65,7 @@ std = [
# Frontier
"fp-account/std",
"fp-evm/std",
"evm-precompile/std"
]
runtime-benchmarks = [
"hex",
Expand Down
60 changes: 29 additions & 31 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ pub mod runner;
mod tests;
pub mod weights;

pub use evm::{
Config as EvmConfig, Context, ExitError, ExitFatal, ExitReason, ExitRevert, ExitSucceed,
};
// pub use evm::{
// Config as EvmConfig, Context, ExitError, ExitFatal, ExitReason, ExitRevert, ExitSucceed,
// };
use hash_db::Hasher;
use impl_trait_for_tuples::impl_for_tuples;
use scale_codec::{Decode, Encode, MaxEncodedLen};
Expand Down Expand Up @@ -96,18 +96,16 @@ use sp_runtime::{
use sp_std::{cmp::min, collections::btree_map::BTreeMap, vec::Vec};
// Frontier
use fp_account::AccountId20;
use fp_evm::GenesisAccount;
pub use fp_evm::{
Account, CallInfo, CreateInfo, ExecutionInfoV2 as ExecutionInfo, FeeCalculator,
IsPrecompileResult, LinearCostPrecompile, Log, Precompile, PrecompileFailure, PrecompileHandle,
PrecompileOutput, PrecompileResult, PrecompileSet, TransactionValidationError, Vicinity,
};
use fp_evm::{FeeCalculator, GenesisAccount};
// pub use fp_evm::{
// Account, CallInfo, CreateInfo, ExecutionInfoV2 as ExecutionInfo, FeeCalculator,
// IsPrecompileResult, LinearCostPrecompile, Log, Precompile, PrecompileFailure, PrecompileHandle,
// PrecompileOutput, PrecompileResult, PrecompileSet, TransactionValidationError, Vicinity,
// };

pub use self::{
pallet::*,
runner::{Runner, RunnerError},
weights::WeightInfo,
};
use evm::standard::PrecompileSet;

pub use self::{pallet::*, runner::Runner, weights::WeightInfo};

#[frame_support::pallet]
pub mod pallet {
Expand Down Expand Up @@ -504,23 +502,23 @@ pub mod pallet {
Undefined,
}

impl<T> From<TransactionValidationError> for Error<T> {
fn from(validation_error: TransactionValidationError) -> Self {
match validation_error {
TransactionValidationError::GasLimitTooLow => Error::<T>::GasLimitTooLow,
TransactionValidationError::GasLimitTooHigh => Error::<T>::GasLimitTooHigh,
TransactionValidationError::BalanceTooLow => Error::<T>::BalanceLow,
TransactionValidationError::TxNonceTooLow => Error::<T>::InvalidNonce,
TransactionValidationError::TxNonceTooHigh => Error::<T>::InvalidNonce,
TransactionValidationError::GasPriceTooLow => Error::<T>::GasPriceTooLow,
TransactionValidationError::PriorityFeeTooHigh => Error::<T>::GasPriceTooLow,
TransactionValidationError::InvalidFeeInput => Error::<T>::GasPriceTooLow,
TransactionValidationError::InvalidChainId => Error::<T>::InvalidChainId,
TransactionValidationError::InvalidSignature => Error::<T>::InvalidSignature,
TransactionValidationError::UnknownError => Error::<T>::Undefined,
}
}
}
// impl<T> From<TransactionValidationError> for Error<T> {
// fn from(validation_error: TransactionValidationError) -> Self {
// match validation_error {
// TransactionValidationError::GasLimitTooLow => Error::<T>::GasLimitTooLow,
// TransactionValidationError::GasLimitTooHigh => Error::<T>::GasLimitTooHigh,
// TransactionValidationError::BalanceTooLow => Error::<T>::BalanceLow,
// TransactionValidationError::TxNonceTooLow => Error::<T>::InvalidNonce,
// TransactionValidationError::TxNonceTooHigh => Error::<T>::InvalidNonce,
// TransactionValidationError::GasPriceTooLow => Error::<T>::GasPriceTooLow,
// TransactionValidationError::PriorityFeeTooHigh => Error::<T>::GasPriceTooLow,
// TransactionValidationError::InvalidFeeInput => Error::<T>::GasPriceTooLow,
// TransactionValidationError::InvalidChainId => Error::<T>::InvalidChainId,
// TransactionValidationError::InvalidSignature => Error::<T>::InvalidSignature,
// TransactionValidationError::UnknownError => Error::<T>::Undefined,
// }
// }
// }

#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
Expand Down
26 changes: 9 additions & 17 deletions frame/evm/src/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,11 @@
pub mod stack;

use crate::{Config, Weight};
use fp_evm::{CallInfo, CreateInfo};
use evm::{standard::TransactValue, ExitError};
use sp_core::{H160, H256, U256};
use sp_std::vec::Vec;

#[derive(Debug)]
pub struct RunnerError<E: Into<sp_runtime::DispatchError>> {
pub error: E,
pub weight: Weight,
}

pub trait Runner<T: Config> {
type Error: Into<sp_runtime::DispatchError>;

fn validate(
source: H160,
target: Option<H160>,
Expand All @@ -44,8 +36,8 @@ pub trait Runner<T: Config> {
is_transactional: bool,
weight_limit: Option<Weight>,
proof_size_base_cost: Option<u64>,
evm_config: &evm::Config,
) -> Result<(), RunnerError<Self::Error>>;
evm_config: &&evm::standard::Config,
) -> Result<(), ExitError>;

fn call(
source: H160,
Expand All @@ -61,8 +53,8 @@ pub trait Runner<T: Config> {
validate: bool,
weight_limit: Option<Weight>,
proof_size_base_cost: Option<u64>,
config: &evm::Config,
) -> Result<CallInfo, RunnerError<Self::Error>>;
config: &&evm::standard::Config,
) -> Result<TransactValue, ExitError>;

fn create(
source: H160,
Expand All @@ -77,8 +69,8 @@ pub trait Runner<T: Config> {
validate: bool,
weight_limit: Option<Weight>,
proof_size_base_cost: Option<u64>,
config: &evm::Config,
) -> Result<CreateInfo, RunnerError<Self::Error>>;
config: &&evm::standard::Config,
) -> Result<TransactValue, ExitError>;

fn create2(
source: H160,
Expand All @@ -94,6 +86,6 @@ pub trait Runner<T: Config> {
validate: bool,
weight_limit: Option<Weight>,
proof_size_base_cost: Option<u64>,
config: &evm::Config,
) -> Result<CreateInfo, RunnerError<Self::Error>>;
config: &&evm::standard::Config,
) -> Result<TransactValue, ExitError>;
}
Loading

0 comments on commit 0de823a

Please sign in to comment.