@@ -606,16 +606,26 @@ func NewVerifier[FR emulated.FieldParams, G1El algebra.G1ElementT, G2El algebra.
606606// AssertProof asserts that the SNARK proof holds for the given witness and
607607// verifying key.
608608func (v * Verifier [FR , G1El , G2El , GtEl ]) AssertProof (vk VerifyingKey [G1El , G2El , GtEl ], proof Proof [G1El , G2El ], witness Witness [FR ], opts ... VerifierOption ) error {
609+ isValid , err := v .IsValidProof (vk , proof , witness , opts ... )
610+ if err != nil {
611+ return err
612+ }
613+ v .api .AssertIsEqual (isValid , 1 )
614+ return nil
615+ }
616+
617+ // IsValidProof returns a variable that is 1 if the proof is valid and 0 otherwise.
618+ func (v * Verifier [FR , G1El , G2El , GtEl ]) IsValidProof (vk VerifyingKey [G1El , G2El , GtEl ], proof Proof [G1El , G2El ], witness Witness [FR ], opts ... VerifierOption ) (frontend.Variable , error ) {
609619 if len (vk .CommitmentKeys ) != len (proof .Commitments ) {
610- return fmt .Errorf ("invalid number of commitments, got %d, expected %d" , len (proof .Commitments ), len (vk .CommitmentKeys ))
620+ return 0 , fmt .Errorf ("invalid number of commitments, got %d, expected %d" , len (proof .Commitments ), len (vk .CommitmentKeys ))
611621 }
612622 if len (vk .CommitmentKeys ) != len (vk .PublicAndCommitmentCommitted ) {
613- return fmt .Errorf ("invalid number of commitment keys, got %d, expected %d" , len (vk .CommitmentKeys ), len (vk .PublicAndCommitmentCommitted ))
623+ return 0 , fmt .Errorf ("invalid number of commitment keys, got %d, expected %d" , len (vk .CommitmentKeys ), len (vk .PublicAndCommitmentCommitted ))
614624 }
615625 var fr FR
616626 nbPublicVars := len (vk .G1 .K ) - len (vk .PublicAndCommitmentCommitted )
617627 if len (witness .Public ) != nbPublicVars - 1 {
618- return fmt .Errorf ("invalid witness size, got %d, expected %d (public - ONE_WIRE)" , len (witness .Public ), len (vk .G1 .K )- 1 )
628+ return 0 , fmt .Errorf ("invalid witness size, got %d, expected %d (public - ONE_WIRE)" , len (witness .Public ), len (vk .G1 .K )- 1 )
619629 }
620630
621631 inP := make ([]* G1El , len (vk .G1 .K )- 1 ) // first is for the one wire, we add it manually after MSM
@@ -629,11 +639,11 @@ func (v *Verifier[FR, G1El, G2El, GtEl]) AssertProof(vk VerifyingKey[G1El, G2El,
629639
630640 opt , err := newCfg (opts ... )
631641 if err != nil {
632- return fmt .Errorf ("apply options: %w" , err )
642+ return 0 , fmt .Errorf ("apply options: %w" , err )
633643 }
634644 hashToField , err := recursion .NewHash (v .api , fr .Modulus (), true )
635645 if err != nil {
636- return fmt .Errorf ("hash to field: %w" , err )
646+ return 0 , fmt .Errorf ("hash to field: %w" , err )
637647 }
638648
639649 maxNbPublicCommitted := 0
@@ -662,16 +672,16 @@ func (v *Verifier[FR, G1El, G2El, GtEl]) AssertProof(vk VerifyingKey[G1El, G2El,
662672 // explicitly do not verify the commitment as there is nothing
663673 case 1 :
664674 if err = v .commitment .AssertCommitment (proof .Commitments [0 ], proof .CommitmentPok , vk .CommitmentKeys [0 ], opt .pedopt ... ); err != nil {
665- return fmt .Errorf ("assert commitment: %w" , err )
675+ return 0 , fmt .Errorf ("assert commitment: %w" , err )
666676 }
667677 default :
668678 // TODO: we support only a single commitment in the recursion for now
669- return fmt .Errorf ("multiple commitments are not supported" )
679+ return 0 , fmt .Errorf ("multiple commitments are not supported" )
670680 }
671681
672682 kSum , err := v .curve .MultiScalarMul (inP , inS , opt .algopt ... )
673683 if err != nil {
674- return fmt .Errorf ("multi scalar mul: %w" , err )
684+ return 0 , fmt .Errorf ("multi scalar mul: %w" , err )
675685 }
676686 kSum = v .curve .Add (kSum , & vk .G1 .K [0 ])
677687
@@ -686,10 +696,9 @@ func (v *Verifier[FR, G1El, G2El, GtEl]) AssertProof(vk VerifyingKey[G1El, G2El,
686696 }
687697 pairing , err := v .pairing .Pair ([]* G1El {kSum , & proof .Krs , & proof .Ar }, []* G2El {& vk .G2 .GammaNeg , & vk .G2 .DeltaNeg , & proof .Bs })
688698 if err != nil {
689- return fmt .Errorf ("pairing: %w" , err )
699+ return 0 , fmt .Errorf ("pairing: %w" , err )
690700 }
691- v .pairing .AssertIsEqual (pairing , & vk .E )
692- return nil
701+ return v .pairing .IsEqual (pairing , & vk .E ), nil
693702}
694703
695704// SwitchVerification key switches the verification key based on the provided
0 commit comments