Skip to content

Commit

Permalink
fix: improve some code parts
Browse files Browse the repository at this point in the history
  • Loading branch information
guorong009 committed Sep 25, 2024
1 parent 5d3701f commit 081a70c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 39 deletions.
62 changes: 31 additions & 31 deletions halo2_frontend/src/dev/cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ mod tests {
let mut offset = 0;
let mut instance_copy = Vec::new();
// First "a" value comes from instance
config.s_instance.enable(&mut region, offset).expect("todo");
config.s_instance.enable(&mut region, offset).unwrap();
let res = region
.assign_advice_from_instance(
|| "",
Expand All @@ -782,19 +782,19 @@ mod tests {
config.a,
offset,
)
.expect("todo");
.unwrap();
// Enable the gate on a few consecutive rows with rotations
let (res, _) = config
.assign_gate(&mut region, &mut offset, Some(res), [0, 3, 4, 1])
.expect("todo");
.unwrap();
instance_copy.push(res.clone());
let (res, _) = config
.assign_gate(&mut region, &mut offset, Some(res), [0, 6, 7, 1])
.expect("todo");
.unwrap();
instance_copy.push(res.clone());
let (res, _) = config
.assign_gate(&mut region, &mut offset, Some(res), [0, 8, 9, 1])
.expect("todo");
.unwrap();
instance_copy.push(res.clone());
let (res, _) = config
.assign_gate(
Expand All @@ -803,61 +803,61 @@ mod tests {
Some(res),
[0, 0xffffffff, 0xdeadbeef, 1],
)
.expect("todo");
.unwrap();
let _ = config
.assign_gate(
&mut region,
&mut offset,
Some(res),
[0, 0xabad1d3a, 0x12345678, 0x42424242],
)
.expect("todo");
.unwrap();
offset += 1;

// Enable the gate on non-consecutive rows with advice-advice copy constraints enabled
let (_, abcd1) = config
.assign_gate(&mut region, &mut offset, None, [5, 2, 1, 1])
.expect("todo");
.unwrap();
offset += 1;
let (_, abcd2) = config
.assign_gate(&mut region, &mut offset, None, [2, 3, 1, 1])
.expect("todo");
.unwrap();
offset += 1;
let (_, abcd3) = config
.assign_gate(&mut region, &mut offset, None, [4, 2, 1, 1])
.expect("todo");
.unwrap();
offset += 1;
region
.constrain_equal(abcd1[1].cell(), abcd2[0].cell())
.expect("todo");
.unwrap();
region
.constrain_equal(abcd2[0].cell(), abcd3[1].cell())
.expect("todo");
.unwrap();
instance_copy.push(abcd1[1].clone());
instance_copy.push(abcd2[0].clone());

// Enable the gate on non-consecutive rows with advice-fixed copy constraints enabled
let (_, abcd1) = config
.assign_gate(&mut region, &mut offset, None, [5, 9, 1, 9])
.expect("todo");
.unwrap();
offset += 1;
let (_, abcd2) = config
.assign_gate(&mut region, &mut offset, None, [2, 9, 1, 1])
.expect("todo");
.unwrap();
offset += 1;
let (_, abcd3) = config
.assign_gate(&mut region, &mut offset, None, [9, 2, 1, 1])
.expect("todo");
.unwrap();
offset += 1;
region
.constrain_equal(abcd1[1].cell(), abcd1[3].cell())
.expect("todo");
.unwrap();
region
.constrain_equal(abcd2[1].cell(), abcd1[3].cell())
.expect("todo");
.unwrap();
region
.constrain_equal(abcd3[0].cell(), abcd1[3].cell())
.expect("todo");
.unwrap();

// Enable a dynamic lookup (powers of two)
let table: Vec<_> =
Expand All @@ -874,31 +874,31 @@ mod tests {
offset,
|| Value::known(F::ONE),
)
.expect("todo");
.unwrap();
region
.assign_fixed(
|| "",
config.s_ltable,
offset,
|| Value::known(F::ONE),
)
.expect("todo");
.unwrap();
let lookup_row0 = Value::known(F::from(lookup_row.0));
let lookup_row1 = Value::known(F::from(lookup_row.1));
region
.assign_advice(|| "", config.a, offset, || lookup_row0)
.expect("todo");
.unwrap();
region
.assign_advice(|| "", config.b, offset, || lookup_row1)
.expect("todo");
.unwrap();
let table_row0 = Value::known(F::from(table_row.0));
let table_row1 = Value::known(F::from(table_row.1));
region
.assign_fixed(|| "", config.d, offset, || table_row0)
.expect("todo");
.unwrap();
region
.assign_advice(|| "", config.c, offset, || table_row1)
.expect("todo");
.unwrap();
offset += 1;
}

Expand All @@ -907,14 +907,14 @@ mod tests {
config.s_rlc.enable(&mut region, offset)?;
let (_, _) = config
.assign_gate(&mut region, &mut offset, None, abcd)
.expect("todo");
.unwrap();
let rlc = challenge.map(|ch| {
let [a, b, ..] = abcd;
F::from(a) + ch * F::from(b)
});
region
.assign_advice(|| "", config.e, offset - 1, || rlc)
.expect("todo");
.unwrap();
offset += 1;
}

Expand All @@ -931,23 +931,23 @@ mod tests {
offset,
|| Value::known(F::ONE),
)
.expect("todo");
.unwrap();
region
.assign_fixed(
|| "",
config.s_stable,
offset,
|| Value::known(F::ONE),
)
.expect("todo");
.unwrap();
let shuffle_row0 = Value::known(F::from(*shuffle_row));
region
.assign_advice(|| "", config.a, offset, || shuffle_row0)
.expect("todo");
.unwrap();
let table_row0 = Value::known(F::from(*table_row));
region
.assign_advice(|| "", config.b, offset, || table_row0)
.expect("todo");
.unwrap();
offset += 1;
}

Expand Down Expand Up @@ -994,7 +994,7 @@ mod tests {
loop {
let (rows, instance_copy) = self
.synthesize_unit(config, &mut layouter, id, unit_id)
.expect("todo");
.unwrap();
if total_rows == 0 {
for (i, instance) in instance_copy.iter().enumerate() {
layouter.constrain_instance(
Expand Down
12 changes: 5 additions & 7 deletions halo2_frontend/src/dev/tfp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,13 +607,11 @@ mod tests {
}
}

// // At the start of your test, enable tracing.
// tracing_subscriber::fmt()
// .with_max_level(tracing::Level::DEBUG)
// .with_ansi(false)
// .without_time()
// .init();

// At the start of your test, enable tracing.
//
// Following setup of `SharedStorage` and `tracing_subscriber::fmt` is just for this test.
// For real tests, you don't need to do this.
// Check the example in the doc of [`TracingFloorPlanner`] for details.
let subscriber = tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.with_ansi(false)
Expand Down
2 changes: 1 addition & 1 deletion halo2_proofs/tests/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ fn test_serialization() {
SingleStrategy<Bn256>,
>(
&verifier_params,
&vk, // pk.get_vk()
&vk,
strategy,
instances.as_slice(),
&mut transcript
Expand Down

0 comments on commit 081a70c

Please sign in to comment.