From 6cf07c5637c868c0d00f0713ee7c27767a533b60 Mon Sep 17 00:00:00 2001
From: Deepanshu Hooda <43631678+gitofdeepanshu@users.noreply.github.com>
Date: Wed, 11 Oct 2023 09:37:17 +0530
Subject: [PATCH] remove batch precompile (#1047)
---
Cargo.lock | 32 --
Cargo.toml | 1 -
precompiles/batch/Batch.sol | 77 ----
precompiles/batch/Cargo.toml | 57 ---
precompiles/batch/src/lib.rs | 337 ---------------
precompiles/batch/src/mock.rs | 225 ----------
precompiles/batch/src/tests.rs | 638 -----------------------------
runtime/astar/Cargo.toml | 2 -
runtime/astar/src/precompiles.rs | 12 +-
runtime/local/Cargo.toml | 2 -
runtime/local/src/precompiles.rs | 13 +-
runtime/shibuya/Cargo.toml | 2 -
runtime/shibuya/src/precompiles.rs | 5 -
runtime/shiden/Cargo.toml | 2 -
runtime/shiden/src/precompiles.rs | 12 +-
15 files changed, 9 insertions(+), 1408 deletions(-)
delete mode 100644 precompiles/batch/Batch.sol
delete mode 100644 precompiles/batch/Cargo.toml
delete mode 100644 precompiles/batch/src/lib.rs
delete mode 100644 precompiles/batch/src/mock.rs
delete mode 100644 precompiles/batch/src/tests.rs
diff --git a/Cargo.lock b/Cargo.lock
index 2f81d10f4c..45cc22a2fe 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -585,7 +585,6 @@ dependencies = [
"pallet-ethereum",
"pallet-evm",
"pallet-evm-precompile-assets-erc20",
- "pallet-evm-precompile-batch",
"pallet-evm-precompile-blake2",
"pallet-evm-precompile-bn128",
"pallet-evm-precompile-dapps-staking",
@@ -6005,7 +6004,6 @@ dependencies = [
"pallet-ethereum-checked",
"pallet-evm",
"pallet-evm-precompile-assets-erc20",
- "pallet-evm-precompile-batch",
"pallet-evm-precompile-blake2",
"pallet-evm-precompile-bn128",
"pallet-evm-precompile-dapps-staking",
@@ -7848,34 +7846,6 @@ dependencies = [
"sp-std",
]
-[[package]]
-name = "pallet-evm-precompile-batch"
-version = "0.1.0"
-dependencies = [
- "derive_more",
- "evm",
- "fp-evm",
- "frame-support",
- "frame-system",
- "hex-literal",
- "log",
- "num_enum 0.5.11",
- "pallet-balances",
- "pallet-evm",
- "pallet-timestamp",
- "parity-scale-codec",
- "paste",
- "precompile-utils",
- "scale-info",
- "serde",
- "sha3",
- "slices",
- "sp-core",
- "sp-io",
- "sp-runtime",
- "sp-std",
-]
-
[[package]]
name = "pallet-evm-precompile-blake2"
version = "2.0.0-dev"
@@ -13082,7 +13052,6 @@ dependencies = [
"pallet-evm",
"pallet-evm-chain-id",
"pallet-evm-precompile-assets-erc20",
- "pallet-evm-precompile-batch",
"pallet-evm-precompile-blake2",
"pallet-evm-precompile-bn128",
"pallet-evm-precompile-dapps-staking",
@@ -13184,7 +13153,6 @@ dependencies = [
"pallet-ethereum",
"pallet-evm",
"pallet-evm-precompile-assets-erc20",
- "pallet-evm-precompile-batch",
"pallet-evm-precompile-blake2",
"pallet-evm-precompile-bn128",
"pallet-evm-precompile-dapps-staking",
diff --git a/Cargo.toml b/Cargo.toml
index c5828cc529..2fddd69b2d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -289,7 +289,6 @@ pallet-evm-precompile-substrate-ecdsa = { path = "./precompiles/substrate-ecdsa"
pallet-evm-precompile-xcm = { path = "./precompiles/xcm", default-features = false }
pallet-evm-precompile-xvm = { path = "./precompiles/xvm", default-features = false }
pallet-evm-precompile-dapps-staking = { path = "./precompiles/dapps-staking", default-features = false }
-pallet-evm-precompile-batch = { path = "./precompiles/batch", default-features = false }
pallet-chain-extension-dapps-staking = { path = "./chain-extensions/dapps-staking", default-features = false }
pallet-chain-extension-xvm = { path = "./chain-extensions/xvm", default-features = false }
diff --git a/precompiles/batch/Batch.sol b/precompiles/batch/Batch.sol
deleted file mode 100644
index b2884de6d3..0000000000
--- a/precompiles/batch/Batch.sol
+++ /dev/null
@@ -1,77 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-only
-pragma solidity >=0.8.3;
-
-/// Interface to the precompiled contract on Shibuya/Shiden/Astar
-/// Predeployed at the address 0x0000000000000000000000000000000000005006
-/// For better understanding check the source code:
-/// repo: https://github.com/AstarNetwork/astar
-
-/// @title Batch precompile
-/// @dev Allows to perform multiple calls through one call to the precompile.
-/// Can be used by EOA to do multiple calls in a single transaction.
-interface Batch {
- /// @dev Batch multiple calls into a single transaction.
- /// All calls are performed from the address calling this precompile.
- ///
- /// In case of one subcall reverting following subcalls will still be attempted.
- ///
- /// @param to List of addresses to call.
- /// @param value List of values for each subcall. If array is shorter than `to` then additional
- /// calls will be performed with a value of 0.
- /// @param callData Call data for each `to` address. If array is shorter than `to` then
- /// additional calls will be performed with an empty call data.
- /// @param gasLimit Gas limit for each `to` address. Use 0 to forward all the remaining gas.
- /// If array is shorter than `to` then the remaining gas available will be used.
- function batchSome(
- address[] memory to,
- uint256[] memory value,
- bytes[] memory callData,
- uint64[] memory gasLimit
- ) external;
-
- /// @dev Batch multiple calls into a single transaction.
- /// All calls are performed from the address calling this precompile.
- ///
- /// In case of one subcall reverting, no more subcalls will be executed but
- /// the batch transaction will succeed. Use "batchAll" to revert on any subcall revert.
- ///
- /// @param to List of addresses to call.
- /// @param value List of values for each subcall. If array is shorter than `to` then additional
- /// calls will be performed with a value of 0.
- /// @param callData Call data for each `to` address. If array is shorter than `to` then
- /// additional calls will be performed with an empty call data.
- /// @param gasLimit Gas limit for each `to` address. Use 0 to forward all the remaining gas.
- /// If array is shorter than `to` then the remaining gas available will be used.
- function batchSomeUntilFailure(
- address[] memory to,
- uint256[] memory value,
- bytes[] memory callData,
- uint64[] memory gasLimit
- ) external;
-
- /// @dev Batch multiple calls into a single transaction.
- /// All calls are performed from the address calling this precompile.
- ///
- /// In case of one subcall reverting, the entire batch will revert.
- ///
- /// @param to List of addresses to call.
- /// @param value List of values for each subcall. If array is shorter than `to` then additional
- /// calls will be performed with a value of 0.
- /// @param callData Call data for each `to` address. If array is shorter than `to` then
- /// additional calls will be performed with an empty call data.
- /// @param gasLimit Gas limit for each `to` address. Use 0 to forward all the remaining gas.
- /// If array is shorter than `to` then the remaining gas available will be used.
- function batchAll(
- address[] memory to,
- uint256[] memory value,
- bytes[] memory callData,
- uint64[] memory gasLimit
- ) external;
-
- /// Emitted when a subcall succeeds.
- event SubcallSucceeded(uint256 index);
-
- /// Emitted when a subcall fails.
- event SubcallFailed(uint256 index);
-
-}
diff --git a/precompiles/batch/Cargo.toml b/precompiles/batch/Cargo.toml
deleted file mode 100644
index 56a366b43e..0000000000
--- a/precompiles/batch/Cargo.toml
+++ /dev/null
@@ -1,57 +0,0 @@
-[package]
-name = "pallet-evm-precompile-batch"
-description = "A Precompile to batch multiple calls."
-version = "0.1.0"
-authors = ["StakeTechnologies", "PureStake"]
-edition.workspace = true
-homepage.workspace = true
-repository.workspace = true
-
-[dependencies]
-log = { workspace = true }
-num_enum = { workspace = true }
-paste = { workspace = true }
-slices = { workspace = true }
-
-# Moonbeam
-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-std = { workspace = true }
-
-# Frontier
-evm = { workspace = true, features = ["with-codec"] }
-fp-evm = { workspace = true }
-pallet-evm = { workspace = true }
-
-[dev-dependencies]
-derive_more = { workspace = true }
-hex-literal = { workspace = true }
-serde = { workspace = true }
-sha3 = { workspace = true }
-
-pallet-balances = { workspace = true, features = ["std"] }
-pallet-timestamp = { workspace = true, features = ["std"] }
-parity-scale-codec = { workspace = true, features = ["max-encoded-len", "std"] }
-precompile-utils = { workspace = true, features = ["std", "testing"] }
-scale-info = { workspace = true, features = ["derive", "std"] }
-sp-runtime = { workspace = true, features = ["std"] }
-
-[features]
-default = ["std"]
-std = [
- "fp-evm/std",
- "frame-support/std",
- "frame-system/std",
- "pallet-evm/std",
- "parity-scale-codec/std",
- "precompile-utils/std",
- "sp-core/std",
- "sp-io/std",
- "sp-std/std",
-]
diff --git a/precompiles/batch/src/lib.rs b/precompiles/batch/src/lib.rs
deleted file mode 100644
index 029c2e09a1..0000000000
--- a/precompiles/batch/src/lib.rs
+++ /dev/null
@@ -1,337 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) 2019-2023 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 .
-
-// Copyright 2019-2022 PureStake Inc.
-// Copyright 2022 Stake Technologies
-// This file is part of pallet-evm-precompile-batch package, originally developed by Purestake Inc.
-// pallet-evm-precompile-batch package used in Astar Network in terms of GPLv3.
-//
-// pallet-evm-precompile-batch 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.
-
-// pallet-evm-precompile-batch 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 pallet-evm-precompile-batch. If not, see .
-#![cfg_attr(not(feature = "std"), no_std)]
-
-use ::evm::{ExitError, ExitReason};
-use fp_evm::{Context, Log, PrecompileFailure, PrecompileHandle, Transfer};
-use frame_support::{
- dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo},
- traits::ConstU32,
-};
-use pallet_evm::{Precompile, PrecompileOutput};
-use precompile_utils::{bytes::BoundedBytes, data::BoundedVec, *};
-use sp_core::{H160, U256};
-use sp_std::{iter::repeat, marker::PhantomData, vec, vec::Vec};
-
-#[cfg(test)]
-mod mock;
-#[cfg(test)]
-mod tests;
-
-#[derive(Copy, Clone, Debug, PartialEq)]
-pub enum Mode {
- BatchSome, // = "batchSome(address[],uint256[],bytes[],uint64[])",
- BatchSomeUntilFailure, // = "batchSomeUntilFailure(address[],uint256[],bytes[],uint64[])",
- BatchAll, // = "batchAll(address[],uint256[],bytes[],uint64[])",
-}
-
-pub const LOG_SUBCALL_SUCCEEDED: [u8; 32] = keccak256!("SubcallSucceeded(uint256)");
-pub const LOG_SUBCALL_FAILED: [u8; 32] = keccak256!("SubcallFailed(uint256)");
-pub const CALL_DATA_LIMIT: u32 = 2u32.pow(16);
-pub const ARRAY_LIMIT: u32 = 2u32.pow(9);
-
-type GetCallDataLimit = ConstU32;
-type GetArrayLimit = ConstU32;
-
-fn log_subcall_succeeded(address: impl Into, index: usize) -> Log {
- LogsBuilder::new(address.into()).log1(
- LOG_SUBCALL_SUCCEEDED,
- data::encode_event_data(U256::from(index)),
- )
-}
-
-fn log_subcall_failed(address: impl Into, index: usize) -> Log {
- LogsBuilder::new(address.into()).log1(
- LOG_SUBCALL_FAILED,
- data::encode_event_data(U256::from(index)),
- )
-}
-
-#[precompile_utils::generate_function_selector]
-#[derive(Debug, PartialEq)]
-pub enum Action {
- BatchSome = "batchSome(address[],uint256[],bytes[],uint64[])",
- BatchSomeUntilFailure = "batchSomeUntilFailure(address[],uint256[],bytes[],uint64[])",
- BatchAll = "batchAll(address[],uint256[],bytes[],uint64[])",
-}
-
-/// Batch precompile.
-#[derive(Debug, Clone)]
-pub struct BatchPrecompile(PhantomData);
-
-impl Precompile for BatchPrecompile
-where
- Runtime: pallet_evm::Config,
- Runtime::RuntimeCall: Dispatchable + GetDispatchInfo,
-{
- fn execute(handle: &mut impl PrecompileHandle) -> EvmResult {
- let selector = handle.read_selector()?;
-
- handle.check_function_modifier(FunctionModifier::NonPayable)?;
- match selector {
- Action::BatchSome => Self::batch_some(handle),
- Action::BatchAll => Self::batch_all(handle),
- Action::BatchSomeUntilFailure => Self::batch_some_until_failure(handle),
- }
- }
-}
-// No funds are transfered to the precompile address.
-// Transfers will directly be made on the behalf of the user by the precompile.
-// #[precompile_utils::precompile]
-impl BatchPrecompile
-where
- Runtime: pallet_evm::Config,
- Runtime::RuntimeCall: Dispatchable + GetDispatchInfo,
-{
- fn batch_some(handle: &mut impl PrecompileHandle) -> EvmResult {
- let mut input = handle.read_input()?;
- input.expect_arguments(4)?;
- let to = input.read::>()?;
- let value = input.read::>()?;
- let call_data =
- input.read::, GetArrayLimit>>()?;
- let gas_limit = input.read::>()?;
- log::trace!(target: "batch-precompile", "batch_some\n to address(s) {:?}, value(s) {:?} call_data(s) {:?}, gas_limit(s) {:?}", to, value,call_data, gas_limit);
- Self::inner_batch(Mode::BatchSome, handle, to, value, call_data, gas_limit)
- }
-
- fn batch_some_until_failure(handle: &mut impl PrecompileHandle) -> EvmResult {
- let mut input = handle.read_input()?;
- input.expect_arguments(4)?;
- let to = input.read::>()?;
- let value = input.read::>()?;
- let call_data =
- input.read::, GetArrayLimit>>()?;
- let gas_limit = input.read::>()?;
- log::trace!(target: "batch-precompile", "batch_some_until_failure\n to address(s) {:?}, value(s) {:?} call_data(s) {:?}, gas_limit(s) {:?}", to, value,call_data, gas_limit);
- Self::inner_batch(
- Mode::BatchSomeUntilFailure,
- handle,
- to,
- value,
- call_data,
- gas_limit,
- )
- }
-
- fn batch_all(handle: &mut impl PrecompileHandle) -> EvmResult {
- let mut input = handle.read_input()?;
- input.expect_arguments(4)?;
- let to = input.read::>()?;
- let value = input.read::>()?;
- let call_data =
- input.read::, GetArrayLimit>>()?;
- let gas_limit = input.read::>()?;
- log::trace!(target: "batch-precompile", "batch_all\n to address(s) {:?}, value(s) {:?} call_data(s) {:?}, gas_limit(s) {:?}", to, value,call_data, gas_limit);
- Self::inner_batch(Mode::BatchAll, handle, to, value, call_data, gas_limit)
- }
-
- fn inner_batch(
- mode: Mode,
- handle: &mut impl PrecompileHandle,
- to: BoundedVec,
- value: BoundedVec,
- call_data: BoundedVec, GetArrayLimit>,
- gas_limit: BoundedVec,
- ) -> EvmResult {
- let addresses = Vec::from(to).into_iter().enumerate();
- let values = Vec::from(value)
- .into_iter()
- .map(|x| Some(x))
- .chain(repeat(None));
- let calls_data = Vec::from(call_data)
- .into_iter()
- .map(|x| Some(x.into()))
- .chain(repeat(None));
- let gas_limits = Vec::from(gas_limit).into_iter().map(|x|
- // x = 0 => forward all remaining gas
- if x == 0 {
- None
- } else {
- Some(x)
- }
- ).chain(repeat(None));
-
- // Cost of batch log. (doesn't change when index changes)
- let log_cost = log_subcall_failed(handle.code_address(), 0)
- .compute_cost()
- .map_err(|_| revert("Failed to compute log cost"))?;
-
- for ((i, address), (value, (call_data, gas_limit))) in
- addresses.zip(values.zip(calls_data.zip(gas_limits)))
- {
- let address = address.0;
- let value = value.unwrap_or(U256::zero());
- let call_data = call_data.unwrap_or(vec![]);
-
- let sub_context = Context {
- caller: handle.context().caller,
- address: address.clone(),
- apparent_value: value,
- };
-
- let transfer = if value.is_zero() {
- None
- } else {
- Some(Transfer {
- source: handle.context().caller,
- target: address.clone(),
- value,
- })
- };
-
- // We reserve enough gas to emit a final log and perform the subcall itself.
- // If not enough gas we stop there according to Mode strategy.
- let remaining_gas = handle.remaining_gas();
-
- let forwarded_gas = match (remaining_gas.checked_sub(log_cost), mode) {
- (Some(remaining), _) => remaining,
- (None, Mode::BatchAll) => {
- return Err(PrecompileFailure::Error {
- exit_status: ExitError::OutOfGas,
- })
- }
- (None, _) => {
- return Ok(succeed(EvmDataWriter::new().write(true).build()));
- }
- };
-
- // Cost of the call itself that the batch precompile must pay.
- let call_cost = call_cost(value, ::config());
-
- let forwarded_gas = match forwarded_gas.checked_sub(call_cost) {
- Some(remaining) => remaining,
- None => {
- let log = log_subcall_failed(handle.code_address(), i);
- handle.record_log_costs(&[&log])?;
- log.record(handle)?;
-
- match mode {
- Mode::BatchAll => {
- return Err(PrecompileFailure::Error {
- exit_status: ExitError::OutOfGas,
- })
- }
- Mode::BatchSomeUntilFailure => {
- return Ok(succeed(EvmDataWriter::new().write(true).build()))
- }
- Mode::BatchSome => continue,
- }
- }
- };
-
- // If there is a provided gas limit we ensure there is enough gas remaining.
- let forwarded_gas = match gas_limit {
- None => forwarded_gas, // provide all gas if no gas limit,
- Some(limit) => {
- if limit > forwarded_gas {
- let log = log_subcall_failed(handle.code_address(), i);
- handle.record_log_costs(&[&log])?;
- log.record(handle)?;
-
- match mode {
- Mode::BatchAll => {
- return Err(PrecompileFailure::Error {
- exit_status: ExitError::OutOfGas,
- })
- }
- Mode::BatchSomeUntilFailure => {
- return Ok(succeed(EvmDataWriter::new().write(true).build()))
- }
- Mode::BatchSome => continue,
- }
- }
- limit
- }
- };
-
- let (reason, output) = handle.call(
- address,
- transfer,
- call_data,
- Some(forwarded_gas),
- false,
- &sub_context,
- );
-
- // Logs
- // We reserved enough gas so this should not OOG.
- match reason {
- ExitReason::Revert(_) | ExitReason::Error(_) => {
- let log = log_subcall_failed(handle.code_address(), i);
- handle.record_log_costs(&[&log])?;
- log.record(handle)?
- }
- ExitReason::Succeed(_) => {
- let log = log_subcall_succeeded(handle.code_address(), i);
- handle.record_log_costs(&[&log])?;
- log.record(handle)?
- }
- _ => (),
- }
-
- // How to proceed
- match (mode, reason) {
- // _: Fatal is always fatal
- (_, ExitReason::Fatal(exit_status)) => {
- return Err(PrecompileFailure::Fatal { exit_status })
- }
-
- // BatchAll : Reverts and errors are immediatly forwarded.
- (Mode::BatchAll, ExitReason::Revert(exit_status)) => {
- return Err(PrecompileFailure::Revert {
- exit_status,
- output,
- })
- }
- (Mode::BatchAll, ExitReason::Error(exit_status)) => {
- return Err(PrecompileFailure::Error { exit_status })
- }
-
- // BatchSomeUntilFailure : Reverts and errors prevent subsequent subcalls to
- // be executed but the precompile still succeed.
- (Mode::BatchSomeUntilFailure, ExitReason::Revert(_) | ExitReason::Error(_)) => {
- return Ok(succeed(EvmDataWriter::new().write(true).build()))
- }
-
- // Success or ignored revert/error.
- (_, _) => (),
- }
- }
-
- Ok(succeed(EvmDataWriter::new().write(true).build()))
- }
-}
diff --git a/precompiles/batch/src/mock.rs b/precompiles/batch/src/mock.rs
deleted file mode 100644
index 4ac61de881..0000000000
--- a/precompiles/batch/src/mock.rs
+++ /dev/null
@@ -1,225 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) 2019-2023 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 .
-
-// Copyright 2019-2022 PureStake Inc.
-// Copyright 2022 Stake Technologies
-// This file is part of pallet-evm-precompile-batch package, originally developed by Purestake Inc.
-// pallet-evm-precompile-batch package used in Astar Network in terms of GPLv3.
-//
-// pallet-evm-precompile-batch 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.
-
-// pallet-evm-precompile-batch 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 pallet-evm-precompile-batch. If not, see .
-
-//! Test utilities
-use super::*;
-
-use fp_evm::IsPrecompileResult;
-use frame_support::traits::{ConstU64, Everything};
-use frame_support::{construct_runtime, parameter_types, weights::Weight};
-use pallet_evm::{EnsureAddressNever, EnsureAddressRoot, PrecompileResult, PrecompileSet};
-use precompile_utils::{mock_account, testing::MockAccount};
-use sp_core::H256;
-use sp_runtime::{
- traits::{BlakeTwo256, IdentityLookup},
- Perbill,
-};
-
-pub type AccountId = MockAccount;
-pub type Balance = u128;
-pub type BlockNumber = u32;
-
-type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic;
-type Block = frame_system::mocking::MockBlock;
-
-construct_runtime!(
- pub enum Runtime where
- Block = Block,
- NodeBlock = Block,
- UncheckedExtrinsic = UncheckedExtrinsic,
- {
- System: frame_system::{Pallet, Call, Config, Storage, Event},
- Balances: pallet_balances::{Pallet, Call, Storage, Config, Event},
- Evm: pallet_evm::{Pallet, Call, Storage, Event},
- Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
- }
-);
-
-parameter_types! {
- pub const BlockHashCount: u32 = 250;
- pub const MaximumBlockWeight: Weight = Weight::from_parts(1024, 1);
- pub const MaximumBlockLength: u32 = 2 * 1024;
- pub const AvailableBlockRatio: Perbill = Perbill::one();
- pub const SS58Prefix: u8 = 42;
-}
-
-impl frame_system::Config for Runtime {
- type BaseCallFilter = Everything;
- type DbWeight = ();
- type RuntimeOrigin = RuntimeOrigin;
- type Index = u64;
- type BlockNumber = BlockNumber;
- type RuntimeCall = RuntimeCall;
- type Hash = H256;
- type Hashing = BlakeTwo256;
- type AccountId = AccountId;
- type Lookup = IdentityLookup;
- type Header = sp_runtime::generic::Header;
- type RuntimeEvent = RuntimeEvent;
- type BlockHashCount = BlockHashCount;
- type Version = ();
- type PalletInfo = PalletInfo;
- type AccountData = pallet_balances::AccountData;
- type OnNewAccount = ();
- type OnKilledAccount = ();
- type SystemWeightInfo = ();
- type BlockWeights = ();
- type BlockLength = ();
- type SS58Prefix = SS58Prefix;
- type OnSetCode = ();
- type MaxConsumers = frame_support::traits::ConstU32<16>;
-}
-parameter_types! {
- pub const ExistentialDeposit: u128 = 1;
-}
-impl pallet_balances::Config for Runtime {
- type MaxReserves = ();
- type ReserveIdentifier = [u8; 4];
- type MaxLocks = ();
- type Balance = Balance;
- type RuntimeEvent = RuntimeEvent;
- type DustRemoval = ();
- type ExistentialDeposit = ExistentialDeposit;
- type AccountStore = System;
- type WeightInfo = ();
- type HoldIdentifier = ();
- type FreezeIdentifier = ();
- type MaxHolds = ();
- type MaxFreezes = ();
-}
-
-pub fn precompile_address() -> H160 {
- H160::from_low_u64_be(0x5002)
-}
-
-#[derive(Debug, Clone, Copy)]
-pub struct BatchPrecompileMock(PhantomData);
-
-impl PrecompileSet for BatchPrecompileMock
-where
- R: pallet_evm::Config,
- BatchPrecompile: Precompile,
-{
- fn execute(&self, handle: &mut impl PrecompileHandle) -> Option {
- match handle.code_address() {
- a if a == precompile_address() => Some(BatchPrecompile::::execute(handle)),
- _ => None,
- }
- }
-
- fn is_precompile(&self, address: sp_core::H160, _gas: u64) -> IsPrecompileResult {
- IsPrecompileResult::Answer {
- is_precompile: address == precompile_address(),
- extra_cost: 0,
- }
- }
-}
-
-mock_account!(Revert, |_| MockAccount::from_u64(2));
-
-parameter_types! {
- pub BlockGasLimit: U256 = U256::max_value();
- pub PrecompilesValue: BatchPrecompileMock = BatchPrecompileMock(Default::default());
- pub const WeightPerGas: Weight = Weight::from_parts(1, 0);
-}
-
-impl pallet_evm::Config for Runtime {
- type FeeCalculator = ();
- type GasWeightMapping = pallet_evm::FixedGasWeightMapping;
- type WeightPerGas = WeightPerGas;
- type CallOrigin = EnsureAddressRoot;
- type WithdrawOrigin = EnsureAddressNever;
- type AddressMapping = AccountId;
- type Currency = Balances;
- type RuntimeEvent = RuntimeEvent;
- type Runner = pallet_evm::runner::stack::Runner;
- type PrecompilesType = BatchPrecompileMock;
- type PrecompilesValue = PrecompilesValue;
- type Timestamp = Timestamp;
- type ChainId = ();
- type OnChargeTransaction = ();
- type BlockGasLimit = BlockGasLimit;
- type BlockHashMapping = pallet_evm::SubstrateBlockHashMapping;
- type FindAuthor = ();
- type OnCreate = ();
- type WeightInfo = ();
- type GasLimitPovSizeRatio = ConstU64<4>;
-}
-
-parameter_types! {
- pub const MinimumPeriod: u64 = 5;
-}
-impl pallet_timestamp::Config for Runtime {
- type Moment = u64;
- type OnTimestampSet = ();
- type MinimumPeriod = MinimumPeriod;
- type WeightInfo = ();
-}
-
-pub(crate) struct ExtBuilder {
- // endowed accounts with balances
- balances: Vec<(AccountId, Balance)>,
-}
-
-impl Default for ExtBuilder {
- fn default() -> ExtBuilder {
- ExtBuilder { balances: vec![] }
- }
-}
-
-impl ExtBuilder {
- pub(crate) fn build(self) -> sp_io::TestExternalities {
- let mut t = frame_system::GenesisConfig::default()
- .build_storage::()
- .expect("Frame system builds valid default genesis config");
-
- pallet_balances::GenesisConfig:: {
- balances: self.balances,
- }
- .assimilate_storage(&mut t)
- .expect("Pallet balances storage can be assimilated");
-
- let mut ext = sp_io::TestExternalities::new(t);
- ext.execute_with(|| {
- System::set_block_number(1);
- pallet_evm::Pallet::::create_account(
- Revert.into(),
- hex_literal::hex!("1460006000fd").to_vec(),
- );
- });
- ext
- }
-}
diff --git a/precompiles/batch/src/tests.rs b/precompiles/batch/src/tests.rs
deleted file mode 100644
index 55241fe08a..0000000000
--- a/precompiles/batch/src/tests.rs
+++ /dev/null
@@ -1,638 +0,0 @@
-// This file is part of Astar.
-
-// Copyright (C) 2019-2023 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 .
-
-// Copyright 2019-2022 PureStake Inc.
-// Copyright 2022 Stake Technologies
-// This file is part of pallet-evm-precompile-batch package, originally developed by Purestake Inc.
-// pallet-evm-precompile-batch package used in Astar Network in terms of GPLv3.
-//
-// pallet-evm-precompile-batch 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.
-
-// pallet-evm-precompile-batch 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 pallet-evm-precompile-batch. If not, see .
-
-use crate::mock::{precompile_address, BatchPrecompileMock, ExtBuilder, PrecompilesValue, Runtime};
-use crate::{log_subcall_failed, log_subcall_succeeded, Mode, *};
-use fp_evm::ExitError;
-use precompile_utils::{call_cost, testing::*, LogsBuilder};
-use sp_core::{H256, U256};
-
-fn precompiles() -> BatchPrecompileMock {
- PrecompilesValue::get()
-}
-
-fn costs() -> (u64, u64) {
- let return_log_cost = log_subcall_failed(precompile_address(), 0)
- .compute_cost()
- .unwrap();
- let call_cost =
- return_log_cost + call_cost(U256::one(), ::config());
- (return_log_cost, call_cost)
-}
-
-#[test]
-fn batch_some_empty() {
- ExtBuilder::default().build().execute_with(|| {
- precompiles()
- .prepare_test(
- Alice,
- precompile_address(),
- EvmDataWriter::new_with_selector(Action::BatchSome)
- .write::>(vec![])
- .write::>(vec![])
- .write::>(vec![])
- .write::>(vec![])
- .build(),
- )
- .execute_returns(EvmDataWriter::new().write(true).build());
- })
-}
-
-#[test]
-fn batch_some_until_failure_empty() {
- ExtBuilder::default().build().execute_with(|| {
- precompiles()
- .prepare_test(
- Alice,
- precompile_address(),
- EvmDataWriter::new_with_selector(Action::BatchSomeUntilFailure)
- .write::>(vec![])
- .write::>(vec![])
- .write::>(vec![])
- .write::>(vec![])
- .build(),
- )
- .execute_returns(EvmDataWriter::new().write(true).build());
- })
-}
-
-#[test]
-fn batch_all_empty() {
- ExtBuilder::default().build().execute_with(|| {
- precompiles()
- .prepare_test(
- Alice,
- precompile_address(),
- EvmDataWriter::new_with_selector(Action::BatchAll)
- .write::>(vec![])
- .write::>(vec![])
- .write::>(vec![])
- .write::>(vec![])
- .build(),
- )
- .execute_returns(EvmDataWriter::new().write(true).build());
- })
-}
-
-fn check_mode(mode: Mode) -> Action {
- match mode {
- Mode::BatchAll => Action::BatchAll,
- Mode::BatchSome => Action::BatchSome,
- Mode::BatchSomeUntilFailure => Action::BatchSomeUntilFailure,
- }
-}
-
-fn batch_returns(
- precompiles: &BatchPrecompileMock,
- mode: Mode,
-) -> PrecompilesTester> {
- let mut counter = 0;
- let one = b"one";
- let two = b"two";
- let (_, total_call_cost) = costs();
-
- precompiles
- .prepare_test(
- Alice,
- precompile_address(),
- EvmDataWriter::new_with_selector(check_mode(mode))
- .write(vec![Address(Bob.into()), Address(Charlie.into())])
- .write(vec![U256::from(1u8), U256::from(2u8)])
- .write(vec![Bytes::from(&one[..]), Bytes::from(&two[..])])
- .write::>(vec![])
- .build(),
- )
- .with_target_gas(Some(100_000))
- .with_subcall_handle(move |subcall| {
- let Subcall {
- address,
- transfer,
- input,
- target_gas,
- is_static,
- context,
- } = subcall;
-
- // Called from the precompile caller.
- assert_eq!(context.caller, Alice.into());
- assert_eq!(is_static, false);
-
- match address {
- a if a == Bob.into() => {
- assert_eq!(counter, 0, "this is the first call");
- counter += 1;
-
- assert_eq!(
- target_gas,
- Some(100_000 - total_call_cost),
- "batch forward all gas"
- );
- let transfer = transfer.expect("there is a transfer");
- assert_eq!(transfer.source, Alice.into());
- assert_eq!(transfer.target, Bob.into());
- assert_eq!(transfer.value, 1u8.into());
-
- assert_eq!(context.address, Bob.into());
- assert_eq!(context.apparent_value, 1u8.into());
-
- assert_eq!(&input, b"one");
-
- SubcallOutput {
- cost: 13,
- logs: vec![
- LogsBuilder::new(Bob.into()).log1(H256::repeat_byte(0x11), vec![])
- ],
- ..SubcallOutput::succeed()
- }
- }
- a if a == Charlie.into() => {
- assert_eq!(counter, 1, "this is the second call");
- counter += 1;
-
- assert_eq!(
- target_gas,
- Some(100_000 - 13 - total_call_cost * 2),
- "batch forward all gas"
- );
- let transfer = transfer.expect("there is a transfer");
- assert_eq!(transfer.source, Alice.into());
- assert_eq!(transfer.target, Charlie.into());
- assert_eq!(transfer.value, 2u8.into());
-
- assert_eq!(context.address, Charlie.into());
- assert_eq!(context.apparent_value, 2u8.into());
-
- assert_eq!(&input, b"two");
-
- SubcallOutput {
- cost: 17,
- logs: vec![
- LogsBuilder::new(Charlie.into()).log1(H256::repeat_byte(0x22), vec![])
- ],
- ..SubcallOutput::succeed()
- }
- }
- _ => panic!("unexpected subcall"),
- }
- })
- .expect_cost(13 + 17 + total_call_cost * 2)
-}
-
-#[test]
-fn batch_some_returns() {
- ExtBuilder::default().build().execute_with(|| {
- batch_returns(&precompiles(), Mode::BatchSome)
- .expect_log(LogsBuilder::new(Bob.into()).log1(H256::repeat_byte(0x11), vec![]))
- .expect_log(log_subcall_succeeded(precompile_address(), 0))
- .expect_log(LogsBuilder::new(Charlie.into()).log1(H256::repeat_byte(0x22), vec![]))
- .expect_log(log_subcall_succeeded(precompile_address(), 1))
- .execute_returns(EvmDataWriter::new().write(true).build())
- })
-}
-
-#[test]
-fn batch_some_until_failure_returns() {
- ExtBuilder::default().build().execute_with(|| {
- batch_returns(&precompiles(), Mode::BatchSomeUntilFailure)
- .expect_log(LogsBuilder::new(Bob.into()).log1(H256::repeat_byte(0x11), vec![]))
- .expect_log(log_subcall_succeeded(precompile_address(), 0))
- .expect_log(LogsBuilder::new(Charlie.into()).log1(H256::repeat_byte(0x22), vec![]))
- .expect_log(log_subcall_succeeded(precompile_address(), 1))
- .execute_returns(EvmDataWriter::new().write(true).build())
- })
-}
-
-#[test]
-fn batch_all_returns() {
- ExtBuilder::default().build().execute_with(|| {
- batch_returns(&precompiles(), Mode::BatchAll)
- .expect_log(LogsBuilder::new(Bob.into()).log1(H256::repeat_byte(0x11), vec![]))
- .expect_log(log_subcall_succeeded(precompile_address(), 0))
- .expect_log(LogsBuilder::new(Charlie.into()).log1(H256::repeat_byte(0x22), vec![]))
- .expect_log(log_subcall_succeeded(precompile_address(), 1))
- .execute_returns(EvmDataWriter::new().write(true).build())
- })
-}
-
-fn batch_out_of_gas(
- precompiles: &BatchPrecompileMock,
- mode: Mode,
-) -> PrecompilesTester> {
- let one = b"one";
- let (_, total_call_cost) = costs();
- precompiles
- .prepare_test(
- Alice,
- precompile_address(),
- EvmDataWriter::new_with_selector(check_mode(mode))
- .write(vec![Address(Bob.into())])
- .write(vec![U256::from(1u8)])
- .write(vec![Bytes::from(&one[..])])
- .write::>(vec![])
- .build(),
- )
- .with_target_gas(Some(50_000))
- .with_subcall_handle(move |subcall| {
- let Subcall {
- address,
- transfer,
- input,
- target_gas,
- is_static,
- context,
- } = subcall;
-
- // Called from the precompile caller.
- assert_eq!(context.caller, Alice.into());
- assert_eq!(is_static, false);
-
- match address {
- a if a == Bob.into() => {
- assert_eq!(
- target_gas,
- Some(50_000 - total_call_cost),
- "batch forward all gas"
- );
- let transfer = transfer.expect("there is a transfer");
- assert_eq!(transfer.source, Alice.into());
- assert_eq!(transfer.target, Bob.into());
- assert_eq!(transfer.value, 1u8.into());
-
- assert_eq!(context.address, Bob.into());
- assert_eq!(context.apparent_value, 1u8.into());
-
- assert_eq!(&input, b"one");
-
- SubcallOutput {
- cost: 11_000,
- ..SubcallOutput::out_of_gas()
- }
- }
- _ => panic!("unexpected subcall"),
- }
- })
-}
-
-#[test]
-fn batch_some_out_of_gas() {
- ExtBuilder::default().build().execute_with(|| {
- batch_out_of_gas(&precompiles(), Mode::BatchSome)
- .expect_log(log_subcall_failed(precompile_address(), 0))
- .execute_returns(EvmDataWriter::new().write(true).build())
- })
-}
-
-#[test]
-fn batch_some_until_failure_out_of_gas() {
- ExtBuilder::default().build().execute_with(|| {
- batch_out_of_gas(&precompiles(), Mode::BatchSomeUntilFailure)
- .expect_log(log_subcall_failed(precompile_address(), 0))
- .execute_returns(EvmDataWriter::new().write(true).build())
- })
-}
-
-#[test]
-fn batch_all_out_of_gas() {
- ExtBuilder::default().build().execute_with(|| {
- batch_out_of_gas(&precompiles(), Mode::BatchAll).execute_error(ExitError::OutOfGas)
- })
-}
-
-fn batch_incomplete(
- precompiles: &BatchPrecompileMock,
- mode: Mode,
-) -> PrecompilesTester> {
- let mut counter = 0;
- let one = b"one";
-
- let (_, total_call_cost) = costs();
-
- precompiles
- .prepare_test(
- Alice,
- precompile_address(),
- EvmDataWriter::new_with_selector(check_mode(mode))
- .write(vec![
- Address(Bob.into()),
- Address(Charlie.into()),
- Address(Alice.into()),
- ])
- .write(vec![U256::from(1u8), U256::from(2u8), U256::from(3u8)])
- .write(vec![Bytes::from(&one[..])])
- .write::>(vec![])
- .build(),
- )
- .with_target_gas(Some(300_000))
- .with_subcall_handle(move |subcall| {
- let Subcall {
- address,
- transfer,
- input,
- target_gas,
- is_static,
- context,
- } = subcall;
-
- // Called from the precompile caller.
- assert_eq!(context.caller, Alice.into());
- assert_eq!(is_static, false);
-
- match address {
- a if a == Bob.into() => {
- assert_eq!(counter, 0, "this is the first call");
- counter += 1;
-
- assert_eq!(
- target_gas,
- Some(300_000 - total_call_cost),
- "batch forward all gas"
- );
- let transfer = transfer.expect("there is a transfer");
- assert_eq!(transfer.source, Alice.into());
- assert_eq!(transfer.target, Bob.into());
- assert_eq!(transfer.value, 1u8.into());
-
- assert_eq!(context.address, Bob.into());
- assert_eq!(context.apparent_value, 1u8.into());
-
- assert_eq!(&input, b"one");
-
- SubcallOutput {
- cost: 13,
- logs: vec![
- LogsBuilder::new(Bob.into()).log1(H256::repeat_byte(0x11), vec![])
- ],
- ..SubcallOutput::succeed()
- }
- }
- a if a == Charlie.into() => {
- assert_eq!(counter, 1, "this is the second call");
- counter += 1;
-
- assert_eq!(
- target_gas,
- Some(300_000 - 13 - total_call_cost * 2),
- "batch forward all gas"
- );
- let transfer = transfer.expect("there is a transfer");
- assert_eq!(transfer.source, Alice.into());
- assert_eq!(transfer.target, Charlie.into());
- assert_eq!(transfer.value, 2u8.into());
-
- assert_eq!(context.address, Charlie.into());
- assert_eq!(context.apparent_value, 2u8.into());
-
- assert_eq!(&input, b"");
-
- SubcallOutput {
- output: String::from("Revert message").as_bytes().to_vec(),
- cost: 17,
- ..SubcallOutput::revert()
- }
- }
- a if a == Alice.into() => {
- assert_eq!(counter, 2, "this is the third call");
- counter += 1;
-
- assert_eq!(
- target_gas,
- Some(300_000 - 13 - 17 - total_call_cost * 3),
- "batch forward all gas"
- );
- let transfer = transfer.expect("there is a transfer");
- assert_eq!(transfer.source, Alice.into());
- assert_eq!(transfer.target, Alice.into());
- assert_eq!(transfer.value, 3u8.into());
-
- assert_eq!(context.address, Alice.into());
- assert_eq!(context.apparent_value, 3u8.into());
-
- assert_eq!(&input, b"");
-
- SubcallOutput {
- cost: 19,
- logs: vec![
- LogsBuilder::new(Alice.into()).log1(H256::repeat_byte(0x33), vec![])
- ],
- ..SubcallOutput::succeed()
- }
- }
- _ => panic!("unexpected subcall"),
- }
- })
-}
-
-#[test]
-fn batch_some_incomplete() {
- ExtBuilder::default().build().execute_with(|| {
- let (_, total_call_cost) = costs();
-
- batch_incomplete(&precompiles(), Mode::BatchSome)
- .expect_log(LogsBuilder::new(Bob.into()).log1(H256::repeat_byte(0x11), vec![]))
- .expect_log(log_subcall_succeeded(precompile_address(), 0))
- .expect_log(log_subcall_failed(precompile_address(), 1))
- .expect_log(LogsBuilder::new(Alice.into()).log1(H256::repeat_byte(0x33), vec![]))
- .expect_log(log_subcall_succeeded(precompile_address(), 2))
- .expect_cost(13 + 17 + 19 + total_call_cost * 3)
- .execute_returns(EvmDataWriter::new().write(true).build())
- })
-}
-
-#[test]
-fn batch_some_until_failure_incomplete() {
- ExtBuilder::default().build().execute_with(|| {
- let (_, total_call_cost) = costs();
-
- batch_incomplete(&precompiles(), Mode::BatchSomeUntilFailure)
- .expect_log(LogsBuilder::new(Bob.into()).log1(H256::repeat_byte(0x11), vec![]))
- .expect_log(log_subcall_succeeded(precompile_address(), 0))
- .expect_log(log_subcall_failed(precompile_address(), 1))
- .expect_cost(13 + 17 + total_call_cost * 2)
- .execute_returns(EvmDataWriter::new().write(true).build())
- })
-}
-
-#[test]
-fn batch_all_incomplete() {
- ExtBuilder::default().build().execute_with(|| {
- batch_incomplete(&precompiles(), Mode::BatchAll)
- .execute_reverts(|output| output == b"Revert message")
- })
-}
-
-fn batch_log_out_of_gas(
- precompiles: &BatchPrecompileMock,
- mode: Mode,
-) -> PrecompilesTester> {
- let (log_cost, _) = costs();
- let one = b"one";
-
- precompiles
- .prepare_test(
- Alice,
- precompile_address(),
- EvmDataWriter::new_with_selector(check_mode(mode))
- .write(vec![Address(Bob.into())])
- .write(vec![U256::from(1u8)])
- .write(vec![Bytes::from(&one[..])])
- .write::>(vec![])
- .build(),
- )
- .with_target_gas(Some(log_cost - 1))
- .with_subcall_handle(move |_subcall| panic!("there shouldn't be any subcalls"))
-}
-
-#[test]
-fn batch_all_log_out_of_gas() {
- ExtBuilder::default().build().execute_with(|| {
- batch_log_out_of_gas(&precompiles(), Mode::BatchAll).execute_error(ExitError::OutOfGas);
- })
-}
-
-#[test]
-fn batch_some_log_out_of_gas() {
- ExtBuilder::default().build().execute_with(|| {
- batch_log_out_of_gas(&precompiles(), Mode::BatchSome)
- .expect_no_logs()
- .execute_returns(EvmDataWriter::new().write(true).build());
- })
-}
-
-#[test]
-fn batch_some_until_failure_log_out_of_gas() {
- ExtBuilder::default().build().execute_with(|| {
- batch_log_out_of_gas(&precompiles(), Mode::BatchSomeUntilFailure)
- .expect_no_logs()
- .execute_returns(EvmDataWriter::new().write(true).build());
- })
-}
-
-fn batch_call_out_of_gas(
- precompiles: &BatchPrecompileMock,
- mode: Mode,
-) -> PrecompilesTester> {
- let (_, total_call_cost) = costs();
- let one = b"one";
-
- precompiles
- .prepare_test(
- Alice,
- precompile_address(),
- EvmDataWriter::new_with_selector(check_mode(mode))
- .write(vec![Address(Bob.into())])
- .write(vec![U256::from(1u8)])
- .write(vec![Bytes::from(&one[..])])
- .write::>(vec![])
- .build(),
- )
- .with_target_gas(Some(total_call_cost - 1))
- .with_subcall_handle(move |_subcall| panic!("there shouldn't be any subcalls"))
-}
-
-#[test]
-fn batch_all_call_out_of_gas() {
- ExtBuilder::default().build().execute_with(|| {
- batch_call_out_of_gas(&precompiles(), Mode::BatchAll).execute_error(ExitError::OutOfGas);
- })
-}
-
-#[test]
-fn batch_some_call_out_of_gas() {
- ExtBuilder::default().build().execute_with(|| {
- batch_call_out_of_gas(&precompiles(), Mode::BatchSome)
- .expect_log(log_subcall_failed(precompile_address(), 0))
- .execute_returns(EvmDataWriter::new().write(true).build());
- })
-}
-
-#[test]
-fn batch_some_until_failure_call_out_of_gas() {
- ExtBuilder::default().build().execute_with(|| {
- batch_call_out_of_gas(&precompiles(), Mode::BatchSomeUntilFailure)
- .expect_log(log_subcall_failed(precompile_address(), 0))
- .execute_returns(EvmDataWriter::new().write(true).build());
- })
-}
-
-fn batch_gas_limit(
- precompiles: &BatchPrecompileMock,
- mode: Mode,
-) -> PrecompilesTester> {
- let (_, total_call_cost) = costs();
- let one = b"one";
-
- precompiles
- .prepare_test(
- Alice,
- precompile_address(),
- EvmDataWriter::new_with_selector(check_mode(mode))
- .write(vec![Address(Bob.into())])
- .write(vec![U256::from(1u8)])
- .write(vec![Bytes::from(&one[..])])
- .write::>(vec![U256::from(50_000 - total_call_cost + 1)])
- .build(),
- )
- .with_target_gas(Some(50_000))
- .with_subcall_handle(move |_subcall| panic!("there shouldn't be any subcalls"))
-}
-
-#[test]
-fn batch_all_gas_limit() {
- ExtBuilder::default().build().execute_with(|| {
- batch_gas_limit(&precompiles(), Mode::BatchAll).execute_error(ExitError::OutOfGas);
- })
-}
-
-#[test]
-fn batch_some_gas_limit() {
- ExtBuilder::default().build().execute_with(|| {
- let (return_log_cost, _) = costs();
-
- batch_gas_limit(&precompiles(), Mode::BatchSome)
- .expect_log(log_subcall_failed(precompile_address(), 0))
- .expect_cost(return_log_cost)
- .execute_returns(EvmDataWriter::new().write(true).build());
- })
-}
-
-#[test]
-fn batch_some_until_failure_gas_limit() {
- ExtBuilder::default().build().execute_with(|| {
- batch_gas_limit(&precompiles(), Mode::BatchSomeUntilFailure)
- .expect_log(log_subcall_failed(precompile_address(), 0))
- .execute_returns(EvmDataWriter::new().write(true).build());
- })
-}
diff --git a/runtime/astar/Cargo.toml b/runtime/astar/Cargo.toml
index a888abeabd..3818890d5b 100644
--- a/runtime/astar/Cargo.toml
+++ b/runtime/astar/Cargo.toml
@@ -46,7 +46,6 @@ pallet-contracts = { workspace = true }
pallet-contracts-primitives = { workspace = true }
pallet-ethereum = { workspace = true }
pallet-evm = { workspace = true }
-pallet-evm-precompile-batch = { workspace = true }
pallet-evm-precompile-blake2 = { workspace = true }
pallet-evm-precompile-bn128 = { workspace = true }
pallet-evm-precompile-dispatch = { workspace = true }
@@ -151,7 +150,6 @@ std = [
"pallet-block-reward/std",
"pallet-dapps-staking/std",
"pallet-evm-precompile-dapps-staking/std",
- "pallet-evm-precompile-batch/std",
"pallet-evm-precompile-sr25519/std",
"pallet-evm-precompile-assets-erc20/std",
"pallet-evm-precompile-substrate-ecdsa/std",
diff --git a/runtime/astar/src/precompiles.rs b/runtime/astar/src/precompiles.rs
index 600719736b..3a0d442f09 100644
--- a/runtime/astar/src/precompiles.rs
+++ b/runtime/astar/src/precompiles.rs
@@ -26,7 +26,6 @@ use pallet_evm::{
PrecompileResult, PrecompileSet,
};
use pallet_evm_precompile_assets_erc20::{AddressToAssetId, Erc20AssetsPrecompileSet};
-use pallet_evm_precompile_batch::BatchPrecompile;
use pallet_evm_precompile_blake2::Blake2F;
use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing};
use pallet_evm_precompile_dapps_staking::DappsStakingWrapper;
@@ -77,11 +76,9 @@ impl AstarNetworkPrecompiles {
/// Return all addresses that contain precompiles. This can be used to populate dummy code
/// under the precompile.
pub fn used_addresses() -> impl Iterator- {
- sp_std::vec![
- 1, 2, 3, 4, 5, 6, 7, 8, 1024, 1025, 1026, 1027, 20481, 20482, 20483, 20484, 20486
- ]
- .into_iter()
- .map(hash)
+ sp_std::vec![1, 2, 3, 4, 5, 6, 7, 8, 1024, 1025, 1026, 1027, 20481, 20482, 20483, 20484,]
+ .into_iter()
+ .map(hash)
}
/// Returns all addresses which are blacklisted for dummy code deployment.
@@ -99,7 +96,6 @@ impl PrecompileSet for AstarNetworkPrecompiles
where
Erc20AssetsPrecompileSet: PrecompileSet,
DappsStakingWrapper: Precompile,
- BatchPrecompile: Precompile,
XcmPrecompile: Precompile,
Dispatch>: Precompile,
R: pallet_evm::Config
@@ -148,8 +144,6 @@ where
a if a == hash(20483) => Some(SubstrateEcdsaPrecompile::::execute(handle)),
// Xcm 0x5004
a if a == hash(20484) => Some(XcmPrecompile::::execute(handle)),
- // Batch 0x5006
- a if a == hash(20486) => Some(BatchPrecompile::::execute(handle)),
// If the address matches asset prefix, the we route through the asset precompile set
a if &a.to_fixed_bytes()[0..4] == ASSET_PRECOMPILE_ADDRESS_PREFIX => {
Erc20AssetsPrecompileSet::::new().execute(handle)
diff --git a/runtime/local/Cargo.toml b/runtime/local/Cargo.toml
index 2dc340bcc6..7727e61bad 100644
--- a/runtime/local/Cargo.toml
+++ b/runtime/local/Cargo.toml
@@ -28,7 +28,6 @@ pallet-democracy = { workspace = true }
pallet-ethereum = { workspace = true }
pallet-ethereum-checked = { workspace = true }
pallet-evm = { workspace = true }
-pallet-evm-precompile-batch = { workspace = true }
pallet-evm-precompile-blake2 = { workspace = true }
pallet-evm-precompile-bn128 = { workspace = true }
pallet-evm-precompile-dispatch = { workspace = true }
@@ -128,7 +127,6 @@ std = [
"pallet-evm-precompile-modexp/std",
"pallet-evm-precompile-sha3fips/std",
"pallet-evm-precompile-dapps-staking/std",
- "pallet-evm-precompile-batch/std",
"pallet-evm-precompile-sr25519/std",
"pallet-evm-precompile-substrate-ecdsa/std",
"pallet-evm-precompile-xvm/std",
diff --git a/runtime/local/src/precompiles.rs b/runtime/local/src/precompiles.rs
index b2ccb203b3..3efe471c33 100644
--- a/runtime/local/src/precompiles.rs
+++ b/runtime/local/src/precompiles.rs
@@ -26,7 +26,6 @@ use pallet_evm::{
PrecompileResult, PrecompileSet,
};
use pallet_evm_precompile_assets_erc20::{AddressToAssetId, Erc20AssetsPrecompileSet};
-use pallet_evm_precompile_batch::BatchPrecompile;
use pallet_evm_precompile_blake2::Blake2F;
use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing};
use pallet_evm_precompile_dapps_staking::DappsStakingWrapper;
@@ -75,11 +74,9 @@ impl LocalNetworkPrecompiles {
/// Return all addresses that contain precompiles. This can be used to populate dummy code
/// under the precompile.
pub fn used_addresses() -> impl Iterator
- {
- sp_std::vec![
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 1024, 1025, 1026, 1027, 20481, 20482, 20483, 20485, 20846
- ]
- .into_iter()
- .map(hash)
+ sp_std::vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 1024, 1025, 1026, 1027, 20481, 20482, 20483, 20485,]
+ .into_iter()
+ .map(hash)
}
}
@@ -90,7 +87,6 @@ impl PrecompileSet for LocalNetworkPrecompiles
where
Erc20AssetsPrecompileSet: PrecompileSet,
DappsStakingWrapper: Precompile,
- BatchPrecompile: Precompile,
XvmPrecompile>: Precompile,
Dispatch>: Precompile,
R: pallet_evm::Config
@@ -140,9 +136,6 @@ where
a if a == hash(20485) => {
Some(XvmPrecompile::>::execute(handle))
}
- // Batch 0x5006
- a if a == hash(20486) => Some(BatchPrecompile::::execute(handle)),
-
// If the address matches asset prefix, the we route through the asset precompile set
a if &a.to_fixed_bytes()[0..4] == ASSET_PRECOMPILE_ADDRESS_PREFIX => {
Erc20AssetsPrecompileSet::::new().execute(handle)
diff --git a/runtime/shibuya/Cargo.toml b/runtime/shibuya/Cargo.toml
index 86fbdc5a57..046458d50e 100644
--- a/runtime/shibuya/Cargo.toml
+++ b/runtime/shibuya/Cargo.toml
@@ -103,7 +103,6 @@ pallet-dapps-staking = { workspace = true }
pallet-dynamic-evm-base-fee = { workspace = true }
pallet-ethereum-checked = { workspace = true }
pallet-evm-precompile-assets-erc20 = { workspace = true }
-pallet-evm-precompile-batch = { workspace = true }
pallet-evm-precompile-dapps-staking = { workspace = true }
pallet-evm-precompile-sr25519 = { workspace = true }
pallet-evm-precompile-substrate-ecdsa = { workspace = true }
@@ -179,7 +178,6 @@ std = [
"pallet-evm-precompile-modexp/std",
"pallet-evm-precompile-sha3fips/std",
"pallet-evm-precompile-dapps-staking/std",
- "pallet-evm-precompile-batch/std",
"pallet-evm-precompile-sr25519/std",
"pallet-evm-precompile-substrate-ecdsa/std",
"pallet-evm-precompile-assets-erc20/std",
diff --git a/runtime/shibuya/src/precompiles.rs b/runtime/shibuya/src/precompiles.rs
index d87b7e31fa..11c32ff776 100644
--- a/runtime/shibuya/src/precompiles.rs
+++ b/runtime/shibuya/src/precompiles.rs
@@ -26,7 +26,6 @@ use pallet_evm::{
PrecompileResult, PrecompileSet,
};
use pallet_evm_precompile_assets_erc20::{AddressToAssetId, Erc20AssetsPrecompileSet};
-use pallet_evm_precompile_batch::BatchPrecompile;
use pallet_evm_precompile_blake2::Blake2F;
use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing};
use pallet_evm_precompile_dapps_staking::DappsStakingWrapper;
@@ -80,7 +79,6 @@ impl ShibuyaNetworkPrecompiles {
pub fn used_addresses() -> impl Iterator
- {
sp_std::vec![
1, 2, 3, 4, 5, 6, 7, 8, 9, 1024, 1025, 1026, 1027, 20481, 20482, 20483, 20484, 20485,
- 20486
]
.into_iter()
.map(hash)
@@ -95,7 +93,6 @@ where
Erc20AssetsPrecompileSet: PrecompileSet,
DappsStakingWrapper: Precompile,
XcmPrecompile: Precompile,
- BatchPrecompile: Precompile,
XvmPrecompile>: Precompile,
Dispatch>: Precompile,
R: pallet_evm::Config
@@ -149,8 +146,6 @@ where
a if a == hash(20485) => {
Some(XvmPrecompile::>::execute(handle))
}
- // Batch 0x5006
- a if a == hash(20486) => Some(BatchPrecompile::::execute(handle)),
// If the address matches asset prefix, the we route through the asset precompile set
a if &a.to_fixed_bytes()[0..4] == ASSET_PRECOMPILE_ADDRESS_PREFIX => {
Erc20AssetsPrecompileSet::::new().execute(handle)
diff --git a/runtime/shiden/Cargo.toml b/runtime/shiden/Cargo.toml
index 4a454e12ff..dc7aad78d4 100644
--- a/runtime/shiden/Cargo.toml
+++ b/runtime/shiden/Cargo.toml
@@ -47,7 +47,6 @@ pallet-contracts = { workspace = true }
pallet-contracts-primitives = { workspace = true }
pallet-ethereum = { workspace = true }
pallet-evm = { workspace = true }
-pallet-evm-precompile-batch = { workspace = true }
pallet-evm-precompile-blake2 = { workspace = true }
pallet-evm-precompile-bn128 = { workspace = true }
pallet-evm-precompile-dispatch = { workspace = true }
@@ -162,7 +161,6 @@ std = [
"pallet-evm-precompile-modexp/std",
"pallet-evm-precompile-sha3fips/std",
"pallet-dapps-staking/std",
- "pallet-evm-precompile-batch/std",
"pallet-evm-precompile-dapps-staking/std",
"pallet-evm-precompile-sr25519/std",
"pallet-evm-precompile-assets-erc20/std",
diff --git a/runtime/shiden/src/precompiles.rs b/runtime/shiden/src/precompiles.rs
index ae426d9e22..89a29be023 100644
--- a/runtime/shiden/src/precompiles.rs
+++ b/runtime/shiden/src/precompiles.rs
@@ -26,7 +26,6 @@ use pallet_evm::{
PrecompileResult, PrecompileSet,
};
use pallet_evm_precompile_assets_erc20::{AddressToAssetId, Erc20AssetsPrecompileSet};
-use pallet_evm_precompile_batch::BatchPrecompile;
use pallet_evm_precompile_blake2::Blake2F;
use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing};
use pallet_evm_precompile_dapps_staking::DappsStakingWrapper;
@@ -77,11 +76,9 @@ impl ShidenNetworkPrecompiles {
/// Return all addresses that contain precompiles. This can be used to populate dummy code
/// under the precompile.
pub fn used_addresses() -> impl Iterator
- {
- sp_std::vec![
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 1024, 1025, 1026, 1027, 20481, 20482, 20483, 20484, 20486
- ]
- .into_iter()
- .map(hash)
+ sp_std::vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 1024, 1025, 1026, 1027, 20481, 20482, 20483, 20484,]
+ .into_iter()
+ .map(hash)
}
/// Returns all addresses which are blacklisted for dummy code deployment.
@@ -99,7 +96,6 @@ impl PrecompileSet for ShidenNetworkPrecompiles
where
Erc20AssetsPrecompileSet: PrecompileSet,
DappsStakingWrapper: Precompile,
- BatchPrecompile: Precompile,
XcmPrecompile: Precompile,
Dispatch>: Precompile,
R: pallet_evm::Config
@@ -148,8 +144,6 @@ where
a if a == hash(20483) => Some(SubstrateEcdsaPrecompile::::execute(handle)),
// Xcm 0x5004
a if a == hash(20484) => Some(XcmPrecompile::::execute(handle)),
- // Batch 0x5006
- a if a == hash(20486) => Some(BatchPrecompile::::execute(handle)),
// If the address matches asset prefix, the we route through the asset precompile set
a if &a.to_fixed_bytes()[0..4] == ASSET_PRECOMPILE_ADDRESS_PREFIX => {
Erc20AssetsPrecompileSet::::new().execute(handle)