Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
merge master
  • Loading branch information
zqhxuyuan committed Jun 7, 2022
commit 439904a288dc6717904cf4eebf5fd5dfc02ff3df
10 changes: 5 additions & 5 deletions modules/evm-accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,6 @@ impl<T: Config> Pallet<T> {

let eth_address = T::AddressMapping::get_or_create_evm_address(&who);

Self::deposit_event(Event::ClaimAccount {
account_id: who,
evm_address: eth_address,
});

Ok(eth_address)
}
}
Expand Down Expand Up @@ -321,6 +316,11 @@ where
Accounts::<T>::insert(&addr, &account_id);
EvmAddresses::<T>::insert(&account_id, &addr);

Pallet::<T>::deposit_event(Event::ClaimAccount {
account_id: account_id.clone(),
evm_address: addr,
});

addr
})
}
Expand Down
4 changes: 4 additions & 0 deletions modules/evm-accounts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ fn account_to_evm_with_create_default() {
EvmAddressMapping::<Runtime>::get_or_create_evm_address(&ALICE),
default_evm_account
);
System::assert_last_event(Event::EvmAccountsModule(crate::Event::ClaimAccount {
account_id: ALICE,
evm_address: default_evm_account,
}));
assert_eq!(
EvmAddressMapping::<Runtime>::get_evm_address(&ALICE),
Some(default_evm_account)
Expand Down
16 changes: 16 additions & 0 deletions modules/evm/src/precompiles/ecrecover_publickey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,19 @@ impl LinearCostPrecompile for ECRecoverPublicKey {
Ok((ExitSucceed::Returned, pubkey.to_vec()))
}
}

