Skip to content

Commit 4f85ca0

Browse files
committed
[kimchi] fix test after witness change (bis)
1 parent e3e622e commit 4f85ca0

File tree

4 files changed

+65
-82
lines changed

4 files changed

+65
-82
lines changed

dlog/plonk-15-wires/tests/ec.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
use ark_ec::{AffineCurve, ProjectiveCurve};
2-
use ark_ff::{BigInteger, BitIteratorLE, Field, One, PrimeField, UniformRand, Zero};
3-
use ark_poly::{univariate::DensePolynomial, EvaluationDomain, Radix2EvaluationDomain as D};
2+
use ark_ff::{Field, One, PrimeField, UniformRand, Zero};
43
use array_init::array_init;
54
use colored::Colorize;
65
use commitment_dlog::{
7-
commitment::{b_poly_coefficients, ceil_log2, CommitmentCurve},
6+
commitment::CommitmentCurve,
87
srs::{endos, SRS},
98
};
109
use groupmap::GroupMap;
1110
use mina_curves::pasta::{
1211
fp::Fp as F,
13-
pallas::{Affine as Other, Projective as OtherProjective},
12+
pallas::Affine as Other,
1413
vesta::{Affine, VestaParameters},
1514
};
1615
use oracle::{
17-
poseidon::{ArithmeticSponge, PlonkSpongeConstants15W, Sponge, SpongeConstants},
18-
sponge::{DefaultFqSponge, DefaultFrSponge, ScalarChallenge},
16+
poseidon::PlonkSpongeConstants15W,
17+
sponge::{DefaultFqSponge, DefaultFrSponge},
1918
};
2019
use plonk_15_wires_circuits::{
21-
expr::{Column, Constants, Expr, Linearization, PolishToken},
22-
gate::{CircuitGate, GateType, LookupInfo, LookupsUsed},
23-
gates::poseidon::ROUNDS_PER_ROW,
24-
nolookup::constraints::{zk_w3, ConstraintSystem},
25-
nolookup::scalars::{LookupEvaluations, ProofEvaluations},
26-
polynomials::endosclmul,
20+
gate::{CircuitGate, GateType},
21+
nolookup::constraints::ConstraintSystem,
2722
wires::*,
2823
};
2924
use plonk_15_wires_protocol_dlog::{index::Index, prover::ProverProof};
3025
use rand::{rngs::StdRng, SeedableRng};
31-
use std::fmt::{Display, Formatter};
3226
use std::{rc::Rc, time::Instant};
3327

