Skip to content

Commit

Permalink
deps: update substrate to polkadot-v1.3.0 (polkadot-evm#1265)
Browse files Browse the repository at this point in the history
* deps: update substrate to polkadot-sdk#8b061a5c5d29a4ef8efa0f2919fdc5c3cfc36361

* some trivials

* adjust the log level of pending runtime api

* deps: update substrate to polkadot-v1.3.0

* fix mock

* use release-polkadot-v1.3.0 branch and remove version field

* update some deps

---------

Co-authored-by: Wei Tang <wei@pacna.org>
  • Loading branch information
koushiro and sorpaas committed Jan 14, 2024
1 parent 16404e1 commit e262e80
Show file tree
Hide file tree
Showing 9 changed files with 558 additions and 381 deletions.
698 changes: 449 additions & 249 deletions Cargo.lock

Large diffs are not rendered by default.

157 changes: 78 additions & 79 deletions Cargo.toml

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions frame/ethereum/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,24 @@ parameter_types! {
// For weight estimation, we assume that the most locks on an individual account will be 50.
// This number may need to be adjusted in the future if this assumption no longer holds true.
pub const MaxLocks: u32 = 50;
pub const MaxReserves: u32 = 50;
}

impl pallet_balances::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeFreezeReason;
type WeightInfo = ();
type Balance = u64;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type ReserveIdentifier = ();
type RuntimeHoldReason = ();
type FreezeIdentifier = ();
type ReserveIdentifier = [u8; 8];
type FreezeIdentifier = RuntimeFreezeReason;
type MaxLocks = MaxLocks;
type MaxReserves = ();
type MaxHolds = ();
type MaxFreezes = ();
type MaxReserves = MaxReserves;
type MaxHolds = ConstU32<5>;
type MaxFreezes = ConstU32<1>;
}

parameter_types! {
Expand Down
7 changes: 4 additions & 3 deletions frame/evm/precompile/dispatch/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,15 @@ parameter_types! {
}
impl pallet_balances::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeFreezeReason;
type WeightInfo = ();
type Balance = u64;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type ReserveIdentifier = ();
type RuntimeHoldReason = ();
type FreezeIdentifier = ();
type ReserveIdentifier = [u8; 8];
type FreezeIdentifier = RuntimeFreezeReason;
type MaxLocks = ();
type MaxReserves = ();
type MaxHolds = ();
Expand Down
7 changes: 4 additions & 3 deletions frame/evm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@ parameter_types! {
}
impl pallet_balances::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeFreezeReason;
type WeightInfo = ();
type Balance = u64;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type ReserveIdentifier = ();
type RuntimeHoldReason = ();
type FreezeIdentifier = ();
type ReserveIdentifier = [u8; 8];
type FreezeIdentifier = RuntimeFreezeReason;
type MaxLocks = ();
type MaxReserves = ();
type MaxHolds = ();
Expand Down
7 changes: 4 additions & 3 deletions precompiles/tests-external/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,15 @@ parameter_types! {
}
impl pallet_balances::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeFreezeReason;
type WeightInfo = ();
type Balance = Balance;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type ReserveIdentifier = [u8; 4];
type RuntimeHoldReason = ();
type FreezeIdentifier = ();
type ReserveIdentifier = [u8; 8];
type FreezeIdentifier = RuntimeFreezeReason;
type MaxLocks = ();
type MaxReserves = ();
type MaxHolds = ();
Expand Down
6 changes: 0 additions & 6 deletions template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,12 @@ fp-account = { workspace = true, features = ["serde"] }
fp-evm = { workspace = true, features = ["serde"] }
fp-rpc = { workspace = true }
fp-self-contained = { workspace = true, features = ["serde"] }
precompile-utils = { workspace = true }
# Frontier FRAME
pallet-base-fee = { workspace = true }
pallet-dynamic-fee = { workspace = true }
pallet-ethereum = { workspace = true }
pallet-evm = { workspace = true }
pallet-evm-chain-id = { workspace = true }
pallet-evm-precompile-blake2 = { workspace = true }
pallet-evm-precompile-bn128 = { workspace = true }
pallet-evm-precompile-modexp = { workspace = true }
pallet-evm-precompile-sha3fips = { workspace = true }
pallet-evm-precompile-simple = { workspace = true }
Expand Down Expand Up @@ -103,15 +100,12 @@ std = [
"fp-evm/std",
"fp-rpc/std",
"fp-self-contained/std",
"precompile-utils/std",
# Frontier FRAME
"pallet-base-fee/std",
"pallet-dynamic-fee/std",
"pallet-ethereum/std",
"pallet-evm/std",
"pallet-evm-chain-id/std",
"pallet-evm-precompile-blake2/std",
"pallet-evm-precompile-bn128/std",
"pallet-evm-precompile-modexp/std",
"pallet-evm-precompile-sha3fips/std",
"pallet-evm-precompile-simple/std",
Expand Down
12 changes: 7 additions & 5 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,22 +263,24 @@ parameter_types! {
// For weight estimation, we assume that the most locks on an individual account will be 50.
// This number may need to be adjusted in the future if this assumption no longer holds true.
pub const MaxLocks: u32 = 50;
pub const MaxReserves: u32 = 50;
}

impl pallet_balances::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type RuntimeFreezeReason = RuntimeFreezeReason;
type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;
type Balance = Balance;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type ReserveIdentifier = [u8; 8];
type RuntimeHoldReason = ();
type FreezeIdentifier = ();
type FreezeIdentifier = RuntimeFreezeReason;
type MaxLocks = MaxLocks;
type MaxReserves = ();
type MaxHolds = ();
type MaxFreezes = ();
type MaxReserves = MaxReserves;
type MaxHolds = ConstU32<5>;
type MaxFreezes = ConstU32<1>;
}

parameter_types! {
Expand Down
31 changes: 4 additions & 27 deletions template/runtime/src/precompiles.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
use sp_core::H160;
use sp_std::marker::PhantomData;

use pallet_evm::{
IsPrecompileResult, Precompile, PrecompileHandle, PrecompileResult, PrecompileSet,
};
use pallet_evm_precompile_blake2::Blake2F;
use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing};
use sp_core::H160;
use sp_std::marker::PhantomData;

use pallet_evm_precompile_modexp::Modexp;
use pallet_evm_precompile_sha3fips::Sha3FIPS256;
use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256};
use precompile_utils::prelude::revert;

