Skip to content

Commit dd68938

Browse files
Remove evaluation from barycentric circuit assignment. (#1430)
* use computed evaluation value instead of input * remove unused argument --------- Co-authored-by: Rohit Narurkar <[email protected]>
1 parent 39d6bdf commit dd68938

File tree

3 files changed

+60
-58
lines changed

3 files changed

+60
-58
lines changed

aggregator/src/aggregation/barycentric.rs

+60-56
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use num_bigint::{BigInt, Sign};
1818
use std::{iter::successors, sync::LazyLock};
1919

2020
use crate::{
21-
blob::BLOB_WIDTH,
21+
blob::{BLOB_WIDTH, N_BYTES_U256},
2222
constants::{BITS, LIMBS},
2323
};
2424

@@ -103,7 +103,6 @@ impl BarycentricEvaluationConfig {
103103
ctx: &mut Context<Fr>,
104104
blob: &[U256; BLOB_WIDTH],
105105
challenge_digest: U256,
106-
evaluation: U256,
107106
) -> AssignedBarycentricEvaluationConfig {
108107
// some constants for later use.
109108
let one = self.scalar.load_constant(ctx, fe_to_biguint(&Fr::one()));
@@ -180,57 +179,6 @@ impl BarycentricEvaluationConfig {
180179
QuantumCell::Existing(challenge_crt.truncation.limbs[2]),
181180
);
182181

183-
////////////////////////////////////////////////////////////////////////////////////////
184-
////////////////////////////////// PRECHECKS y /////////////////////////////////////////
185-
////////////////////////////////////////////////////////////////////////////////////////
186-
let evaluation_le = self.scalar.range().gate.assign_witnesses(
187-
ctx,
188-
evaluation
189-
.to_le_bytes()
190-
.iter()
191-
.map(|&x| Value::known(Fr::from(x as u64))),
192-
);
193-
let evaluation_scalar = Scalar::from_raw(evaluation.0);
194-
let evaluation_crt = self
195-
.scalar
196-
.load_private(ctx, Value::known(fe_to_biguint(&evaluation_scalar).into()));
197-
let evaluation_limb1 = self.scalar.range().gate.inner_product(
198-
ctx,
199-
evaluation_le[0..11]
200-
.iter()
201-
.map(|&x| QuantumCell::Existing(x)),
202-
powers_of_256[0..11].to_vec(),
203-
);
204-
let evaluation_limb2 = self.scalar.range().gate.inner_product(
205-
ctx,
206-
evaluation_le[11..22]
207-
.iter()
208-
.map(|&x| QuantumCell::Existing(x)),
209-
powers_of_256[0..11].to_vec(),
210-
);
211-
let evaluation_limb3 = self.scalar.range().gate.inner_product(
212-
ctx,
213-
evaluation_le[22..32]
214-
.iter()
215-
.map(|&x| QuantumCell::Existing(x)),
216-
powers_of_256[0..11].to_vec(),
217-
);
218-
self.scalar.range().gate.assert_equal(
219-
ctx,
220-
QuantumCell::Existing(evaluation_limb1),
221-
QuantumCell::Existing(evaluation_crt.truncation.limbs[0]),
222-
);
223-
self.scalar.range().gate.assert_equal(
224-
ctx,
225-
QuantumCell::Existing(evaluation_limb2),
226-
QuantumCell::Existing(evaluation_crt.truncation.limbs[1]),
227-
);
228-
self.scalar.range().gate.assert_equal(
229-
ctx,
230-
QuantumCell::Existing(evaluation_limb3),
231-
QuantumCell::Existing(evaluation_crt.truncation.limbs[2]),
232-
);
233-
234182
////////////////////////////////////////////////////////////////////////////////////////
235183
////////////////////////////// BARYCENTRIC EVALUATION //////////////////////////////////
236184
////////////////////////////////////////////////////////////////////////////////////////
@@ -317,9 +265,65 @@ impl BarycentricEvaluationConfig {
317265
evaluation_computed = self.scalar.mul(ctx, &evaluation_computed, &factor);
318266
evaluation_computed = self.scalar.carry_mod(ctx, &evaluation_computed);
319267

320-
// computed evaluation matches the expected evaluation.
321-
self.scalar
322-
.assert_equal(ctx, &evaluation_computed, &evaluation_crt);
268+
////////////////////////////////////////////////////////////////////////////////////////
269+
////////////////////////////////// PRECHECKS y /////////////////////////////////////////
270+
////////////////////////////////////////////////////////////////////////////////////////
271+
let evaluation_le_bytes = evaluation_computed
272+
.value
273+
.map(|x| {
274+
x.to_bytes_le()
275+
.1
276+
.into_iter()
277+
.chain(std::iter::repeat(0u8))
278+
.map(u64::from)
279+
.map(Fr::from)
280+
.take(N_BYTES_U256)
281+
.collect_vec()
282+
})
283+
.transpose_vec(N_BYTES_U256);
284+
285+
let evaluation_le = self
286+
.scalar
287+
.range()
288+
.gate
289+
.assign_witnesses(ctx, evaluation_le_bytes);
290+
291+
let evaluation_limb1 = self.scalar.range().gate.inner_product(
292+
ctx,
293+
evaluation_le[0..11]
294+
.iter()
295+
.map(|&x| QuantumCell::Existing(x)),
296+
powers_of_256[0..11].to_vec(),
297+
);
298+
let evaluation_limb2 = self.scalar.range().gate.inner_product(
299+
ctx,
300+
evaluation_le[11..22]
301+
.iter()
302+
.map(|&x| QuantumCell::Existing(x)),
303+
powers_of_256[0..11].to_vec(),
304+
);
305+
let evaluation_limb3 = self.scalar.range().gate.inner_product(
306+
ctx,
307+
evaluation_le[22..32]
308+
.iter()
309+
.map(|&x| QuantumCell::Existing(x)),
310+
powers_of_256[0..11].to_vec(),
311+
);
312+
self.scalar.range().gate.assert_equal(
313+
ctx,
314+
QuantumCell::Existing(evaluation_limb1),
315+
QuantumCell::Existing(evaluation_computed.truncation.limbs[0]),
316+
);
317+
self.scalar.range().gate.assert_equal(
318+
ctx,
319+
QuantumCell::Existing(evaluation_limb2),
320+
QuantumCell::Existing(evaluation_computed.truncation.limbs[1]),
321+
);
322+
self.scalar.range().gate.assert_equal(
323+
ctx,
324+
QuantumCell::Existing(evaluation_limb3),
325+
QuantumCell::Existing(evaluation_computed.truncation.limbs[2]),
326+
);
323327

324328
////////////////////////////////////////////////////////////////////////////////////////
325329
////////////////////////////////////// EXPORT //////////////////////////////////////////

aggregator/src/aggregation/circuit.rs

-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ impl<const N_SNARKS: usize> Circuit<Fr> for BatchCircuit<N_SNARKS> {
256256
self.batch_hash
257257
.point_evaluation_assignments
258258
.challenge_digest,
259-
self.batch_hash.point_evaluation_assignments.evaluation,
260259
);
261260

262261
ctx.print_stats(&["barycentric"]);

aggregator/src/tests/blob.rs

-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ impl Circuit<Fr> for BlobCircuit {
149149
&mut ctx,
150150
&point_eval.coefficients,
151151
point_eval.challenge_digest,
152-
point_eval.evaluation,
153152
))
154153
},
155154
)?;

0 commit comments

Comments
 (0)