Skip to content

Commit 9b1a5a9

Browse files
committed
Implemented prev_challenges test
1 parent a268fb1 commit 9b1a5a9

2 files changed

Lines changed: 110 additions & 1 deletion

File tree

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

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,108 @@ pub fn compute_prev_challenges(
233233

234234
Ok(recursion_challenges)
235235
}
236+
237+
#[cfg(test)]
238+
mod tests {
239+
use kimchi::{
240+
mina_curves::pasta::{Fp, Fq, Pallas},
241+
poly_commitment::PolyComm,
242+
};
243+
use o1_utils::FieldHelpers;
244+
245+
use crate::pickles_preproc::state_proof::{
246+
BulletproofChallenge, Prechallenge, WRAP_SCALARS_PER_CHALLENGE,
247+
};
248+
249+
use super::compute_prev_challenges;
250+
251+
#[test]
252+
fn prev_challenges_tests() {
253+
// reference values were taken from OpenMina's tests, and checked by calling Mina's
254+
// `to_field()` OCaml function.
255+
// https://github.com/openmina/openmina/blob/main/ledger/src/proofs/public_input/scalar_challenge.rs#L120
256+
257+
let bulletproof_challenges_1: [BulletproofChallenge; WRAP_SCALARS_PER_CHALLENGE] = [
258+
["7486980280913238963", "4173194488927267133"],
259+
["-8437921285878338178", "-2241273202573544127"],
260+
["7651331705457292674", "-3583141513394030281"],
261+
["-3464302417307075879", "-436261906098457727"],
262+
["8255044994932440761", "5640094314955753085"],
263+
["-2513734760972484960", "1161566061253204655"],
264+
["7525998242613288472", "3436443803216159028"],
265+
["6809231383204761158", "-1877195934091894696"],
266+
["-2746520749286704399", "-3783224604272248786"],
267+
["-36686536733916892", "-7835584350097226223"],
268+
["-487486487490201322", "2756145684490201109"],
269+
["-2928903316653004982", "346819656816504982"],
270+
["-6510054999844554738", "5242613218253829938"],
271+
["-9192160905410203809", "9069127704639200224"],
272+
["-1805085648820294365", "4705625510417283644"],
273+
]
274+
.map(|prechallenge| BulletproofChallenge {
275+
prechallenge: Prechallenge {
276+
inner: prechallenge.map(str::to_string),
277+
},
278+
});
279+
let bulletproof_challenges_0: [BulletproofChallenge; WRAP_SCALARS_PER_CHALLENGE] = [
280+
["7486980280913238963", "4173194488927267133"],
281+
["-8437921285878338178", "-2241273202573544127"],
282+
["7651331705457292674", "-3583141513394030281"],
283+
["-3464302417307075879", "-436261906098457727"],
284+
["8255044994932440761", "5640094314955753085"],
285+
["-2513734760972484960", "1161566061253204655"],
286+
["7525998242613288472", "3436443803216159028"],
287+
["6809231383204761158", "-1877195934091894696"],
288+
["-2746520749286704399", "-3783224604272248786"],
289+
["-36686536733916892", "-7835584350097226223"],
290+
["-487486487490201322", "2756145684490201109"],
291+
["-2928903316653004982", "346819656816504982"],
292+
["-6510054999844554738", "5242613218253829938"],
293+
["-9192160905410203809", "9069127704639200224"],
294+
["-1805085648820294365", "4705625510417283644"],
295+
]
296+
.map(|prechallenge| BulletproofChallenge {
297+
prechallenge: Prechallenge {
298+
inner: prechallenge.map(str::to_string),
299+
},
300+
});
301+
302+
let old_bulletproof_challenges = [bulletproof_challenges_0, bulletproof_challenges_1];
303+
let challenge_polynomial_commitments = [
304+
["1", "2"].map(str::to_string),
305+
["1", "2"].map(str::to_string),
306+
];
307+
308+
let prev_challenges =
309+
compute_prev_challenges(old_bulletproof_challenges, challenge_polynomial_commitments)
310+
.unwrap();
311+
312+
let mut ocaml_results = [
313+
"29DA5323EE2A35AFA4DF5EF02FD009F8D2FC7A2840525EBE06D519BD10DE22A9",
314+
"1D52604A0D982FD2B0E3123CDE4F801B4ED1D7159B4E5B592014F6F248742A24",
315+
"07407D5D1BF2A0345F94610AE734EBA90DA7377FF0D9F394D7ABB16A44F412B4",
316+
"0D35562107CCF36FCEE46BE6D07CACDED87E5A8134B6B6EBF37B4202419E7FC5",
317+
"08184AD059400E9C0F4BC42FE7CA928645AE2FFE06827B8FEF0A85E383129B73",
318+
"3E50BB9FA5E9622478755CD1A00FF52376E02EC668615C0ACE437A8202F2B303",
319+
"067953A48294C5A2B9D834F5F11B98D7D202A856E654E350ABEF4ECA1A32F835",
320+
"11ADB6896D03E99B915AC779FB33C67C90AB7D34CBEFC6FC7AEB6E29C9633C9F",
321+
"2F17B8300653C1CBADD031C71F53127D76A1074574BEFD64F4535B45473FE702",
322+
"2D8FC93295F902A7AAABC447ADACAFCEB4D3691742D8F6EB7691D24FA51E8D4F",
323+
"2D6B91A4A7C41007DEA2D7C55FB80FDAC61F7BBBD0A5C1036239C791147B4BA4",
324+
"28BDA221025B5B8F684CB66E6E23301C189EB2100A1AADD482C151C159CA5E34",
325+
"26D8EC29B0C0769401BFA8659E6C49563CAB16911DA6052B8F442460C5091639",
326+
"1448AB1F39A083F31B21BC22FE150BA031D8E2D9DD2D0146C73A38763B0611C6",
327+
"05BEBF5D1E8D15AF1F90E6FEA892000B8FAB1EB5BE8662E3E3CC1DBFA8C90F73",
328+
]
329+
.map(|hex| Fq::from_hex(hex).unwrap());
330+
ocaml_results.reverse();
331+
332+
assert_eq!(prev_challenges[0].chals, ocaml_results);
333+
assert_eq!(
334+
prev_challenges[0].comm,
335+
PolyComm {
336+
elems: vec![Pallas::new(Fp::from(1), Fp::from(2), false)]
337+
}
338+
);
339+
}
340+
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ impl TryFrom<HexPointCoordinates> for WrapECPoint {
139139
// TODO: Handle point at infinity.
140140
let x = Fp::from_hex(&value[0]).map_err(|err| err.to_string())?;
141141
let y = Fp::from_hex(&value[1]).map_err(|err| err.to_string())?;
142-
Ok(WrapECPoint(Pallas::new(x, y, false)))
142+
let point = Pallas::new(x, y, false);
143+
if !point.is_on_curve() {
144+
return Err("Deserialized point is not on curve.".to_string());
145+
}
146+
Ok(WrapECPoint(point))
143147
}
144148
}
145149

0 commit comments

Comments
 (0)