Skip to content

Commit 807f779

Browse files
committed
tmp
1 parent 3a9ae24 commit 807f779

File tree

2 files changed

+73
-31
lines changed

2 files changed

+73
-31
lines changed

ledger/src/proofs/accumulator_check.rs

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,77 @@ use poly_commitment::{commitment::CommitmentCurve, srs::SRS};
77
use super::public_input::scalar_challenge::ScalarChallenge;
88
use super::urs_utils;
99

10+
/*
11+
let%bind accumulator_check =
12+
Ipa.Step.accumulator_check
13+
(List.map ts ~f:(fun (T (_, _, _, _, _, T t)) ->
14+
( t.statement.proof_state.messages_for_next_wrap_proof
15+
.challenge_polynomial_commitment
16+
, Ipa.Step.compute_challenges
17+
t.statement.proof_state.deferred_values.bulletproof_challenges ) )
18+
)
19+
20+
21+
let accumulator_check comm_chals =
22+
let chals =
23+
Array.concat
24+
@@ List.map comm_chals ~f:(fun (_, chals) -> Vector.to_array chals)
25+
in
26+
let comms =
27+
Array.of_list_map comm_chals ~f:(fun (comm, _) ->
28+
Or_infinity.Finite comm )
29+
in
30+
let urs = Backend.Tick.Keypair.load_urs () in
31+
Promise.run_in_thread (fun () ->
32+
Kimchi_bindings.Protocol.SRS.Fp.batch_accumulator_check urs
33+
(Array.map comms ~f:or_infinite_conv)
34+
chals )
35+
*/
36+
1037
pub fn accumulator_check(
1138
urs: &SRS<Vesta>,
12-
proof: &PicklesProofProofsVerified2ReprStableV2,
39+
proofs: &[&PicklesProofProofsVerified2ReprStableV2],
1340
) -> Result<bool, InvalidBigInt> {
1441
// accumulator check
1542
// Note:
1643
// comms: statement.proof_state.messages_for_next_wrap_proof.challenge_polynomial_commitment
1744
// chals: statement.proof_state.deferred_values.bulletproof_challenges
1845

19-
let deferred_values = &proof.statement.proof_state.deferred_values;
20-
let bulletproof_challenges = &deferred_values.bulletproof_challenges;
21-
let bulletproof_challenges: Vec<Fp> = bulletproof_challenges
22-
.iter()
23-
.map(|chal| {
24-
let prechallenge = &chal.prechallenge.inner;
25-
let prechallenge: [u64; 2] = prechallenge.each_ref().map(|c| c.as_u64());
26-
27-
ScalarChallenge::limbs_to_field(&prechallenge)
28-
})
29-
.collect();
30-
31-
let of_coord =
32-
|(x, y): &(BigInt, BigInt)| Ok(Vesta::of_coordinates(x.to_field()?, y.to_field()?));
33-
34-
// statement.proof_state.messages_for_next_wrap_proof.challenge_polynomial_commitment
35-
let acc_comm = &proof
36-
.statement
37-
.proof_state
38-
.messages_for_next_wrap_proof
39-
.challenge_polynomial_commitment;
40-
let acc_comm: Vesta = of_coord(acc_comm)?;
41-
42-
let acc_check =
43-
urs_utils::batch_dlog_accumulator_check(urs, &[acc_comm], &bulletproof_challenges);
46+
let mut comms = Vec::with_capacity(proofs.len());
47+
let mut bulletproof_challenges = vec![];
48+
49+
for proof in proofs {
50+
let bp_chals = &proof
51+
.statement
52+
.proof_state
53+
.deferred_values
54+
.bulletproof_challenges;
55+
let mut bp_chals: Vec<Fp> = bp_chals
56+
.iter()
57+
.map(|chal| {
58+
let prechallenge = &chal.prechallenge.inner;
59+
let prechallenge: [u64; 2] = prechallenge.each_ref().map(|c| c.as_u64());
60+
61+
ScalarChallenge::limbs_to_field(&prechallenge)
62+
})
63+
.collect();
64+
bulletproof_challenges.append(&mut bp_chals);
65+
66+
let of_coord =
67+
|(x, y): &(BigInt, BigInt)| Ok(Vesta::of_coordinates(x.to_field()?, y.to_field()?));
68+
69+
// statement.proof_state.messages_for_next_wrap_proof.challenge_polynomial_commitment
70+
let acc_comm = &proof
71+
.statement
72+
.proof_state
73+
.messages_for_next_wrap_proof
74+
.challenge_polynomial_commitment;
75+
let acc_comm: Vesta = of_coord(acc_comm)?;
76+
77+
comms.push(acc_comm);
78+
}
79+
80+
let acc_check = urs_utils::batch_dlog_accumulator_check(urs, &comms, &bulletproof_challenges);
4481

4582
if !acc_check {
4683
println!("accumulator_check failed");

ledger/src/proofs/verification.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ pub fn verify_block(
746746
let protocol_state_hash = MinaHash::hash(&protocol_state);
747747

748748
let accum_check =
749-
accumulator_check::accumulator_check(srs, protocol_state_proof).unwrap_or(false);
749+
accumulator_check::accumulator_check(srs, &[protocol_state_proof]).unwrap_or(false);
750750
let verified = verify_impl(&protocol_state_hash, protocol_state_proof, &vk).unwrap_or(false);
751751

752752
accum_check && verified
@@ -768,16 +768,20 @@ pub fn verify_transaction<'a>(
768768
&PicklesProofProofsVerified2ReprStableV2,
769769
&VK,
770770
)> = Vec::with_capacity(128);
771-
let mut accum_check = true;
771+
772+
let mut accum_check_proofs: Vec<&PicklesProofProofsVerified2ReprStableV2> =
773+
Vec::with_capacity(128);
772774

773775
proofs
774776
.into_iter()
775777
.for_each(|(statement, transaction_proof)| {
776-
accum_check = accum_check
777-
&& accumulator_check::accumulator_check(srs, transaction_proof).unwrap_or(false);
778+
accum_check_proofs.push(transaction_proof);
778779
inputs.push((statement, transaction_proof, &vk));
779780
});
780781

782+
let accum_check =
783+
accumulator_check::accumulator_check(srs, &accum_check_proofs).unwrap_or(false);
784+
781785
let verified = batch_verify_impl(inputs.as_slice()).unwrap_or(false);
782786
accum_check && verified
783787
}
@@ -797,7 +801,8 @@ pub fn verify_zkapp(
797801
data: (),
798802
};
799803

800-
let accum_check = accumulator_check::accumulator_check(srs, sideloaded_proof).unwrap_or(false);
804+
let accum_check =
805+
accumulator_check::accumulator_check(srs, &[sideloaded_proof]).unwrap_or(false);
801806
let verified = verify_impl(&zkapp_statement, sideloaded_proof, &vk).unwrap_or(false);
802807

803808
let ok = accum_check && verified;

0 commit comments

Comments
 (0)