Skip to content

Commit

Permalink
Amend chainspec for EVM.
Browse files Browse the repository at this point in the history
  • Loading branch information
firke committed Dec 22, 2021
1 parent 2f7e090 commit 2376eb7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/runtime-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
47 changes: 23 additions & 24 deletions node/opportunity/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -269,6 +268,11 @@ fn opportunity_testnet_config_genesis(
(x.clone(), x.clone(), STASH, StakerStatus::Nominator(nominations))
}))
.collect::<Vec<_>>();
// 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 {
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 3 additions & 1 deletion runtime/opportunity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runtime>;

use primitives::{AccountId, AssetId, Balance, Hash, Index, Signature};

Expand Down
20 changes: 20 additions & 0 deletions runtime/opportunity/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,37 @@ use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripe

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

// impl<R> FrontierPrecompiles<R>
// where
// R: pallet_evm::Config,
// {
// pub fn new() -> Self {
// Self(Default::default())
// }
// pub fn used_addresses() -> sp_std::vec::Vec<H160> {
// sp_std::vec![1, 2, 3, 4, 5, 1024, 1025].into_iter().map(|x| hash(x)).collect()
// }
// }

impl<R> FrontierPrecompiles<R>
where
R: pallet_evm::Config,
{
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<Item = R::AccountId> {
// 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<H160> {
sp_std::vec![1, 2, 3, 4, 5, 1024, 1025].into_iter().map(|x| hash(x)).collect()
}
}

impl<R> PrecompileSet for FrontierPrecompiles<R>
where
R: pallet_evm::Config,
Expand Down

0 comments on commit 2376eb7

Please sign in to comment.