From 9d718103f12f5f687976c8a1d7f4cd64f561b73a Mon Sep 17 00:00:00 2001 From: ethan-000 Date: Fri, 18 Aug 2023 13:52:03 +0100 Subject: [PATCH] remove directive log --- acir/src/circuit/directives.rs | 12 -------- acir/src/circuit/opcodes.rs | 11 +------- acvm/src/compiler/mod.rs | 1 - acvm/src/pwg/directives/mod.rs | 50 +--------------------------------- 4 files changed, 2 insertions(+), 72 deletions(-) diff --git a/acir/src/circuit/directives.rs b/acir/src/circuit/directives.rs index 2f2dac415..4bcbb11a4 100644 --- a/acir/src/circuit/directives.rs +++ b/acir/src/circuit/directives.rs @@ -39,7 +39,6 @@ pub enum Directive { bits: Vec, // control bits of the network which permutes the inputs into its sorted version sort_by: Vec, // 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 { @@ -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), -} diff --git a/acir/src/circuit/opcodes.rs b/acir/src/circuit/opcodes.rs index ea6b5fac3..6f7b0356d 100644 --- a/acir/src/circuit/opcodes.rs +++ b/acir/src/circuit/opcodes.rs @@ -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}; @@ -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)?; diff --git a/acvm/src/compiler/mod.rs b/acvm/src/compiler/mod.rs index 67c98ec15..9afe18a3f 100644 --- a/acvm/src/compiler/mod.rs +++ b/acvm/src/compiler/mod.rs @@ -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()); diff --git a/acvm/src/pwg/directives/mod.rs b/acvm/src/pwg/directives/mod.rs index e0fc46e11..dc5957266 100644 --- a/acvm/src/pwg/directives/mod.rs +++ b/acvm/src/pwg/directives/mod.rs @@ -1,7 +1,7 @@ use std::cmp::Ordering; use acir::{ - circuit::directives::{Directive, LogInfo, QuotientDirective}, + circuit::directives::{Directive, QuotientDirective}, native_types::WitnessMap, FieldElement, }; @@ -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)]