From f6813dc3b4c8c475033f4e0a06a4f8fda699bcc0 Mon Sep 17 00:00:00 2001 From: Mason Liang Date: Mon, 6 Nov 2023 21:51:15 -0500 Subject: [PATCH] cherry pick https://github.com/scroll-tech/mpt-circuit/commit/452a80c1f207752b238a3ae89535782843f87ab5 --- Cargo.toml | 1 + src/constraint_builder/column.rs | 18 +++++++++++++++++- src/gadgets/is_zero.rs | 9 +++------ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f07ec310..86304d35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ ethers-core = { git = "https://github.com/scroll-tech/ethers-rs.git", branch = " [features] # printout the layout of circuits for demo and some unittests print_layout = ["halo2_proofs/dev-graph"] +default = ["halo2_proofs/mock-batch-inv", "halo2_proofs/parallel_syn"] [dev-dependencies] mpt-zktrie = { git = "https://github.com/scroll-tech/zkevm-circuits.git", rev = "7d9bc181953cfc6e7baf82ff0ce651281fd70a8a" } diff --git a/src/constraint_builder/column.rs b/src/constraint_builder/column.rs index f59eafae..dbcadeb2 100644 --- a/src/constraint_builder/column.rs +++ b/src/constraint_builder/column.rs @@ -3,7 +3,7 @@ use crate::assignment_map::Column as ColumnEnum; use halo2_proofs::{ arithmetic::FieldExt, circuit::{Region, Value}, - plonk::{Advice, Column, Fixed}, + plonk::{Advice, Assigned, Column, Fixed}, }; use std::fmt::Debug; @@ -141,6 +141,22 @@ impl AdviceColumn { Value::known(value.try_into().unwrap()), ) } + + pub fn assign_inverse_or_zero( + &self, + region: &mut Region<'_, F>, + offset: usize, + value: F, + ) { + region + .assign_advice( + || "advice", + self.0, + offset, + || Value::known(Assigned::::from(value).invert()), + ) + .expect("failed assign_inverse_or_zero"); + } } #[derive(Clone, Copy, Hash, Eq, PartialEq, PartialOrd, Ord)] diff --git a/src/gadgets/is_zero.rs b/src/gadgets/is_zero.rs index 88efc926..67d092ae 100644 --- a/src/gadgets/is_zero.rs +++ b/src/gadgets/is_zero.rs @@ -30,11 +30,8 @@ impl IsZeroGadget { ) where >::Error: Debug, { - self.inverse_or_zero.assign( - region, - offset, - value.try_into().unwrap().invert().unwrap_or(F::zero()), - ); + self.inverse_or_zero + .assign_inverse_or_zero(region, offset, value.try_into().unwrap()); } pub fn assignments>( @@ -49,7 +46,7 @@ impl IsZeroGadget { self.value.assignment(offset, value), self.inverse_or_zero.assignment( offset, - value.try_into().unwrap().invert().unwrap_or(F::zero()), + (value.try_into().unwrap()).invert().unwrap_or_else(F::zero), ), ] }