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 authored and Mason Liang committed Nov 19, 2023
1 parent eab825e commit f44ce39
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
33 changes: 31 additions & 2 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ log = "0.4"
mpt-zktrie = { git = "https://github.com/scroll-tech/zkevm-circuits.git", rev = "7d9bc181953cfc6e7baf82ff0ce651281fd70a8a" }
rand_chacha = "0.3.0"
criterion = { version = "0.4", optional = true}
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 @@ -33,7 +34,8 @@ 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"]
bench = [ "dep:criterion" ]
bench = [ "default", "dep:criterion" ]
default = ["halo2_proofs/mock-batch-inv", "halo2_proofs/parallel_syn"]

[dev-dependencies]
# mpt-zktrie = { path = "../scroll-circuits/zktrie" }
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 @@ -96,6 +96,7 @@ fn verifying_key_constant() {

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

Expand Down Expand Up @@ -765,6 +766,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 f44ce39

Please sign in to comment.