3428
const PUBLIC: usize = 0;
@@ -64,7 +58,7 @@ fn ec_test() {
6458
srs.add_lagrange_basis(cs.domain.d1);
6559

6660
let fq_sponge_params = oracle::pasta::fq::params();
67-
let (endo_q, endo_r) = endos::<Other>();
61+
let (endo_q, _endo_r) = endos::<Other>();
6862
let srs = Rc::new(srs);
6963

7064
let index = Index::<Affine>::create(cs, fq_sponge_params, endo_q, srs);

dlog/plonk-15-wires/tests/generic.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use array_init::array_init;
66
use commitment_dlog::{
77
commitment::{b_poly_coefficients, ceil_log2, CommitmentCurve},
88
srs::{endos, SRS},
9-
PolyComm,
109
};
1110
use groupmap::GroupMap;
1211
use mina_curves::pasta::{
@@ -23,10 +22,7 @@ use plonk_15_wires_circuits::{
2322
nolookup::constraints::ConstraintSystem,
2423
wires::{Wire, COLUMNS, GENERICS},
2524
};
26-
use plonk_15_wires_protocol_dlog::{
27-
index::{Index, VerifierIndex},
28-
prover::ProverProof,
29-
};
25+
use plonk_15_wires_protocol_dlog::{index::Index, prover::ProverProof};
3026
use rand::{rngs::StdRng, SeedableRng};
3127

3228
// aliases

dlog/tests/poseidon_vesta_15_wires.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ fn positive(index: &Index<Affine>) {
121121
let mut start = Instant::now();
122122
for test in 0..1 {
123123
// witness for Poseidon permutation custom constraints
124-
let mut witness: [Vec<Fp>; COLUMNS] = array_init(|_| vec![Fp::zero(); max_size]);
124+
let mut witness_cols: [Vec<Fp>; COLUMNS] =
125+
array_init(|_| vec![Fp::zero(); 5 + POS_ROWS_PER_HASH * NUM_POS]);
125126

126127
// creates a random initial state
127128
let init = vec![Fp::rand(rng), Fp::rand(rng), Fp::rand(rng)];
@@ -133,7 +134,7 @@ fn positive(index: &Index<Affine>) {
133134
let first_row = h * (POS_ROWS_PER_HASH + 1);
134135

135136
// initialize the sponge in the circuit with our random state
136-
let first_state_cols = &mut witness[round_to_cols(0)];
137+
let first_state_cols = &mut witness_cols[round_to_cols(0)];
137138
for state_idx in 0..SPONGE_WIDTH {
138139
first_state_cols[state_idx][first_row] = init[state_idx];
139140
}
@@ -162,7 +163,7 @@ fn positive(index: &Index<Affine>) {
162163

163164
// apply the sponge and record the result in the witness
164165
let cols_to_update = round_to_cols((round + 1) % ROUNDS_PER_ROW);
165-
witness[cols_to_update]
166+
witness_cols[cols_to_update]
166167
.iter_mut()
167168
.zip(sponge.state.iter())
168169
// update the state (last update is on the next row)
@@ -172,7 +173,7 @@ fn positive(index: &Index<Affine>) {
172173
}
173174

174175
// verify the circuit satisfiability by the computed witness
175-
index.cs.verify(&witness).unwrap();
176+
index.cs.verify(&witness_cols).unwrap();
176177

177178
//
178179
let prev = {
@@ -194,7 +195,7 @@ fn positive(index: &Index<Affine>) {
194195
batch.push(
195196
ProverProof::create::<BaseSponge, ScalarSponge>(
196197
&group_map,
197-
&witness,
198+
&witness_cols,
198199
&index,
199200
vec![prev],
200201
)

dlog/tests/varbasemul.rs

+50-58
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
1+
use ark_ec::{AffineCurve, ProjectiveCurve};
2+
use ark_ff::{BigInteger, BitIteratorLE, Field, One, PrimeField, UniformRand, Zero};
3+
use array_init::array_init;
14
use colored::Colorize;
25
use commitment_dlog::{
3-
commitment::{b_poly_coefficients, ceil_log2, CommitmentCurve},
6+
commitment::CommitmentCurve,
47
srs::{endos, SRS},
58
};
6-
use ark_ec::{AffineCurve, ProjectiveCurve};
7-
use ark_ff::{BigInteger, Field, PrimeField, BitIteratorLE, UniformRand, Zero, One};
8-
use ark_poly::{univariate::DensePolynomial, Radix2EvaluationDomain as D, EvaluationDomain};
9-
use plonk_15_wires_circuits::{
10-
polynomials::varbasemul,
11-
gate::{CircuitGate, GateType, LookupInfo, LookupsUsed},
12-
expr::{PolishToken, Constants, Expr, Column, Linearization},
13-
gates::poseidon::ROUNDS_PER_ROW,
14-
nolookup::constraints::{zk_w3, ConstraintSystem},
15-
nolookup::scalars::{ProofEvaluations, LookupEvaluations},
16-
wires::*,
17-
};
9+
use groupmap::GroupMap;
1810
use mina_curves::pasta::{
19-
fp::{Fp as F},
20-
pallas::{Affine as Other, Projective as OtherProjective},
11+
fp::Fp as F,
12+
pallas::Affine as Other,
2113
vesta::{Affine, VestaParameters},
2214
};
23-
use plonk_15_wires_protocol_dlog::{
24-
index::{Index},
25-
prover::ProverProof,
26-
};
27-
use rand::{rngs::StdRng, SeedableRng};
28-
use array_init::array_init;
29-
use std::fmt::{Formatter, Display};
30-
use groupmap::GroupMap;
3115
use oracle::{
32-
poseidon::{ArithmeticSponge, PlonkSpongeConstants15W, Sponge, SpongeConstants},
16+
poseidon::PlonkSpongeConstants15W,
3317
sponge::{DefaultFqSponge, DefaultFrSponge},
3418
};
19+
use plonk_15_wires_circuits::{
20+
gate::{CircuitGate, GateType},
21+
nolookup::constraints::ConstraintSystem,
22+
polynomials::varbasemul,
23+
wires::*,
24+
};
25+
use plonk_15_wires_protocol_dlog::{index::Index, prover::ProverProof};
26+
use rand::{rngs::StdRng, SeedableRng};
3527
use std::{rc::Rc, time::Instant};
3628

3729
const PUBLIC: usize = 0;
@@ -55,24 +47,21 @@ fn varbase_mul_test() {
5547

5648
for i in 0..(chunks * num_scalars) {
5749
let row = 2 * i;
58-
gates.push(
59-
CircuitGate {
60-
row,
61-
typ: GateType::Vbmul,
62-
wires: Wire::new(row),
63-
c: vec![],
64-
});
65-
gates.push(
66-
CircuitGate {
67-
row: row + 1,
68-
typ: GateType::Zero,
69-
wires: Wire::new(row + 1),
70-
c: vec![]
71-
});
50+
gates.push(CircuitGate {
51+
row,
52+
typ: GateType::Vbmul,
53+
wires: Wire::new(row),
54+
c: vec![],
55+
});
56+
gates.push(CircuitGate {
57+
row: row + 1,
58+
typ: GateType::Zero,
59+
wires: Wire::new(row + 1),
60+
c: vec![],
61+
});
7262
}
7363

74-
let cs = ConstraintSystem::<F>::create(
75-
gates, vec![], fp_sponge_params, PUBLIC).unwrap();
64+
let cs = ConstraintSystem::<F>::create(gates, vec![], fp_sponge_params, PUBLIC).unwrap();
7665
let n = cs.domain.d1.size as usize;
7766

7867
let mut srs = SRS::create(cs.domain.d1.size as usize);
@@ -98,41 +87,44 @@ fn varbase_mul_test() {
9887
for i in 0..num_scalars {
9988
let x = F::rand(rng);
10089
let bits_lsb: Vec<_> = BitIteratorLE::new(x.into_repr()).take(num_bits).collect();
101-
let x_ = <Other as AffineCurve>::ScalarField::from_repr(<F as PrimeField>::BigInt::from_bits_le(&bits_lsb[..])).unwrap();
90+
let x_ = <Other as AffineCurve>::ScalarField::from_repr(
91+
<F as PrimeField>::BigInt::from_bits_le(&bits_lsb[..]),
92+
)
93+
.unwrap();
10294

10395
let base = Other::prime_subgroup_generator();
10496
let g = Other::prime_subgroup_generator().into_projective();
10597
let acc = (g + g).into_affine();
10698
let acc = (acc.x, acc.y);
10799

108-
let bits_msb: Vec<_> =
109-
bits_lsb.iter().take(num_bits).map(|x| *x).rev().collect();
100+
let bits_msb: Vec<_> = bits_lsb.iter().take(num_bits).map(|x| *x).rev().collect();
110101

111-
let res =
112-
varbasemul::witness(
113-
&mut witness,
114-
i * rows_per_scalar,
115-
(base.x, base.y),
116-
&bits_msb,
117-
acc);
102+
let res = varbasemul::witness(
103+
&mut witness,
104+
i * rows_per_scalar,
105+
(base.x, base.y),
106+
&bits_msb,
107+
acc,
108+
);
118109

119110
let shift = <Other as AffineCurve>::ScalarField::from(2).pow(&[(bits_msb.len()) as u64]);
120-
let expected =
121-
g.mul((<Other as AffineCurve>::ScalarField::one() + shift + x_.double()).into_repr())
111+
let expected = g
112+
.mul((<Other as AffineCurve>::ScalarField::one() + shift + x_.double()).into_repr())
122113
.into_affine();
123114

124115
assert_eq!(x_.into_repr(), res.n.into_repr());
125116
assert_eq!((expected.x, expected.y), res.acc);
126117
}
127-
println!("{}{:?}", "Witness generation time: ".yellow(), start.elapsed());
118+
println!(
119+
"{}{:?}",
120+
"Witness generation time: ".yellow(),
121+
start.elapsed()
122+
);
128123

129124
let start = Instant::now();
130125
let proof =
131-
ProverProof::create::<BaseSponge, ScalarSponge>(
132-
&group_map,
133-
&witness,
134-
&index,
135-
vec![]).unwrap();
126+
ProverProof::create::<BaseSponge, ScalarSponge>(&group_map, &witness, &index, vec![])
127+
.unwrap();
136128
println!("{}{:?}", "Prover time: ".yellow(), start.elapsed());
137129

138130
let batch: Vec<_> = vec![(&verifier_index, &lgr_comms, &proof)];

0 commit comments

Comments
 (0)