Skip to content
This repository was archived by the owner on Apr 9, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 0 additions & 12 deletions acir/src/circuit/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ pub enum Directive {
bits: Vec<Witness>, // control bits of the network which permutes the inputs into its sorted version
sort_by: Vec<u32>, // specify primary index to sort by, then the secondary,... For instance, if tuple is 2 and sort_by is [1,0], then a=[(a0,b0),..] is sorted by bi and then ai.
},
Log(LogInfo),
}

impl Directive {
Expand All @@ -49,17 +48,6 @@ impl Directive {
Directive::Quotient(_) => "quotient",
Directive::ToLeRadix { .. } => "to_le_radix",
Directive::PermutationSort { .. } => "permutation_sort",
Directive::Log { .. } => "log",
}
}
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
// If values are compile time and/or known during
// evaluation, we can form an output string during ACIR generation.
// Otherwise, we must store witnesses whose values will
// be fetched during the PWG stage.
pub enum LogInfo {
FinalizedOutput(String),
WitnessOutput(Vec<Witness>),
}
11 changes: 1 addition & 10 deletions acir/src/circuit/opcodes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
brillig::Brillig,
directives::{Directive, LogInfo, QuotientDirective},
directives::{Directive, QuotientDirective},
};
use crate::native_types::{Expression, Witness};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -143,15 +143,6 @@ impl std::fmt::Display for Opcode {
bits.last().unwrap().witness_index(),
)
}
Opcode::Directive(Directive::Log(info)) => match info {
LogInfo::FinalizedOutput(output_string) => write!(f, "Log: {output_string}"),
LogInfo::WitnessOutput(witnesses) => write!(
f,
"Log: _{}..._{}",
witnesses.first().unwrap().witness_index(),
witnesses.last().unwrap().witness_index()
),
},
Opcode::Brillig(brillig) => {
write!(f, "BRILLIG: ")?;
writeln!(f, "inputs: {:?}", brillig.inputs)?;
Expand Down
1 change: 0 additions & 1 deletion acvm/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ pub fn compile(
transformer.mark_solvable(*witness);
}
}
Directive::Log(_) => (),
}
new_acir_opcode_positions.push(acir_opcode_positions[index]);
transformed_gates.push(opcode.clone());
Expand Down
50 changes: 1 addition & 49 deletions acvm/src/pwg/directives/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::cmp::Ordering;

use acir::{
circuit::directives::{Directive, LogInfo, QuotientDirective},
circuit::directives::{Directive, QuotientDirective},
native_types::WitnessMap,
FieldElement,
};
Expand Down Expand Up @@ -123,55 +123,7 @@ pub(super) fn solve_directives(
}
Ok(())
}
Directive::Log(info) => {
let witnesses = match info {
LogInfo::FinalizedOutput(output_string) => {
println!("{output_string}");
return Ok(());
}
LogInfo::WitnessOutput(witnesses) => witnesses,
};

if witnesses.len() == 1 {
let witness = &witnesses[0];
let log_value = witness_to_value(initial_witness, *witness)?;
println!("{}", format_field_string(*log_value));
return Ok(());
}

// If multiple witnesses are to be fetched for a log directive,
// it assumed that an array is meant to be printed to standard output
//
// Collect all field element values corresponding to the given witness indices
// and convert them to hex strings.
let mut elements_as_hex = Vec::with_capacity(witnesses.len());
for witness in witnesses {
let element = witness_to_value(initial_witness, *witness)?;
elements_as_hex.push(format_field_string(*element));
}

// Join all of the hex strings using a comma
let comma_separated_elements = elements_as_hex.join(", ");

let output_witnesses_string = "[".to_owned() + &comma_separated_elements + "]";

println!("{output_witnesses_string}");

Ok(())
}
}
}

/// This trims any leading zeroes.
/// A singular '0' will be prepended as well if the trimmed string has an odd length.
/// A hex string's length needs to be even to decode into bytes, as two digits correspond to
/// one byte.
fn format_field_string(field: FieldElement) -> String {
let mut trimmed_field = field.to_hex().trim_start_matches('0').to_owned();
if trimmed_field.len() % 2 != 0 {
trimmed_field = "0".to_owned() + &trimmed_field
}
"0x".to_owned() + &trimmed_field
}

#[cfg(test)]
Expand Down