Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add author mapping precompile to Moonbeam and Moonriver #1160

Merged
merged 1 commit into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -77,7 +78,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 @@ -99,6 +101,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 @@ -154,6 +157,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