Skip to content

Commit 6c4dd0c

Browse files
authored
chore(acir): Unify how we display witness indices (#8192)
1 parent 3e3e302 commit 6c4dd0c

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

  • acvm-repo/acir/src/circuit

acvm-repo/acir/src/circuit/mod.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,13 @@ impl<F: AcirField + for<'a> Deserialize<'a>> Program<F> {
323323

324324
impl<F: AcirField> std::fmt::Display for Circuit<F> {
325325
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
326-
writeln!(f, "current witness index : {}", self.current_witness_index)?;
326+
writeln!(f, "current witness index : _{}", self.current_witness_index)?;
327327

328328
let write_witness_indices =
329329
|f: &mut std::fmt::Formatter<'_>, indices: &[u32]| -> Result<(), std::fmt::Error> {
330330
write!(f, "[")?;
331331
for (index, witness_index) in indices.iter().enumerate() {
332-
write!(f, "{witness_index}")?;
332+
write!(f, "_{witness_index}")?;
333333
if index != indices.len() - 1 {
334334
write!(f, ", ")?;
335335
}
@@ -509,6 +509,44 @@ mod tests {
509509
assert!(deserialization_result.is_err());
510510
}
511511

512+
#[test]
513+
fn circuit_display_snapshot() {
514+
let circuit = Circuit {
515+
current_witness_index: 3,
516+
expression_width: ExpressionWidth::Unbounded,
517+
opcodes: vec![
518+
Opcode::AssertZero(crate::native_types::Expression {
519+
mul_terms: vec![],
520+
linear_combinations: vec![(FieldElement::from(2u128), Witness(1))],
521+
q_c: FieldElement::from(8u128),
522+
}),
523+
range_opcode(),
524+
and_opcode(),
525+
keccakf1600_opcode(),
526+
],
527+
private_parameters: BTreeSet::new(),
528+
public_parameters: PublicInputs(BTreeSet::from_iter(vec![Witness(2)])),
529+
return_values: PublicInputs(BTreeSet::from_iter(vec![Witness(2)])),
530+
assert_messages: Default::default(),
531+
};
532+
533+
// We want to make sure that we witness indices are displayed in a unified format.
534+
// All witnesses are expected to be formatted as `_{witness_index}`.
535+
insta::assert_snapshot!(
536+
circuit.to_string(),
537+
@r"
538+
current witness index : _3
539+
private parameters indices : []
540+
public parameters indices : [_2]
541+
return value indices : [_2]
542+
EXPR [ (2, _1) 8 ]
543+
BLACKBOX::RANGE [(_1, 8)] []
544+
BLACKBOX::AND [(_1, 4), (_2, 4)] [_3]
545+
BLACKBOX::KECCAKF1600 [(_1, 8), (_2, 8), (_3, 8), (_4, 8), (_5, 8), (_6, 8), (_7, 8), (_8, 8), (_9, 8), (_10, 8), (_11, 8), (_12, 8), (_13, 8), (_14, 8), (_15, 8), (_16, 8), (_17, 8), (_18, 8), (_19, 8), (_20, 8), (_21, 8), (_22, 8), (_23, 8), (_24, 8), (_25, 8)] [_26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50]
546+
"
547+
);
548+
}
549+
512550
/// Property based testing for serialization
513551
mod props {
514552
use acir_field::FieldElement;

0 commit comments

Comments
 (0)