Skip to content

Commit

Permalink
Merge pull request #612 from freeverseio/feature/checking_evm_config
Browse files Browse the repository at this point in the history
Rename FrontierPrecompiles -> LaosPrecompiles
  • Loading branch information
asiniscalchi committed Jun 4, 2024
2 parents b666969 + ac69b0a commit e5b8dd4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions runtime/laos/src/configs/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! Pallets that enable EVM execution on Substrate
use crate::{
precompiles::FrontierPrecompiles, types::ToAuthor, weights, AccountId, Aura, Balances, BaseFee,
precompiles::LaosPrecompiles, types::ToAuthor, weights, AccountId, Aura, Balances, BaseFee,
EVMChainId, Runtime, RuntimeEvent, Timestamp,
};
use frame_support::{
Expand All @@ -39,7 +39,7 @@ const WEIGHT_PER_GAS: u64 = WEIGHT_REF_TIME_PER_SECOND / GAS_PER_SECOND;

parameter_types! {
pub BlockGasLimit: U256 = U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS);
pub PrecompilesValue: FrontierPrecompiles<Runtime> = FrontierPrecompiles::<_>::new();
pub PrecompilesValue: LaosPrecompiles<Runtime> = LaosPrecompiles::<_>::new();
pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0);
/// The amount of gas per pov. A ratio of 4 if we convert ref_time to gas and we compare
/// it with the pov_size for a block. E.g.
Expand All @@ -62,7 +62,7 @@ impl pallet_evm::Config for Runtime {
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
type OnChargeTransaction = pallet_evm::EVMCurrencyAdapter<Balances, ToAuthor<Self>>;
type OnCreate = ();
type PrecompilesType = FrontierPrecompiles<Self>;
type PrecompilesType = LaosPrecompiles<Self>;
type PrecompilesValue = PrecompilesValue;
type Runner = pallet_evm::runner::stack::Runner<Self>;
type RuntimeEvent = RuntimeEvent;
Expand Down
4 changes: 2 additions & 2 deletions runtime/laos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub use laos_primitives::{
};
pub use pallet_evm_evolution_collection_factory::REVERT_BYTECODE;
pub use pallet_parachain_staking::{InflationInfo, Range};
use precompiles::FrontierPrecompiles;
use precompiles::LaosPrecompiles;
use sp_runtime::{create_runtime_str, generic, impl_opaque_keys, Permill};
use sp_std::prelude::*;
#[cfg(feature = "std")]
Expand All @@ -50,7 +50,7 @@ pub type Block = generic::Block<Header, UncheckedExtrinsic>;
/// BlockId type as expected by this runtime.
pub type BlockId = generic::BlockId<Block>;

pub type Precompiles = FrontierPrecompiles<Runtime>;
pub type Precompiles = LaosPrecompiles<Runtime>;

/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
Expand Down
6 changes: 3 additions & 3 deletions runtime/laos/src/precompiles/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use sp_core::{H160, U256};
use sp_runtime::{traits::IdentityLookup, ConsensusEngineId};
use sp_std::{boxed::Box, prelude::*, str::FromStr};

use super::FrontierPrecompiles;
use super::LaosPrecompiles;

type Block = frame_system::mocking::MockBlock<Runtime>;
type AccountId = H160;
Expand Down Expand Up @@ -102,7 +102,7 @@ parameter_types! {
pub BlockGasLimit: U256 = U256::from(BLOCK_GAS_LIMIT);
pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE);
pub WeightPerGas: Weight = Weight::from_parts(20_000, 0);
pub PrecompilesValue: FrontierPrecompiles<Runtime> = FrontierPrecompiles::<_>::new();
pub PrecompilesValue: LaosPrecompiles<Runtime> = LaosPrecompiles::<_>::new();
}

