Skip to content

Commit

Permalink
cherry pick 452a80c
Browse files Browse the repository at this point in the history
  • Loading branch information
Mason Liang committed Nov 7, 2023
1 parent b433de5 commit f6813dc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
18 changes: 17 additions & 1 deletion src/constraint_builder/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -141,6 +141,22 @@ impl AdviceColumn {
Value::known(value.try_into().unwrap()),
)
}

pub fn assign_inverse_or_zero<F: FieldExt>(
&self,
region: &mut Region<'_, F>,
offset: usize,
value: F,
) {
region
.assign_advice(
|| "advice",
self.0,
offset,
|| Value::known(Assigned::<F>::from(value).invert()),
)
.expect("failed assign_inverse_or_zero");
}
}

#[derive(Clone, Copy, Hash, Eq, PartialEq, PartialOrd, Ord)]
Expand Down
9 changes: 3 additions & 6 deletions src/gadgets/is_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ impl IsZeroGadget {
) where
<T as TryInto<F>>::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<F: FieldExt, T: Copy + TryInto<F>>(
Expand All @@ -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),
),
]
}
Expand Down

0 comments on commit f6813dc

Please sign in to comment.