Skip to content

Commit

Permalink
add author mapping precompile to moonbeam and moonriver (#1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanocryk authored Jan 12, 2022
1 parent 93e0647 commit 0113033
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions runtime/moonbeam/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ parachain-staking = { path = "../../pallets/parachain-staking", default-features

# Moonbeam precompiles
crowdloan-rewards-precompiles = { path = "../../precompiles/crowdloan-rewards", default-features = false }
pallet-author-mapping-precompiles = { path = "../../precompiles/author-mapping", default-features = false }
parachain-staking-precompiles = { path = "../../precompiles/parachain-staking", default-features = false }

# Moonbeam tracing
Expand Down Expand Up @@ -131,6 +132,7 @@ std = [
"moonbeam-rpc-primitives-txpool/std",
"nimbus-primitives/std",
"pallet-author-inherent/std",
"pallet-author-mapping-precompiles/std",
"pallet-author-mapping/std",
"pallet-author-slot-filter/std",
"pallet-balances/std",
Expand Down
7 changes: 6 additions & 1 deletion runtime/moonbeam/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use crowdloan_rewards_precompiles::CrowdloanRewardsWrapper;
use fp_evm::Context;
use pallet_author_mapping_precompiles::AuthorMappingWrapper;
use pallet_evm::{AddressMapping, Precompile, PrecompileResult, PrecompileSet};
use pallet_evm_precompile_blake2::Blake2F;
use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing};
Expand Down Expand Up @@ -45,7 +46,7 @@ where
/// 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, 6, 7, 8, 9, 1024, 1025, 1026, 2048, 2049]
sp_std::vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 1024, 1025, 1026, 2048, 2049, 2055]
.into_iter()
.map(|x| R::AddressMapping::into_account_id(hash(x)))
}
Expand All @@ -60,6 +61,7 @@ where
Dispatch<R>: Precompile,
ParachainStakingWrapper<R>: Precompile,
CrowdloanRewardsWrapper<R>: Precompile,
AuthorMappingWrapper<R>: Precompile,
R: pallet_evm::Config,
{
fn execute(
Expand Down Expand Up @@ -98,6 +100,9 @@ where
a if a == hash(2049) => Some(CrowdloanRewardsWrapper::<R>::execute(
input, target_gas, context, is_static,
)),
a if a == hash(2055) => Some(AuthorMappingWrapper::<R>::execute(
input, target_gas, context, is_static,
)),
_ => None,
}
}
Expand Down
2 changes: 2 additions & 0 deletions runtime/moonriver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ xcm-transactor = { path = "../../pallets/xcm-transactor", default-features = fal

# Moonbeam precompiles
crowdloan-rewards-precompiles = { path = "../../precompiles/crowdloan-rewards", default-features = false }
pallet-author-mapping-precompiles = { path = "../../precompiles/author-mapping", default-features = false }
pallet-democracy-precompiles = { path = "../../precompiles/pallet-democracy", default-features = false }
pallet-evm-precompile-assets-erc20 = { path = "../../precompiles/assets-erc20", default-features = false }
pallet-evm-precompile-balances-erc20 = { path = "../../precompiles/balances-erc20", default-features = false }
Expand Down Expand Up @@ -166,6 +167,7 @@ std = [
"pallet-asset-manager/std",
"pallet-assets/std",
"pallet-author-inherent/std",
"pallet-author-mapping-precompiles/std",
"pallet-author-mapping/std",
"pallet-author-slot-filter/std",
"pallet-balances/std",
Expand Down
8 changes: 7 additions & 1 deletion runtime/moonriver/src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use crowdloan_rewards_precompiles::CrowdloanRewardsWrapper;
use fp_evm::Context;
use moonbeam_relay_encoder::kusama::KusamaEncoder;
use pallet_author_mapping_precompiles::AuthorMappingWrapper;
use pallet_democracy_precompiles::DemocracyWrapper;
use pallet_evm::{AddressMapping, Precompile, PrecompileResult, PrecompileSet};
use pallet_evm_precompile_assets_erc20::Erc20AssetsPrecompileSet;
Expand Down Expand Up @@ -83,7 +84,8 @@ where
/// under the precompile.
pub fn used_addresses() -> impl Iterator<Item = R::AccountId> {
sp_std::vec![
1, 2, 3, 4, 5, 6, 7, 8, 9, 1024, 1025, 1026, 2048, 2049, 2050, 2051, 2052, 2053, 2054
1, 2, 3, 4, 5, 6, 7, 8, 9, 1024, 1025, 1026, 2048, 2049, 2050, 2051, 2052, 2053, 2054,
2055
]
.into_iter()
.map(|x| R::AddressMapping::into_account_id(hash(x)))
Expand All @@ -105,6 +107,7 @@ where
RelayEncoderWrapper<R, KusamaEncoder>: Precompile,
XcmTransactorWrapper<R>: Precompile,
DemocracyWrapper<R>: Precompile,
AuthorMappingWrapper<R>: Precompile,
R: pallet_evm::Config,
{
fn execute(
Expand Down Expand Up @@ -160,6 +163,9 @@ where
a if a == hash(2054) => Some(XcmTransactorWrapper::<R>::execute(
input, target_gas, context, is_static,
)),
a if a == hash(2055) => Some(AuthorMappingWrapper::<R>::execute(
input, target_gas, context, is_static,
)),
// If the address matches asset prefix, the we route through the asset precompile set
a if &a.to_fixed_bytes()[0..4] == ASSET_PRECOMPILE_ADDRESS_PREFIX => {
Erc20AssetsPrecompileSet::<R>::new()
Expand Down

0 comments on commit 0113033

Please sign in to comment.