Skip to content

Commit

Permalink
replace value_of with display
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenfeizhang committed Dec 10, 2024
1 parent 36729e7 commit 90b8381
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 32 deletions.
12 changes: 2 additions & 10 deletions expander_compiler/src/frontend/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub trait BasicAPI<C: Config> {
binary_op!(or);
binary_op!(and);

fn display(&self, _x: impl ToVariableOrValue<C::CircuitField>) {}
fn display(&self, _label: &str, _x: impl ToVariableOrValue<C::CircuitField>) {}
fn div(
&mut self,
x: impl ToVariableOrValue<C::CircuitField>,
Expand Down Expand Up @@ -78,15 +78,7 @@ pub trait UnconstrainedAPI<C: Config> {
binary_op!(unconstrained_bit_xor);
}

// DebugAPI is used for debugging purposes
// Only DebugBuilder will implement functions in this trait, other builders will panic
pub trait DebugAPI<C: Config> {
fn value_of(&self, x: impl ToVariableOrValue<C::CircuitField>) -> C::CircuitField;
}

pub trait RootAPI<C: Config>:
Sized + BasicAPI<C> + UnconstrainedAPI<C> + DebugAPI<C> + 'static
{
pub trait RootAPI<C: Config>: Sized + BasicAPI<C> + UnconstrainedAPI<C> + 'static {
fn memorized_simple_call<F: Fn(&mut Self, &Vec<Variable>) -> Vec<Variable> + 'static>(
&mut self,
f: F,
Expand Down
8 changes: 1 addition & 7 deletions expander_compiler/src/frontend/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
utils::function_id::get_function_id,
};

use super::api::{BasicAPI, DebugAPI, RootAPI, UnconstrainedAPI};
use super::api::{BasicAPI, RootAPI, UnconstrainedAPI};

pub struct Builder<C: Config> {
instructions: Vec<SourceInstruction<C>>,
Expand Down Expand Up @@ -447,12 +447,6 @@ impl<C: Config> RootAPI<C> for RootBuilder<C> {
}
}

impl<C: Config> DebugAPI<C> for RootBuilder<C> {
fn value_of(&self, _x: impl ToVariableOrValue<C::CircuitField>) -> C::CircuitField {
panic!("ValueOf is not supported in non-debug mode");
}
}

impl<C: Config> RootBuilder<C> {
pub fn new(
num_inputs: usize,
Expand Down
12 changes: 3 additions & 9 deletions expander_compiler/src/frontend/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
};

use super::{
api::{BasicAPI, DebugAPI, RootAPI, UnconstrainedAPI},
api::{BasicAPI, RootAPI, UnconstrainedAPI},
builder::{get_variable_id, new_variable, ToVariableOrValue, VariableOrValue},
Variable,
};
Expand All @@ -20,9 +20,9 @@ pub struct DebugBuilder<C: Config> {
}

impl<C: Config> BasicAPI<C> for DebugBuilder<C> {
fn display(&self, x: impl ToVariableOrValue<<C as Config>::CircuitField>) {
fn display(&self, str: &str, x: impl ToVariableOrValue<<C as Config>::CircuitField>) {
let x = self.convert_to_value(x);
println!("x: {:?}", x);
println!("{}: {:?}", str, x);
}

fn add(
Expand Down Expand Up @@ -372,12 +372,6 @@ impl<C: Config> UnconstrainedAPI<C> for DebugBuilder<C> {
}
}

impl<C: Config> DebugAPI<C> for DebugBuilder<C> {
fn value_of(&self, x: impl ToVariableOrValue<C::CircuitField>) -> C::CircuitField {
self.convert_to_value(x)
}
}

impl<C: Config> RootAPI<C> for DebugBuilder<C> {
fn memorized_simple_call<F: Fn(&mut Self, &Vec<Variable>) -> Vec<Variable> + 'static>(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion expander_compiler/src/frontend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub mod internal {
}

pub mod extra {
pub use super::api::{DebugAPI, UnconstrainedAPI};
pub use super::api::UnconstrainedAPI;
pub use super::debug::DebugBuilder;
pub use crate::utils::serde::Serde;

Expand Down
6 changes: 1 addition & 5 deletions rsa_circuit/src/tests/u2048_mul_no_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ impl GenericDefine<BN254Config> for MulNoModCircuit<Variable> {

let res = U2048Variable::mul_without_mod_reduction(&x, &y, &two_to_120, builder);

// for i in 0..2 * N_LIMBS {
// println!("{i}");
// builder.display(res[i]);
// builder.display(self.result[i]);
// }
// builder.display("first limb", x.limbs[0]);

for i in 0..2 * N_LIMBS {
builder.assert_is_equal(res[i], self.result[i]);
Expand Down

0 comments on commit 90b8381

Please sign in to comment.