Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useless macro #467

Merged
merged 1 commit into from
Oct 28, 2024
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
16 changes: 0 additions & 16 deletions ceno_zkvm/src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,22 +639,6 @@ impl WitIn {
}
}

#[macro_export]
/// this is to avoid non-monomial expression
macro_rules! create_witin_from_expr {
// Handle the case for a single expression
($name:expr, $builder:expr, $debug:expr, $e:expr) => {
WitIn::from_expr($name, $builder, $e, $debug)
};
// Recursively handle multiple expressions and create a flat tuple with error handling
($name:expr, $builder:expr, $debug:expr, $e:expr, $($rest:expr),+) => {
{
// Return a Result tuple, handling errors
Ok::<_, ZKVMError>((WitIn::from_expr($name, $builder, $e, $debug)?, $(WitIn::from_expr($name, $builder, $rest)?),*))
}
};
}

pub trait ToExpr<E: ExtensionField> {
type Output;
fn expr(&self) -> Self::Output;
Expand Down
13 changes: 5 additions & 8 deletions ceno_zkvm/src/uint/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use itertools::{Itertools, izip};
use super::{UIntLimbs, UintLimb};
use crate::{
circuit_builder::CircuitBuilder,
create_witin_from_expr,
error::ZKVMError,
expression::{Expression, ToExpr, WitIn},
gadgets::AssertLTConfig,
Expand Down Expand Up @@ -281,7 +280,7 @@ impl<const M: usize, const C: usize, E: ExtensionField> UIntLimbs<M, C, E> {
.iter()
.fold(Expression::ZERO, |acc, flag| acc.clone() + flag.expr());

let sum_flag = create_witin_from_expr!(|| "sum_flag", circuit_builder, false, sum_expr)?;
let sum_flag = WitIn::from_expr(|| "sum_flag", circuit_builder, sum_expr, false)?;
let (is_equal, diff_inv) =
circuit_builder.is_equal(sum_flag.expr(), Expression::from(n_limbs))?;
Ok(IsEqualConfig {
Expand Down Expand Up @@ -314,7 +313,7 @@ impl<const M: usize, E: ExtensionField> UIntLimbs<M, 8, E> {

let inv_128 = F::from(128).invert().unwrap();
let msb = (high_limb - high_limb_no_msb.expr()) * Expression::Constant(inv_128);
let msb = create_witin_from_expr!(|| "msb", circuit_builder, false, msb)?;
let msb = WitIn::from_expr(|| "msb", circuit_builder, msb, false)?;
Ok(MsbConfig {
msb,
high_limb_no_msb,
Expand Down Expand Up @@ -359,7 +358,7 @@ impl<const M: usize, E: ExtensionField> UIntLimbs<M, 8, E> {
.rev()
.enumerate()
.map(|(i, expr)| {
create_witin_from_expr!(|| format!("si_expr_{i}"), circuit_builder, false, expr)
WitIn::from_expr(|| format!("si_expr_{i}"), circuit_builder, expr, false)
})
.collect::<Result<Vec<WitIn>, ZKVMError>>()?;

Expand Down Expand Up @@ -394,10 +393,8 @@ impl<const M: usize, E: ExtensionField> UIntLimbs<M, 8, E> {

// check the first byte difference has a inverse
// unwrap is safe because vector len > 0
let lhs_ne_byte =
create_witin_from_expr!(|| "lhs_ne_byte", circuit_builder, false, sa.clone())?;
let rhs_ne_byte =
create_witin_from_expr!(|| "rhs_ne_byte", circuit_builder, false, sb.clone())?;
let lhs_ne_byte = WitIn::from_expr(|| "lhs_ne_byte", circuit_builder, sa.clone(), false)?;
let rhs_ne_byte = WitIn::from_expr(|| "rhs_ne_byte", circuit_builder, sb.clone(), false)?;
let index_ne = si.first().unwrap();
circuit_builder.require_zero(
|| "byte inverse check",
Expand Down
Loading