Skip to content

Commit 473e2af

Browse files
Removed the pairing chips, added fill_dummy_row to TraceStep, other minor improvements
1 parent 0d37f5d commit 473e2af

File tree

28 files changed

+92
-2348
lines changed

28 files changed

+92
-2348
lines changed

crates/circuits/mod-builder/src/core_chip.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use itertools::Itertools;
22
use num_bigint::BigUint;
3+
use num_traits::Zero;
34
use openvm_circuit::{
45
arch::{
56
AdapterAirContext, AdapterExecutorE1, AdapterTraceStep, DynAdapterInterface, DynArray,
@@ -283,6 +284,20 @@ where
283284
let (adapter_row, _) = row.split_at_mut(A::WIDTH);
284285
self.adapter.fill_trace_row(mem_helper, (), adapter_row);
285286
}
287+
288+
// We will be setting is_valid = 0. That forces all flags be 0 (otherwise setup will be -1).
289+
// We generate a dummy row with all flags set to 0, then we set is_valid = 0.
290+
fn fill_dummy_trace_row(&self, _mem_helper: &MemoryAuxColsFactory<F>, row: &mut [F]) {
291+
let inputs: Vec<BigUint> = vec![BigUint::zero(); self.num_inputs()];
292+
let flags: Vec<bool> = vec![false; self.num_flags()];
293+
let core_row = &mut row[A::WIDTH..];
294+
// We **do not** want this trace row to update the range checker
295+
// so we must create a temporary range checker
296+
let tmp_range_checker = SharedVariableRangeCheckerChip::new(self.range_checker.bus());
297+
self.expr
298+
.generate_subrow((tmp_range_checker.as_ref(), inputs, flags), core_row);
299+
core_row[0] = F::ZERO; // is_valid = 0
300+
}
286301
}
287302

288303
impl<F, A> StepExecutorE1<F> for FieldExpressionStep<A>
@@ -321,7 +336,7 @@ fn run_field_expression<F: PrimeField32, A>(
321336

322337
assert_eq!(data.len(), step.num_inputs() * field_element_limbs);
323338

324-
let mut inputs = vec![];
339+
let mut inputs = Vec::with_capacity(step.num_inputs());
325340
for i in 0..step.num_inputs() {
326341
let start = i * field_element_limbs;
327342
let end = start + field_element_limbs;

crates/vm/src/arch/integration_api.rs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,26 @@ pub trait TraceStep<F, CTX> {
172172
/// [`TraceStep::execute`], so the `trace` should already contain context necessary to
173173
/// fill in the rest of it.
174174
// TODO(ayush): come up with a better abstraction for chips that fill a dynamic number of rows
175-
fn fill_trace(&self, mem_helper: &MemoryAuxColsFactory<F>, trace: &mut [F], width: usize)
176-
where
175+
fn fill_trace(
176+
&self,
177+
mem_helper: &MemoryAuxColsFactory<F>,
178+
trace: &mut [F],
179+
width: usize,
180+
rows_used: usize,
181+
) where
177182
Self: Send + Sync,
178183
F: Send + Sync,
179184
{
180-
trace.par_chunks_exact_mut(width).for_each(|row_slice| {
181-
self.fill_trace_row(mem_helper, row_slice);
182-
});
185+
trace[..rows_used * width]
186+
.par_chunks_exact_mut(width)
187+
.for_each(|row_slice| {
188+
self.fill_trace_row(mem_helper, row_slice);
189+
});
190+
trace[rows_used * width..]
191+
.par_chunks_exact_mut(width)
192+
.for_each(|row_slice| {
193+
self.fill_dummy_trace_row(mem_helper, row_slice);
194+
});
183195
}
184196

185197
/// Populates `row_slice`. This function will always be called after
@@ -192,6 +204,13 @@ pub trait TraceStep<F, CTX> {
192204
unreachable!("fill_trace_row is not implemented")
193205
}
194206

207+
/// Populates `row_slice`. This function will be called on dummy rows.
208+
/// By default the trace is padded with empty (all 0) rows to make the height a power of 2.
209+
///
210+
/// The provided `row_slice` will have length equal to the width of the AIR.
211+
fn fill_dummy_trace_row(&self, mem_helper: &MemoryAuxColsFactory<F>, row_slice: &mut [F]) {
212+
// By default, the row is filled with zeroes
213+
}
195214
/// Returns a list of public values to publish.
196215
fn generate_public_values(&self) -> Vec<F> {
197216
vec![]
@@ -292,14 +311,8 @@ where
292311
assert!(height.checked_mul(self.width).unwrap() <= self.trace_buffer.len());
293312
self.trace_buffer.truncate(height * self.width);
294313
let mem_helper = self.mem_helper.as_borrowed();
295-
// This zip only goes through used rows.
296-
// TODO: check if zero-init assumption changes
297-
// The padding(=dummy) rows between rows_used..height are ASSUMED to be filled with zeros.
298-
self.step.fill_trace(
299-
&mem_helper,
300-
&mut self.trace_buffer[..rows_used * self.width],
301-
self.width,
302-
);
314+
self.step
315+
.fill_trace(&mem_helper, &mut self.trace_buffer, self.width, rows_used);
303316
drop(self.mem_helper);
304317
let trace = RowMajorMatrix::new(self.trace_buffer, self.width);
305318
// self.inner.finalize(&mut trace, num_records);

extensions/ecc/circuit/src/weierstrass_chip/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ fn test_p256_double() {
290290
chip.0.step.offset + Rv32WeierstrassOpcode::EC_DOUBLE as usize,
291291
);
292292

293+
tester.execute(&mut chip, &instruction);
294+
// Adding another row to make sure there are dummy rows, and that the dummy row constraints are satisfied
293295
tester.execute(&mut chip, &instruction);
294296
let tester = tester.build().load(chip).load(bitwise_chip).finalize();
295297

extensions/pairing/circuit/src/fp12_chip/add.rs

Lines changed: 0 additions & 20 deletions
This file was deleted.

extensions/pairing/circuit/src/fp12_chip/mod.rs

Lines changed: 0 additions & 44 deletions
This file was deleted.

extensions/pairing/circuit/src/fp12_chip/mul.rs

Lines changed: 0 additions & 204 deletions
This file was deleted.

0 commit comments

Comments
 (0)