Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions acvm-repo/acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,6 @@ impl<F: AcirField + for<'a> Deserialize<'a>> Program<F> {

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

let write_witness_indices =
|f: &mut std::fmt::Formatter<'_>, indices: &[u32]| -> Result<(), std::fmt::Error> {
write!(f, "[")?;
Expand Down Expand Up @@ -540,14 +538,13 @@ mod tests {
insta::assert_snapshot!(
circuit.to_string(),
@r"
current witness: w3
private parameters: []
public parameters: [w2]
return values: [w2]
EXPR 0 = 2*w1 + 8
BLACKBOX::RANGE [w1]:8 bits []
BLACKBOX::AND [w1, w2]:4 bits [w3]
BLACKBOX::KECCAKF1600 [w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15, w16, w17, w18, w19, w20, w21, w22, w23, w24, w25] [w26, w27, w28, w29, w30, w31, w32, w33, w34, w35, w36, w37, w38, w39, w40, w41, w42, w43, w44, w45, w46, w47, w48, w49, w50]
ASSERT 0 = 2*w1 + 8
BLACKBOX::RANGE input: w1, bits: 8
BLACKBOX::AND inputs: [w1, w2], bits: 4, output: w3
BLACKBOX::KECCAKF1600 inputs: [w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14, w15, w16, w17, w18, w19, w20, w21, w22, w23, w24, w25], outputs: [w26, w27, w28, w29, w30, w31, w32, w33, w34, w35, w36, w37, w38, w39, w40, w41, w42, w43, w44, w45, w46, w47, w48, w49, w50]
"
);
}
Expand Down
24 changes: 11 additions & 13 deletions acvm-repo/acir/src/circuit/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,16 @@ impl<F: AcirField> std::fmt::Display for Opcode<F> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Opcode::AssertZero(expr) => {
write!(f, "EXPR ")?;
write!(f, "ASSERT ")?;
display_expression(expr, true, f)
}
Opcode::BlackBoxFuncCall(g) => g.fmt(f),
Opcode::MemoryOp { block_id, op } => {
write!(f, "MEM ")?;

let is_read = op.operation.is_zero();
if is_read {
write!(f, "id: {}, read at: {}, value: {}", block_id.0, op.index, op.value)
write!(f, "READ {} = b{}[{}]", op.value, block_id.0, op.index)
Comment thread
asterite marked this conversation as resolved.
} else {
write!(f, "id: {}, write: {} at: {}", block_id.0, op.value, op.index)
write!(f, "WRITE b{}[{}] = {}", block_id.0, op.index, op.value)
}
}
Opcode::MemoryInit { block_id, init, block_type: databus } => {
Expand All @@ -169,14 +167,14 @@ impl<F: AcirField> std::fmt::Display for Opcode<F> {
}
let witnesses =
init.iter().map(|w| format!("{w}")).collect::<Vec<String>>().join(", ");
write!(f, "id: {}, len: {}, witnesses: [{witnesses}]", block_id.0, init.len())
write!(f, "b{} = [{witnesses}]", block_id.0)
}
// We keep the display for a BrilligCall and circuit Call separate as they
// are distinct in their functionality and we should maintain this separation for debugging.
Opcode::BrilligCall { id, inputs, outputs, predicate } => {
write!(f, "BRILLIG CALL func {id}: ")?;
write!(f, "BRILLIG CALL func: {id}, ")?;
if let Some(pred) = predicate {
writeln!(f, "PREDICATE: {pred}")?;
write!(f, "predicate: {pred}, ")?;
}

let inputs = inputs
Expand All @@ -194,9 +192,9 @@ impl<F: AcirField> std::fmt::Display for Opcode<F> {
write!(f, "outputs: [{outputs}]")
}
Opcode::Call { id, inputs, outputs, predicate } => {
write!(f, "CALL func {id}: ")?;
write!(f, "CALL func: {id}, ")?;
if let Some(pred) = predicate {
writeln!(f, "PREDICATE: {pred}")?;
write!(f, "predicate: {pred}, ")?;
}
let inputs =
inputs.iter().map(|w| format!("{w}")).collect::<Vec<String>>().join(", ");
Expand Down Expand Up @@ -237,7 +235,7 @@ mod tests {

insta::assert_snapshot!(
mem_init.to_string(),
@"INIT id: 42, len: 10, witnesses: [w0, w1, w2, w3, w4, w5, w6, w7, w8, w9]"
@"INIT b42 = [w0, w1, w2, w3, w4, w5, w6, w7, w8, w9]"
);
}

Expand All @@ -252,7 +250,7 @@ mod tests {

insta::assert_snapshot!(
xor.to_string(),
@"BLACKBOX::XOR [w0, w1]:32 bits [w3]"
@"BLACKBOX::XOR inputs: [w0, w1], bits: 32, output: w3"
);
}

Expand All @@ -265,7 +263,7 @@ mod tests {

insta::assert_snapshot!(
range.to_string(),
@"BLACKBOX::RANGE [w0]:32 bits []"
@"BLACKBOX::RANGE input: w0, bits: 32"
);
}
}
41 changes: 22 additions & 19 deletions acvm-repo/acir/src/circuit/opcodes/black_box_function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,31 +434,34 @@ impl<F: std::fmt::Display + Copy> std::fmt::Display for BlackBoxFuncCall<F> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let uppercase_name = self.name().to_uppercase();
write!(f, "BLACKBOX::{uppercase_name} ")?;
// INPUTS

let inputs_str = &self
.get_inputs_vec()
.iter()
.map(|i| i.to_string())
.collect::<Vec<String>>()
.join(", ");
// inputs
let inputs = &self.get_inputs_vec();
let inputs_str = inputs.iter().map(|i| i.to_string()).collect::<Vec<String>>().join(", ");
if inputs.len() == 1 {
write!(f, "input: {inputs_str}")?;
} else {
write!(f, "inputs: [{inputs_str}]")?;
}

write!(f, "[{inputs_str}]")?;
// bits
if let Some(bit_size) = self.bit_size() {
write!(f, ":{bit_size} bits")?;
write!(f, ", bits: {bit_size}")?;
}
write!(f, " ")?;

// OUTPUTS

let outputs_str = &self
.get_outputs_vec()
.iter()
.map(ToString::to_string)
.collect::<Vec<String>>()
.join(", ");
// outputs
let outputs = &self.get_outputs_vec();
if !outputs.is_empty() {
let outputs_str =
outputs.iter().map(ToString::to_string).collect::<Vec<String>>().join(", ");
if outputs.len() == 1 {
write!(f, ", output: {outputs_str}")?;
} else {
write!(f, ", outputs: [{outputs_str}]")?;
}
}

write!(f, "[{outputs_str}]")
Ok(())
}
}

Expand Down
11 changes: 8 additions & 3 deletions acvm-repo/acir/src/parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,21 @@ impl<'a> Lexer<'a> {
}
'*' => self.single_char_token(Token::Star),
'=' => self.single_char_token(Token::Equal),
'w' if self.peek_char().is_some_and(|char| char.is_ascii_digit()) => {
'b' | 'w' if self.peek_char().is_some_and(|char| char.is_ascii_digit()) => {
let start = self.position;

// Witness token format is 'w' followed by digits
// Witness token format is 'w' followed by digits.
// Block token format is 'b' followed by digits.
let digits = self.eat_while(None, |ch| ch.is_ascii_digit());
let end = self.position;

// Parse digits into u32
match digits.parse::<u32>() {
Ok(value) => Ok(Token::Witness(value).into_span(start, end)),
Ok(value) => {
let token =
if ch == 'w' { Token::Witness(value) } else { Token::Block(value) };
Ok(token.into_span(start, end))
}
Err(_) => Err(LexerError::InvalidIntegerLiteral {
span: Span::inclusive(start, end),
found: digits,
Expand Down
Loading
Loading