diff --git a/Cargo.lock b/Cargo.lock
index 8c1daf875a..fe6affe7da 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6645,7 +6645,6 @@ dependencies = [
"frame-support",
"frame-system",
"hex",
- "libsecp256k1",
"moonbeam-rpc-primitives-debug",
"pallet-assets",
"pallet-aura",
@@ -6654,11 +6653,9 @@ dependencies = [
"pallet-collective",
"pallet-collective-proxy",
"pallet-contracts",
- "pallet-contracts-uapi",
"pallet-dapp-staking",
"pallet-democracy",
"pallet-ethereum",
- "pallet-ethereum-checked",
"pallet-evm",
"pallet-evm-precompile-assets-erc20",
"pallet-evm-precompile-dispatch",
@@ -6669,7 +6666,6 @@ dependencies = [
"pallet-session",
"pallet-timestamp",
"pallet-tx-pause",
- "pallet-unified-accounts",
"pallet-utility",
"pallet-xcm",
"parity-scale-codec",
@@ -6678,7 +6674,6 @@ dependencies = [
"sha3",
"shibuya-runtime",
"shiden-runtime",
- "smallvec",
"sp-consensus-aura",
"sp-core",
"sp-io",
@@ -6686,7 +6681,6 @@ dependencies = [
"sp-trie",
"staging-xcm",
"staging-xcm-executor",
- "unified-accounts-chain-extension-types",
"xcm-runtime-apis",
]
@@ -9317,26 +9311,6 @@ dependencies = [
"sp-runtime",
]
-[[package]]
-name = "pallet-chain-extension-unified-accounts"
-version = "0.1.0"
-dependencies = [
- "astar-primitives",
- "frame-support",
- "frame-system",
- "log",
- "num-traits",
- "pallet-contracts",
- "pallet-evm",
- "pallet-unified-accounts",
- "parity-scale-codec",
- "scale-info",
- "sp-core",
- "sp-runtime",
- "sp-std",
- "unified-accounts-chain-extension-types",
-]
-
[[package]]
name = "pallet-child-bounties"
version = "40.0.0"
@@ -9656,31 +9630,6 @@ dependencies = [
"sp-version",
]
-[[package]]
-name = "pallet-ethereum-checked"
-version = "0.1.0"
-dependencies = [
- "astar-primitives",
- "ethereum",
- "ethereum-types 0.15.1",
- "fp-ethereum",
- "fp-evm",
- "fp-rpc",
- "frame-benchmarking",
- "frame-support",
- "frame-system",
- "hex",
- "pallet-balances",
- "pallet-ethereum",
- "pallet-evm",
- "pallet-timestamp",
- "parity-scale-codec",
- "scale-info",
- "sp-io",
- "sp-runtime",
- "sp-std",
-]
-
[[package]]
name = "pallet-evm"
version = "6.0.0-dev"
@@ -9915,35 +9864,6 @@ dependencies = [
"sp-std",
]
-[[package]]
-name = "pallet-evm-precompile-unified-accounts"
-version = "0.1.0"
-dependencies = [
- "astar-primitives",
- "derive_more 0.99.20",
- "ethers",
- "fp-evm",
- "frame-support",
- "frame-system",
- "hex",
- "hex-literal",
- "libsecp256k1",
- "log",
- "num_enum 0.5.11",
- "pallet-balances",
- "pallet-evm",
- "pallet-timestamp",
- "pallet-unified-accounts",
- "parity-scale-codec",
- "precompile-utils",
- "scale-info",
- "serde",
- "sp-core",
- "sp-io",
- "sp-runtime",
- "sp-std",
-]
-
[[package]]
name = "pallet-evm-precompile-xcm"
version = "0.11.0"
@@ -10796,31 +10716,6 @@ dependencies = [
"scale-info",
]
-[[package]]
-name = "pallet-unified-accounts"
-version = "0.1.0"
-dependencies = [
- "astar-primitives",
- "ethers",
- "frame-benchmarking",
- "frame-support",
- "frame-system",
- "hex",
- "libsecp256k1",
- "log",
- "pallet-balances",
- "pallet-ethereum",
- "pallet-evm",
- "pallet-timestamp",
- "parity-scale-codec",
- "precompile-utils",
- "scale-info",
- "sp-core",
- "sp-io",
- "sp-runtime",
- "sp-std",
-]
-
[[package]]
name = "pallet-utility"
version = "41.0.0"
@@ -15844,7 +15739,6 @@ dependencies = [
name = "shibuya-runtime"
version = "22.0.4"
dependencies = [
- "array-bytes 6.2.3",
"astar-primitives",
"astar-xcm-benchmarks",
"cumulus-pallet-aura-ext",
@@ -15867,7 +15761,6 @@ dependencies = [
"frame-system-benchmarking",
"frame-system-rpc-runtime-api",
"frame-try-runtime",
- "hex-literal",
"log",
"moonbeam-evm-tracer",
"moonbeam-rpc-primitives-debug",
@@ -15879,7 +15772,6 @@ dependencies = [
"pallet-aura",
"pallet-authorship",
"pallet-balances",
- "pallet-chain-extension-unified-accounts",
"pallet-collator-selection 4.0.0",
"pallet-collective",
"pallet-collective-proxy",
@@ -15888,7 +15780,6 @@ dependencies = [
"pallet-democracy",
"pallet-dynamic-evm-base-fee",
"pallet-ethereum",
- "pallet-ethereum-checked",
"pallet-evm",
"pallet-evm-chain-id",
"pallet-evm-precompile-assets-erc20",
@@ -15903,7 +15794,6 @@ dependencies = [
"pallet-evm-precompile-simple",
"pallet-evm-precompile-sr25519",
"pallet-evm-precompile-substrate-ecdsa",
- "pallet-evm-precompile-unified-accounts",
"pallet-evm-precompile-xcm",
"pallet-identity",
"pallet-inflation",
@@ -15923,7 +15813,6 @@ dependencies = [
"pallet-transaction-payment-rpc-runtime-api",
"pallet-treasury 37.0.0",
"pallet-tx-pause",
- "pallet-unified-accounts",
"pallet-utility",
"pallet-vesting",
"pallet-xc-asset-config",
@@ -18732,17 +18621,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e"
-[[package]]
-name = "unified-accounts-chain-extension-types"
-version = "0.1.0"
-dependencies = [
- "num_enum 0.5.11",
- "parity-scale-codec",
- "scale-info",
- "sp-core",
- "sp-runtime",
-]
-
[[package]]
name = "universal-hash"
version = "0.5.1"
diff --git a/Cargo.toml b/Cargo.toml
index 1993f74cb1..653e27004d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,8 +11,6 @@ members = [
"pallets/*",
"precompiles/*",
"primitives",
- "chain-extensions/unified-accounts",
- "chain-extensions/types/*",
"vendor/evm-tracing",
"vendor/primitives/debug",
"vendor/primitives/evm-tracing-events",
@@ -315,10 +313,8 @@ orml-xcm-support = { git = "https://github.com/AstarNetwork/open-runtime-module-
pallet-collator-selection = { path = "./pallets/collator-selection", default-features = false }
pallet-dapp-staking = { path = "./pallets/dapp-staking", default-features = false }
pallet-xc-asset-config = { path = "./pallets/xc-asset-config", default-features = false }
-pallet-ethereum-checked = { path = "./pallets/ethereum-checked", default-features = false }
pallet-inflation = { path = "./pallets/inflation", default-features = false }
pallet-dynamic-evm-base-fee = { path = "./pallets/dynamic-evm-base-fee", default-features = false }
-pallet-unified-accounts = { path = "./pallets/unified-accounts", default-features = false }
astar-xcm-benchmarks = { path = "./pallets/astar-xcm-benchmarks", default-features = false }
pallet-collective-proxy = { path = "./pallets/collective-proxy", default-features = false }
vesting-mbm = { path = "./pallets/vesting-mbm", default-features = false }
@@ -335,13 +331,8 @@ pallet-evm-precompile-sr25519 = { path = "./precompiles/sr25519", default-featur
pallet-evm-precompile-substrate-ecdsa = { path = "./precompiles/substrate-ecdsa", default-features = false }
pallet-evm-precompile-xcm = { path = "./precompiles/xcm", default-features = false }
pallet-evm-precompile-dapp-staking = { path = "./precompiles/dapp-staking", default-features = false }
-pallet-evm-precompile-unified-accounts = { path = "./precompiles/unified-accounts", default-features = false }
pallet-evm-precompile-dispatch-lockdrop = { path = "./precompiles/dispatch-lockdrop", default-features = false }
-pallet-chain-extension-unified-accounts = { path = "./chain-extensions/unified-accounts", default-features = false }
-
-unified-accounts-chain-extension-types = { path = "./chain-extensions/types/unified-accounts", default-features = false }
-
shibuya-runtime = { path = "./runtime/shibuya", default-features = false }
shiden-runtime = { path = "./runtime/shiden", default-features = false }
astar-runtime = { path = "./runtime/astar", default-features = false }
diff --git a/chain-extensions/types/unified-accounts/Cargo.toml b/chain-extensions/types/unified-accounts/Cargo.toml
deleted file mode 100644
index 351b2f03a0..0000000000
--- a/chain-extensions/types/unified-accounts/Cargo.toml
+++ /dev/null
@@ -1,30 +0,0 @@
-[package]
-name = "unified-accounts-chain-extension-types"
-version = "0.1.0"
-description = "Types definitions for contracts using Unified Accounts chain-extension."
-authors.workspace = true
-edition.workspace = true
-homepage.workspace = true
-repository.workspace = true
-
-[lints]
-workspace = true
-
-[dependencies]
-num_enum = { workspace = true }
-parity-scale-codec = { workspace = true }
-scale-info = { workspace = true }
-
-#substarte
-sp-core = { workspace = true }
-sp-runtime = { workspace = true }
-
-[features]
-default = ["std"]
-std = [
- "num_enum/std",
- "parity-scale-codec/std",
- "scale-info/std",
- "sp-core/std",
- "sp-runtime/std",
-]
diff --git a/chain-extensions/types/unified-accounts/src/lib.rs b/chain-extensions/types/unified-accounts/src/lib.rs
deleted file mode 100644
index 7ee82eb9dc..0000000000
--- a/chain-extensions/types/unified-accounts/src/lib.rs
+++ /dev/null
@@ -1,48 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) Stake Technologies Pte.Ltd.
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// Astar is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Astar is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Astar. If not, see .
-
-#![cfg_attr(not(feature = "std"), no_std)]
-
-use num_enum::{IntoPrimitive, TryFromPrimitive};
-use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
-
-#[repr(u16)]
-#[derive(TryFromPrimitive, IntoPrimitive, Decode, Encode)]
-pub enum Command {
- /// Get the mapped Evm address if any
- GetEvmAddress = 0,
- /// Get the mapped Evm address if any otheriwse default associated Evm address
- GetEvmAddressOrDefault = 1,
- /// Get the mapped Native address if any
- GetNativeAddress = 2,
- /// Get the mapped Native address if any otheriwse default associated Native address
- GetNativeAddressOrDefault = 3,
-}
-
-#[derive(Debug, Copy, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen)]
-#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
-pub enum UnifiedAddress {
- /// The address fetched from the mappings and the account
- /// is unified
- #[codec(index = 0)]
- Mapped(T),
- /// The default address associated with account as there
- /// is no mapping found and accounts are not unified
- #[codec(index = 1)]
- Default(T),
-}
diff --git a/chain-extensions/unified-accounts/Cargo.toml b/chain-extensions/unified-accounts/Cargo.toml
deleted file mode 100644
index 7cdba58e85..0000000000
--- a/chain-extensions/unified-accounts/Cargo.toml
+++ /dev/null
@@ -1,49 +0,0 @@
-[package]
-name = "pallet-chain-extension-unified-accounts"
-version = "0.1.0"
-description = "Chain extension for AU"
-authors.workspace = true
-edition.workspace = true
-homepage.workspace = true
-repository.workspace = true
-
-[lints]
-workspace = true
-
-[dependencies]
-frame-support = { workspace = true }
-frame-system = { workspace = true }
-log = { workspace = true }
-num-traits = { workspace = true }
-pallet-contracts = { workspace = true }
-pallet-evm = { workspace = true }
-parity-scale-codec = { workspace = true }
-scale-info = { workspace = true }
-sp-core = { workspace = true }
-sp-runtime = { workspace = true }
-sp-std = { workspace = true }
-
-# Astar
-astar-primitives = { workspace = true }
-pallet-unified-accounts = { workspace = true }
-unified-accounts-chain-extension-types = { workspace = true }
-
-[features]
-default = ["std"]
-std = [
- "parity-scale-codec/std",
- "frame-support/std",
- "frame-system/std",
- "num-traits/std",
- "pallet-contracts/std",
- "pallet-evm/std",
- "scale-info/std",
- "sp-std/std",
- "sp-core/std",
- "sp-runtime/std",
- # Astar
- "astar-primitives/std",
- "pallet-unified-accounts/std",
- "unified-accounts-chain-extension-types/std",
- "log/std",
-]
diff --git a/chain-extensions/unified-accounts/src/lib.rs b/chain-extensions/unified-accounts/src/lib.rs
deleted file mode 100644
index 56c8037535..0000000000
--- a/chain-extensions/unified-accounts/src/lib.rs
+++ /dev/null
@@ -1,85 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) Stake Technologies Pte.Ltd.
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// Astar is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Astar is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Astar. If not, see .
-
-#![cfg_attr(not(feature = "std"), no_std)]
-
-use astar_primitives::evm::{EvmAddress, UnifiedAddressMapper};
-use core::marker::PhantomData;
-use sp_runtime::DispatchError;
-
-use frame_support::DefaultNoBound;
-use pallet_contracts::chain_extension::{
- ChainExtension, Environment, Ext, InitState, Result as DispatchResult, RetVal,
-};
-use pallet_unified_accounts::WeightInfo;
-use parity_scale_codec::Encode;
-pub use unified_accounts_chain_extension_types::Command::{self, *};
-
-type UAWeight = ::WeightInfo;
-
-#[derive(DefaultNoBound)]
-pub struct UnifiedAccountsExtension(PhantomData<(T, UA)>);
-
-impl ChainExtension for UnifiedAccountsExtension
-where
- T: pallet_contracts::Config + pallet_unified_accounts::Config,
- UA: UnifiedAddressMapper,
-{
- fn call(&mut self, env: Environment) -> DispatchResult
- where
- E: Ext,
- {
- let mut env = env.buf_in_buf_out();
- match env.func_id().try_into().map_err(|_| {
- DispatchError::Other("Unsupported func id in Unified Accounts Chain Extension")
- })? {
- GetEvmAddress => {
- let account_id: T::AccountId = env.read_as()?;
- // charge weight
- env.charge_weight(UAWeight::::to_h160())?;
- // write to buffer
- UA::to_h160(&account_id).using_encoded(|r| env.write(r, false, None))?;
- }
- GetEvmAddressOrDefault => {
- let account_id: T::AccountId = env.read_as()?;
- // charge weight
- env.charge_weight(UAWeight::::to_h160_or_default())?;
-
- // write to buffer
- UA::to_h160_or_default(&account_id).using_encoded(|r| env.write(r, false, None))?;
- }
- GetNativeAddress => {
- let evm_address: EvmAddress = env.read_as()?;
- // charge weight
- env.charge_weight(UAWeight::::to_account_id())?;
- // write to buffer
- UA::to_account_id(&evm_address).using_encoded(|r| env.write(r, false, None))?;
- }
- GetNativeAddressOrDefault => {
- let evm_address: EvmAddress = env.read_as()?;
- // charge weight
- env.charge_weight(UAWeight::::to_account_id_or_default())?;
-
- // write to buffer
- UA::to_account_id_or_default(&evm_address)
- .using_encoded(|r| env.write(r, false, None))?;
- }
- };
- Ok(RetVal::Converging(0))
- }
-}
diff --git a/pallets/ethereum-checked/Cargo.toml b/pallets/ethereum-checked/Cargo.toml
deleted file mode 100644
index ed6f8a1daf..0000000000
--- a/pallets/ethereum-checked/Cargo.toml
+++ /dev/null
@@ -1,80 +0,0 @@
-[package]
-name = "pallet-ethereum-checked"
-version = "0.1.0"
-description = "Pallet for Ethereum like checked transactions"
-authors.workspace = true
-edition.workspace = true
-homepage.workspace = true
-repository.workspace = true
-
-[lints]
-workspace = true
-
-[dependencies]
-hex = { workspace = true, optional = true }
-parity-scale-codec = { workspace = true }
-scale-info = { workspace = true }
-
-ethereum-types = { workspace = true }
-fp-ethereum = { workspace = true }
-fp-evm = { workspace = true }
-pallet-evm = { workspace = true }
-
-frame-benchmarking = { workspace = true, optional = true }
-frame-support = { workspace = true }
-frame-system = { workspace = true }
-sp-runtime = { workspace = true }
-sp-std = { workspace = true }
-
-astar-primitives = { workspace = true }
-
-[dev-dependencies]
-ethereum = { workspace = true }
-fp-rpc = { workspace = true }
-pallet-balances = { workspace = true }
-pallet-ethereum = { workspace = true }
-pallet-evm = { workspace = true }
-pallet-timestamp = { workspace = true }
-sp-io = { workspace = true }
-
-[features]
-default = ["std"]
-std = [
- "hex/std",
- "parity-scale-codec/std",
- "scale-info/std",
- "ethereum/std",
- "ethereum-types/std",
- "fp-ethereum/std",
- "fp-evm/std",
- "pallet-evm/std",
- "sp-std/std",
- "sp-runtime/std",
- "sp-io/std",
- "frame-support/std",
- "frame-system/std",
- "pallet-balances/std",
- "pallet-timestamp/std",
- "pallet-evm/std",
- "pallet-ethereum/std",
- "astar-primitives/std",
- "frame-benchmarking?/std",
-]
-runtime-benchmarks = [
- "hex",
- "frame-benchmarking",
- "frame-support/runtime-benchmarks",
- "frame-system/runtime-benchmarks",
- "sp-runtime/runtime-benchmarks",
- "pallet-ethereum/runtime-benchmarks",
- "astar-primitives/runtime-benchmarks",
- "frame-benchmarking/runtime-benchmarks",
- "pallet-evm/runtime-benchmarks",
-]
-try-runtime = [
- "frame-support/try-runtime",
- "astar-primitives/try-runtime",
- "frame-system/try-runtime",
- "pallet-evm/try-runtime",
- "sp-runtime/try-runtime",
-]
diff --git a/pallets/ethereum-checked/src/benchmarking.rs b/pallets/ethereum-checked/src/benchmarking.rs
deleted file mode 100644
index 9c0090d642..0000000000
--- a/pallets/ethereum-checked/src/benchmarking.rs
+++ /dev/null
@@ -1,71 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) Stake Technologies Pte.Ltd.
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// Astar is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Astar is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Astar. If not, see .
-
-use super::*;
-
-use astar_primitives::ethereum_checked::EthereumTxInput;
-use frame_benchmarking::v2::*;
-use sp_std::prelude::*;
-
-#[benchmarks]
-mod benchmarks {
- use super::*;
-
- #[benchmark]
- fn transact_without_apply() {
- let origin = T::XcmTransactOrigin::try_successful_origin().unwrap();
- let target =
- H160::from_slice(&hex::decode("dfb975d018f03994a3b943808e3aa0964bd78463").unwrap());
- // Calling `store(3)`
- let input = EthereumTxInput::try_from(
- hex::decode("6057361d0000000000000000000000000000000000000000000000000000000000000003")
- .unwrap(),
- )
- .unwrap();
- let checked_tx = CheckedEthereumTx {
- gas_limit: U256::from(1_000_000),
- target,
- value: U256::zero(),
- input,
- maybe_access_list: None,
- };
-
- #[block]
- {
- Pallet::::transact_without_apply(origin, checked_tx).unwrap();
- }
-
- assert_eq!(Nonce::::get(), U256::one())
- }
-
- impl_benchmark_test_suite!(
- Pallet,
- crate::benchmarking::tests::new_test_ext(),
- crate::mock::TestRuntime,
- );
-}
-
-#[cfg(test)]
-mod tests {
- use crate::mock;
- use sp_io::TestExternalities;
-
- pub fn new_test_ext() -> TestExternalities {
- mock::ExtBuilder::default().build()
- }
-}
diff --git a/pallets/ethereum-checked/src/lib.rs b/pallets/ethereum-checked/src/lib.rs
deleted file mode 100644
index 2ff9fd399d..0000000000
--- a/pallets/ethereum-checked/src/lib.rs
+++ /dev/null
@@ -1,296 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) Stake Technologies Pte.Ltd.
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// Astar is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Astar is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Astar. If not, see .
-
-//! # Ethereum Checked Pallet
-//!
-//! ## Overview
-//!
-//! A `pallet-ethereum` like pallet that execute transactions from checked source,
-//! like XCM remote call. Only `Call` transactions are supported
-//! (no `Create`).
-//!
-//! The checked source guarantees that transactions are valid with prior checks, so these
-//! transactions are not required to include valid signatures. Instead, `pallet-ethereum-checked`
-//! will add the same dummy signature to them. To avoid transaction hash collisions, a global
-//! nonce shared with all users are used.
-//!
-//! ## Interface
-//!
-//! ### Dispatch-able calls
-//!
-//! - `transact`: transact an Ethereum transaction. Similar to `pallet_ethereum::Transact`,
-//! but is only for XCM remote call.
-//!
-
-#![cfg_attr(not(feature = "std"), no_std)]
-
-use parity_scale_codec::{Decode, Encode};
-use scale_info::TypeInfo;
-
-use ethereum_types::U256;
-use fp_ethereum::{Transaction, TransactionData, ValidatedTransaction};
-use fp_evm::{
- CallInfo, CallOrCreateInfo, CheckEvmTransaction, CheckEvmTransactionConfig, ExitReason,
- ExitSucceed, TransactionValidationError,
-};
-use pallet_evm::GasWeightMapping;
-
-use frame_support::{
- dispatch::{DispatchErrorWithPostInfo, PostDispatchInfo},
- pallet_prelude::*,
-};
-use frame_system::pallet_prelude::*;
-#[cfg(feature = "runtime-benchmarks")]
-use sp_runtime::traits::TrailingZeroInput;
-use sp_runtime::traits::UniqueSaturatedInto;
-use sp_std::{marker::PhantomData, result::Result};
-
-use astar_primitives::{
- ethereum_checked::CheckedEthereumTx,
- evm::{UnifiedAddressMapper, H160},
-};
-
-pub use pallet::*;
-
-#[cfg(feature = "runtime-benchmarks")]
-mod benchmarking;
-
-// TODO: after integrated into Astar/Shiden runtime, redo benchmarking with them.
-// The reason is that `EVMChainId` storage read only happens in Shibuya
-pub mod weights;
-pub use weights::WeightInfo;
-
-mod mock;
-mod tests;
-
-pub type WeightInfoOf = ::WeightInfo;
-
-/// Origin for dispatch-able calls.
-#[derive(
- PartialEq,
- Eq,
- Clone,
- Encode,
- Decode,
- DecodeWithMemTracking,
- RuntimeDebug,
- TypeInfo,
- MaxEncodedLen,
-)]
-pub enum RawOrigin {
- XcmEthereumTx(AccountId),
-}
-
-/// Ensure the origin is with XCM calls.
-pub struct EnsureXcmEthereumTx(PhantomData);
-impl, O>> + From>, AccountId: Decode>
- EnsureOrigin for EnsureXcmEthereumTx
-{
- type Success = AccountId;
-
- fn try_origin(o: O) -> Result {
- o.into().map(|o| match o {
- RawOrigin::XcmEthereumTx(account_id) => account_id,
- })
- }
-
- #[cfg(feature = "runtime-benchmarks")]
- fn try_successful_origin() -> Result {
- let zero_account_id =
- AccountId::decode(&mut TrailingZeroInput::zeroes()).map_err(|_| ())?;
- Ok(O::from(RawOrigin::XcmEthereumTx(zero_account_id)))
- }
-}
-
-/// Transaction kind.
-#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo)]
-pub enum CheckedEthereumTxKind {
- /// The tx is from XCM remote call.
- Xcm,
-}
-
-#[frame_support::pallet]
-pub mod pallet {
- use super::*;
-
- #[pallet::pallet]
- pub struct Pallet(PhantomData);
-
- #[pallet::config]
- pub trait Config: frame_system::Config + pallet_evm::Config {
- /// Reserved Xcmp weight for block gas limit calculation.
- type ReservedXcmpWeight: Get;
-
- /// Invalid tx error.
- type InvalidEvmTransactionError: From;
-
- /// Validated tx execution.
- type ValidatedTransaction: ValidatedTransaction;
-
- /// Account mapping.
- type AddressMapper: UnifiedAddressMapper;
-
- /// Origin for `transact` call.
- type XcmTransactOrigin: EnsureOrigin;
-
- /// Weight information for extrinsics in this pallet.
- type WeightInfo: WeightInfo;
- }
-
- #[pallet::origin]
- pub type Origin = RawOrigin<::AccountId>;
-
- /// Global nonce for all transactions to avoid hash collision, which is
- /// caused by the same dummy signatures for all transactions.
- #[pallet::storage]
- pub type Nonce = StorageValue<_, U256, ValueQuery>;
-
- #[pallet::call]
- impl Pallet {
- /// Transact an Ethereum transaction. Similar to `pallet_ethereum::Transact`,
- /// but is only for XCM remote call.
- #[pallet::call_index(0)]
- #[pallet::weight({
- let weight_limit = T::GasWeightMapping::gas_to_weight(tx.gas_limit.unique_saturated_into(), false);
- weight_limit.saturating_add(WeightInfoOf::::transact_without_apply())
- })]
- pub fn transact(origin: OriginFor, tx: CheckedEthereumTx) -> DispatchResultWithPostInfo {
- let source = T::XcmTransactOrigin::ensure_origin(origin)?;
- Self::do_transact(
- T::AddressMapper::to_h160_or_default(&source).into_address(),
- tx.into(),
- CheckedEthereumTxKind::Xcm,
- false,
- )
- .map(|(post_info, _)| post_info)
- }
- }
-}
-
-impl Pallet {
- /// Validate and execute the checked tx. Only `Call` transaction action is allowed.
- fn do_transact(
- source: H160,
- checked_tx: CheckedEthereumTx,
- tx_kind: CheckedEthereumTxKind,
- skip_apply: bool,
- ) -> Result<(PostDispatchInfo, CallInfo), DispatchErrorWithPostInfo> {
- let chain_id = T::ChainId::get();
- let nonce = Nonce::::get();
- let tx: Transaction = checked_tx
- .into_ethereum_tx(Nonce::::get(), chain_id)
- .into();
- let tx_data: TransactionData = (&tx).into();
-
- let (weight_limit, proof_size_base_cost) =
- match ::GasWeightMapping::gas_to_weight(
- tx_data.gas_limit.unique_saturated_into(),
- true,
- ) {
- weight_limit if weight_limit.proof_size() > 0 => (
- Some(weight_limit),
- // measured PoV should be correct to use here
- Some(WeightInfoOf::::transact_without_apply().proof_size()),
- ),
- _ => (None, None),
- };
-
- // Validate the tx.
- let _ = CheckEvmTransaction::::new(
- CheckEvmTransactionConfig {
- evm_config: T::config(),
- block_gas_limit: U256::from(Self::block_gas_limit(&tx_kind)),
- base_fee: U256::zero(),
- chain_id,
- is_transactional: true,
- },
- tx_data.into(),
- weight_limit,
- proof_size_base_cost,
- )
- // Gas limit validation. The fee payment has been validated as the tx is `checked`.
- .validate_common()
- .map_err(|_| DispatchErrorWithPostInfo {
- post_info: PostDispatchInfo {
- // actual_weight = overhead - nonce_write_1
- actual_weight: Some(
- WeightInfoOf::::transact_without_apply()
- .saturating_sub(T::DbWeight::get().writes(1)),
- ),
- pays_fee: Pays::Yes,
- },
- error: DispatchError::Other("Failed to validate Ethereum tx"),
- })?;
-
- Nonce::::put(nonce.saturating_add(U256::one()));
-
- if skip_apply {
- return Ok((
- PostDispatchInfo {
- actual_weight: Some(WeightInfoOf::::transact_without_apply()),
- pays_fee: Pays::Yes,
- },
- CallInfo {
- exit_reason: ExitReason::Succeed(ExitSucceed::Returned),
- value: Default::default(),
- used_gas: fp_evm::UsedGas {
- standard: checked_tx.gas_limit,
- effective: checked_tx.gas_limit,
- },
- weight_info: None,
- logs: Default::default(),
- },
- ));
- }
-
- // Execute the tx.
- let (post_info, apply_info) = T::ValidatedTransaction::apply(source, tx, None)?;
- match apply_info {
- CallOrCreateInfo::Call(info) => Ok((post_info, info)),
- // It is not possible to have a `Create` transaction via `CheckedEthereumTx`.
- CallOrCreateInfo::Create(_) => {
- unreachable!("Cannot create a 'Create' transaction; qed")
- }
- }
- }
-
- /// Block gas limit calculation based on the tx kind.
- fn block_gas_limit(tx_kind: &CheckedEthereumTxKind) -> u64 {
- let weight_limit = match tx_kind {
- CheckedEthereumTxKind::Xcm => T::ReservedXcmpWeight::get(),
- };
- T::GasWeightMapping::weight_to_gas(weight_limit)
- }
-
- /// Similar to `transact` dispatch-able call that transacts an Ethereum transaction,
- /// but not to apply it. This is to benchmark the weight overhead in addition to `gas_limit`.
- #[cfg(feature = "runtime-benchmarks")]
- pub fn transact_without_apply(
- origin: OriginFor,
- tx: CheckedEthereumTx,
- ) -> DispatchResultWithPostInfo {
- let source = T::XcmTransactOrigin::ensure_origin(origin)?;
- Self::do_transact(
- T::AddressMapper::to_h160_or_default(&source).into_address(),
- tx.into(),
- CheckedEthereumTxKind::Xcm,
- true,
- )
- .map(|(post_info, _)| post_info)
- }
-}
diff --git a/pallets/ethereum-checked/src/mock.rs b/pallets/ethereum-checked/src/mock.rs
deleted file mode 100644
index 586de8df9f..0000000000
--- a/pallets/ethereum-checked/src/mock.rs
+++ /dev/null
@@ -1,290 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) Stake Technologies Pte.Ltd.
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// Astar is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Astar is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Astar. If not, see .
-
-#![cfg(test)]
-
-use super::*;
-use crate as pallet_ethereum_checked;
-
-use ethereum_types::H256;
-
-use frame_support::{
- assert_ok, construct_runtime, derive_impl, parameter_types,
- traits::{ConstU128, ConstU64, FindAuthor},
- weights::Weight,
-};
-use pallet_ethereum::PostLogContent;
-use pallet_evm::{AddressMapping, FeeCalculator};
-use sp_io::{hashing::blake2_256, TestExternalities};
-use sp_runtime::{
- traits::{BlakeTwo256, IdentityLookup},
- AccountId32, BuildStorage, ConsensusEngineId,
-};
-
-parameter_types! {
- pub BlockWeights: frame_system::limits::BlockWeights =
- frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, 0));
-}
-
-#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
-impl frame_system::Config for TestRuntime {
- type Block = Block;
- type AccountId = AccountId;
- type Lookup = IdentityLookup;
- type AccountData = pallet_balances::AccountData;
-}
-
-#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
-impl pallet_balances::Config for TestRuntime {
- type Balance = Balance;
- type ExistentialDeposit = ConstU128<2>;
- type AccountStore = System;
-}
-
-#[derive_impl(pallet_timestamp::config_preludes::TestDefaultConfig)]
-impl pallet_timestamp::Config for TestRuntime {
- type MinimumPeriod = ConstU64<3>;
-}
-
-pub struct MockFeeCalculator;
-impl FeeCalculator for MockFeeCalculator {
- fn min_gas_price() -> (U256, Weight) {
- (U256::one(), Weight::zero())
- }
-}
-
-pub struct MockFindAuthor;
-impl FindAuthor for MockFindAuthor {
- fn find_author<'a, I>(_digests: I) -> Option
- where
- I: 'a + IntoIterator- ,
- {
- Some(H160::from_low_u64_be(1))
- }
-}
-
-pub struct MockAddressMapping;
-impl AddressMapping for MockAddressMapping {
- fn into_account_id(address: H160) -> AccountId32 {
- if address == ALICE_H160 {
- return ALICE;
- }
- if address == BOB_H160 {
- return BOB;
- }
- if address == CHARLIE_H160 {
- return CHARLIE;
- }
-
- return pallet_evm::HashedAddressMapping::::into_account_id(address);
- }
-}
-
-pub struct MockAddressMapper;
-impl UnifiedAddressMapper for MockAddressMapper {
- fn to_h160(account_id: &AccountId32) -> Option {
- if account_id == &ALICE {
- Some(ALICE_H160)
- } else if account_id == &BOB {
- Some(BOB_H160)
- } else if account_id == &CHARLIE {
- Some(CHARLIE_H160)
- } else {
- None
- }
- }
-
- fn to_default_h160(account_id: &AccountId32) -> H160 {
- let data = (b"evm:", account_id);
- H160::from_slice(&data.using_encoded(blake2_256)[0..20])
- }
-
- // this method is not used in tests
- fn to_default_account_id(_: &H160) -> AccountId32 {
- unimplemented!("not used in tests")
- }
-
- // this method is not used in tests
- fn to_account_id(_: &H160) -> Option {
- unimplemented!("not used in tests")
- }
-}
-
-parameter_types! {
- pub WeightPerGas: Weight = Weight::from_parts(1, 0);
- pub const BlockGasLimit: U256 = U256::MAX;
-}
-
-impl pallet_evm::Config for TestRuntime {
- type FeeCalculator = MockFeeCalculator;
- type GasWeightMapping = pallet_evm::FixedGasWeightMapping;
- type WeightPerGas = WeightPerGas;
- type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping;
- type CallOrigin = pallet_evm::EnsureAddressRoot;
- type WithdrawOrigin = pallet_evm::EnsureAddressTruncated;
- type AddressMapping = MockAddressMapping;
- type Currency = Balances;
- type Runner = pallet_evm::runner::stack::Runner;
- type PrecompilesType = ();
- type PrecompilesValue = ();
- type ChainId = ConstU64<1024>;
- type OnChargeTransaction = ();
- type BlockGasLimit = BlockGasLimit;
- type OnCreate = ();
- type FindAuthor = MockFindAuthor;
- type Timestamp = Timestamp;
- type WeightInfo = pallet_evm::weights::SubstrateWeight;
- type GasLimitPovSizeRatio = ConstU64<4>;
- type AccountProvider = pallet_evm::FrameSystemAccountProvider;
- type GasLimitStorageGrowthRatio = ConstU64<0>;
- type CreateOriginFilter = ();
- type CreateInnerOriginFilter = ();
-}
-
-parameter_types! {
- pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;
-}
-
-impl pallet_ethereum::Config for TestRuntime {
- type StateRoot =
- pallet_ethereum::IntermediateStateRoot<::Version>;
- type PostLogContent = PostBlockAndTxnHashes;
- type ExtraDataLength = ConstU32<30>;
-}
-
-parameter_types! {
- pub TxWeightLimit: Weight = Weight::from_parts(u64::max_value(), 0);
-}
-
-impl pallet_ethereum_checked::Config for TestRuntime {
- type ReservedXcmpWeight = TxWeightLimit;
- type InvalidEvmTransactionError = pallet_ethereum::InvalidTransactionWrapper;
- type ValidatedTransaction = pallet_ethereum::ValidatedTransaction;
- type AddressMapper = MockAddressMapper;
- type XcmTransactOrigin = EnsureXcmEthereumTx;
- type WeightInfo = ();
-}
-
-pub(crate) type AccountId = AccountId32;
-pub(crate) type Balance = u128;
-
-pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]);
-pub const BOB: AccountId32 = AccountId32::new([1u8; 32]);
-pub const CHARLIE: AccountId32 = AccountId32::new([2u8; 32]);
-
-type Block = frame_system::mocking::MockBlock;
-
-construct_runtime!(
- pub struct TestRuntime
- {
- System: frame_system,
- Timestamp: pallet_timestamp,
- Balances: pallet_balances,
- Evm: pallet_evm,
- Ethereum: pallet_ethereum,
- EthereumChecked: pallet_ethereum_checked::{Pallet, Call, Origin},
- }
-);
-
-pub const ALICE_H160: H160 = H160::repeat_byte(1);
-pub const BOB_H160: H160 = H160::repeat_byte(2);
-pub const CHARLIE_H160: H160 = H160::repeat_byte(3);
-
-/* Testing contract
-
-pragma solidity >=0.8.2 <0.9.0;
-
-contract Storage {
- uint256 number;
-
- /**
- * @dev Store value in variable
- * @param num value to store
- */
- function store(uint256 num) public {
- number = num;
- }
-
- /**
- * @dev Return value
- * @return value of 'number'
- */
- function retrieve() public view returns (uint256){
- return number;
- }
-}
-*/
-const STORAGE_CONTRACT: &str = "608060405234801561001057600080fd5b50610150806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80632e64cec11461003b5780636057361d14610059575b600080fd5b610043610075565b60405161005091906100a1565b60405180910390f35b610073600480360381019061006e91906100ed565b61007e565b005b60008054905090565b8060008190555050565b6000819050919050565b61009b81610088565b82525050565b60006020820190506100b66000830184610092565b92915050565b600080fd5b6100ca81610088565b81146100d557600080fd5b50565b6000813590506100e7816100c1565b92915050565b600060208284031215610103576101026100bc565b5b6000610111848285016100d8565b9150509291505056fea2646970667358221220322c78243e61b783558509c9cc22cb8493dde6925aa5e89a08cdf6e22f279ef164736f6c63430008120033";
-
-pub fn contract_address() -> H160 {
- H160::from_slice(&hex::decode("dfb975d018f03994a3b943808e3aa0964bd78463").unwrap())
-}
-
-pub struct ExtBuilder {
- balances: Vec<(AccountId, Balance)>,
-}
-
-impl Default for ExtBuilder {
- fn default() -> Self {
- Self {
- balances: vec![
- (ALICE, 1_000_000_000_000),
- (BOB, 1_000_000_000_000),
- (CHARLIE, 1_000_000_000_000),
- ],
- }
- }
-}
-
-impl ExtBuilder {
- pub fn build(self) -> TestExternalities {
- let mut t = frame_system::GenesisConfig::::default()
- .build_storage()
- .unwrap();
-
- pallet_balances::GenesisConfig:: {
- balances: self.balances,
- ..Default::default()
- }
- .assimilate_storage(&mut t)
- .unwrap();
-
- let mut ext = TestExternalities::from(t);
- ext.execute_with(|| {
- System::set_block_number(1);
-
- assert_ok!(Evm::create2(
- RuntimeOrigin::root(),
- ALICE_H160,
- hex::decode(STORAGE_CONTRACT).expect("invalid code hex"),
- H256::zero(),
- U256::zero(),
- 1_000_000,
- U256::one(),
- None,
- Some(U256::zero()),
- vec![],
- vec![],
- ));
- System::assert_last_event(RuntimeEvent::Evm(pallet_evm::Event::Created {
- address: contract_address(),
- }));
- });
- ext
- }
-}
diff --git a/pallets/ethereum-checked/src/tests.rs b/pallets/ethereum-checked/src/tests.rs
deleted file mode 100644
index 504b9b46b3..0000000000
--- a/pallets/ethereum-checked/src/tests.rs
+++ /dev/null
@@ -1,133 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) Stake Technologies Pte.Ltd.
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// Astar is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Astar is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Astar. If not, see .
-
-#![cfg(test)]
-
-use super::*;
-use mock::*;
-
-use astar_primitives::ethereum_checked::EthereumTxInput;
-use ethereum::{ReceiptV4 as Receipt, TransactionV3 as Transaction};
-use frame_support::{assert_noop, assert_ok};
-use sp_runtime::DispatchError;
-
-fn bounded_input(data: &'static str) -> EthereumTxInput {
- EthereumTxInput::try_from(hex::decode(data).expect("invalid input hex"))
- .expect("input too large")
-}
-
-#[test]
-fn transact_works() {
- ExtBuilder::default().build().execute_with(|| {
- let store_tx = CheckedEthereumTx {
- gas_limit: U256::from(1_000_000),
- target: contract_address(),
- value: U256::zero(),
- // Calling `store(3)`
- input: bounded_input(
- "6057361d0000000000000000000000000000000000000000000000000000000000000003",
- ),
- maybe_access_list: None,
- };
- assert_ok!(EthereumChecked::transact(
- RawOrigin::XcmEthereumTx(ALICE).into(),
- store_tx.clone()
- ));
- assert_ok!(EthereumChecked::transact(
- RawOrigin::XcmEthereumTx(ALICE).into(),
- store_tx
- ));
- let pending0 = pallet_ethereum::Pending::::get(0);
- let pending1 = pallet_ethereum::Pending::::get(1);
- assert_eq!(pallet_ethereum::Pending::::count(), 2);
-
- match pending0 {
- Some((Transaction::EIP1559(ref t), _, Receipt::EIP1559(ref r))) => {
- // nonce 0, status code 1 (success)
- assert_eq!(t.nonce, U256::zero());
- assert_eq!(r.status_code, 1);
- }
- _ => panic!("unexpected transaction type"),
- }
- match pending1 {
- Some((Transaction::EIP1559(ref t), _, Receipt::EIP1559(ref r))) => {
- // nonce 1, status code 1 (success)
- assert_eq!(t.nonce, U256::one());
- assert_eq!(r.status_code, 1);
- }
- _ => panic!("unexpected transaction type"),
- }
- assert_eq!(Nonce::::get(), U256::from(2));
- });
-}
-
-#[test]
-fn origin_check_works() {
- ExtBuilder::default().build().execute_with(|| {
- let store_tx = CheckedEthereumTx {
- gas_limit: U256::from(1_000_000),
- target: contract_address(),
- value: U256::zero(),
- // Calling `store(3)`
- input: bounded_input(
- "6057361d0000000000000000000000000000000000000000000000000000000000000003",
- ),
- maybe_access_list: None,
- };
- assert_noop!(
- EthereumChecked::transact(RuntimeOrigin::signed(ALICE), store_tx.clone()),
- DispatchError::BadOrigin
- );
- assert_noop!(
- EthereumChecked::transact(RuntimeOrigin::root(), store_tx.clone()),
- DispatchError::BadOrigin
- );
- assert_noop!(
- EthereumChecked::transact(RuntimeOrigin::none(), store_tx),
- DispatchError::BadOrigin
- );
- });
-}
-
-#[test]
-fn no_hash_collision() {
- ExtBuilder::default().build().execute_with(|| {
- let store_tx = CheckedEthereumTx {
- gas_limit: U256::from(1_000_000),
- target: contract_address(),
- value: U256::zero(),
- // Calling `store(3)`
- input: bounded_input(
- "6057361d0000000000000000000000000000000000000000000000000000000000000003",
- ),
- maybe_access_list: None,
- };
- for _ in 0..5 {
- assert_ok!(EthereumChecked::transact(
- RawOrigin::XcmEthereumTx(ALICE).into(),
- store_tx.clone()
- ));
- }
-
- let mut tx_hashes = pallet_ethereum::Pending::::iter()
- .map(|(_, (tx, _, _))| tx.hash())
- .collect::>();
- tx_hashes.dedup();
- assert_eq!(tx_hashes.len(), 5);
- });
-}
diff --git a/pallets/ethereum-checked/src/weights.rs b/pallets/ethereum-checked/src/weights.rs
deleted file mode 100644
index d47d3a1340..0000000000
--- a/pallets/ethereum-checked/src/weights.rs
+++ /dev/null
@@ -1,87 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) Stake Technologies Pte.Ltd.
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// Astar is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Astar is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Astar. If not, see .
-
-//! Autogenerated weights for pallet_ethereum_checked
-//!
-//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
-//! DATE: 2023-07-17, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
-//! WORST CASE MAP SIZE: `1000000`
-//! HOSTNAME: `devserver-01`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz`
-//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024
-
-// Executed Command:
-// ./target/release/astar-collator
-// benchmark
-// pallet
-// --chain=shibuya-dev
-// --steps=50
-// --repeat=20
-// --pallet=pallet_ethereum_checked
-// --extrinsic=*
-// --execution=wasm
-// --wasm-execution=compiled
-// --heap-pages=4096
-// --output=./benchmark-results/ethereum_checked_weights.rs
-// --template=./scripts/templates/weight-template.hbs
-
-#![cfg_attr(rustfmt, rustfmt_skip)]
-#![allow(unused_parens)]
-#![allow(unused_imports)]
-
-use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
-use sp_std::marker::PhantomData;
-
-/// Weight functions needed for pallet_ethereum_checked.
-pub trait WeightInfo {
- fn transact_without_apply() -> Weight;
-}
-
-/// Weights for pallet_ethereum_checked using the Substrate node and recommended hardware.
-pub struct SubstrateWeight(PhantomData);
-impl WeightInfo for SubstrateWeight {
- /// Storage: EVMChainId ChainId (r:1 w:0)
- /// Proof: EVMChainId ChainId (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen)
- /// Storage: EthereumChecked Nonce (r:1 w:1)
- /// Proof: EthereumChecked Nonce (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen)
- fn transact_without_apply() -> Weight {
- // Proof Size summary in bytes:
- // Measured: `150`
- // Estimated: `3010`
- // Minimum execution time: 8_838_000 picoseconds.
- Weight::from_parts(9_229_000, 3010)
- .saturating_add(T::DbWeight::get().reads(2_u64))
- .saturating_add(T::DbWeight::get().writes(1_u64))
- }
-}
-
-// For backwards compatibility and tests
-impl WeightInfo for () {
- /// Storage: EVMChainId ChainId (r:1 w:0)
- /// Proof: EVMChainId ChainId (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen)
- /// Storage: EthereumChecked Nonce (r:1 w:1)
- /// Proof: EthereumChecked Nonce (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen)
- fn transact_without_apply() -> Weight {
- // Proof Size summary in bytes:
- // Measured: `150`
- // Estimated: `3010`
- // Minimum execution time: 8_838_000 picoseconds.
- Weight::from_parts(9_229_000, 3010)
- .saturating_add(RocksDbWeight::get().reads(2_u64))
- .saturating_add(RocksDbWeight::get().writes(1_u64))
- }
-}
diff --git a/pallets/unified-accounts/Cargo.toml b/pallets/unified-accounts/Cargo.toml
deleted file mode 100644
index 3cf6e706e8..0000000000
--- a/pallets/unified-accounts/Cargo.toml
+++ /dev/null
@@ -1,87 +0,0 @@
-[package]
-name = "pallet-unified-accounts"
-version = "0.1.0"
-description = "Pallet for mapping VM accounts with native accounts"
-authors.workspace = true
-edition.workspace = true
-homepage.workspace = true
-repository.workspace = true
-
-[lints]
-workspace = true
-
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
-[dependencies]
-libsecp256k1 = { workspace = true, optional = true, features = ["hmac", "static-context"] }
-log = { workspace = true }
-parity-scale-codec = { workspace = true }
-scale-info = { workspace = true }
-
-frame-support = { workspace = true }
-frame-system = { workspace = true }
-sp-core = { workspace = true }
-sp-io = { workspace = true }
-sp-runtime = { workspace = true }
-sp-std = { workspace = true }
-
-# Benchmarks
-frame-benchmarking = { workspace = true, optional = true }
-
-precompile-utils = { workspace = true }
-
-# frontier
-pallet-evm = { workspace = true }
-
-# Astar
-astar-primitives = { workspace = true }
-
-[dev-dependencies]
-ethers = { workspace = true }
-hex = { workspace = true }
-pallet-balances = { workspace = true }
-pallet-ethereum = { workspace = true }
-pallet-evm = { workspace = true }
-pallet-timestamp = { workspace = true }
-
-[features]
-default = ["std"]
-std = [
- "hex/std",
- "log/std",
- "libsecp256k1",
- "libsecp256k1/std",
- "parity-scale-codec/std",
- "scale-info/std",
- "sp-std/std",
- "sp-core/std",
- "sp-io/std",
- "sp-runtime/std",
- "frame-support/std",
- "frame-system/std",
- "astar-primitives/std",
- "precompile-utils/std",
- "pallet-evm/std",
- "pallet-balances/std",
- "pallet-timestamp/std",
- "pallet-ethereum/std",
- "frame-benchmarking?/std",
-]
-runtime-benchmarks = [
- "libsecp256k1/hmac",
- "frame-benchmarking",
- "frame-support/runtime-benchmarks",
- "frame-system/runtime-benchmarks",
- "sp-runtime/runtime-benchmarks",
- "astar-primitives/runtime-benchmarks",
- "pallet-ethereum/runtime-benchmarks",
- "pallet-evm/runtime-benchmarks",
- "frame-benchmarking/runtime-benchmarks",
-]
-try-runtime = [
- "frame-support/try-runtime",
- "pallet-evm/try-runtime",
- "astar-primitives/try-runtime",
- "frame-system/try-runtime",
- "sp-runtime/try-runtime",
-]
diff --git a/pallets/unified-accounts/src/benchmarking.rs b/pallets/unified-accounts/src/benchmarking.rs
deleted file mode 100644
index 0ca8845f17..0000000000
--- a/pallets/unified-accounts/src/benchmarking.rs
+++ /dev/null
@@ -1,162 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) Stake Technologies Pte.Ltd.
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// Astar is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Astar is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Astar. If not, see .
-
-#![cfg(feature = "runtime-benchmarks")]
-
-use super::*;
-use frame_benchmarking::v2::*;
-use frame_support::assert_ok;
-use frame_system::RawOrigin;
-use sp_std::prelude::*;
-
-/// Assert that the last event equals the provided one.
-fn assert_last_event(generic_event: crate::Event) {
- frame_system::Pallet::::assert_last_event(generic_event.into());
-}
-
-#[benchmarks]
-mod benchmarks {
- use super::*;
-
- #[benchmark]
- fn claim_evm_address() {
- let caller: T::AccountId = whitelisted_caller();
- let eth_secret_key = libsecp256k1::SecretKey::parse(&keccak_256(b"Alice")).unwrap();
- let evm_address = Pallet::::eth_address(ð_secret_key);
- let signature = Pallet::::eth_sign_prehash(
- &Pallet::::build_signing_payload(&caller),
- ð_secret_key,
- )
- .into();
-
- assert_ok!(T::Currency::mint_into(
- &caller,
- T::AccountMappingStorageFee::get()
- ));
- let caller_clone = caller.clone();
-
- #[extrinsic_call]
- _(RawOrigin::Signed(caller), evm_address, signature);
-
- assert_last_event::(
- Event::::AccountClaimed {
- account_id: caller_clone,
- evm_address,
- }
- .into(),
- );
- }
-
- #[benchmark]
- fn claim_default_evm_address() {
- let caller: T::AccountId = whitelisted_caller();
- let evm_address = T::DefaultMappings::to_default_h160(&caller);
-
- assert_ok!(T::Currency::mint_into(
- &caller,
- T::AccountMappingStorageFee::get()
- ));
-
- #[extrinsic_call]
- _(RawOrigin::Signed(caller.clone()));
-
- assert_last_event::(
- Event::::AccountClaimed {
- account_id: caller,
- evm_address,
- }
- .into(),
- );
- }
-
- #[benchmark]
- fn to_account_id() {
- let caller: T::AccountId = whitelisted_caller();
- let evm_address = T::DefaultMappings::to_default_h160(&caller.clone());
- assert_ok!(T::Currency::mint_into(
- &caller,
- T::AccountMappingStorageFee::get()
- ));
- // claim mapping
- assert_ok!(Pallet::::claim_default_evm_address(
- RawOrigin::Signed(caller.clone()).into()
- ));
-
- #[block]
- {
- let _ = as UnifiedAddressMapper>::to_account_id(&evm_address);
- }
- }
-
- #[benchmark]
- fn to_account_id_or_default() {
- let caller: T::AccountId = whitelisted_caller();
- let evm_address = T::DefaultMappings::to_default_h160(&caller.clone());
- assert_ok!(T::Currency::mint_into(
- &caller,
- T::AccountMappingStorageFee::get()
- ));
- // claim mapping
- assert_ok!(Pallet::::claim_default_evm_address(
- RawOrigin::Signed(caller.clone()).into()
- ));
-
- #[block]
- {
- let _ = as UnifiedAddressMapper>::to_account_id_or_default(
- &evm_address,
- );
- }
- }
-
- #[benchmark]
- fn to_h160() {
- let caller: T::AccountId = whitelisted_caller();
- assert_ok!(T::Currency::mint_into(
- &caller,
- T::AccountMappingStorageFee::get()
- ));
- // claim mapping
- assert_ok!(Pallet::::claim_default_evm_address(
- RawOrigin::Signed(caller.clone()).into()
- ));
-
- #[block]
- {
- let _ = as UnifiedAddressMapper>::to_h160(&caller);
- }
- }
-
- #[benchmark]
- fn to_h160_or_default() {
- let caller: T::AccountId = whitelisted_caller();
- assert_ok!(T::Currency::mint_into(
- &caller,
- T::AccountMappingStorageFee::get()
- ));
- // claim mapping
- assert_ok!(Pallet::::claim_default_evm_address(
- RawOrigin::Signed(caller.clone()).into()
- ));
-
- #[block]
- {
- let _ = as UnifiedAddressMapper>::to_h160_or_default(&caller);
- }
- }
-}
diff --git a/pallets/unified-accounts/src/lib.rs b/pallets/unified-accounts/src/lib.rs
deleted file mode 100644
index 08939fc20d..0000000000
--- a/pallets/unified-accounts/src/lib.rs
+++ /dev/null
@@ -1,413 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) Stake Technologies Pte.Ltd.
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// Astar is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Astar is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Astar. If not, see .
-
-//! # Pallet Unified Account
-//!
-//! A simple module for managing mappings (both ways) between different
-//! address schemes, inspired from Acala's evm-accounts pallet
-//! https://github.com/AcalaNetwork/Acala/tree/master/modules/evm-accounts
-//!
-//! - [`Config`]
-//! - [`Call`]
-//!
-//! ## Overview
-//!
-//! The Unified Accounts module provide functionality for native account holders to
-//! connect their evm address to have a unified experience across the different VMs.
-//! - Connect evm address you control
-//! - Connect default evm address
-//!
-//! ## Interface
-//!
-//! * `claim_evm_address`: Creates the double mappings for the provided evm address with caller
-//! account id given that no prior mapping exists for both and signature provided is valid.
-//! * `claim_default_evm_address`: Creates the double mapping with default evm address given that
-//! no prior mapping exists.
-//!
-//! ## Storage Fee
-//! User is also charged a storage fee [`AccountMappingStorageFee`](`crate::Config::AccountMappingStorageFee`)
-//! before mappings are created to prevent storage abuse.
-//!
-//! WARNINGS:
-//! * This pallet only handles transfer of native balance only, for the rest of native assets
-//! hold by evm address like XC20, DAppStaking unclaimed rewards, etc should be transferred
-//! manually beforehand by user himself otherwise FUNDS WILL BE LOST FOREVER.
-//! * Once mapping is created it cannot be changed.
-//!
-//! ## Traits
-//!
-//! * `UnifiedAddressMapper`: Interface to access pallet's mappings with defaults
-//!
-//! ## Implementations
-//!
-//! * [`StaticLookup`](sp_runtime::traits::StaticLookup): Lookup implementations for accepting H160
-//! * [`AddressMapping`](pallet_evm::AddressMapping): Wrapper over `UnifiedAddressMapper` for evm address mapping
-//! to account id.
-//! * `KillAccountMapping`: [`OnKilledAccount`](frame_support::traits::OnKilledAccount) implementation to remove
-//! the mappings from storage after account is reaped.
-
-#![cfg_attr(not(feature = "std"), no_std)]
-
-use astar_primitives::{
- evm::{EvmAddress, UnifiedAddressMapper},
- Balance,
-};
-use frame_support::{
- pallet_prelude::*,
- traits::{
- fungible::{Inspect as FungibleInspect, Mutate as FungibleMutate},
- tokens::{Fortitude::*, Precision::*, Preservation::*},
- OnKilledAccount,
- },
-};
-use frame_system::{ensure_signed, pallet_prelude::*};
-use pallet_evm::AddressMapping;
-use precompile_utils::keccak256;
-use sp_core::{H160, H256, U256};
-use sp_io::hashing::keccak_256;
-use sp_runtime::{
- traits::{LookupError, StaticLookup, Zero},
- MultiAddress,
-};
-use sp_std::marker::PhantomData;
-
-pub use pallet::*;
-
-pub mod weights;
-pub use weights::WeightInfo;
-
-#[cfg(feature = "runtime-benchmarks")]
-mod benchmarking;
-mod mock;
-mod tests;
-
-/// ECDSA Signature type, with last bit for recovering address
-type EvmSignature = [u8; 65];
-
-#[frame_support::pallet]
-pub mod pallet {
- use super::*;
-
- #[pallet::pallet]
- pub struct Pallet(PhantomData);
-
- #[pallet::config]
- pub trait Config: frame_system::Config {
- /// The Currency for managing evm address assets
- type Currency: FungibleMutate;
- /// Default address conversion
- type DefaultMappings: UnifiedAddressMapper;
- /// EVM chain id
- #[pallet::constant]
- type ChainId: Get;
- /// The amount of currency needed for mappings to be added.
- /// Two storage items with values sizes, sizeof(AccountId) and sizeof(H160)
- /// respectively
- #[pallet::constant]
- type AccountMappingStorageFee: Get;
- /// Weight information for the extrinsics in this module
- type WeightInfo: WeightInfo;
- }
-
- #[pallet::error]
- pub enum Error {
- /// AccountId or EvmAddress already mapped
- AlreadyMapped,
- /// The signature is malformed
- UnexpectedSignatureFormat,
- /// The signature verification failed due to mismatch evm address
- InvalidSignature,
- /// Funds unavailable to claim account
- FundsUnavailable,
- }
-
- #[pallet::event]
- #[pallet::generate_deposit(pub(super) fn deposit_event)]
- pub enum Event {
- /// Evm Address claimed.
- /// Double Mapping b/w native and evm address created
- AccountClaimed {
- account_id: T::AccountId,
- evm_address: EvmAddress,
- },
- }
-
- /// Native accounts for evm address
- /// EvmToNative: EvmAddress => Option
- #[pallet::storage]
- pub type EvmToNative =
- StorageMap<_, Blake2_128Concat, EvmAddress, T::AccountId, OptionQuery>;
-
- /// Evm addresses for native accounts
- /// NativeToEvm: AccountId => Option
- #[pallet::storage]
- pub type NativeToEvm =
- StorageMap<_, Blake2_128Concat, T::AccountId, EvmAddress, OptionQuery>;
-
- #[pallet::call]
- impl Pallet {
- /// Claim account mapping between Substrate account and Evm address.
- /// Ensure no prior mapping exists for evm address.
- ///
- /// - `evm_address`: The evm address to bind to the caller's account
- /// - `signature`: A signature generated by the address to prove ownership
- ///
- /// WARNING:
- /// - This extrinsic only handles transfer of native balance, if your EVM
- /// address contains any other native assets like XC20, DAppStaking unclaimed rewards,
- /// etc you need to transfer them before hand, otherwise FUNDS WILL BE LOST FOREVER.
- /// - Once connected user cannot change their mapping EVER.
- #[pallet::call_index(0)]
- #[pallet::weight(T::WeightInfo::claim_evm_address())]
- pub fn claim_evm_address(
- origin: OriginFor,
- evm_address: EvmAddress,
- signature: EvmSignature,
- ) -> DispatchResult {
- let who = ensure_signed(origin)?;
- // make sure no prior mapping exists
- ensure!(
- !NativeToEvm::::contains_key(&who),
- Error::::AlreadyMapped
- );
- ensure!(
- !EvmToNative::::contains_key(evm_address),
- Error::::AlreadyMapped
- );
-
- // recover evm address from signature
- let address = Self::verify_signature(&who, &signature)
- .ok_or(Error::::UnexpectedSignatureFormat)?;
-
- ensure!(evm_address == address, Error::::InvalidSignature);
-
- // charge the storage fee
- Self::charge_storage_fee(&who)?;
-
- // Check if the default account id already exists for this evm address
- let default_account_id = T::DefaultMappings::to_default_account_id(&evm_address);
- if frame_system::Pallet::::account_exists(&default_account_id) {
- // Transfer all the free native balance from old account id to the newly
- // since this `default_account_id` will no longer be connected to evm address
- // and users cannot access it.
- // For the reset of the assets types (like XC20, etc) that should be handled by UI.
- T::Currency::transfer(
- &default_account_id,
- &who,
- T::Currency::reducible_balance(&default_account_id, Expendable, Polite),
- Expendable,
- )?;
- }
-
- // create double mappings for the pair
- EvmToNative::::insert(&evm_address, &who);
- NativeToEvm::::insert(&who, &evm_address);
-
- Self::deposit_event(Event::AccountClaimed {
- account_id: who,
- evm_address,
- });
- Ok(())
- }
-
- /// Claim default evm address for given account id
- /// Ensure no prior mapping exists for the account
- ///
- /// WARNINGS: Once connected user cannot change their mapping EVER.
- #[pallet::call_index(1)]
- #[pallet::weight(T::WeightInfo::claim_default_evm_address())]
- pub fn claim_default_evm_address(origin: OriginFor) -> DispatchResult {
- let who = ensure_signed(origin)?;
- // claim default evm address
- let _ = Self::do_claim_default_evm_address(who)?;
- Ok(())
- }
- }
-}
-
-impl Pallet {
- /// Claim the default evm address
- fn do_claim_default_evm_address(account_id: T::AccountId) -> Result {
- ensure!(
- !NativeToEvm::::contains_key(&account_id),
- Error::::AlreadyMapped
- );
- // get the default evm address
- let evm_address = T::DefaultMappings::to_default_h160(&account_id);
- // make sure default address is not already mapped, this should not
- // happen but for sanity check.
- ensure!(
- !EvmToNative::::contains_key(&evm_address),
- Error::::AlreadyMapped
- );
-
- Self::charge_storage_fee(&account_id)?;
-
- // create double mappings for the pair with default evm address
- EvmToNative::::insert(&evm_address, &account_id);
- NativeToEvm::::insert(&account_id, &evm_address);
-
- Self::deposit_event(Event::AccountClaimed {
- account_id,
- evm_address,
- });
- Ok(evm_address)
- }
-
- /// Charge the (exact) storage fee (politely) from the user and burn it
- /// while preserving the account from being reaped.
- fn charge_storage_fee(who: &T::AccountId) -> Result {
- let balance = T::Currency::reducible_balance(who, Preserve, Polite);
- let fee = T::AccountMappingStorageFee::get();
- ensure!(balance >= fee, Error::::FundsUnavailable);
- T::Currency::burn_from(
- who,
- T::AccountMappingStorageFee::get(),
- Preserve,
- Exact,
- Polite,
- )
- }
-}
-
-/// EIP-712 compatible signature scheme for verifying ownership of EVM Address
-/// https://eips.ethereum.org/EIPS/eip-712
-///
-/// Raw Data = Domain Separator + Type Hash + keccak256(AccountId)
-impl Pallet {
- pub fn build_signing_payload(who: &T::AccountId) -> [u8; 32] {
- let domain_separator = Self::build_domain_separator();
- let args_hash = Self::build_args_hash(who);
-
- let mut payload = b"\x19\x01".to_vec();
- payload.extend_from_slice(&domain_separator);
- payload.extend_from_slice(&args_hash);
- keccak_256(&payload)
- }
-
- pub fn verify_signature(who: &T::AccountId, sig: &EvmSignature) -> Option {
- let payload_hash = Self::build_signing_payload(who);
-
- sp_io::crypto::secp256k1_ecdsa_recover(sig, &payload_hash)
- .map(|pubkey| H160::from(H256::from_slice(&keccak_256(&pubkey))))
- .ok()
- }
-
- fn build_domain_separator() -> [u8; 32] {
- let mut domain =
- keccak256!("EIP712Domain(string name,string version,uint256 chainId,bytes32 salt)")
- .to_vec();
- domain.extend_from_slice(&keccak256!("Astar EVM Claim")); // name
- domain.extend_from_slice(&keccak256!("1")); // version
- domain.extend_from_slice(&U256::from(T::ChainId::get()).to_big_endian()); // chain id
- domain.extend_from_slice(
- frame_system::Pallet::::block_hash(BlockNumberFor::::zero()).as_ref(),
- ); // genesis block hash
- keccak_256(domain.as_slice())
- }
-
- fn build_args_hash(account: &T::AccountId) -> [u8; 32] {
- let mut args_hash = keccak256!("Claim(bytes substrateAddress)").to_vec();
- args_hash.extend_from_slice(&keccak_256(&account.encode()));
- keccak_256(args_hash.as_slice())
- }
-}
-
-#[cfg(any(feature = "std", feature = "runtime-benchmarks"))]
-impl Pallet {
- /// Sign the given prehash with provided eth private key
- pub fn eth_sign_prehash(prehash: &[u8; 32], secret: &libsecp256k1::SecretKey) -> [u8; 65] {
- let (sig, recovery_id) = libsecp256k1::sign(&libsecp256k1::Message::parse(prehash), secret);
- let mut r = [0u8; 65];
- r[0..64].copy_from_slice(&sig.serialize()[..]);
- r[64] = recovery_id.serialize();
- r
- }
-
- /// Get the eth address for given eth private key
- pub fn eth_address(secret: &libsecp256k1::SecretKey) -> EvmAddress {
- EvmAddress::from_slice(
- &sp_io::hashing::keccak_256(
- &libsecp256k1::PublicKey::from_secret_key(secret).serialize()[1..65],
- )[12..],
- )
- }
-}
-
-/// UnifiedAddressMapper implementation using pallet's mapping
-/// and default address scheme from pallet's config
-impl UnifiedAddressMapper for Pallet {
- fn to_account_id(evm_address: &EvmAddress) -> Option {
- EvmToNative::::get(evm_address)
- }
-
- fn to_default_account_id(evm_address: &EvmAddress) -> T::AccountId {
- T::DefaultMappings::to_default_account_id(evm_address)
- }
-
- fn to_h160(account_id: &T::AccountId) -> Option {
- NativeToEvm::::get(account_id)
- }
-
- fn to_default_h160(account_id: &T::AccountId) -> EvmAddress {
- T::DefaultMappings::to_default_h160(account_id)
- }
-}
-
-/// AddressMapping wrapper implementation
-impl AddressMapping for Pallet {
- fn into_account_id(evm_address: H160) -> T::AccountId {
- >::to_account_id_or_default(&evm_address)
- .into_address()
- }
-}
-
-/// OnKilledAccount hooks implementation for removing storage mapping
-/// for killed accounts
-pub struct KillAccountMapping(PhantomData);
-impl OnKilledAccount for KillAccountMapping {
- fn on_killed_account(who: &T::AccountId) {
- // remove mappings of account reaped
- if let Some(evm_addr) = NativeToEvm::::take(who) {
- EvmToNative::::remove(evm_addr);
- NativeToEvm::::remove(who);
- }
- }
-}
-
-/// A lookup implementation returning the `AccountId` from `MultiAddress::Address20` (EVM Address).
-impl StaticLookup for Pallet {
- type Source = MultiAddress;
- type Target = T::AccountId;
-
- fn lookup(a: Self::Source) -> Result {
- match a {
- MultiAddress::Address20(i) => Ok(
- >::to_account_id_or_default(
- &EvmAddress::from_slice(&i),
- )
- .into_address(),
- ),
- _ => Err(LookupError),
- }
- }
-
- fn unlookup(a: Self::Target) -> Self::Source {
- MultiAddress::Id(a)
- }
-}
diff --git a/pallets/unified-accounts/src/mock.rs b/pallets/unified-accounts/src/mock.rs
deleted file mode 100644
index 3b9b9dcbfc..0000000000
--- a/pallets/unified-accounts/src/mock.rs
+++ /dev/null
@@ -1,198 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) Stake Technologies Pte.Ltd.
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// Astar is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Astar is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Astar. If not, see .
-
-#![cfg(test)]
-
-use super::*;
-use crate as pallet_unified_accounts;
-use astar_primitives::evm::HashedDefaultMappings;
-use frame_support::{
- construct_runtime, derive_impl, parameter_types,
- traits::{ConstU64, FindAuthor},
- weights::Weight,
-};
-use pallet_ethereum::PostLogContent;
-use pallet_evm::FeeCalculator;
-use sp_core::{keccak_256, H160, U256};
-use sp_io::TestExternalities;
-use sp_runtime::{
- traits::{AccountIdLookup, BlakeTwo256},
- AccountId32, BuildStorage, ConsensusEngineId,
-};
-
-parameter_types! {
- pub BlockWeights: frame_system::limits::BlockWeights =
- frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, 0));
- pub const ExistentialDeposit: u128 = 100;
-}
-
-#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
-impl frame_system::Config for TestRuntime {
- type Block = Block;
- type AccountId = AccountId;
- type Lookup = (AccountIdLookup, UnifiedAccounts);
- type AccountData = pallet_balances::AccountData;
- type OnKilledAccount = KillAccountMapping;
-}
-
-#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
-impl pallet_balances::Config for TestRuntime {
- type Balance = Balance;
- type ExistentialDeposit = ExistentialDeposit;
- type AccountStore = System;
-}
-
-#[derive_impl(pallet_timestamp::config_preludes::TestDefaultConfig)]
-impl pallet_timestamp::Config for TestRuntime {
- type MinimumPeriod = ConstU64<3>;
-}
-
-pub struct MockFeeCalculator;
-impl FeeCalculator for MockFeeCalculator {
- fn min_gas_price() -> (U256, Weight) {
- (U256::one(), Weight::zero())
- }
-}
-
-pub struct MockFindAuthor;
-impl FindAuthor for MockFindAuthor {
- fn find_author<'a, I>(_digests: I) -> Option
- where
- I: 'a + IntoIterator
- ,
- {
- Some(H160::from_low_u64_be(1))
- }
-}
-
-parameter_types! {
- pub WeightPerGas: Weight = Weight::from_parts(1, 0);
- pub const BlockGasLimit: U256 = U256::MAX;
- pub ChainId: u64 = 1024;
-}
-
-impl pallet_evm::Config for TestRuntime {
- type FeeCalculator = MockFeeCalculator;
- type GasWeightMapping = pallet_evm::FixedGasWeightMapping;
- type WeightPerGas = WeightPerGas;
- type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping;
- type CallOrigin = pallet_evm::EnsureAddressRoot;
- type WithdrawOrigin = pallet_evm::EnsureAddressTruncated;
- type AddressMapping = UnifiedAccounts;
- type Currency = Balances;
- type Runner = pallet_evm::runner::stack::Runner;
- type PrecompilesType = ();
- type PrecompilesValue = ();
- type ChainId = ChainId;
- type OnChargeTransaction = ();
- type BlockGasLimit = BlockGasLimit;
- type OnCreate = ();
- type FindAuthor = MockFindAuthor;
- type Timestamp = Timestamp;
- type WeightInfo = pallet_evm::weights::SubstrateWeight;
- type GasLimitPovSizeRatio = ConstU64<4>;
- type AccountProvider = pallet_evm::FrameSystemAccountProvider;
- type GasLimitStorageGrowthRatio = ConstU64<0>;
- type CreateOriginFilter = ();
- type CreateInnerOriginFilter = ();
-}
-
-parameter_types! {
- pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes;
-}
-
-impl pallet_ethereum::Config for TestRuntime {
- type StateRoot =
- pallet_ethereum::IntermediateStateRoot<::Version>;
- type PostLogContent = PostBlockAndTxnHashes;
- type ExtraDataLength = ConstU32<30>;
-}
-
-parameter_types! {
- pub const AccountMappingStorageFee: u128 = 100_000_000;
-}
-
-impl pallet_unified_accounts::Config for TestRuntime {
- type Currency = Balances;
- type DefaultMappings = HashedDefaultMappings;
- type ChainId = ChainId;
- type AccountMappingStorageFee = AccountMappingStorageFee;
- type WeightInfo = ();
-}
-
-pub(crate) type AccountId = AccountId32;
-pub(crate) type Balance = u128;
-
-pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]);
-pub const BOB: AccountId32 = AccountId32::new([1u8; 32]);
-pub const CHARLIE: AccountId32 = AccountId32::new([2u8; 32]);
-
-pub fn alice_secret() -> libsecp256k1::SecretKey {
- libsecp256k1::SecretKey::parse(&keccak_256(b"Alice")).unwrap()
-}
-
-pub fn bob_secret() -> libsecp256k1::SecretKey {
- libsecp256k1::SecretKey::parse(&keccak_256(b"Bob")).unwrap()
-}
-
-type Block = frame_system::mocking::MockBlock;
-
-construct_runtime!(
- pub struct TestRuntime {
- System: frame_system,
- Timestamp: pallet_timestamp,
- Balances: pallet_balances,
- Evm: pallet_evm,
- Ethereum: pallet_ethereum,
- UnifiedAccounts: pallet_unified_accounts,
- }
-);
-
-pub struct ExtBuilder {
- balances: Vec<(AccountId, Balance)>,
-}
-
-impl Default for ExtBuilder {
- fn default() -> Self {
- Self {
- balances: vec![
- (ALICE, 1_000_000_000_000),
- (BOB, 1_000_000_000_000),
- (CHARLIE, 1_000_000_000_000),
- ],
- }
- }
-}
-
-impl ExtBuilder {
- pub fn build(self) -> TestExternalities {
- let mut t = frame_system::GenesisConfig::::default()
- .build_storage()
- .unwrap();
-
- pallet_balances::GenesisConfig:: {
- balances: self.balances,
- ..Default::default()
- }
- .assimilate_storage(&mut t)
- .unwrap();
-
- let mut ext = TestExternalities::from(t);
- ext.execute_with(|| System::set_block_number(1));
- ext
- }
-}
diff --git a/pallets/unified-accounts/src/tests.rs b/pallets/unified-accounts/src/tests.rs
deleted file mode 100644
index 42ee3bfe27..0000000000
--- a/pallets/unified-accounts/src/tests.rs
+++ /dev/null
@@ -1,399 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) Stake Technologies Pte.Ltd.
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// Astar is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Astar is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Astar. If not, see .
-
-#![cfg(test)]
-
-use super::*;
-use frame_support::{assert_noop, assert_ok};
-use mock::*;
-
-use ethers::{
- contract::{Eip712, EthAbiType},
- core::types::{transaction::eip712::Eip712, Bytes},
-};
-use parity_scale_codec::Encode;
-use sp_runtime::{traits::StaticLookup, AccountId32, MultiAddress};
-
-/// EIP712 Payload struct
-#[derive(Eip712, EthAbiType, Clone)]
-#[eip712(
- name = "Astar EVM Claim",
- version = "1",
- chain_id = 1024,
- // mock genisis hash
- raw_salt = "0x4545454545454545454545454545454545454545454545454545454545454545"
- )]
-struct Claim {
- substrate_address: Bytes,
-}
-
-/// Build the signature payload for given native account and eth private key
-fn get_evm_signature(who: &AccountId32, secret: &libsecp256k1::SecretKey) -> [u8; 65] {
- // sign the payload
- UnifiedAccounts::eth_sign_prehash(
- &Claim {
- substrate_address: who.encode().into(),
- }
- .encode_eip712()
- .unwrap(),
- secret,
- )
-}
-
-/// Create the mappings for the accounts
-fn connect_accounts(who: &AccountId32, secret: &libsecp256k1::SecretKey) {
- assert_ok!(UnifiedAccounts::claim_evm_address(
- RuntimeOrigin::signed(who.clone()),
- UnifiedAccounts::eth_address(secret),
- get_evm_signature(who, secret)
- ));
-}
-
-#[test]
-fn eip712_signature_verify_works() {
- ExtBuilder::default().build().execute_with(|| {
- let claim = Claim {
- substrate_address: ALICE.encode().into(),
- };
-
- let claim_hash = UnifiedAccounts::build_signing_payload(&ALICE);
- // assert signing payload is correct
- assert_eq!(
- claim.encode_eip712().unwrap(),
- claim_hash,
- "signing payload should match"
- );
-
- // sign the payload
- let sig = UnifiedAccounts::eth_sign_prehash(&claim_hash, &alice_secret());
- assert_eq!(
- Some(UnifiedAccounts::eth_address(&alice_secret())),
- UnifiedAccounts::verify_signature(&ALICE, &sig),
- "signature verification should work"
- );
- });
-}
-
-#[test]
-fn static_lookup_works() {
- ExtBuilder::default().build().execute_with(|| {
- let alice_eth = UnifiedAccounts::eth_address(&alice_secret());
- let bob_eth = UnifiedAccounts::eth_address(&bob_secret());
- let bob_default_account_id =
- >::to_default_account_id(&bob_eth);
-
- // create mappings for alice
- connect_accounts(&ALICE, &alice_secret());
-
- // mapping should work if available
- assert_eq!(
- ::lookup(MultiAddress::Address20(alice_eth.into()))
- .unwrap(),
- ALICE
- );
-
- // should use default if not mapping
- assert_eq!(
- ::lookup(MultiAddress::Address20(bob_eth.into()))
- .unwrap(),
- bob_default_account_id
- );
- });
-}
-
-#[test]
-fn on_killed_account_hook() {
- ExtBuilder::default().build().execute_with(|| {
- let alice_eth = UnifiedAccounts::eth_address(&alice_secret());
-
- // create the mappings
- connect_accounts(&ALICE, &alice_secret());
-
- // kill alice by transfering everything to bob
- Balances::set_balance(&ALICE, 0);
-
- // check killed account events
- assert!(System::events().iter().any(|r| matches!(
- &r.event,
- RuntimeEvent::System(frame_system::Event::KilledAccount { account }) if account == &ALICE
- )));
-
- // make sure mapping is removed
- assert_eq!(NativeToEvm::::get(ALICE), None);
- assert_eq!(EvmToNative::::get(alice_eth), None);
- });
-}
-
-#[test]
-fn account_claim_should_work() {
- ExtBuilder::default().build().execute_with(|| {
- let alice_eth = UnifiedAccounts::eth_address(&alice_secret());
- // default ss58 account associated with eth address
- let alice_eth_old_account =
- ::DefaultMappings::to_default_account_id(&alice_eth);
- let signature = get_evm_signature(&ALICE, &alice_secret());
-
- // transfer some funds to alice_eth (H160)
- assert_ok!(Balances::transfer_allow_death(
- RuntimeOrigin::signed(BOB),
- alice_eth_old_account.clone().into(),
- 1001
- ));
-
- // claim the account
- assert_ok!(UnifiedAccounts::claim_evm_address(
- RuntimeOrigin::signed(ALICE),
- alice_eth,
- signature
- ));
-
- // check if all of balances is transfered to new account (ALICE) from
- // old account (alice_eth_old_account)
- assert!(System::events().iter().any(|r| matches!(
- &r.event,
- RuntimeEvent::System(frame_system::Event::KilledAccount { account })
- if account == &alice_eth_old_account
- )));
-
- // check if storage fee is charged and burned
- assert!(System::events().iter().any(|r| matches!(
- &r.event,
- RuntimeEvent::Balances(pallet_balances::Event::Burned { who, amount })
- if who == &ALICE && amount == &AccountMappingStorageFee::get()
- )));
-
- // check for claim account event
- System::assert_last_event(RuntimeEvent::UnifiedAccounts(
- crate::Event::AccountClaimed {
- account_id: ALICE.clone(),
- evm_address: alice_eth.clone(),
- },
- ));
-
- // make sure mappings are in place
- assert_eq!(EvmToNative::::get(alice_eth).unwrap(), ALICE);
- assert_eq!(NativeToEvm::::get(ALICE).unwrap(), alice_eth)
- });
-}
-
-#[test]
-fn account_default_claim_works() {
- ExtBuilder::default().build().execute_with(|| {
- let alice_default_evm = ::DefaultMappings::to_default_h160(&ALICE);
-
- // claim default account
- assert_ok!(UnifiedAccounts::claim_default_evm_address(
- RuntimeOrigin::signed(ALICE)
- ));
- System::assert_last_event(RuntimeEvent::UnifiedAccounts(
- crate::Event::AccountClaimed {
- account_id: ALICE.clone(),
- evm_address: alice_default_evm.clone(),
- },
- ));
-
- // check if storage fee is charged and burned
- assert!(System::events().iter().any(|r| matches!(
- &r.event,
- RuntimeEvent::Balances(pallet_balances::Event::Burned { who, amount })
- if who == &ALICE && amount == &AccountMappingStorageFee::get()
- )));
-
- // check UnifiedAddressMapper's mapping works
- assert_eq!(
- >::to_h160(&ALICE),
- Some(alice_default_evm)
- );
- assert_eq!(
- >::to_account_id(&alice_default_evm),
- Some(ALICE)
- );
-
- // should not allow to claim afterwards
- assert_noop!(
- UnifiedAccounts::claim_evm_address(
- RuntimeOrigin::signed(ALICE),
- UnifiedAccounts::eth_address(&alice_secret()),
- get_evm_signature(&ALICE, &alice_secret())
- ),
- Error::::AlreadyMapped
- );
- });
-}
-
-#[test]
-fn account_default_claim_should_not_work_if_collision() {
- ExtBuilder::default().build().execute_with(|| {
- let bob_default_h160 = >::to_default_h160(&BOB);
-
- // create mapping of alice native with bob's default address
- // in real world possibilty of this happening is minuscule
- EvmToNative::::insert(&bob_default_h160, &ALICE);
- NativeToEvm::::insert(&ALICE, &bob_default_h160);
-
- // bob try claiming default h160 address, it should fail since alice already
- // has mapping in place with it.
- assert_noop!(
- UnifiedAccounts::claim_default_evm_address(RuntimeOrigin::signed(BOB)),
- Error::::AlreadyMapped
- );
-
- // check mappings are consistent
- assert_eq!(
- >::to_h160(&ALICE),
- Some(bob_default_h160)
- );
- assert_eq!(
- >::to_account_id(&bob_default_h160),
- Some(ALICE)
- );
- });
-}
-
-#[test]
-fn replay_attack_should_not_be_possible() {
- ExtBuilder::default().build().execute_with(|| {
- let alice_eth = UnifiedAccounts::eth_address(&alice_secret());
- let alice_signature = get_evm_signature(&ALICE, &alice_secret());
-
- // alice claim her eth address first
- assert_ok!(UnifiedAccounts::claim_evm_address(
- RuntimeOrigin::signed(ALICE),
- alice_eth,
- alice_signature
- ));
-
- // bob intercepted alice signature and tries to perform
- // replay attack to claim alice eth address as his own,
- // this should fail.
- assert_noop!(
- UnifiedAccounts::claim_evm_address(
- RuntimeOrigin::signed(BOB),
- alice_eth,
- alice_signature
- ),
- Error::::AlreadyMapped
- );
- });
-}
-
-#[test]
-fn frontrun_attack_should_not_be_possible() {
- ExtBuilder::default().build().execute_with(|| {
- let alice_eth = UnifiedAccounts::eth_address(&alice_secret());
- let alice_signature = get_evm_signature(&ALICE, &alice_secret());
-
- // bob intercepted alice signature and tries to perform
- // frontrun attack to claim alice eth address as his own
- // this should fail with InvalidSignature.
- assert_noop!(
- UnifiedAccounts::claim_evm_address(
- RuntimeOrigin::signed(BOB),
- alice_eth,
- alice_signature
- ),
- Error::::InvalidSignature
- );
-
- // alice can claim her eth address
- assert_ok!(UnifiedAccounts::claim_evm_address(
- RuntimeOrigin::signed(ALICE),
- alice_eth,
- alice_signature
- ));
- });
-}
-
-#[test]
-fn connecting_mapped_accounts_should_not_work() {
- ExtBuilder::default().build().execute_with(|| {
- // connect ALICE accounts
- connect_accounts(&ALICE, &alice_secret());
-
- // AccountId already mapped
- // ALICE attempts to connect another evm address
- assert_noop!(
- UnifiedAccounts::claim_evm_address(
- RuntimeOrigin::signed(ALICE),
- UnifiedAccounts::eth_address(&bob_secret()),
- get_evm_signature(&BOB, &bob_secret())
- ),
- Error::::AlreadyMapped
- );
-
- // eth address already mapped
- // BOB attempts to connect alice_eth that is already mapped
- assert_noop!(
- UnifiedAccounts::claim_evm_address(
- RuntimeOrigin::signed(BOB),
- UnifiedAccounts::eth_address(&alice_secret()),
- get_evm_signature(&ALICE, &alice_secret())
- ),
- Error::::AlreadyMapped
- );
- });
-}
-
-#[test]
-fn charging_storage_fee_should_not_reap_account() {
- ExtBuilder::default().build().execute_with(|| {
- let alice_eth = UnifiedAccounts::eth_address(&alice_secret());
- let alice_signature = get_evm_signature(&ALICE, &alice_secret());
-
- // set alice balance just enough to claim accounts without being reaped
- Balances::set_balance(
- &ALICE,
- ExistentialDeposit::get() + AccountMappingStorageFee::get(),
- );
-
- //
- // With sufficent funds, claim should succeed
- //
- assert_ok!(UnifiedAccounts::claim_evm_address(
- RuntimeOrigin::signed(ALICE),
- alice_eth,
- alice_signature
- ));
- // check for claimed event
- System::assert_last_event(RuntimeEvent::UnifiedAccounts(
- crate::Event::AccountClaimed {
- account_id: ALICE.clone(),
- evm_address: alice_eth,
- },
- ));
-
- // confirm the balance, should be equal to ED
- assert_eq!(Balances::total_balance(&ALICE), ExistentialDeposit::get());
-
- // clear mappings
- EvmToNative::::remove(alice_eth);
- NativeToEvm::::remove(ALICE);
-
- //
- // When funds are less than required, should fail with funds unavailable
- //
- assert_noop!(
- UnifiedAccounts::claim_evm_address(
- RuntimeOrigin::signed(ALICE),
- alice_eth,
- alice_signature
- ),
- Error::::FundsUnavailable
- );
- });
-}
diff --git a/pallets/unified-accounts/src/weights.rs b/pallets/unified-accounts/src/weights.rs
deleted file mode 100644
index cc4bea93a5..0000000000
--- a/pallets/unified-accounts/src/weights.rs
+++ /dev/null
@@ -1,210 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) Stake Technologies Pte.Ltd.
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// Astar is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Astar is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Astar. If not, see .
-
-//! Autogenerated weights for pallet_unified_accounts
-//!
-//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
-//! DATE: 2023-10-27, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
-//! WORST CASE MAP SIZE: `1000000`
-//! HOSTNAME: `devserver-01`, CPU: `Intel(R) Xeon(R) E-2236 CPU @ 3.40GHz`
-//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("shibuya-dev"), DB CACHE: 1024
-
-// Executed Command:
-// ./target/release/astar-collator
-// benchmark
-// pallet
-// --chain=shibuya-dev
-// --steps=50
-// --repeat=20
-// --pallet=pallet_unified_accounts
-// --extrinsic=*
-// --execution=wasm
-// --wasm-execution=compiled
-// --heap-pages=4096
-// --output=./benchmark-results/shibuya-dev/unified_accounts_weights.rs
-// --template=./scripts/templates/weight-template.hbs
-
-#![cfg_attr(rustfmt, rustfmt_skip)]
-#![allow(unused_parens)]
-#![allow(unused_imports)]
-
-use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
-use core::marker::PhantomData;
-
-/// Weight functions needed for pallet_unified_accounts.
-pub trait WeightInfo {
- fn claim_evm_address() -> Weight;
- fn claim_default_evm_address() -> Weight;
- fn to_account_id() -> Weight;
- fn to_account_id_or_default() -> Weight;
- fn to_h160() -> Weight;
- fn to_h160_or_default() -> Weight;
-}
-
-/// Weights for pallet_unified_accounts using the Substrate node and recommended hardware.
-pub struct SubstrateWeight(PhantomData);
-impl WeightInfo for SubstrateWeight {
- /// Storage: UnifiedAccounts NativeToEvm (r:1 w:1)
- /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
- /// Storage: UnifiedAccounts EvmToNative (r:1 w:1)
- /// Proof: UnifiedAccounts EvmToNative (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
- /// Storage: EVMChainId ChainId (r:1 w:0)
- /// Proof: EVMChainId ChainId (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen)
- /// Storage: System BlockHash (r:1 w:0)
- /// Proof: System BlockHash (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen)
- /// Storage: System Account (r:1 w:0)
- /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
- fn claim_evm_address() -> Weight {
- // Proof Size summary in bytes:
- // Measured: `256`
- // Estimated: `3593`
- // Minimum execution time: 91_231_000 picoseconds.
- Weight::from_parts(91_688_000, 3593)
- .saturating_add(T::DbWeight::get().reads(5_u64))
- .saturating_add(T::DbWeight::get().writes(2_u64))
- }
- /// Storage: UnifiedAccounts NativeToEvm (r:1 w:1)
- /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
- /// Storage: UnifiedAccounts EvmToNative (r:1 w:1)
- /// Proof: UnifiedAccounts EvmToNative (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
- fn claim_default_evm_address() -> Weight {
- // Proof Size summary in bytes:
- // Measured: `42`
- // Estimated: `3533`
- // Minimum execution time: 40_749_000 picoseconds.
- Weight::from_parts(41_411_000, 3533)
- .saturating_add(T::DbWeight::get().reads(2_u64))
- .saturating_add(T::DbWeight::get().writes(2_u64))
- }
- /// Storage: UnifiedAccounts EvmToNative (r:1 w:0)
- /// Proof: UnifiedAccounts EvmToNative (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
- fn to_account_id() -> Weight {
- // Proof Size summary in bytes:
- // Measured: `170`
- // Estimated: `3533`
- // Minimum execution time: 5_478_000 picoseconds.
- Weight::from_parts(5_661_000, 3533)
- .saturating_add(T::DbWeight::get().reads(1_u64))
- }
- /// Storage: UnifiedAccounts EvmToNative (r:1 w:0)
- /// Proof: UnifiedAccounts EvmToNative (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
- fn to_account_id_or_default() -> Weight {
- // Proof Size summary in bytes:
- // Measured: `170`
- // Estimated: `3533`
- // Minimum execution time: 5_515_000 picoseconds.
- Weight::from_parts(5_700_000, 3533)
- .saturating_add(T::DbWeight::get().reads(1_u64))
- }
- /// Storage: UnifiedAccounts NativeToEvm (r:1 w:0)
- /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
- fn to_h160() -> Weight {
- // Proof Size summary in bytes:
- // Measured: `170`
- // Estimated: `3533`
- // Minimum execution time: 5_626_000 picoseconds.
- Weight::from_parts(5_827_000, 3533)
- .saturating_add(T::DbWeight::get().reads(1_u64))
- }
- /// Storage: UnifiedAccounts NativeToEvm (r:1 w:0)
- /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
- fn to_h160_or_default() -> Weight {
- // Proof Size summary in bytes:
- // Measured: `170`
- // Estimated: `3533`
- // Minimum execution time: 5_578_000 picoseconds.
- Weight::from_parts(5_719_000, 3533)
- .saturating_add(T::DbWeight::get().reads(1_u64))
- }
-}
-
-// For backwards compatibility and tests
-impl WeightInfo for () {
- /// Storage: UnifiedAccounts NativeToEvm (r:1 w:1)
- /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
- /// Storage: UnifiedAccounts EvmToNative (r:1 w:1)
- /// Proof: UnifiedAccounts EvmToNative (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
- /// Storage: EVMChainId ChainId (r:1 w:0)
- /// Proof: EVMChainId ChainId (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen)
- /// Storage: System BlockHash (r:1 w:0)
- /// Proof: System BlockHash (max_values: None, max_size: Some(44), added: 2519, mode: MaxEncodedLen)
- /// Storage: System Account (r:1 w:0)
- /// Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen)
- fn claim_evm_address() -> Weight {
- // Proof Size summary in bytes:
- // Measured: `256`
- // Estimated: `3593`
- // Minimum execution time: 91_231_000 picoseconds.
- Weight::from_parts(91_688_000, 3593)
- .saturating_add(RocksDbWeight::get().reads(5_u64))
- .saturating_add(RocksDbWeight::get().writes(2_u64))
- }
- /// Storage: UnifiedAccounts NativeToEvm (r:1 w:1)
- /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
- /// Storage: UnifiedAccounts EvmToNative (r:1 w:1)
- /// Proof: UnifiedAccounts EvmToNative (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
- fn claim_default_evm_address() -> Weight {
- // Proof Size summary in bytes:
- // Measured: `42`
- // Estimated: `3533`
- // Minimum execution time: 40_749_000 picoseconds.
- Weight::from_parts(41_411_000, 3533)
- .saturating_add(RocksDbWeight::get().reads(2_u64))
- .saturating_add(RocksDbWeight::get().writes(2_u64))
- }
- /// Storage: UnifiedAccounts EvmToNative (r:1 w:0)
- /// Proof: UnifiedAccounts EvmToNative (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
- fn to_account_id() -> Weight {
- // Proof Size summary in bytes:
- // Measured: `170`
- // Estimated: `3533`
- // Minimum execution time: 5_478_000 picoseconds.
- Weight::from_parts(5_661_000, 3533)
- .saturating_add(RocksDbWeight::get().reads(1_u64))
- }
- /// Storage: UnifiedAccounts EvmToNative (r:1 w:0)
- /// Proof: UnifiedAccounts EvmToNative (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
- fn to_account_id_or_default() -> Weight {
- // Proof Size summary in bytes:
- // Measured: `170`
- // Estimated: `3533`
- // Minimum execution time: 5_515_000 picoseconds.
- Weight::from_parts(5_700_000, 3533)
- .saturating_add(RocksDbWeight::get().reads(1_u64))
- }
- /// Storage: UnifiedAccounts NativeToEvm (r:1 w:0)
- /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
- fn to_h160() -> Weight {
- // Proof Size summary in bytes:
- // Measured: `170`
- // Estimated: `3533`
- // Minimum execution time: 5_626_000 picoseconds.
- Weight::from_parts(5_827_000, 3533)
- .saturating_add(RocksDbWeight::get().reads(1_u64))
- }
- /// Storage: UnifiedAccounts NativeToEvm (r:1 w:0)
- /// Proof: UnifiedAccounts NativeToEvm (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen)
- fn to_h160_or_default() -> Weight {
- // Proof Size summary in bytes:
- // Measured: `170`
- // Estimated: `3533`
- // Minimum execution time: 5_578_000 picoseconds.
- Weight::from_parts(5_719_000, 3533)
- .saturating_add(RocksDbWeight::get().reads(1_u64))
- }
-}
diff --git a/precompiles/unified-accounts/Cargo.toml b/precompiles/unified-accounts/Cargo.toml
deleted file mode 100644
index 9589e69164..0000000000
--- a/precompiles/unified-accounts/Cargo.toml
+++ /dev/null
@@ -1,68 +0,0 @@
-[package]
-name = "pallet-evm-precompile-unified-accounts"
-description = "Evm Precompile for AU"
-version = "0.1.0"
-authors.workspace = true
-edition.workspace = true
-homepage.workspace = true
-repository.workspace = true
-
-[lints]
-workspace = true
-
-[dependencies]
-hex = { workspace = true }
-log = { workspace = true }
-num_enum = { workspace = true }
-precompile-utils = { workspace = true }
-
-# Substrate
-frame-support = { workspace = true }
-frame-system = { workspace = true }
-parity-scale-codec = { workspace = true, features = ["max-encoded-len"] }
-sp-core = { workspace = true }
-sp-io = { workspace = true }
-sp-runtime = { workspace = true }
-sp-std = { workspace = true }
-
-# Frontier
-fp-evm = { workspace = true }
-pallet-evm = { workspace = true }
-pallet-unified-accounts = { workspace = true }
-
-# Astar
-astar-primitives = { workspace = true }
-
-[dev-dependencies]
-derive_more = { workspace = true }
-hex-literal = { workspace = true }
-scale-info = { workspace = true }
-serde = { workspace = true }
-
-precompile-utils = { workspace = true, features = ["testing"] }
-
-ethers = { workspace = true }
-libsecp256k1 = { workspace = true, features = ["hmac", "static-context"] }
-pallet-balances = { workspace = true, features = ["std"] }
-pallet-timestamp = { workspace = true }
-sp-runtime = { workspace = true }
-
-[features]
-default = ["std"]
-std = [
- "parity-scale-codec/std",
- "pallet-unified-accounts/std",
- "fp-evm/std",
- "frame-support/std",
- "frame-system/std",
- "pallet-evm/std",
- "precompile-utils/std",
- "sp-core/std",
- "sp-std/std",
- "sp-io/std",
- "sp-runtime/std",
- "astar-primitives/std",
- "hex/std",
- "log/std",
- "num_enum/std",
-]
diff --git a/precompiles/unified-accounts/UnifiedAccounts.sol b/precompiles/unified-accounts/UnifiedAccounts.sol
deleted file mode 100644
index 9569af44e3..0000000000
--- a/precompiles/unified-accounts/UnifiedAccounts.sol
+++ /dev/null
@@ -1,28 +0,0 @@
-pragma solidity ^0.8.0;
-
-/**
- * @title UA interface.
- */
-
-/// Interface to the precompiled contract
-/// Predeployed at the address 0x0000000000000000000000000000000000005006
-/// For better understanding check the source code:
-/// repo: https://github.com/AstarNetwork/astar
-/// code: pallets/unified-accounts/src/lib.rs
-interface UnifiedAccounts {
- /// Gets the evm address associated with given account id. If no mapping exists,
- /// then return the default account id.
- /// @param accountId: The account id for which you want the evm address for.
- /// @return (mapped_address, true) if there is a mapping found otherwise (default_address, false)
- function get_evm_address_or_default(
- bytes32 accountId
- ) external view returns (address, bool);
-
- /// Gets the account id associated with given evm address. If no mapping exists,
- /// then return the default evm address.
- /// @param evmAddress: The evm address for which you want the account id for.
- /// @return (mapped_account, true) if there is a mapping found otherwise (default_account, false)
- function get_native_address_or_default(
- address evmAddress
- ) external view returns (bytes32, bool);
-}
diff --git a/precompiles/unified-accounts/src/lib.rs b/precompiles/unified-accounts/src/lib.rs
deleted file mode 100644
index 3fa2f2a6f6..0000000000
--- a/precompiles/unified-accounts/src/lib.rs
+++ /dev/null
@@ -1,70 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) Stake Technologies Pte.Ltd.
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// Astar is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Astar is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Astar. If not, see .
-
-#![cfg_attr(not(feature = "std"), no_std)]
-
-use astar_primitives::evm::{UnifiedAddress, UnifiedAddressMapper};
-use core::marker::PhantomData;
-use fp_evm::PrecompileHandle;
-use frame_support::traits::IsType;
-use precompile_utils::prelude::*;
-use sp_core::{crypto::AccountId32, H256};
-
-#[cfg(test)]
-mod mock;
-#[cfg(test)]
-mod tests;
-
-/// A precompile that expose AU related functions.
-pub struct UnifiedAccountsPrecompile(PhantomData<(T, UA)>);
-
-#[precompile_utils::precompile]
-impl UnifiedAccountsPrecompile
-where
- R: pallet_evm::Config + pallet_unified_accounts::Config,
- ::AccountId: IsType,
- UA: UnifiedAddressMapper,
-{
- #[precompile::public("get_evm_address_or_default(bytes32)")]
- #[precompile::view]
- fn get_evm_address_or_default(
- _: &mut impl PrecompileHandle,
- account_id: H256,
- ) -> EvmResult<(Address, bool)> {
- let account_id = AccountId32::new(account_id.into()).into();
-
- let output: (Address, bool) = match UA::to_h160_or_default(&account_id) {
- UnifiedAddress::Mapped(address) => (address.into(), true),
- UnifiedAddress::Default(address) => (address.into(), false),
- };
- Ok(output)
- }
-
- #[precompile::public("get_native_address_or_default(address)")]
- #[precompile::view]
- fn get_native_address_or_default(
- _: &mut impl PrecompileHandle,
- evm_address: Address,
- ) -> EvmResult<(H256, bool)> {
- let output: (H256, bool) = match UA::to_account_id_or_default(&evm_address.into()) {
- UnifiedAddress::Mapped(account_id) => (H256::from(account_id.into().as_ref()), true),
- UnifiedAddress::Default(account_id) => (H256::from(account_id.into().as_ref()), false),
- };
- Ok(output)
- }
-}
diff --git a/precompiles/unified-accounts/src/mock.rs b/precompiles/unified-accounts/src/mock.rs
deleted file mode 100644
index dfe14e9673..0000000000
--- a/precompiles/unified-accounts/src/mock.rs
+++ /dev/null
@@ -1,243 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) Stake Technologies Pte.Ltd.
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// Astar is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Astar is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Astar. If not, see .
-
-use super::*;
-
-use fp_evm::{IsPrecompileResult, Precompile};
-use frame_support::{
- construct_runtime, derive_impl, parameter_types, traits::ConstU64, weights::Weight,
-};
-pub use pallet_evm::{EnsureAddressNever, EnsureAddressRoot, PrecompileResult, PrecompileSet};
-use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
-use scale_info::TypeInfo;
-use serde::{Deserialize, Serialize};
-use sp_core::{keccak_256, H160};
-use sp_runtime::{
- traits::{BlakeTwo256, IdentityLookup},
- AccountId32, BuildStorage,
-};
-
-use ethers::{
- contract::{Eip712, EthAbiType},
- core::types::transaction::eip712::Eip712,
-};
-
-use astar_primitives::evm::HashedDefaultMappings;
-pub type AccountId = AccountId32;
-pub type Balance = u128;
-pub type Block = frame_system::mocking::MockBlock;
-
-pub const PRECOMPILE_ADDRESS: H160 = H160::repeat_byte(0x7B);
-
-pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]);
-
-pub fn alice_secret() -> libsecp256k1::SecretKey {
- libsecp256k1::SecretKey::parse(&keccak_256(b"Alice")).unwrap()
-}
-/// EIP712 Payload struct
-#[derive(Eip712, EthAbiType, Clone)]
-#[eip712(
- name = "Astar EVM Claim",
- version = "1",
- chain_id = 1024,
- // mock genisis hash
- raw_salt = "0x4545454545454545454545454545454545454545454545454545454545454545"
- )]
-struct Claim {
- substrate_address: ethers::core::types::Bytes,
-}
-
-/// Build the signature payload for given native account and eth private key
-pub fn get_evm_signature(who: &AccountId32, secret: &libsecp256k1::SecretKey) -> [u8; 65] {
- // sign the payload
- UnifiedAccounts::eth_sign_prehash(
- &Claim {
- substrate_address: who.encode().into(),
- }
- .encode_eip712()
- .unwrap(),
- secret,
- )
-}
-
-#[derive(
- Eq,
- PartialEq,
- Ord,
- PartialOrd,
- Clone,
- Encode,
- Decode,
- Debug,
- MaxEncodedLen,
- Serialize,
- Deserialize,
- derive_more::Display,
- TypeInfo,
-)]
-pub enum TestAccount {
- Viktor,
- Precompile,
-}
-impl Default for TestAccount {
- fn default() -> Self {
- Self::Viktor
- }
-}
-impl From for H160 {
- fn from(value: TestAccount) -> H160 {
- match value {
- TestAccount::Viktor => H160::repeat_byte(0xAA),
- TestAccount::Precompile => PRECOMPILE_ADDRESS,
- }
- }
-}
-
-parameter_types! {
- pub const BlockHashCount: u64 = 250;
- pub BlockWeights: frame_system::limits::BlockWeights =
- frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, 0));
-}
-
-#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
-impl frame_system::Config for TestRuntime {
- type Block = Block;
- type AccountId = AccountId32;
- type Lookup = IdentityLookup;
- type AccountData = pallet_balances::AccountData;
-}
-#[derive(Debug, Clone, Copy)]
-pub struct TestPrecompileSet(PhantomData);
-
-impl PrecompileSet for TestPrecompileSet
-where
- R: pallet_evm::Config,
- UnifiedAccountsPrecompile>: Precompile,
-{
- fn execute(&self, handle: &mut impl PrecompileHandle) -> Option {
- match handle.code_address() {
- a if a == PRECOMPILE_ADDRESS => Some(UnifiedAccountsPrecompile::<
- R,
- pallet_unified_accounts::Pallet,
- >::execute(handle)),
- _ => None,
- }
- }
-
- fn is_precompile(&self, address: H160, _gas: u64) -> IsPrecompileResult {
- IsPrecompileResult::Answer {
- is_precompile: address == PRECOMPILE_ADDRESS,
- extra_cost: 0,
- }
- }
-}
-
-parameter_types! {
- pub const ExistentialDeposit: u128 = 1;
-}
-
-#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
-impl pallet_balances::Config for TestRuntime {
- type Balance = Balance;
- type ExistentialDeposit = ExistentialDeposit;
- type AccountStore = System;
-}
-
-parameter_types! {
- pub const MinimumPeriod: u64 = 5;
-}
-
-#[derive_impl(pallet_timestamp::config_preludes::TestDefaultConfig)]
-impl pallet_timestamp::Config for TestRuntime {
- type MinimumPeriod = MinimumPeriod;
-}
-
-parameter_types! {
- pub const PrecompilesValue: TestPrecompileSet =
- TestPrecompileSet(PhantomData);
- pub WeightPerGas: Weight = Weight::from_parts(1, 0);
-}
-
-pub type PrecompileCall = UnifiedAccountsPrecompileCall;
-
-impl pallet_evm::Config for TestRuntime {
- type FeeCalculator = ();
- type GasWeightMapping = pallet_evm::FixedGasWeightMapping;
- type WeightPerGas = WeightPerGas;
- type CallOrigin = EnsureAddressRoot;
- type WithdrawOrigin = EnsureAddressNever;
- type AddressMapping = UnifiedAccounts;
- type Currency = Balances;
- type Runner = pallet_evm::runner::stack::Runner;
- type PrecompilesType = TestPrecompileSet;
- type PrecompilesValue = PrecompilesValue;
- type Timestamp = Timestamp;
- type ChainId = ChainId;
- type OnChargeTransaction = ();
- type BlockGasLimit = ();
- type BlockHashMapping = pallet_evm::SubstrateBlockHashMapping;
- type FindAuthor = ();
- type OnCreate = ();
- type WeightInfo = ();
- type GasLimitPovSizeRatio = ConstU64<4>;
- type AccountProvider = pallet_evm::FrameSystemAccountProvider;
- type GasLimitStorageGrowthRatio = ConstU64<0>;
- type CreateOriginFilter = ();
- type CreateInnerOriginFilter = ();
-}
-
-parameter_types! {
- // 2 storage items with value size 20 and 32
- pub const AccountMappingStorageFee: u128 = 0;
- pub ChainId: u64 = 1024;
-}
-
-impl pallet_unified_accounts::Config for TestRuntime {
- type Currency = Balances;
- type DefaultMappings = HashedDefaultMappings;
- type ChainId = ChainId;
- type AccountMappingStorageFee = AccountMappingStorageFee;
- type WeightInfo = pallet_unified_accounts::weights::SubstrateWeight;
-}
-
-// Configure a mock runtime to test the pallet.
-construct_runtime!(
- pub enum TestRuntime
- {
- System: frame_system,
- Evm: pallet_evm,
- UnifiedAccounts: pallet_unified_accounts,
- Balances : pallet_balances,
- Timestamp: pallet_timestamp,
- }
-);
-
-#[derive(Default)]
-pub(crate) struct ExtBuilder;
-
-impl ExtBuilder {
- pub(crate) fn build(self) -> sp_io::TestExternalities {
- let t = frame_system::GenesisConfig::::default()
- .build_storage()
- .expect("Frame system builds valid default genesis config");
-
- let mut ext = sp_io::TestExternalities::new(t);
- ext.execute_with(|| System::set_block_number(1));
- ext
- }
-}
diff --git a/precompiles/unified-accounts/src/tests.rs b/precompiles/unified-accounts/src/tests.rs
deleted file mode 100644
index 8eaa8d69bd..0000000000
--- a/precompiles/unified-accounts/src/tests.rs
+++ /dev/null
@@ -1,130 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) Stake Technologies Pte.Ltd.
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// Astar is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Astar is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Astar. If not, see .
-
-use crate::mock::*;
-use crate::*;
-
-use frame_support::assert_ok;
-use precompile_utils::testing::*;
-
-fn precompiles() -> TestPrecompileSet {
- PrecompilesValue::get()
-}
-
-#[test]
-fn test_get_evm_address() {
- // Case 1 : Address Not Mapped
- ExtBuilder.build().execute_with(|| {
- let alice_default_evm =
- ::DefaultMappings::to_default_h160(
- &ALICE,
- );
-
- let res: (Address, bool) = (alice_default_evm.into(), false);
- precompiles()
- .prepare_test(
- TestAccount::Viktor,
- PRECOMPILE_ADDRESS,
- PrecompileCall::get_evm_address_or_default {
- account_id: H256::zero(), // Alice's Address
- },
- )
- .expect_no_logs()
- .execute_returns(res);
- });
-
- // Case 2 : Address Mapped
- ExtBuilder.build().execute_with(|| {
- let alice_eth = UnifiedAccounts::eth_address(&alice_secret());
- let signature = get_evm_signature(&ALICE, &alice_secret());
-
- // claim the account
- assert_ok!(UnifiedAccounts::claim_evm_address(
- RuntimeOrigin::signed(ALICE),
- alice_eth,
- signature
- ));
-
- let res: (Address, bool) = (alice_eth.into(), true);
- precompiles()
- .prepare_test(
- TestAccount::Viktor,
- PRECOMPILE_ADDRESS,
- PrecompileCall::get_evm_address_or_default {
- account_id: H256::zero(), // Alice's Address
- },
- )
- .expect_no_logs()
- .execute_returns(res);
- });
-}
-
-#[test]
-fn test_get_native_address() {
- // Case 1: not mapped native address (default address)
- ExtBuilder.build().execute_with(|| {
- let alice_eth = UnifiedAccounts::eth_address(&alice_secret());
- let alice_eth_address: Address = alice_eth.into();
-
- // default ss58 account associated with eth address
- let alice_eth_old_account =
- ::DefaultMappings::to_default_account_id(
- &alice_eth,
- );
-
- // for let binding
- let alice_eth_old_account_converted: &[u8; 32] = alice_eth_old_account.as_ref();
- let res: (H256, bool) = (alice_eth_old_account_converted.into(), false);
- precompiles()
- .prepare_test(
- TestAccount::Viktor,
- PRECOMPILE_ADDRESS,
- PrecompileCall::get_native_address_or_default { evm_address: alice_eth_address }
- )
- .expect_no_logs()
- .execute_returns(res);
- });
-
- // Case 2 : mapped address
- ExtBuilder.build().execute_with(|| {
- // claiming address
- let alice_eth: Address = UnifiedAccounts::eth_address(&alice_secret()).into();
- let signature = get_evm_signature(&ALICE, &alice_secret());
-
- // claim the account
- assert_ok!(UnifiedAccounts::claim_evm_address(
- RuntimeOrigin::signed(ALICE),
- alice_eth.into(),
- signature
- ));
-
- let alice_converted: &[u8; 32] = ALICE.as_ref();
-
- let res: (H256, bool) = (alice_converted.into(), true);
- precompiles()
- .prepare_test(
- TestAccount::Viktor,
- PRECOMPILE_ADDRESS,
- PrecompileCall::get_native_address_or_default {
- evm_address: alice_eth,
- },
- )
- .expect_no_logs()
- .execute_returns(res);
- });
-}
diff --git a/primitives/src/ethereum_checked.rs b/primitives/src/ethereum_checked.rs
deleted file mode 100644
index 56117ba53e..0000000000
--- a/primitives/src/ethereum_checked.rs
+++ /dev/null
@@ -1,82 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) Stake Technologies Pte.Ltd.
-// SPDX-License-Identifier: GPL-3.0-or-later
-
-// Astar is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Astar is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Astar. If not, see .
-
-use parity_scale_codec::{Decode, Encode};
-use scale_info::TypeInfo;
-
-use ethereum::{
- eip2930::TransactionSignature, AccessListItem, EIP1559Transaction, TransactionAction,
- TransactionV2 as Transaction,
-};
-use ethereum_types::{H160, H256, U256};
-use frame_support::{pallet_prelude::*, traits::ConstU32, BoundedVec};
-use sp_std::prelude::*;
-
-/// Max Ethereum tx input size: 65_536 bytes
-pub const MAX_ETHEREUM_TX_INPUT_SIZE: u32 = 2u32.pow(16);
-
-pub type EthereumTxInput = BoundedVec>;
-
-/// The checked Ethereum transaction. Only contracts `call` is support(no `create`).
-#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, TypeInfo, DecodeWithMemTracking)]
-pub struct CheckedEthereumTx {
- /// Gas limit.
- pub gas_limit: U256,
- /// Contract address to call.
- pub target: H160,
- /// Amount to transfer.
- pub value: U256,
- /// Input of a contract call.
- pub input: EthereumTxInput,
- /// Optional access list, specified in EIP-2930.
- pub maybe_access_list: Option