Skip to content

Commit

Permalink
defer invert to be batched
Browse files Browse the repository at this point in the history
  • Loading branch information
kunxian-xia committed Nov 2, 2023
1 parent 8628ea1 commit 452a80c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
16 changes: 15 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ num-bigint = "0.4"
hex = "0.4"
thiserror = "1.0"
log = "0.4"
env_logger = "0.9.0"

[patch."https://github.com/privacy-scaling-explorations/halo2.git"]
halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "develop" }
Expand All @@ -30,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
12 changes: 12 additions & 0 deletions src/constraint_builder/column.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{BinaryQuery, Query};
use halo2_proofs::plonk::Assigned;
use halo2_proofs::{
arithmetic::FieldExt,
circuit::{Region, Value},
Expand Down Expand Up @@ -101,6 +102,17 @@ impl AdviceColumn {
)
.expect("failed assign_advice");
}

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

#[derive(Clone, Copy)]
Expand Down
5 changes: 3 additions & 2 deletions src/gadgets/is_zero.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::constraint_builder::{AdviceColumn, BinaryQuery, ConstraintBuilder, Query};
use halo2_proofs::plonk::Assigned;
use halo2_proofs::{arithmetic::FieldExt, circuit::Region, plonk::ConstraintSystem};
use std::fmt::Debug;

Expand All @@ -25,10 +26,10 @@ impl IsZeroGadget {
) where
<T as TryInto<F>>::Error: Debug,
{
self.inverse_or_zero.assign(
self.inverse_or_zero.assign_rational(
region,
offset,
value.try_into().unwrap().invert().unwrap_or(F::zero()),
Assigned::<F>::from(value.try_into().unwrap()).invert(),
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ fn verifying_key_constant() {

#[test]
fn all_padding() {
env_logger::init();
mock_prove(vec![]);
}

Expand Down Expand Up @@ -816,6 +817,7 @@ fn empty_storage_type_1_update_c() {

#[test]
fn multiple_updates() {
env_logger::init();
let witness = vec![
(
MPTProofType::StorageChanged,
Expand Down

0 comments on commit 452a80c

Please sign in to comment.