11// Copyright © Aptos Foundation
22
3+ use super :: circuit_constants:: MAX_EXTRA_FIELD_BYTES ;
34use crate :: {
45 jwks:: rsa:: RSA_JWK ,
56 keyless:: {
@@ -14,6 +15,7 @@ use ark_bn254::{Fq, Fq2, Fr, G1Affine, G1Projective, G2Affine, G2Projective};
1415use ark_ff:: PrimeField ;
1516use ark_serialize:: { CanonicalDeserialize , CanonicalSerialize } ;
1617use num_traits:: { One , Zero } ;
18+ use once_cell:: sync:: Lazy ;
1719use serde:: { Deserialize , Deserializer , Serialize , Serializer } ;
1820use serde_big_array:: BigArray ;
1921
@@ -22,6 +24,10 @@ use serde_big_array::BigArray;
2224pub const G1_PROJECTIVE_COMPRESSED_NUM_BYTES : usize = 32 ;
2325pub const G2_PROJECTIVE_COMPRESSED_NUM_BYTES : usize = 64 ;
2426
27+ // When the extra_field is none, use this hash value which is equal to the hash of a single space string.
28+ static EMPTY_EXTRA_FIELD_HASH : Lazy < Fr > =
29+ Lazy :: new ( || poseidon_bn254:: pad_and_hash_string ( " " , MAX_EXTRA_FIELD_BYTES as usize ) . unwrap ( ) ) ;
30+
2531/// This will do the proper subgroup membership checks.
2632pub fn g1_projective_str_to_affine ( x : & str , y : & str ) -> anyhow:: Result < G1Affine > {
2733 let g1_affine = G1Bytes :: new_unchecked ( x, y) ?. deserialize_into_affine ( ) ?;
@@ -240,7 +246,7 @@ pub fn get_public_inputs_hash(
240246) -> anyhow:: Result < Fr > {
241247 if let EphemeralCertificate :: ZeroKnowledgeSig ( proof) = & sig. cert {
242248 let ( has_extra_field, extra_field_hash) = match & proof. extra_field {
243- None => ( Fr :: zero ( ) , Fr :: zero ( ) ) ,
249+ None => ( Fr :: zero ( ) , * Lazy :: force ( & EMPTY_EXTRA_FIELD_HASH ) ) ,
244250 Some ( extra_field) => (
245251 Fr :: one ( ) ,
246252 poseidon_bn254:: pad_and_hash_string (
0 commit comments