Skip to content

Commit a268fb1

Browse files
committed
Implement computation of prev challenges
1 parent 84ec18d commit a268fb1

2 files changed

Lines changed: 70 additions & 17 deletions

File tree

operator/mina/lib/src/pickles_preproc/preprocess.rs

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
use 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

89
use 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

1617
use 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
}

operator/mina/lib/src/pickles_preproc/state_proof.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ use serde::Deserialize;
77

88
use super::type_aliases::{WrapECPoint, WrapPointEvaluations, WrapScalar};
99

10-
type DecimalSigned = String;
11-
type HexScalar = String;
12-
type HexPointCoordinates = [String; 2];
13-
type HexPointEvaluations = [String; 2];
10+
pub const WRAP_PREV_CHALLENGES: usize = 2;
11+
pub const WRAP_SCALARS_PER_CHALLENGE: usize = 15;
12+
13+
pub type DecimalSigned = String;
14+
pub type HexScalar = String;
15+
pub type HexPointCoordinates = [String; 2];
16+
pub type HexPointEvaluations = [String; 2];
1417

1518
#[derive(Deserialize)]
1619
pub struct StateProof {
@@ -58,6 +61,7 @@ pub struct Evaluations {
5861

5962
#[derive(Deserialize)]
6063
pub struct Statement {
64+
pub proof_state: ProofState,
6165
pub messages_for_next_step_proof: MessagesForNextStepProof,
6266
}
6367

@@ -124,13 +128,15 @@ pub struct FeatureFlags {
124128
#[derive(Deserialize)]
125129
pub struct MessagesForNextWrapProof {
126130
pub challenge_polynomial_commitment: HexPointCoordinates,
127-
pub old_bulletproof_challenges: [[BulletproofChallenge; 16]; 2],
131+
pub old_bulletproof_challenges:
132+
[[BulletproofChallenge; WRAP_SCALARS_PER_CHALLENGE]; WRAP_PREV_CHALLENGES],
128133
}
129134

130135
impl TryFrom<HexPointCoordinates> for WrapECPoint {
131136
type Error = String;
132137

133138
fn try_from(value: HexPointCoordinates) -> Result<Self, Self::Error> {
139+
// TODO: Handle point at infinity.
134140
let x = Fp::from_hex(&value[0]).map_err(|err| err.to_string())?;
135141
let y = Fp::from_hex(&value[1]).map_err(|err| err.to_string())?;
136142
Ok(WrapECPoint(Pallas::new(x, y, false)))

0 commit comments

Comments
 (0)