pub struct FrontierPrecompiles<R>(PhantomData<R>);

Expand All @@ -20,17 +17,13 @@ where
pub fn new() -> Self {
Self(Default::default())
}
pub fn used_addresses() -> [H160; 11] {
pub fn used_addresses() -> [H160; 7] {
[
hash(1),
hash(2),
hash(3),
hash(4),
hash(5),
hash(6),
hash(7),
hash(8),
hash(9),
hash(1024),
hash(1025),
]
Expand All @@ -41,29 +34,13 @@ where
R: pallet_evm::Config,
{
fn execute(&self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {
let (code_addr, context_addr) = (handle.code_address(), handle.context().address);
// For chains that possess their own stateful precompiles, it is advisable to activate this verification measure.
// This measure prohibits the use of DELEGATECALL or CALLCODE for any precompiles other than the official Ethereum precompiles, which are inherently stateless.
if Self::used_addresses().contains(&code_addr)
&& code_addr > hash(9)
&& code_addr != context_addr
{
return Some(Err(revert(
"cannot be called with DELEGATECALL or CALLCODE",
)));
};

match handle.code_address() {
// Ethereum precompiles :
a if a == hash(1) => Some(ECRecover::execute(handle)),
a if a == hash(2) => Some(Sha256::execute(handle)),
a if a == hash(3) => Some(Ripemd160::execute(handle)),
a if a == hash(4) => Some(Identity::execute(handle)),
a if a == hash(5) => Some(Modexp::execute(handle)),
a if a == hash(6) => Some(Bn128Add::execute(handle)),
a if a == hash(7) => Some(Bn128Mul::execute(handle)),
a if a == hash(8) => Some(Bn128Pairing::execute(handle)),
a if a == hash(9) => Some(Blake2F::execute(handle)),
// Non-Frontier specific nor Ethereum precompiles :
a if a == hash(1024) => Some(Sha3FIPS256::execute(handle)),
a if a == hash(1025) => Some(ECRecoverPublicKey::execute(handle)),
Expand Down

0 comments on commit e262e80

Please sign in to comment.