Skip to content

Commit

Permalink
Merge branch 'main' into gr@improve-synthesis-error
Browse files Browse the repository at this point in the history
  • Loading branch information
guorong009 committed Sep 26, 2024
2 parents 4ffff57 + 81c7058 commit 3baa282
Show file tree
Hide file tree
Showing 26 changed files with 1,161 additions and 76 deletions.
44 changes: 30 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,36 @@ on:
- main

jobs:

fmt:
name: Rustfmt
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
override: false
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

typos-check:
needs: [skip_check]
if: |
github.event.pull_request.draft == false &&
(github.event.action == 'ready_for_review' || needs.skip_check.outputs.should_skip != 'true')
name: TyposCheck
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: crate-ci/[email protected]
with:
config: ./typos.toml
isolated: true
test:
name: Test on ${{ matrix.os }} with ${{ matrix.feature_set }} features
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -101,18 +131,4 @@ jobs:
command: doc
args: --all --document-private-items

fmt:
name: Rustfmt
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
override: false
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Cargo.lock
.DS_Store

layout.png
serialization-test.pk
serialization-example.vk
serialization-example.pk
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This repository contains the [halo2](https://github.com/zcash/halo2) fork from
PSE and includes contributions from the community.

We use the `main` branch for development, which means it may contain
unstable/unfinished features. For end-users we recomend using the tag releases
unstable/unfinished features. For end-users we recommend using the tag releases
which can be seen as curated checkpoints with some level of guarantee of
stability.

Expand Down
4 changes: 2 additions & 2 deletions book/src/user/experimental-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ When using `create_proof` and `verify_proof`, we need to specify the commitment
create_proof<IPACommitmentScheme<_>, ProverIPA<_>, _, _, _, _>
verify_proof<IPACommitmentScheme<_>, ProverIPA<_>, _, _, _>

// Using KZG with GWC19 mutli-open strategy
// Using KZG with GWC19 multi-open strategy
create_proof<KZGCommitmentScheme<_>, ProverGWC<_>, _, _, _, _>
verify_proof<KZGCommitmentScheme<_>, ProverGWC<_>, _, _, _>

// Using KZG with BDFG20 mutli-open strategy
// Using KZG with BDFG20 multi-open strategy
create_proof<KZGCommitmentScheme<_>, ProverSHPLONK<_>, _, _, _, _>
verify_proof<KZGCommitmentScheme<_>, ProverSHPLONK<_>, _, _, _>
```
Expand Down
2 changes: 1 addition & 1 deletion halo2_backend/src/plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ where
return Err(io::Error::new(
io::ErrorKind::InvalidData,
format!(
"circuit size value (k): {} exceeds maxium: {}",
"circuit size value (k): {} exceeds maximum: {}",
k,
C::Scalar::S
),
Expand Down
44 changes: 44 additions & 0 deletions halo2_backend/src/plonk/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,47 @@ fn shuffle_argument_required_degree<F: Field, V: Variable>(arg: &shuffle::Argume
// (1 - (l_last + l_blind)) (z(\omega X) (s(X) + \gamma) - z(X) (a(X) + \gamma))
std::cmp::max(2 + shuffle_degree, 2 + input_degree)
}

#[cfg(test)]
mod tests {
use super::ExpressionBack;
use halo2curves::bn256::Fr;

#[test]
fn expressionback_iter_sum() {
let exprs: Vec<ExpressionBack<Fr>> = vec![
ExpressionBack::Constant(1.into()),
ExpressionBack::Constant(2.into()),
ExpressionBack::Constant(3.into()),
];
let happened: ExpressionBack<Fr> = exprs.into_iter().sum();
let expected: ExpressionBack<Fr> = ExpressionBack::Sum(
Box::new(ExpressionBack::Sum(
Box::new(ExpressionBack::Constant(1.into())),
Box::new(ExpressionBack::Constant(2.into())),
)),
Box::new(ExpressionBack::Constant(3.into())),
);

assert_eq!(happened, expected);
}

#[test]
fn expressionback_iter_product() {
let exprs: Vec<ExpressionBack<Fr>> = vec![
ExpressionBack::Constant(1.into()),
ExpressionBack::Constant(2.into()),
ExpressionBack::Constant(3.into()),
];
let happened: ExpressionBack<Fr> = exprs.into_iter().product();
let expected: ExpressionBack<Fr> = ExpressionBack::Product(
Box::new(ExpressionBack::Product(
Box::new(ExpressionBack::Constant(1.into())),
Box::new(ExpressionBack::Constant(2.into())),
)),
Box::new(ExpressionBack::Constant(3.into())),
);

assert_eq!(happened, expected);
}
}
6 changes: 3 additions & 3 deletions halo2_backend/src/plonk/evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ impl Calculation {
/// Evaluator
#[derive(Clone, Default, Debug)]
pub(crate) struct Evaluator<C: CurveAffine> {
/// Custom gates evalution
/// Custom gates evaluation
custom_gates: GraphEvaluator<C>,
/// Lookups evalution
/// Lookups evaluation
lookups: Vec<GraphEvaluator<C>>,
/// Shuffle evalution
/// Shuffle evaluation
shuffles: Vec<GraphEvaluator<C>>,
}

Expand Down
73 changes: 37 additions & 36 deletions halo2_backend/src/plonk/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,10 @@ impl<

/// Finalizes the proof creation.
/// The following steps are performed:
/// - 1. Generate commited lookup polys
/// - 2. Generate commited permutation polys
/// - 3. Generate commited lookup polys
/// - 4. Generate commited shuffle polys
/// - 1. Generate committed lookup polys
/// - 2. Generate committed permutation polys
/// - 3. Generate committed lookup polys
/// - 4. Generate committed shuffle polys
/// - 5. Commit to the vanishing argument's random polynomial
/// - 6. Generate the advice polys
/// - 7. Evaluate the h(X) polynomial
Expand Down Expand Up @@ -523,7 +523,7 @@ impl<
.map(|index| challenges.remove(&index).unwrap())
.collect::<Vec<_>>();

// 1. Generate commited ( added to transcript ) lookup polys ---------------------------------------
// 1. Generate committed ( added to transcript ) lookup polys ---------------------------------------

// Sample theta challenge for keeping lookup columns linearly independent
// [TRANSCRIPT-5]
Expand Down Expand Up @@ -574,9 +574,9 @@ impl<
// [TRANSCRIPT-8]
let gamma: ChallengeGamma<_> = self.transcript.squeeze_challenge_scalar();

// 2. Generate commited permutation polys -----------------------------------------
// 2. Generate committed permutation polys -----------------------------------------
// [TRANSCRIPT-9]
let permutations_commited: Vec<permutation::prover::Committed<Scheme::Curve>> = instances
let permutations_committed: Vec<permutation::prover::Committed<Scheme::Curve>> = instances
.iter()
.zip(advices.iter())
.map(|(instance, advice)| {
Expand All @@ -597,34 +597,35 @@ impl<
})
.collect::<Result<Vec<_>, _>>()?;

// 3. Generate commited lookup polys ----------------------------------------------------------
// 3. Generate committed lookup polys ----------------------------------------------------------

// [TRANSCRIPT-10]
let lookups_commited: Vec<Vec<lookup::prover::Committed<Scheme::Curve>>> = permuted_lookups
.into_iter()
.map(|lookups| -> Result<Vec<_>, _> {
// Construct and commit to products for each lookup
lookups
.into_iter()
.map(|lookup| {
lookup.commit_product(
&self.engine,
pk,
params,
beta,
gamma,
&mut rng,
self.transcript,
)
})
.collect::<Result<Vec<_>, _>>()
})
.collect::<Result<Vec<_>, _>>()?;
let lookups_committed: Vec<Vec<lookup::prover::Committed<Scheme::Curve>>> =
permuted_lookups
.into_iter()
.map(|lookups| -> Result<Vec<_>, _> {
// Construct and commit to products for each lookup
lookups
.into_iter()
.map(|lookup| {
lookup.commit_product(
&self.engine,
pk,
params,
beta,
gamma,
&mut rng,
self.transcript,
)
})
.collect::<Result<Vec<_>, _>>()
})
.collect::<Result<Vec<_>, _>>()?;

// 4. Generate commited shuffle polys -------------------------------------------------------
// 4. Generate committed shuffle polys -------------------------------------------------------

// [TRANSCRIPT-11]
let shuffles_commited: Vec<Vec<shuffle::prover::Committed<Scheme::Curve>>> = instances
let shuffles_committed: Vec<Vec<shuffle::prover::Committed<Scheme::Curve>>> = instances
.iter()
.zip(advices.iter())
.map(|(instance, advice)| -> Result<Vec<_>, _> {
Expand Down Expand Up @@ -703,9 +704,9 @@ impl<
*beta,
*gamma,
*theta,
&lookups_commited,
&shuffles_commited,
&permutations_commited,
&lookups_committed,
&shuffles_committed,
&permutations_committed,
);

// 8. Construct the vanishing argument's h(X) commitments --------------------------------------
Expand Down Expand Up @@ -796,15 +797,15 @@ impl<
// Evaluate the permutations, if any, at omega^i x.
// [TRANSCRIPT-21]
let permutations_evaluated: Vec<permutation::prover::Evaluated<Scheme::Curve>> =
permutations_commited
permutations_committed
.into_iter()
.map(|permutation| -> Result<_, _> { permutation.evaluate(pk, x, self.transcript) })
.collect::<Result<Vec<_>, _>>()?;

// Evaluate the lookups, if any, at omega^i x.
// [TRANSCRIPT-22]
let lookups_evaluated: Vec<Vec<lookup::prover::Evaluated<Scheme::Curve>>> =
lookups_commited
lookups_committed
.into_iter()
.map(|lookups| -> Result<Vec<_>, _> {
lookups
Expand All @@ -817,7 +818,7 @@ impl<
// Evaluate the shuffles, if any, at omega^i x.
// [TRANSCRIPT-23]
let shuffles_evaluated: Vec<Vec<shuffle::prover::Evaluated<Scheme::Curve>>> =
shuffles_commited
shuffles_committed
.into_iter()
.map(|shuffles| -> Result<Vec<_>, _> {
shuffles
Expand Down
3 changes: 3 additions & 0 deletions halo2_frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ tabbycat = { version = "0.1", features = ["attributes"], optional = true }
proptest = "1"
rand_core = { version = "0.6", default-features = false, features = ["getrandom"] }
serde_json = "1"
tracing-subscriber = { version = "0.3" }
tracing = "0.1"
tracing-capture = "0.1"

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies]
getrandom = { version = "0.2", features = ["js"] }
Expand Down
6 changes: 3 additions & 3 deletions halo2_frontend/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ mod tests {
#[cfg(feature = "lookup-any-sanity-checks")]
#[test]
#[should_panic(
expected = "pair of tagging expressions(query of the tag columns or mutiple query combinations) should be included"
expected = "pair of tagging expressions(query of the tag columns or multiple query combinations) should be included"
)]
fn bad_lookup_any_not_add_tagging_pairs() {
const K: u32 = 4;
Expand Down Expand Up @@ -2020,7 +2020,7 @@ mod tests {
}

#[test]
fn contraint_unsatisfied() {
fn constraint_unsatisfied() {
const K: u32 = 4;

#[derive(Clone)]
Expand Down Expand Up @@ -2263,7 +2263,7 @@ mod tests {
instance[0] = InstanceValue::Assigned(Fp::from(11));
assert_eq!(prover.verify(), Err(vec![err2.clone()]));

// then we modify the witness -> the contraint `squared` will fail
// then we modify the witness -> the constraint `squared` will fail
let advice0 = prover.advice_mut(0);
advice0[2] = CellValue::Assigned(Fp::from(10));
assert_eq!(prover.verify(), Err(vec![err1, err2]));
Expand Down
8 changes: 7 additions & 1 deletion halo2_frontend/src/dev/cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,12 @@ mod tests {
Ok(())
}
}
CircuitCost::<Eq, MyCircuit>::measure(K, &MyCircuit).proof_size(1);
let cost = CircuitCost::<Eq, MyCircuit>::measure(K, &MyCircuit);

let marginal_proof_size = cost.marginal_proof_size();
assert_eq!(usize::from(marginal_proof_size), 0);

let proof_size = cost.proof_size(1);
assert_eq!(usize::from(proof_size), 608);
}
}
4 changes: 2 additions & 2 deletions halo2_frontend/src/dev/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use super::MockProver;
pub enum CommitmentScheme {
/// Inner Product Argument commitment scheme
IPA,
/// KZG with GWC19 mutli-open strategy
/// KZG with GWC19 multi-open strategy
KZGGWC,
/// KZG with BDFG20 mutli-open strategy
/// KZG with BDFG20 multi-open strategy
KZGSHPLONK,
}

Expand Down
Loading

0 comments on commit 3baa282

Please sign in to comment.