pub struct NativeCrypto;Expand description
Native crypto implementation using system libraries.
Most method bodies live as defaults on the Crypto trait itself. The
P-256 (secp256r1) verify is overridden here to use the assembly-optimized
aws-lc-rs backend when the aws-lc-rs feature is enabled, since the
portable p256 default does two constant-time scalar muls with no
Shamir/basepoint optimization and is a P256VERIFY hot-path outlier. On the
host the BLS12-381 (EIP-2537) defaults likewise route through the
assembly-optimized blst backend (the blst feature, default-on); zkVM
guest builds compile both backends out and use their own Crypto providers
instead of this type. This
struct exists so callers outside zkVM contexts have a concrete type to
instantiate.
Trait Implementations§
Source§impl Crypto for NativeCrypto
Available on crate feature aws-lc-rs only.
impl Crypto for NativeCrypto
Available on crate feature
aws-lc-rs only.Source§fn secp256r1_verify(
&self,
msg: &[u8; 32],
sig: &[u8; 64],
pk: &[u8; 64],
) -> bool
fn secp256r1_verify( &self, msg: &[u8; 32], sig: &[u8; 64], pk: &[u8; 64], ) -> bool
P-256 signature verification. Used by P256VERIFY precompile (0x0100, Osaka).
Source§fn secp256k1_ecrecover(
&self,
sig: &[u8; 64],
recid: u8,
msg: &[u8; 32],
) -> Result<[u8; 32], CryptoError>
fn secp256k1_ecrecover( &self, sig: &[u8; 64], recid: u8, msg: &[u8; 32], ) -> Result<[u8; 32], CryptoError>
Recover the Ethereum address from a 64-byte signature + recovery id + 32-byte message hash.
Used by the ECRECOVER precompile (0x01).
Returns the 32-byte keccak hash of the uncompressed public key (address is last 20 bytes).
Source§fn recover_signer(
&self,
sig: &[u8; 65],
msg: &[u8; 32],
) -> Result<Address, CryptoError>
fn recover_signer( &self, sig: &[u8; 65], msg: &[u8; 32], ) -> Result<Address, CryptoError>
Recover the signer address from a 65-byte signature (r||s||v) + 32-byte message hash.
Used by transaction validation (tx.sender()) and EIP-7702 authority recovery.
Source§fn keccak256(&self, input: &[u8]) -> [u8; 32]
fn keccak256(&self, input: &[u8]) -> [u8; 32]
Keccak-256 hash. Used by the KECCAK256 opcode (0x20) and address derivation.
Source§fn sha256(&self, input: &[u8]) -> [u8; 32]
fn sha256(&self, input: &[u8]) -> [u8; 32]
SHA-256 hash. Used by SHA2-256 precompile (0x02) and KZG point evaluation.
Source§fn ripemd160(&self, input: &[u8]) -> [u8; 32]
fn ripemd160(&self, input: &[u8]) -> [u8; 32]
RIPEMD-160 hash (zero-padded to 32 bytes). Used by RIPEMD-160 precompile (0x03).
Source§fn bn254_g1_add(&self, p1: &[u8], p2: &[u8]) -> Result<[u8; 64], CryptoError>
fn bn254_g1_add(&self, p1: &[u8], p2: &[u8]) -> Result<[u8; 64], CryptoError>
G1 point addition. Used by ECADD precompile (0x06).
Input: two uncompressed G1 points (64 bytes each as big-endian x||y).
Output: uncompressed G1 point (64 bytes).
Source§fn bn254_g1_mul(
&self,
point: &[u8],
scalar: &[u8],
) -> Result<[u8; 64], CryptoError>
fn bn254_g1_mul( &self, point: &[u8], scalar: &[u8], ) -> Result<[u8; 64], CryptoError>
G1 scalar multiplication. Used by ECMUL precompile (0x07).
Input: uncompressed G1 point (64 bytes) + scalar (32 bytes big-endian).
Output: uncompressed G1 point (64 bytes).
Source§fn bn254_pairing_check(
&self,
pairs: &[(&[u8], &[u8])],
) -> Result<bool, CryptoError>
fn bn254_pairing_check( &self, pairs: &[(&[u8], &[u8])], ) -> Result<bool, CryptoError>
Pairing check. Used by ECPAIRING precompile (0x08).
Input: pairs of (G1 64 bytes, G2 128 bytes) as raw byte slices.
Returns true if the pairing equation holds.
Source§fn modexp(
&self,
base: &[u8],
exp: &[u8],
modulus: &[u8],
) -> Result<Vec<u8>, CryptoError>
fn modexp( &self, base: &[u8], exp: &[u8], modulus: &[u8], ) -> Result<Vec<u8>, CryptoError>
Modular exponentiation (arbitrary precision).
Used by MODEXP precompile (0x05).
Source§fn mulmod256(&self, a: &[u8; 32], b: &[u8; 32], m: &[u8; 32]) -> [u8; 32]
fn mulmod256(&self, a: &[u8; 32], b: &[u8; 32], m: &[u8; 32]) -> [u8; 32]
256-bit modular multiplication.
Used by the MULMOD opcode. Default impl uses standard bigint arithmetic.
ZisK overrides with a native circuit instruction.
Source§fn blake2_compress(
&self,
rounds: u32,
h: &mut [u64; 8],
m: [u64; 16],
t: [u64; 2],
f: bool,
)
fn blake2_compress( &self, rounds: u32, h: &mut [u64; 8], m: [u64; 16], t: [u64; 2], f: bool, )
Blake2b compression function F. Used by BLAKE2F precompile (0x09).
fn verify_kzg_proof( &self, z: &[u8; 32], y: &[u8; 32], commitment: &[u8; 48], proof: &[u8; 48], ) -> Result<(), CryptoError>
fn verify_blob_kzg_proof( &self, blob: &[u8], commitment: &[u8; 48], proof: &[u8; 48], ) -> Result<bool, CryptoError>
Source§fn bls12_381_g1_add(
&self,
a: ([u8; 48], [u8; 48]),
b: ([u8; 48], [u8; 48]),
) -> Result<[u8; 96], CryptoError>
fn bls12_381_g1_add( &self, a: ([u8; 48], [u8; 48]), b: ([u8; 48], [u8; 48]), ) -> Result<[u8; 96], CryptoError>
G1 addition. Returns 96-byte unpadded G1 point.
Source§fn bls12_381_g1_msm(
&self,
pairs: &[(([u8; 48], [u8; 48]), [u8; 32])],
) -> Result<[u8; 96], CryptoError>
fn bls12_381_g1_msm( &self, pairs: &[(([u8; 48], [u8; 48]), [u8; 32])], ) -> Result<[u8; 96], CryptoError>
G1 multi-scalar multiplication. Returns 96-byte unpadded G1 point.
Source§fn bls12_381_g2_add(
&self,
a: ([u8; 48], [u8; 48], [u8; 48], [u8; 48]),
b: ([u8; 48], [u8; 48], [u8; 48], [u8; 48]),
) -> Result<[u8; 192], CryptoError>
fn bls12_381_g2_add( &self, a: ([u8; 48], [u8; 48], [u8; 48], [u8; 48]), b: ([u8; 48], [u8; 48], [u8; 48], [u8; 48]), ) -> Result<[u8; 192], CryptoError>
G2 addition. Returns 192-byte unpadded G2 point.
Source§fn bls12_381_g2_msm(
&self,
pairs: &[(([u8; 48], [u8; 48], [u8; 48], [u8; 48]), [u8; 32])],
) -> Result<[u8; 192], CryptoError>
fn bls12_381_g2_msm( &self, pairs: &[(([u8; 48], [u8; 48], [u8; 48], [u8; 48]), [u8; 32])], ) -> Result<[u8; 192], CryptoError>
G2 multi-scalar multiplication. Returns 192-byte unpadded G2 point.
Source§fn bls12_381_pairing_check(
&self,
pairs: &[(([u8; 48], [u8; 48]), ([u8; 48], [u8; 48], [u8; 48], [u8; 48]))],
) -> Result<bool, CryptoError>
fn bls12_381_pairing_check( &self, pairs: &[(([u8; 48], [u8; 48]), ([u8; 48], [u8; 48], [u8; 48], [u8; 48]))], ) -> Result<bool, CryptoError>
BLS12-381 pairing check.
Source§fn bls12_381_fp_to_g1(&self, fp: &[u8; 48]) -> Result<[u8; 96], CryptoError>
fn bls12_381_fp_to_g1(&self, fp: &[u8; 48]) -> Result<[u8; 96], CryptoError>
Map field element to G1 point.
Auto Trait Implementations§
impl Freeze for NativeCrypto
impl RefUnwindSafe for NativeCrypto
impl Send for NativeCrypto
impl Sync for NativeCrypto
impl Unpin for NativeCrypto
impl UnsafeUnpin for NativeCrypto
impl UnwindSafe for NativeCrypto
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more