Trait Crypto

Source
pub trait Crypto:
    Send
    + Sync
    + Debug {
Show 17 methods // Provided methods fn sha256(&self, input: &[u8]) -> [u8; 32] { ... } fn ripemd160(&self, input: &[u8]) -> [u8; 32] { ... } fn bn254_g1_add( &self, p1: &[u8], p2: &[u8], ) -> Result<[u8; 64], PrecompileError> { ... } fn bn254_g1_mul( &self, point: &[u8], scalar: &[u8], ) -> Result<[u8; 64], PrecompileError> { ... } fn bn254_pairing_check( &self, pairs: &[(&[u8], &[u8])], ) -> Result<bool, PrecompileError> { ... } fn secp256k1_ecrecover( &self, sig: &[u8; 64], recid: u8, msg: &[u8; 32], ) -> Result<[u8; 32], PrecompileError> { ... } fn modexp( &self, base: &[u8], exp: &[u8], modulus: &[u8], ) -> Result<Vec<u8>, PrecompileError> { ... } fn blake2_compress( &self, rounds: u32, h: &mut [u64; 8], m: [u64; 16], t: [u64; 2], f: bool, ) { ... } fn secp256r1_verify_signature( &self, msg: &[u8; 32], sig: &[u8; 64], pk: &[u8; 64], ) -> bool { ... } fn verify_kzg_proof( &self, z: &[u8; 32], y: &[u8; 32], commitment: &[u8; 48], proof: &[u8; 48], ) -> Result<(), PrecompileError> { ... } fn bls12_381_g1_add( &self, a: G1Point, b: G1Point, ) -> Result<[u8; 96], PrecompileError> { ... } fn bls12_381_g1_msm( &self, pairs: &mut dyn Iterator<Item = Result<G1PointScalar, PrecompileError>>, ) -> Result<[u8; 96], PrecompileError> { ... } fn bls12_381_g2_add( &self, a: G2Point, b: G2Point, ) -> Result<[u8; 192], PrecompileError> { ... } fn bls12_381_g2_msm( &self, pairs: &mut dyn Iterator<Item = Result<G2PointScalar, PrecompileError>>, ) -> Result<[u8; 192], PrecompileError> { ... } fn bls12_381_pairing_check( &self, pairs: &[(G1Point, G2Point)], ) -> Result<bool, PrecompileError> { ... } fn bls12_381_fp_to_g1( &self, fp: &[u8; 48], ) -> Result<[u8; 96], PrecompileError> { ... } fn bls12_381_fp2_to_g2( &self, fp2: ([u8; 48], [u8; 48]), ) -> Result<[u8; 192], PrecompileError> { ... }
}
Expand description

Crypto operations trait for precompiles.

Provided Methods§

Source

fn sha256(&self, input: &[u8]) -> [u8; 32]

Compute SHA-256 hash

Source

fn ripemd160(&self, input: &[u8]) -> [u8; 32]

Compute RIPEMD-160 hash

Source

fn bn254_g1_add( &self, p1: &[u8], p2: &[u8], ) -> Result<[u8; 64], PrecompileError>

BN254 elliptic curve addition.

Source

fn bn254_g1_mul( &self, point: &[u8], scalar: &[u8], ) -> Result<[u8; 64], PrecompileError>

BN254 elliptic curve scalar multiplication.

Source

fn bn254_pairing_check( &self, pairs: &[(&[u8], &[u8])], ) -> Result<bool, PrecompileError>

BN254 pairing check.

Source

fn secp256k1_ecrecover( &self, sig: &[u8; 64], recid: u8, msg: &[u8; 32], ) -> Result<[u8; 32], PrecompileError>

secp256k1 ECDSA signature recovery.

Source

fn modexp( &self, base: &[u8], exp: &[u8], modulus: &[u8], ) -> Result<Vec<u8>, PrecompileError>

Modular exponentiation.

Source

fn blake2_compress( &self, rounds: u32, h: &mut [u64; 8], m: [u64; 16], t: [u64; 2], f: bool, )

Blake2 compression function.

Source

fn secp256r1_verify_signature( &self, msg: &[u8; 32], sig: &[u8; 64], pk: &[u8; 64], ) -> bool

secp256r1 (P-256) signature verification.

Source

fn verify_kzg_proof( &self, z: &[u8; 32], y: &[u8; 32], commitment: &[u8; 48], proof: &[u8; 48], ) -> Result<(), PrecompileError>

KZG point evaluation.

Source

fn bls12_381_g1_add( &self, a: G1Point, b: G1Point, ) -> Result<[u8; 96], PrecompileError>

BLS12-381 G1 addition (returns 96-byte unpadded G1 point)

Source

fn bls12_381_g1_msm( &self, pairs: &mut dyn Iterator<Item = Result<G1PointScalar, PrecompileError>>, ) -> Result<[u8; 96], PrecompileError>

BLS12-381 G1 multi-scalar multiplication (returns 96-byte unpadded G1 point)

Source

fn bls12_381_g2_add( &self, a: G2Point, b: G2Point, ) -> Result<[u8; 192], PrecompileError>

BLS12-381 G2 addition (returns 192-byte unpadded G2 point)

Source

fn bls12_381_g2_msm( &self, pairs: &mut dyn Iterator<Item = Result<G2PointScalar, PrecompileError>>, ) -> Result<[u8; 192], PrecompileError>

BLS12-381 G2 multi-scalar multiplication (returns 192-byte unpadded G2 point)

Source

fn bls12_381_pairing_check( &self, pairs: &[(G1Point, G2Point)], ) -> Result<bool, PrecompileError>

BLS12-381 pairing check.

Source

fn bls12_381_fp_to_g1(&self, fp: &[u8; 48]) -> Result<[u8; 96], PrecompileError>

BLS12-381 map field element to G1.

Source

fn bls12_381_fp2_to_g2( &self, fp2: ([u8; 48], [u8; 48]), ) -> Result<[u8; 192], PrecompileError>

BLS12-381 map field element to G2.

Implementors§