Skip to content

Commit 816e8c7

Browse files
authored
Enable Bus in tests (#2289)
This PR uses `LinkerMode::Bus` in all tests which: - Are on Goldilocks or BN254 (the bus is not implemented for smaller fields), AND - Are tested with the mock prover or Plonky3 (while Halo2 does support the bus in principle, its runtime is exponential, because it inlines intermediate polynomials) This is true for most tests. Doing so, I came across a few bugs. I added comments for them below.
1 parent aff92d0 commit 816e8c7

File tree

11 files changed

+153
-110
lines changed

11 files changed

+153
-110
lines changed

ast/src/parsed/asm.rs

+10
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ impl SymbolPath {
191191
pub fn into_parts(self) -> impl DoubleEndedIterator + ExactSizeIterator<Item = Part> {
192192
self.parts.into_iter()
193193
}
194+
195+
pub fn is_std(&self) -> bool {
196+
self.parts
197+
.first()
198+
.map(|p| match p {
199+
Part::Named(n) => n == "std",
200+
Part::Super => false,
201+
})
202+
.unwrap_or(false)
203+
}
194204
}
195205

196206
impl FromStr for SymbolPath {

executor/src/witgen/jit/witgen_inference.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use itertools::Itertools;
55
use powdr_ast::analyzed::{
66
AlgebraicBinaryOperation, AlgebraicBinaryOperator, AlgebraicExpression as Expression,
77
AlgebraicReference, AlgebraicUnaryOperation, AlgebraicUnaryOperator, Identity, LookupIdentity,
8-
PermutationIdentity, PhantomBusInteractionIdentity, PhantomLookupIdentity,
9-
PhantomPermutationIdentity, PolynomialIdentity, PolynomialType,
8+
PermutationIdentity, PhantomLookupIdentity, PhantomPermutationIdentity, PolynomialIdentity,
9+
PolynomialType,
1010
};
1111
use powdr_number::FieldElement;
1212

@@ -86,12 +86,8 @@ impl<'a, T: FieldElement, FixedEval: FixedEvaluator<T>> WitgenInference<'a, T, F
8686
&left.expressions,
8787
row_offset,
8888
),
89-
Identity::PhantomBusInteraction(PhantomBusInteractionIdentity {
90-
id,
91-
multiplicity,
92-
tuple,
93-
..
94-
}) => self.process_call(can_process, *id, multiplicity, &tuple.0, row_offset),
89+
// TODO(bus_interaction)
90+
Identity::PhantomBusInteraction(_) => ProcessResult::empty(),
9591
Identity::Connect(_) => ProcessResult::empty(),
9692
};
9793
self.ingest_effects(result)