impl pallet_evm::Config for Runtime {
Expand All @@ -115,7 +115,7 @@ impl pallet_evm::Config for Runtime {
type AddressMapping = IdentityAddressMapping;
type Currency = Balances;
type RuntimeEvent = RuntimeEvent;
type PrecompilesType = FrontierPrecompiles<Self>;
type PrecompilesType = LaosPrecompiles<Self>;
type PrecompilesValue = PrecompilesValue;
type ChainId = ();
type BlockGasLimit = BlockGasLimit;
Expand Down
8 changes: 4 additions & 4 deletions runtime/laos/src/precompiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ use pallet_laos_evolution::address_to_collection_id;

use crate::Runtime;

pub struct FrontierPrecompiles<Runtime>(PhantomData<Runtime>);
pub struct LaosPrecompiles<Runtime>(PhantomData<Runtime>);

impl<Runtime> FrontierPrecompiles<Runtime>
impl<Runtime> LaosPrecompiles<Runtime>
where
Runtime: pallet_evm::Config,
{
Expand Down Expand Up @@ -87,7 +87,7 @@ type EvolutionCollectionFactory = EvolutionCollectionFactoryPrecompile<Runtime>;

type EvolutionCollection = EvolutionCollectionPrecompile<Runtime>;

impl<Runtime> PrecompileSet for FrontierPrecompiles<Runtime>
impl<Runtime> PrecompileSet for LaosPrecompiles<Runtime>
where
Runtime: pallet_evm::Config,
{
Expand Down Expand Up @@ -122,7 +122,7 @@ where

fn is_precompile(&self, address: H160, _gas: u64) -> IsPrecompileResult {
if address_to_collection_id(address).is_ok() {
return IsPrecompileResult::Answer { is_precompile: true, extra_cost: 0 }
return IsPrecompileResult::Answer { is_precompile: true, extra_cost: 0 };
}

IsPrecompileResult::Answer {
Expand Down
16 changes: 8 additions & 8 deletions runtime/laos/src/tests/precompile_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with LAOS. If not, see <http://www.gnu.org/licenses/>.

use crate::precompiles::FrontierPrecompiles;
use crate::precompiles::LaosPrecompiles;

use crate::Runtime;
use core::str::FromStr;
Expand All @@ -32,7 +32,7 @@ fn hash(a: u64) -> H160 {

// Check if a given address corresponds to a precompile.
fn is_precompile(address: H160) -> Result<bool, &'static str> {
let p = FrontierPrecompiles::<Runtime>::new();
let p = LaosPrecompiles::<Runtime>::new();
match p.is_precompile(address, 0) {
IsPrecompileResult::Answer { is_precompile, .. } => Ok(is_precompile),
_ => Err("Unexpected result variant"),
Expand Down Expand Up @@ -68,7 +68,7 @@ fn check_ethereum_precompiled_addresses() {
/// correctly.
#[test]
fn delegatecall_to_non_precompile_is_recognized() {
let precompiles = FrontierPrecompiles::<Runtime>::new();
let precompiles = LaosPrecompiles::<Runtime>::new();

// Address outside the range of standard precompiles
let code_address = hash(11);
Expand All @@ -83,7 +83,7 @@ fn delegatecall_to_non_precompile_is_recognized() {
/// Test to ensure that delegate calls to non-standard Ethereum precompile addresses are recognized.
#[test]
fn delegatecall_to_custom_precompile_is_recognized() {
let precompiles = FrontierPrecompiles::<Runtime>::new();
let precompiles = LaosPrecompiles::<Runtime>::new();

// Address representing a non-standard precompile
let code_address = hash(1027);
Expand All @@ -99,7 +99,7 @@ fn delegatecall_to_custom_precompile_is_recognized() {
/// as custom precompiles.
#[test]
fn delegatecall_to_standard_precompile_not_recognized_as_custom() {
let precompiles = FrontierPrecompiles::<Runtime>::new();
let precompiles = LaosPrecompiles::<Runtime>::new();

let context_address = hash(123456);

Expand All @@ -116,7 +116,7 @@ fn delegatecall_to_standard_precompile_not_recognized_as_custom() {

#[test]
fn execute_delegate_call_on_custom_precompile_should_fail() {
let p = FrontierPrecompiles::<Runtime>::new();
let p = LaosPrecompiles::<Runtime>::new();

let code_address = hash(1027);
let context_address = hash(123456);
Expand All @@ -143,7 +143,7 @@ fn execute_delegate_call_on_custom_precompile_should_fail() {
fn call_unknown_address_does_not_revert() {
ExtBuilder::default().build().execute_with(|| {
let dummy_contract = H160::from_str("0xe4BdA39B4E2730a578D5E2461A0Cc74FCAa64d62").unwrap();
let p = FrontierPrecompiles::<Runtime>::new();
let p = LaosPrecompiles::<Runtime>::new();

// call data for `mint_with_external_uri`
let mint_with_external_uri_input = "0xfd024566000000000000000000000000f24ff3a9cf04c71dbc94d0b566f7a27b94566cac000000000000000000000000000000000000000000000000000000000000007b0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000e746573742d746f6b656e2d757269000000000000000000000000000000000000";
Expand Down Expand Up @@ -203,7 +203,7 @@ fn call_unknown_address_is_noop() {

handle.input = evolve_with_external_uri.as_bytes().to_vec();

let p = FrontierPrecompiles::<Runtime>::new();
let p = LaosPrecompiles::<Runtime>::new();

assert_noop!(
p.execute(&mut handle).ok_or("returned None"),
Expand Down
6 changes: 3 additions & 3 deletions runtime/laos/src/tests/xcm_mock/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ use staging_xcm_builder::{
use staging_xcm_executor::{traits::WeightTrader, XcmExecutor};
use xcm_simulator::PhantomData;

use crate::precompiles::FrontierPrecompiles;
use crate::precompiles::LaosPrecompiles;

pub type Block = frame_system::mocking::MockBlock<Runtime>;
pub type AccountId = H160;
Expand Down Expand Up @@ -151,7 +151,7 @@ parameter_types! {
pub BlockGasLimit: U256 = U256::from(BLOCK_GAS_LIMIT);
pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE);
pub WeightPerGas: Weight = Weight::from_parts(20_000, 0);
pub PrecompilesValue: FrontierPrecompiles<Runtime> = FrontierPrecompiles::<_>::new();
pub PrecompilesValue: LaosPrecompiles<Runtime> = LaosPrecompiles::<_>::new();
}

impl pallet_evm::Config for Runtime {
Expand All @@ -164,7 +164,7 @@ impl pallet_evm::Config for Runtime {
type AddressMapping = IdentityAddressMapping;
type Currency = Balances;
type RuntimeEvent = RuntimeEvent;
type PrecompilesType = FrontierPrecompiles<Self>;
type PrecompilesType = LaosPrecompiles<Self>;
type PrecompilesValue = PrecompilesValue;
type ChainId = ();
type BlockGasLimit = BlockGasLimit;
Expand Down

0 comments on commit e5b8dd4

Please sign in to comment.