Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: add batch precompile #989

Merged
merged 23 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ num-traits = { version = "0.2", default-features = false }
rand = { version = "0.8.5", default-features = false }
bounded-collections = { version = "0.1.5", default-features = false }
hex = { version = "0.4.3", default-features = false }
paste = "1.0.6"

# (native)
array-bytes = "6.0.0"
Expand Down Expand Up @@ -285,6 +286,7 @@ 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 }
Expand Down
72 changes: 72 additions & 0 deletions precompiles/batch/Batch.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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
/// code: frame/dapps-staking/src/pallet

/// @title Batch precompile
/// @dev Allows to perform multiple calls throught one call to the precompile.
gitofdeepanshu marked this conversation as resolved.
Show resolved Hide resolved
/// 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.
gitofdeepanshu marked this conversation as resolved.
Show resolved Hide resolved
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.
gitofdeepanshu marked this conversation as resolved.
Show resolved Hide resolved
///
/// @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;

}
gitofdeepanshu marked this conversation as resolved.
Show resolved Hide resolved
57 changes: 57 additions & 0 deletions precompiles/batch/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[package]
name = "pallet-evm-precompile-batch"
description = "A Precompile to batch multiple calls."
version = "0.1.0"
authors.workspace = true
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, features = ["forbid-evm-reentrancy"] }
gitofdeepanshu marked this conversation as resolved.
Show resolved Hide resolved

[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",
]
Loading