Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into update-polkadot-v…
Browse files Browse the repository at this point in the history
…0.9.42
  • Loading branch information
koushiro committed May 23, 2023
2 parents 5adfcbd + 4b1b168 commit c44ed0a
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 51 deletions.
23 changes: 15 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 @@ -43,7 +43,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.18.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 @@ -95,8 +95,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 @@ -179,7 +179,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,
}
}
}
39 changes: 33 additions & 6 deletions frame/evm/src/runner/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ use sp_std::{
vec::Vec,
};
// Frontier
use fp_evm::{CallInfo, CreateInfo, ExecutionInfo, Log, PrecompileSet, Vicinity};
use fp_evm::{
CallInfo, CreateInfo, ExecutionInfo, IsPrecompileResult, Log, PrecompileSet, Vicinity,
};

use crate::{
runner::Runner as RunnerT, AccountCodes, AccountStorages, AddressMapping, BalanceOf,
Expand Down Expand Up @@ -79,6 +81,7 @@ where
T::PrecompilesType,
>,
) -> (ExitReason, R),
R: Default,
{
let (base_fee, weight) = T::FeeCalculator::min_gas_price();

Expand Down Expand Up @@ -116,7 +119,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 @@ -135,7 +138,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 @@ -147,9 +171,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 @@ -622,6 +644,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 @@ -731,9 +757,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 @@ -32,6 +32,7 @@ use sp_std::vec::Vec;

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

Expand Down
1 change: 1 addition & 0 deletions template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
async-trait = "0.1"
clap = { version = "4.1", features = ["derive", "deprecated"] }
futures = "0.3.25"
hex-literal = { workspace = true }
jsonrpsee = { workspace = true, features = ["server", "macros"] }
log = "0.4.17"
scale-codec = { package = "parity-scale-codec", workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions template/node/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for TransferKeepAliveBuilder {
self.client.as_ref(),
acc,
BalancesCall::transfer_keep_alive {
dest: self.dest.into(),
dest: self.dest,
value: self.value,
}
.into(),
Expand Down Expand Up @@ -171,7 +171,7 @@ pub fn create_benchmark_extrinsic(

runtime::UncheckedExtrinsic::new_signed(
call,
AccountId20::from(sender.public()).into(),
AccountId20::from(sender.public()),
runtime::Signature::new(signature),
extra,
)
Expand Down
44 changes: 23 additions & 21 deletions template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use std::{collections::BTreeMap, str::FromStr};

use hex_literal::hex;
use serde::{Deserialize, Serialize};
// Substrate
use sc_chain_spec::{ChainType, Properties};
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_consensus_grandpa::AuthorityId as GrandpaId;
use sp_core::{ecdsa, storage::Storage, Pair, Public, H160, U256};
#[allow(unused_imports)]
use sp_core::ecdsa;
use sp_core::{storage::Storage, Pair, Public, H160, U256};
use sp_runtime::traits::{IdentifyAccount, Verify};
use sp_state_machine::BasicExternalities;
// Frontier
Expand Down Expand Up @@ -49,9 +52,12 @@ pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Pu
.public()
}

#[allow(dead_code)]
type AccountPublic = <Signature as Verify>::Signer;

/// Generate an account ID from seed.
/// For use with `AccountId32`, `dead_code` if `AccountId20`.
#[allow(dead_code)]
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
Expand Down Expand Up @@ -84,14 +90,16 @@ pub fn development_config(enable_manual_seal: Option<bool>) -> DevChainSpec {
DevGenesisExt {
genesis_config: testnet_genesis(
wasm_binary,
// Sudo account
get_account_id_from_seed::<ecdsa::Public>("Alice"),
// Sudo account (Alith)
AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
// Pre-funded accounts
vec![
get_account_id_from_seed::<ecdsa::Public>("Alice"),
get_account_id_from_seed::<ecdsa::Public>("Bob"),
get_account_id_from_seed::<ecdsa::Public>("Alice//stash"),
get_account_id_from_seed::<ecdsa::Public>("Bob//stash"),
AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), // Alith
AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), // Baltathar
AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), // Charleth
AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")), // Dorothy
AccountId::from(hex!("Ff64d3F6efE2317EE2807d223a0Bdc4c0c49dfDB")), // Ethan
AccountId::from(hex!("C0F0f4ab324C46e55D02D0033343B4Be8A55532d")), // Faith
],
// Initial PoA authorities
vec![authority_keys_from_seed("Alice")],
Expand Down Expand Up @@ -129,22 +137,16 @@ pub fn local_testnet_config() -> ChainSpec {
testnet_genesis(
wasm_binary,
// Initial PoA authorities
// Sudo account
get_account_id_from_seed::<ecdsa::Public>("Alice"),
// Sudo account (Alith)
AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
// Pre-funded accounts
vec![
get_account_id_from_seed::<ecdsa::Public>("Alice"),
get_account_id_from_seed::<ecdsa::Public>("Bob"),
get_account_id_from_seed::<ecdsa::Public>("Charlie"),
get_account_id_from_seed::<ecdsa::Public>("Dave"),
get_account_id_from_seed::<ecdsa::Public>("Eve"),
get_account_id_from_seed::<ecdsa::Public>("Ferdie"),
get_account_id_from_seed::<ecdsa::Public>("Alice//stash"),
get_account_id_from_seed::<ecdsa::Public>("Bob//stash"),
get_account_id_from_seed::<ecdsa::Public>("Charlie//stash"),
get_account_id_from_seed::<ecdsa::Public>("Dave//stash"),
get_account_id_from_seed::<ecdsa::Public>("Eve//stash"),
get_account_id_from_seed::<ecdsa::Public>("Ferdie//stash"),
AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), // Alith
AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")), // Baltathar
AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")), // Charleth
AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")), // Dorothy
AccountId::from(hex!("Ff64d3F6efE2317EE2807d223a0Bdc4c0c49dfDB")), // Ethan
AccountId::from(hex!("C0F0f4ab324C46e55D02D0033343B4Be8A55532d")), // Faith
],
vec![
authority_keys_from_seed("Alice"),
Expand Down
2 changes: 1 addition & 1 deletion template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ pub fn build_full(
}

pub fn new_chain_ops(
mut config: &mut Configuration,
config: &mut Configuration,
eth_config: &EthConfiguration,
) -> Result<
(
Expand Down
8 changes: 4 additions & 4 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use sp_core::{
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{
AccountIdLookup, BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable, Get,
IdentifyAccount, NumberFor, PostDispatchInfoOf, UniqueSaturatedInto, Verify,
BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable, Get, IdentifyAccount,
IdentityLookup, NumberFor, PostDispatchInfoOf, UniqueSaturatedInto, Verify,
},
transaction_validity::{TransactionSource, TransactionValidity, TransactionValidityError},
ApplyExtrinsicResult, ConsensusEngineId, Perbill, Permill,
Expand Down Expand Up @@ -181,7 +181,7 @@ impl frame_system::Config for Runtime {
/// The identifier used to distinguish between accounts.
type AccountId = AccountId;
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
type Lookup = AccountIdLookup<AccountId, ()>;
type Lookup = IdentityLookup<AccountId>;
/// The header type.
type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// The ubiquitous event type.
Expand Down Expand Up @@ -440,7 +440,7 @@ impl fp_rpc::ConvertTransaction<opaque::UncheckedExtrinsic> for TransactionConve
}

/// The address format for describing accounts.
pub type Address = sp_runtime::MultiAddress<AccountId, ()>;
pub type Address = AccountId;
/// Block header type as expected by this runtime.
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// Block type as expected by this runtime.
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 c44ed0a

Please sign in to comment.