diff --git a/.github/workflows/runtime-build.yml b/.github/workflows/runtime-build.yml index 96c909f1..dd735541 100644 --- a/.github/workflows/runtime-build.yml +++ b/.github/workflows/runtime-build.yml @@ -2,7 +2,7 @@ name: Build Runtime env: SRTOOL_IMG: paritytech/srtool - SRTOOL_VERSION: 1.53.0 + SRTOOL_VERSION: 1.56.1 SUBWASM_VERSION: 0.16.1 on: diff --git a/node/opportunity/src/chain_spec.rs b/node/opportunity/src/chain_spec.rs index 56b64d15..20e61f39 100644 --- a/node/opportunity/src/chain_spec.rs +++ b/node/opportunity/src/chain_spec.rs @@ -4,18 +4,17 @@ use sc_client_api::{BadBlocks, ForkBlocks}; use serde::{Deserialize, Serialize}; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; -use sp_core::{sr25519, Pair, Public, H160, U256}; +use sp_core::{sr25519, Pair, Public}; use sp_finality_grandpa::AuthorityId as GrandpaId; use sp_runtime::{ traits::{IdentifyAccount, Verify}, Perbill, }; -use std::{collections::BTreeMap, str::FromStr}; use opportunity_runtime::{ wasm_binary_unwrap, AssetRegistryConfig, BabeConfig, BalancesConfig, Block, CouncilConfig, DemocracyConfig, EVMConfig, ElectionsConfig, EthereumConfig, GrandpaConfig, ImOnlineConfig, - OracleConfig, SessionConfig, SessionKeys, StakerStatus, StakingConfig, SudoConfig, + OracleConfig, Precompiles, SessionConfig, SessionKeys, StakerStatus, StakingConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, TechnicalMembershipConfig, TreasuryConfig, MAX_NOMINATIONS, }; @@ -269,6 +268,11 @@ fn opportunity_testnet_config_genesis( (x.clone(), x.clone(), STASH, StakerStatus::Nominator(nominations)) })) .collect::>(); + // This is supposed the be the simplest bytecode to revert without returning any data. + // We will pre-deploy it under all of our precompiles to ensure they can be called from + // within contracts. + // (PUSH1 0x00 PUSH1 0x00 REVERT) + let revert_bytecode = vec![0x60, 0x00, 0x60, 0x00, 0xFD]; opportunity_runtime::GenesisConfig { system: SystemConfig { @@ -334,27 +338,22 @@ fn opportunity_testnet_config_genesis( technical_membership: TechnicalMembershipConfig::default(), treasury: TreasuryConfig::default(), evm: EVMConfig { - accounts: { - let mut map = BTreeMap::new(); - map.insert( - // H160 address of Alice dev account - // Derived from SS58 (42 prefix) address - // SS58: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY - // hex: 0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d - // Using the full hex key, truncating to the first 20 bytes (the first 40 hex - // chars) - H160::from_str("d43593c715fdd31c61141abd04a99fd6822c8558") - .expect("internal H160 is valid; qed"), - pallet_evm::GenesisAccount { - balance: U256::from_str("0xffffffffffffffffffffffffffffffff") - .expect("internal U256 is valid; qed"), - code: Default::default(), - nonce: Default::default(), - storage: Default::default(), - }, - ); - map - }, + // We need _some_ code inserted at the precompile address so that + // the evm will actually call the address. + accounts: Precompiles::used_addresses() + .iter() + .map(|addr| { + ( + addr.clone(), + pallet_evm::GenesisAccount { + nonce: Default::default(), + balance: Default::default(), + storage: Default::default(), + code: revert_bytecode.clone(), + }, + ) + }) + .collect(), }, ethereum: EthereumConfig {}, dynamic_fee: Default::default(), diff --git a/runtime/opportunity/src/lib.rs b/runtime/opportunity/src/lib.rs index f16228c5..757ce215 100644 --- a/runtime/opportunity/src/lib.rs +++ b/runtime/opportunity/src/lib.rs @@ -62,8 +62,10 @@ use pallet_transaction_payment::CurrencyAdapter; use fp_rpc::TransactionStatus; use pallet_ethereum::{Call::transact, Transaction as EthereumTransaction}; use pallet_evm::{Account as EVMAccount, EnsureAddressTruncated, HashedAddressMapping, Runner}; -mod precompiles; + use precompiles::FrontierPrecompiles; +mod precompiles; +pub type Precompiles = FrontierPrecompiles; use primitives::{AccountId, AssetId, Balance, Hash, Index, Signature}; diff --git a/runtime/opportunity/src/precompiles.rs b/runtime/opportunity/src/precompiles.rs index afb72530..242fd565 100644 --- a/runtime/opportunity/src/precompiles.rs +++ b/runtime/opportunity/src/precompiles.rs @@ -8,6 +8,18 @@ use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripe pub struct FrontierPrecompiles(PhantomData); +// impl FrontierPrecompiles +// where +// R: pallet_evm::Config, +// { +// pub fn new() -> Self { +// Self(Default::default()) +// } +// pub fn used_addresses() -> sp_std::vec::Vec { +// sp_std::vec![1, 2, 3, 4, 5, 1024, 1025].into_iter().map(|x| hash(x)).collect() +// } +// } + impl FrontierPrecompiles where R: pallet_evm::Config, @@ -15,10 +27,18 @@ where pub fn new() -> Self { Self(Default::default()) } + /// Return all addresses that contain precompiles. This can be used to populate dummy code + /// under the precompile. + // pub fn used_addresses() -> impl Iterator { + // sp_std::vec![1, 2, 3, 4, 5, 1024, 1025] + // .into_iter() + // .map(|x| R::AddressMapping::into_account_id(hash(x))) + // } pub fn used_addresses() -> sp_std::vec::Vec { sp_std::vec![1, 2, 3, 4, 5, 1024, 1025].into_iter().map(|x| hash(x)).collect() } } + impl PrecompileSet for FrontierPrecompiles where R: pallet_evm::Config,