executor/src/witgen/machines/block_machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ impl<'a, T: FieldElement> BlockMachine<'a, T> {
450450

451451
let updates = updates.report_side_effect();
452452

453-
let global_latch_row_index = self.data.len() - 1 - self.block_size + self.latch_row;
453+
let global_latch_row_index = self.data.len() - self.block_size + self.latch_row;
454454
self.multiplicity_counter
455455
.increment_at_row(identity_id, global_latch_row_index);
456456

executor/src/witgen/machines/dynamic_machine.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ impl<'a, T: FieldElement> Machine<'a, T> for DynamicMachine<'a, T> {
9696
self.data.extend(updated_data.block);
9797
self.publics.extend(updated_data.publics);
9898

99-
let latch_row = self.data.len() - 1;
99+
// The block we just added contains the first row of the next block,
100+
// so the latch row is the second-to-last row.
101+
let latch_row = self.data.len() - 2;
100102
self.multiplicity_counter
101103
.increment_at_row(identity_id, latch_row);
102104

linker/src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,11 @@ fn namespaced_expression(namespace: String, mut expr: Expression) -> Expression
360360
expr.visit_expressions_mut(
361361
&mut |expr| {
362362
if let Expression::Reference(_, refs) = expr {
363-
refs.path = SymbolPath::from_parts(
364-
once(Part::Named(namespace.clone())).chain(refs.path.clone().into_parts()),
365-
);
363+
if !refs.path.is_std() {
364+
refs.path = SymbolPath::from_parts(
365+
once(Part::Named(namespace.clone())).chain(refs.path.clone().into_parts()),
366+
);
367+
}
366368
}
367369
ControlFlow::Continue::<(), _>(())
368370
},

pipeline/src/test_util.rs

+34-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use powdr_ast::analyzed::Analyzed;
2+
use powdr_linker::{DegreeMode, LinkerMode, LinkerParams};
23
use powdr_number::{
34
BabyBearField, BigInt, Bn254Field, FieldElement, GoldilocksField, KoalaBearField,
45
};
@@ -22,9 +23,17 @@ pub fn resolve_test_file(file_name: &str) -> PathBuf {
2223
/// Makes a new pipeline for the given file. All steps until witness generation are
2324
/// already computed, so that the test can branch off from there, without having to re-compute
2425
/// these steps.
25-
pub fn make_simple_prepared_pipeline<T: FieldElement>(file_name: &str) -> Pipeline<T> {
26+
pub fn make_simple_prepared_pipeline<T: FieldElement>(
27+
file_name: &str,
28+
linker_mode: LinkerMode,
29+
) -> Pipeline<T> {
30+
let linker_params = LinkerParams {
31+
mode: linker_mode,
32+
degree_mode: DegreeMode::Vadcop,
33+
};
2634
let mut pipeline = Pipeline::default()
2735
.with_tmp_output()
36+
.with_linker_params(linker_params)
2837
.from_file(resolve_test_file(file_name));
2938
pipeline.compute_witness().unwrap();
3039
pipeline
@@ -37,9 +46,15 @@ pub fn make_prepared_pipeline<T: FieldElement>(
3746
file_name: &str,
3847
inputs: Vec<T>,
3948
external_witness_values: Vec<(String, Vec<T>)>,
49+
linker_mode: LinkerMode,
4050
) -> Pipeline<T> {
51+
let linker_params = LinkerParams {
52+
mode: linker_mode,
53+
degree_mode: DegreeMode::Vadcop,
54+
};
4155
let mut pipeline = Pipeline::default()
4256
.with_tmp_output()
57+
.with_linker_params(linker_params)
4358
.from_file(resolve_test_file(file_name))
4459
.with_prover_inputs(inputs)
4560
.add_external_witness_values(external_witness_values);
@@ -62,27 +77,37 @@ pub fn regular_test_small_field(file_name: &str, inputs: &[i32]) {
6277
/// Tests witness generation, mock prover, pilcom and plonky3 with BabyBear.
6378
pub fn regular_test_bb(file_name: &str, inputs: &[i32]) {
6479
let inputs_bb = inputs.iter().map(|x| BabyBearField::from(*x)).collect();
65-
let pipeline_bb = make_prepared_pipeline(file_name, inputs_bb, vec![]);
80+
// LinkerMode::Native because the bus is not implemented for small fields
81+
let pipeline_bb = make_prepared_pipeline(file_name, inputs_bb, vec![], LinkerMode::Native);
6682
test_mock_backend(pipeline_bb.clone());
6783
test_plonky3_pipeline(pipeline_bb);
6884
}
6985

7086
/// Tests witness generation, mock prover, pilcom and plonky3 with BabyBear and KoalaBear.
7187
pub fn regular_test_kb(file_name: &str, inputs: &[i32]) {
7288
let inputs_kb = inputs.iter().map(|x| KoalaBearField::from(*x)).collect();
73-
let pipeline_kb = make_prepared_pipeline(file_name, inputs_kb, vec![]);
89+
// LinkerMode::Native because the bus is not implemented for small fields
90+
let pipeline_kb = make_prepared_pipeline(file_name, inputs_kb, vec![], LinkerMode::Native);
7491
test_mock_backend(pipeline_kb.clone());
7592
test_plonky3_pipeline(pipeline_kb);
7693
}
7794

7895
/// Tests witness generation, mock prover, pilcom and plonky3 with Goldilocks.
7996
pub fn regular_test_gl(file_name: &str, inputs: &[i32]) {
80-
let inputs_gl = inputs.iter().map(|x| GoldilocksField::from(*x)).collect();
81-
let pipeline_gl = make_prepared_pipeline(file_name, inputs_gl, vec![]);
82-
83-
test_mock_backend(pipeline_gl.clone());
84-
run_pilcom_with_backend_variant(pipeline_gl.clone(), BackendVariant::Composite).unwrap();
85-
test_plonky3_pipeline(pipeline_gl);
97+
let inputs_gl = inputs
98+
.iter()
99+
.map(|x| GoldilocksField::from(*x))
100+
.collect::<Vec<_>>();
101+
102+
let pipeline_gl_native =
103+
make_prepared_pipeline(file_name, inputs_gl.clone(), vec![], LinkerMode::Native);
104+
test_mock_backend(pipeline_gl_native.clone());
105+
run_pilcom_with_backend_variant(pipeline_gl_native, BackendVariant::Composite).unwrap();
106+
107+
let pipeline_gl_bus =
108+
make_prepared_pipeline(file_name, inputs_gl.clone(), vec![], LinkerMode::Bus);
109+
test_mock_backend(pipeline_gl_bus.clone());
110+
test_plonky3_pipeline(pipeline_gl_bus);
86111
}
87112

88113
pub fn test_pilcom(pipeline: Pipeline<GoldilocksField>) {

0 commit comments

Comments
 (0)