Skip to content

Commit

Permalink
Integrate BLS12-381 curve operations as frontier precompiles to `huma…
Browse files Browse the repository at this point in the history
…node-runtime` (#1012)

Integrate BLS12-381 curve operations as precompiles to humanode-runtime
  • Loading branch information
dmitrylavrenov authored Apr 22, 2024
1 parent dc57dba commit 772da8b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 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 crates/humanode-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pallet-pot = { path = "../pallet-pot", default-features = false }
pallet-token-claims = { path = "../pallet-token-claims", default-features = false }
pallet-vesting = { path = "../pallet-vesting", default-features = false }
precompile-bioauth = { path = "../precompile-bioauth", default-features = false }
precompile-bls12381 = { path = "../precompile-bls12381", default-features = false }
precompile-currency-swap = { path = "../precompile-currency-swap", default-features = false }
precompile-evm-accounts-mapping = { path = "../precompile-evm-accounts-mapping", default-features = false }
precompile-native-currency = { path = "../precompile-native-currency", default-features = false }
Expand Down Expand Up @@ -193,6 +194,7 @@ std = [
"pallet-utility/std",
"pallet-vesting/std",
"precompile-bioauth/std",
"precompile-bls12381/std",
"precompile-currency-swap/std",
"precompile-evm-accounts-mapping/std",
"precompile-native-currency/std",
Expand Down
42 changes: 42 additions & 0 deletions crates/humanode-runtime/src/frontier_precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use pallet_evm_precompile_modexp::Modexp;
use pallet_evm_precompile_sha3fips::Sha3FIPS256;
use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256};
use precompile_bioauth::Bioauth;
use precompile_bls12381::{
Bls12381G1Add, Bls12381G1Mul, Bls12381G1MultiExp, Bls12381G2Add, Bls12381G2Mul,
Bls12381G2MultiExp, Bls12381MapG1, Bls12381MapG2, Bls12381Pairing,
};
use precompile_currency_swap::CurrencySwap;
use precompile_evm_accounts_mapping::EvmAccountsMapping;
use precompile_native_currency::NativeCurrency;
Expand All @@ -28,6 +32,25 @@ pub mod precompiles_constants {
/// `Modexp` precompile constant.
pub const MODEXP: u64 = 5;

/// `Bls12381G1Add` precompile constant.
pub const BLS12381_G1_ADD: u64 = 11;
/// `Bls12381G1Mul` precompile constant.
pub const BLS12381_G1_MUL: u64 = 12;
/// `Bls12381G1MultiExp` precompile constant.
pub const BLS12381_G1_MULTI_EXP: u64 = 13;
/// `Bls12381G2Add` precompile constant.
pub const BLS12381_G2_ADD: u64 = 14;
/// `Bls12381G2Mul` precompile constant.
pub const BLS12381_G2_MUL: u64 = 15;
/// `Bls12381G2MultiExp` precompile constant.
pub const BLS12381_G2_MULTI_EXP: u64 = 16;
/// `Bls12381Pairing` precompile constant.
pub const BLS12381_PAIRING: u64 = 17;
/// `Bls12381MapG1` precompile constant.
pub const BLS12381_MAP_G1: u64 = 18;
/// `Bls12381MapG2` precompile constant.
pub const BLS12381_MAP_G2: u64 = 19;

/// `Sha3FIPS256` precompile constant.
pub const SHA_3_FIPS256: u64 = 1024;
/// `ECRecoverPublicKey` precompile constant.
Expand Down Expand Up @@ -64,6 +87,15 @@ where
RIPEMD_160,
IDENTITY,
MODEXP,
BLS12381_G1_ADD,
BLS12381_G1_MUL,
BLS12381_G1_MULTI_EXP,
BLS12381_G2_ADD,
BLS12381_G2_MUL,
BLS12381_G2_MULTI_EXP,
BLS12381_PAIRING,
BLS12381_MAP_G1,
BLS12381_MAP_G2,
SHA_3_FIPS256,
EC_RECOVER_PUBLIC_KEY,
BIOAUTH,
Expand Down Expand Up @@ -99,6 +131,16 @@ where
a if a == hash(RIPEMD_160) => Some(Ripemd160::execute(handle)),
a if a == hash(IDENTITY) => Some(Identity::execute(handle)),
a if a == hash(MODEXP) => Some(Modexp::execute(handle)),
// BLS12-381 precompiles:
a if a == hash(BLS12381_G1_ADD) => Some(Bls12381G1Add::execute(handle)),
a if a == hash(BLS12381_G1_MUL) => Some(Bls12381G1Mul::execute(handle)),
a if a == hash(BLS12381_G1_MULTI_EXP) => Some(Bls12381G1MultiExp::execute(handle)),
a if a == hash(BLS12381_G2_ADD) => Some(Bls12381G2Add::execute(handle)),
a if a == hash(BLS12381_G2_MUL) => Some(Bls12381G2Mul::execute(handle)),
a if a == hash(BLS12381_G2_MULTI_EXP) => Some(Bls12381G2MultiExp::execute(handle)),
a if a == hash(BLS12381_PAIRING) => Some(Bls12381Pairing::execute(handle)),
a if a == hash(BLS12381_MAP_G1) => Some(Bls12381MapG1::execute(handle)),
a if a == hash(BLS12381_MAP_G2) => Some(Bls12381MapG2::execute(handle)),
// Non-Frontier specific nor Ethereum precompiles :
a if a == hash(SHA_3_FIPS256) => Some(Sha3FIPS256::execute(handle)),
a if a == hash(EC_RECOVER_PUBLIC_KEY) => Some(ECRecoverPublicKey::execute(handle)),
Expand Down

0 comments on commit 772da8b

Please sign in to comment.