#[test]
fn works() {
let input = hex_literal::hex! {"
18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c
000000000000000000000000000000000000000000000000000000000000001c
73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75f
eeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549
"};

let expected = hex_literal::hex!("3a514176466fa815ed481ffad09110a2d344f6c9b78c1d14afc351c3a51be33d8072e77939dc03ba44790779b7a1025baf3003f6732430e20cd9b76d953391b3");

let (exit, output) = ECRecoverPublicKey::execute(&input, 0).unwrap();
assert_eq!(exit, ExitSucceed::Returned);
assert_eq!(output, expected);
}
12 changes: 12 additions & 0 deletions runtime/common/src/precompile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ pub const BN_MUL: H160 = H160(hex!("0000000000000000000000000000000000000007"));
pub const BN_PAIRING: H160 = H160(hex!("0000000000000000000000000000000000000008"));
pub const BLAKE2F: H160 = H160(hex!("0000000000000000000000000000000000000009"));

pub const ETH_PRECOMPILE_END: H160 = BLAKE2F;

pub const ECRECOVER_PUBLICKEY: H160 = H160(hex!("0000000000000000000000000000000000000080"));
pub const SHA3_256: H160 = H160(hex!("0000000000000000000000000000000000000081"));
pub const SHA3_512: H160 = H160(hex!("0000000000000000000000000000000000000082"));
Expand Down Expand Up @@ -223,6 +225,16 @@ where
if !self.is_precompile(address) {
return None;
}

// Filter known precompile addresses except Ethereum officials
if address > ETH_PRECOMPILE_END && context.address != address {
return Some(Err(PrecompileFailure::Revert {
exit_status: ExitRevert::Reverted,
output: "cannot be called with DELEGATECALL or CALLCODE".into(),
cost: target_gas.unwrap_or_default(),
}));
}

log::trace!(target: "evm", "Precompile begin, address: {:?}, input: {:?}, target_gas: {:?}, context: {:?}", address, input, target_gas, context);

// https://github.com/ethereum/go-ethereum/blob/9357280fce5c5d57111d690a336cca5f89e34da6/core/vm/contracts.go#L83
Expand Down
1 change: 0 additions & 1 deletion runtime/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ with-mandala-runtime = [
]
with-karura-runtime = [
"karura-runtime",
"karura-runtime/integration-tests",
"acala-service/with-karura-runtime",
"module-relaychain/kusama"
]
Expand Down
2 changes: 1 addition & 1 deletion runtime/integration-tests/src/dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fn test_trading_pair() {

assert_ok!(AssetRegistry::register_foreign_asset(
Origin::root(),
Box::new(MultiLocation::new(1, X2(Parachain(2001), GeneralKey(KAR.encode()))).into()),
Box::new(MultiLocation::new(1, X2(Parachain(2002), GeneralKey(KAR.encode()))).into()),
Box::new(AssetMetadata {
name: b"Sibling Token".to_vec(),
symbol: b"ST".to_vec(),
Expand Down
24 changes: 13 additions & 11 deletions runtime/integration-tests/src/relaychain/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ use sp_core::{H256, U256};
use std::str::FromStr;
use xcm_emulator::TestExt;

pub const SIBLING_ID: u32 = 2002;
pub const KARURA_ID: u32 = 2000;

pub fn erc20_address_0() -> EvmAddress {
EvmAddress::from_str("0x5e0b4bfa0b55932a3587e648c3552a6515ba56b1").unwrap()
}
Expand All @@ -39,6 +42,13 @@ pub fn alice_evm_addr() -> EvmAddress {
EvmAddress::from_str("1000000000000000000000000000000000000001").unwrap()
}

fn sibling_reserve_account() -> AccountId {
polkadot_parachain::primitives::Sibling::from(SIBLING_ID).into_account()
}
fn karura_reserve_account() -> AccountId {
polkadot_parachain::primitives::Sibling::from(KARURA_ID).into_account()
}

pub fn deploy_erc20_contracts() {
let json: serde_json::Value =
serde_json::from_str(include_str!("../../../../ts-tests/build/Erc20DemoContract2.json")).unwrap();
Expand Down Expand Up @@ -78,10 +88,6 @@ pub fn deploy_erc20_contracts() {
fn erc20_transfer_between_sibling() {
TestNet::reset();

fn sibling_reserve_account() -> AccountId {
polkadot_parachain::primitives::Sibling::from(2001).into_account()
}

Sibling::execute_with(|| {
let erc20_as_foreign_asset = CurrencyId::Erc20(erc20_address_0());
// register Karura's erc20 as foreign asset
Expand Down Expand Up @@ -142,7 +148,7 @@ fn erc20_transfer_between_sibling() {
MultiLocation::new(
1,
X2(
Parachain(2001),
Parachain(SIBLING_ID),
Junction::AccountId32 {
network: NetworkId::Any,
id: BOB.into(),
Expand Down Expand Up @@ -244,16 +250,12 @@ fn erc20_transfer_between_sibling() {
fn sibling_erc20_to_self_as_foreign_asset() {
TestNet::reset();

fn sibling_reserve_account() -> AccountId {
polkadot_parachain::primitives::Sibling::from(2000).into_account()
}

Karura::execute_with(|| {
let erc20_as_foreign_asset = CurrencyId::Erc20(erc20_address_0());
// register Karura's erc20 as foreign asset
assert_ok!(AssetRegistry::register_foreign_asset(
Origin::root(),
Box::new(MultiLocation::new(1, X2(Parachain(2001), GeneralKey(erc20_as_foreign_asset.encode()))).into()),
Box::new(MultiLocation::new(1, X2(Parachain(2002), GeneralKey(erc20_as_foreign_asset.encode()))).into()),
Box::new(AssetMetadata {
name: b"Sibling USDC".to_vec(),
symbol: b"sUSDC".to_vec(),
Expand Down Expand Up @@ -326,7 +328,7 @@ fn sibling_erc20_to_self_as_foreign_asset() {
);
assert_eq!(
10_000_000_000_000,
Currencies::free_balance(CurrencyId::Erc20(erc20_address_0()), &sibling_reserve_account())
Currencies::free_balance(CurrencyId::Erc20(erc20_address_0()), &karura_reserve_account())
);
});

Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.