Skip to main content

sp_evm_precompiles/
lib.rs

1//! EVM precompile primitives
2#![cfg_attr(not(feature = "std"), no_std)]
3#![forbid(unsafe_code)]
4#![warn(rust_2018_idioms)]
5
6use pallet_evm_precompile_modexp::Modexp;
7use pallet_evm_precompile_sha3fips::Sha3FIPS256;
8use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256};
9use precompile_utils::precompile_set::*;
10use transporter_precompile::TransporterPrecompile;
11
12type EthereumPrecompilesChecks = (AcceptDelegateCall, CallableByContract, CallableByPrecompile);
13
14#[precompile_utils::precompile_name_from_address]
15type PrecompilesAt<R> = (
16    // Ethereum precompiles:
17    // We allow DELEGATECALL to stay compliant with Ethereum behavior.
18    PrecompileAt<AddressU64<1>, ECRecover, EthereumPrecompilesChecks>,
19    PrecompileAt<AddressU64<2>, Sha256, EthereumPrecompilesChecks>,
20    PrecompileAt<AddressU64<3>, Ripemd160, EthereumPrecompilesChecks>,
21    PrecompileAt<AddressU64<4>, Identity, EthereumPrecompilesChecks>,
22    PrecompileAt<AddressU64<5>, Modexp, EthereumPrecompilesChecks>,
23    // Non-Frontier specific nor Ethereum precompiles :
24    // Sha3FIPS256 gained <Runtime, WeightInfo> generics in stable2512; () = default weights
25    PrecompileAt<AddressU64<1024>, Sha3FIPS256<R, ()>, (CallableByContract, CallableByPrecompile)>,
26    PrecompileAt<AddressU64<1025>, ECRecoverPublicKey, (CallableByContract, CallableByPrecompile)>,
27    // Subspace specific precompiles
28    PrecompileAt<
29        AddressU64<2048>,
30        TransporterPrecompile<R>,
31        (CallableByContract, CallableByPrecompile),
32    >,
33);
34
35/// The PrecompileSet installed in the EVM Domain runtime.
36/// The following distribution has been decided for the precompiles
37/// 0-1023: Ethereum Mainnet Precompiles
38/// 1024-2047 Precompiles that are not in Ethereum Mainnet, and are not Subspace specific
39/// 2048-4095 Subspace specific precompiles
40pub type Precompiles<R> = PrecompileSetBuilder<
41    R,
42    (
43        // Skip precompiles if out of range.
44        PrecompilesInRangeInclusive<(AddressU64<1>, AddressU64<4095>), PrecompilesAt<R>>,
45    ),
46>;