diff --git a/crates/prover/src/types.rs b/crates/prover/src/types.rs index b4e362e0f..b05776fca 100644 --- a/crates/prover/src/types.rs +++ b/crates/prover/src/types.rs @@ -44,18 +44,33 @@ pub trait HashableKey { /// Hash the key into a digest of BabyBear elements. fn hash_babybear(&self) -> [BabyBear; DIGEST_SIZE]; - /// Hash the key into a digest of u32 elements. + /// Hash the key into a digest of u32 elements. fn hash_u32(&self) -> [u32; DIGEST_SIZE]; + /// Hash the key into a Bn254Fr element. fn hash_bn254(&self) -> Bn254Fr { babybears_to_bn254(&self.hash_babybear()) } + /// Hash the key into a 32 byte hex string, prefixed with "0x". + /// + /// This is ideal for generating a vkey hash for onchain verification. fn bytes32(&self) -> String { let vkey_digest_bn254 = self.hash_bn254(); format!("0x{:0>64}", vkey_digest_bn254.as_canonical_biguint().to_str_radix(16)) } + /// Hash the key into a 32 byte array. + /// + /// This has the same value as `bytes32`, but as a raw byte array. + fn bytes32_raw(&self) -> [u8; 32] { + let vkey_digest_bn254 = self.hash_bn254(); + let vkey_bytes = vkey_digest_bn254.as_canonical_biguint().to_bytes_be(); + let mut result = [0u8; 32]; + result[1..].copy_from_slice(&vkey_bytes); + result + } + /// Hash the key into a digest of bytes elements. fn hash_bytes(&self) -> [u8; DIGEST_SIZE * 4] { words_to_bytes_be(&self.hash_u32())