mina_tree/proofs/
accumulator_check.rs1use ark_ff::fields::arithmetic::InvalidBigInt;
2use mina_curves::pasta::{Fp, Vesta};
3use mina_p2p_messages::{bigint::BigInt, v2::PicklesProofProofsVerified2ReprStableV2};
4use poly_commitment::{commitment::CommitmentCurve, srs::SRS};
5
6use super::{public_input::scalar_challenge::ScalarChallenge, urs_utils};
7
8pub fn accumulator_check(
9 urs: &SRS<Vesta>,
10 proofs: &[&PicklesProofProofsVerified2ReprStableV2],
11) -> Result<bool, InvalidBigInt> {
12 let mut comms = Vec::with_capacity(proofs.len());
21 let mut bulletproof_challenges = vec![];
22
23 for proof in proofs {
24 let chals = &proof
25 .statement
26 .proof_state
27 .deferred_values
28 .bulletproof_challenges;
29 let mut chals: Vec<Fp> = chals
30 .iter()
31 .map(|chal| {
32 let prechallenge = &chal.prechallenge.inner;
33 let prechallenge: [u64; 2] = prechallenge.each_ref().map(|c| c.as_u64());
34
35 ScalarChallenge::limbs_to_field(&prechallenge)
36 })
37 .collect();
38
39 bulletproof_challenges.append(&mut chals);
40
41 let of_coord =
42 |(x, y): &(BigInt, BigInt)| Ok(Vesta::of_coordinates(x.to_field()?, y.to_field()?));
43
44 let acc_comm = &proof
46 .statement
47 .proof_state
48 .messages_for_next_wrap_proof
49 .challenge_polynomial_commitment;
50 let acc_comm: Vesta = of_coord(acc_comm)?;
51
52 comms.push(acc_comm);
53 }
54
55 let acc_check = urs_utils::batch_dlog_accumulator_check(urs, &comms, &bulletproof_challenges);
56
57 if !acc_check {
58 println!("accumulator_check failed");
59 }
60
61 Ok(acc_check)
62}