11use kimchi:: {
22 circuits:: wires:: { COLUMNS , PERMUTS } ,
33 mina_curves:: pasta:: { Fq , Pallas } ,
4- poly_commitment:: PolyComm ,
4+ mina_poseidon:: sponge:: ScalarChallenge ,
5+ poly_commitment:: { srs:: endos, PolyComm } ,
56 proof:: { PointEvaluations , RecursionChallenge } ,
67} ;
78
89use crate :: pickles_preproc:: {
9- state_proof:: { Bulletproof , Commitments , Evaluations } ,
10+ state_proof:: { Bulletproof , Commitments , Evaluations , WRAP_PREV_CHALLENGES } ,
1011 type_aliases:: {
1112 WrapECPoint , WrapOpeningProof , WrapPointEvaluations , WrapProofEvaluations ,
1213 WrapProverCommitments , WrapScalar ,
1314 } ,
1415} ;
1516
1617use super :: {
17- state_proof:: StateProof ,
18+ state_proof:: {
19+ BulletproofChallenge , HexPointCoordinates , StateProof , WRAP_SCALARS_PER_CHALLENGE ,
20+ } ,
1821 type_aliases:: { WrapProverProof , WrapVerifierIndex } ,
1922} ;
2023
@@ -164,13 +167,17 @@ pub fn deserialize_state_proof(
164167
165168 let ft_eval1 = WrapScalar :: try_from ( state_proof. proof . ft_eval1 ) ?. 0 ;
166169
167- // TODO: Calculate prev_challenges
168- let prev_challenges = vec ! [ RecursionChallenge {
169- chals: Vec :: new( ) ,
170- comm: PolyComm {
171- elems: Vec :: <Pallas >:: new( ) ,
172- } ,
173- } ] ;
170+ let prev_challenges = compute_prev_challenges (
171+ state_proof
172+ . statement
173+ . proof_state
174+ . messages_for_next_wrap_proof
175+ . old_bulletproof_challenges ,
176+ state_proof
177+ . statement
178+ . messages_for_next_step_proof
179+ . challenge_polynomial_commitments ,
180+ ) ?;
174181
175182 let _prover_proof = WrapProverProof {
176183 commitments,
@@ -183,6 +190,46 @@ pub fn deserialize_state_proof(
183190 todo ! ( )
184191}
185192
186- pub fn compute_prev_challenges ( ) {
187- todo ! ( )
193+ pub fn compute_prev_challenges (
194+ old_bulletproof_challenges : [ [ BulletproofChallenge ; WRAP_SCALARS_PER_CHALLENGE ] ;
195+ WRAP_PREV_CHALLENGES ] ,
196+ challenge_polynomial_commitments : [ HexPointCoordinates ; WRAP_PREV_CHALLENGES ] ,
197+ ) -> Result < Vec < RecursionChallenge < Pallas > > , String > {
198+ let mut recursion_challenges = Vec :: with_capacity ( WRAP_PREV_CHALLENGES ) ;
199+
200+ for ( chal, comm) in old_bulletproof_challenges
201+ . into_iter ( )
202+ . zip ( challenge_polynomial_commitments. into_iter ( ) )
203+ {
204+ let mut chals = Vec :: with_capacity ( WRAP_SCALARS_PER_CHALLENGE ) ;
205+ for prechallenge in chal. into_iter ( ) . map ( |chal| chal. prechallenge ) {
206+ let [ limb0, limb1] = prechallenge. inner ;
207+
208+ let limb0 = u64:: from_be_bytes (
209+ limb0
210+ . parse :: < i64 > ( )
211+ . map_err ( |err| err. to_string ( ) ) ?
212+ . to_be_bytes ( ) ,
213+ ) as u128 ;
214+ let limb1 = u64:: from_be_bytes (
215+ limb1
216+ . parse :: < i64 > ( )
217+ . map_err ( |err| err. to_string ( ) ) ?
218+ . to_be_bytes ( ) ,
219+ ) as u128 ;
220+
221+ let field = Fq :: from ( limb0 | ( limb1 << 64 ) ) ;
222+
223+ let ( _, endo_r) = endos :: < Pallas > ( ) ;
224+ chals. push ( ScalarChallenge ( field) . to_field ( & endo_r) ) ;
225+ }
226+
227+ let comm = PolyComm {
228+ elems : vec ! [ WrapECPoint :: try_from( comm) ?. 0 ] ,
229+ } ;
230+
231+ recursion_challenges. push ( RecursionChallenge { chals, comm } ) ;
232+ }
233+
234+ Ok ( recursion_challenges)
188235}
0 commit comments