@@ -87,33 +87,13 @@ impl SchnorrVerifierGate {
8787 }
8888 }
8989
90- /// Schnorr verifier instruction.
91- /// See [$verify$][crate::docs::schnorr#verify] of Schnorr signature
92- /// and its [implementation][crate::signatures::primitive::schnorr::Schnorr::verify()].
93- #[ doc = include_str ! ( "../../docs/signatures/schnorr/gate-verify.md" ) ]
94- pub fn assert_verify (
95- & self ,
96- ctx : & mut RegionCtx < ' _ , Base > ,
97- signature : & AssignedSchnorrSignature ,
98- pk : & AssignedEccPoint ,
99- msg : & AssignedValue < Base > ,
100- ) -> Result < ( ) , Error > {
101- let is_verified = self . verify ( ctx, signature, pk, msg) ?;
102- self . ecc_gate
103- . main_gate
104- . assert_one ( ctx, & is_verified) ?;
105- Ok ( ( ) )
106- }
107-
108- /// Schnorr verifier instruction.
109- /// Returns an [AssignedCondition] which is 1 if the signature is valid and 0 otherwise.
110- pub fn verify (
90+ fn verify_prepare (
11191 & self ,
11292 ctx : & mut RegionCtx < ' _ , Base > ,
11393 signature : & AssignedSchnorrSignature ,
11494 pk : & AssignedEccPoint ,
11595 msg : & AssignedValue < Base > ,
116- ) -> Result < AssignedCondition < Base > , Error > {
96+ ) -> Result < ( AssignedEccPoint , AssignedEccPoint ) , Error > {
11797 let two_pk = self . ecc_gate . add ( ctx, pk, pk) ?;
11898 let four_pk = self . ecc_gate . add ( ctx, & two_pk, & two_pk) ?;
11999 let eight_pk = self . ecc_gate . add ( ctx, & four_pk, & four_pk) ?;
@@ -138,7 +118,38 @@ impl SchnorrVerifierGate {
138118
139119 let lhs = self . combined_mul ( ctx, & signature. 1 . 0 , & challenge, & assigned_generator, pk) ?;
140120
141- Ok ( self . ecc_gate . is_equal ( ctx, & lhs, & signature. 0 ) ?)
121+ Ok ( ( lhs, signature. 0 . clone ( ) ) )
122+ }
123+
124+ /// Schnorr verifier instruction.
125+ /// See [$verify$][crate::docs::schnorr#verify] of Schnorr signature
126+ /// and its [implementation][crate::signatures::primitive::schnorr::Schnorr::verify()].
127+ #[ doc = include_str ! ( "../../docs/signatures/schnorr/gate-verify.md" ) ]
128+ pub fn assert_verify (
129+ & self ,
130+ ctx : & mut RegionCtx < ' _ , Base > ,
131+ signature : & AssignedSchnorrSignature ,
132+ pk : & AssignedEccPoint ,
133+ msg : & AssignedValue < Base > ,
134+ ) -> Result < ( ) , Error > {
135+ let ( lhs, signature0) = self . verify_prepare ( ctx, signature, pk, msg) ?;
136+ self . ecc_gate
137+ . constrain_equal ( ctx, & lhs, & signature0) ?;
138+ Ok ( ( ) )
139+ }
140+
141+ /// Schnorr verifier instruction.
142+ /// Returns an [AssignedCondition] which is 1 if the signature is valid and 0 otherwise.
143+ pub fn verify (
144+ & self ,
145+ ctx : & mut RegionCtx < ' _ , Base > ,
146+ signature : & AssignedSchnorrSignature ,
147+ pk : & AssignedEccPoint ,
148+ msg : & AssignedValue < Base > ,
149+ ) -> Result < AssignedCondition < Base > , Error > {
150+ let ( lhs, signature0) = self . verify_prepare ( ctx, signature, pk, msg) ?;
151+
152+ Ok ( self . ecc_gate . is_equal ( ctx, & lhs, & signature0) ?)
142153 }
143154
144155 // We need to negate the second scalar prior to the addition
0 commit comments