Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/structural witin add #740

Merged
merged 36 commits into from
Dec 26, 2024

Conversation

10to4
Copy link
Collaborator

@10to4 10to4 commented Dec 12, 2024

Work for #654

10to4 and others added 17 commits December 12, 2024 16:13
Just to avoid falling too far behind. There seem to be no issues with
the update.
This PR try to turn `Transcript` into a trait so we can apply different
implenents (For example, the `TranscriptSyncronized`) in the future.

We try to split the trait into a basic `Transcript` trait and a extended
`Forkable` (with the `fork` method being provided) one.
The original `Transcript` struct has been renamed into
`BasicTranscript`.
Fixes scroll-tech#691.

- Refactors e2e into smaller steps. 
- Introduces a `run_partial` method which takes a `prefix` argument,
indicating when to stop the run of the pipeline. According to this
argument, different parts of the state are yielded back. This part isn't
too pretty type-wise, but ultimately I think it's not dangerous and a
reasonable compromise for the moment.

Later edit: I've also included a benchmark for witness generation of the
Fibonacci program, since it is a consumer of this refactor and helps to
exemplify it.
Extracted from scroll-tech#667 to make that
PR smaller and easier to review.
…croll-tech#721)

This PR has fixed issue scroll-tech#715 by respect the assertion in `from_base`
method of the Godilock extension field

Notice there is two method `from_base` and `form_limbs` in the
`ExtensionField` trait which is not well illustrated and maybe we should
update them later.

The two running mentioned in scroll-tech#715 have been success under this PR

`cargo run --package ceno_zkvm --bin e2e -- --platform=sp1
ceno_zkvm/examples/fibonacci.elf`

`cargo run --package ceno_zkvm --example riscv_opcodes
-- --start 10 --end 11`
To catch some bugs, like the recent breakage.

---------

Co-authored-by: noelwei <[email protected]>
Just use `cargo fmt` or `cargo fmt --all` for the same effect.

Especially the `fmt` target was obsolote: why would you want to format
specifically only `ceno_zkvm`?
To make the diff for scroll-tech#596 easier
to read.
To help make scroll-tech#596 easier to read
and reason about.

Also introduce a few more conversion helpers.
…ch#723)

Features `non_pow2_rayon_thread` and `riv64` are not tested: we can't
even compile with them.

Because `riv64` is gone, we can make `riv32` invisible: it's effects are
now just the default.
- Modify create_structural_witin() & create_witin() to improve readability
Copy link
Collaborator

@hero78119 hero78119 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work! most looks neat
left some comment of missing functionality

ceno_zkvm/src/expression.rs Outdated Show resolved Hide resolved
ceno_zkvm/src/expression.rs Outdated Show resolved Hide resolved
ceno_zkvm/src/tables/ram/ram_impl.rs Outdated Show resolved Hide resolved
ceno_zkvm/src/scheme/verifier.rs Outdated Show resolved Hide resolved
ceno_zkvm/src/scheme/verifier.rs Outdated Show resolved Hide resolved
-  Remove SetTableAddrType
-  Add  more meta information in StructuralWitIn
-  Remove from_expr
github-merge-queue bot pushed a commit that referenced this pull request Dec 17, 2024
@10to4 Your #740 reminded me of
some old improvements I had lying around.

Especially the use of the standard library's `join`, instead of
implementing the functionality manually.
Copy link
Collaborator

@hero78119 hero78119 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just left some comments related to core design

ceno_zkvm/src/expression.rs Outdated Show resolved Hide resolved
ceno_zkvm/src/scheme/prover.rs Outdated Show resolved Hide resolved
ceno_zkvm/src/tables/ram/ram_impl.rs Outdated Show resolved Hide resolved
@@ -25,6 +25,9 @@ use crate::{
pub enum Expression<E: ExtensionField> {
/// WitIn(Id)
WitIn(WitnessId),
/// StructuralWitIn(WitnessId)
/// same as witin, but it's structual witness and be evaluated by verifier succinctly.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I have a bit of a hard time understanding what you are trying to say.

Could you please fix the grammar? That might already help.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -71,6 +75,7 @@ impl<E: ExtensionField> Expression<E> {
&self,
fixed_in: &impl Fn(&Fixed) -> T,
wit_in: &impl Fn(WitnessId) -> T, // witin id
structural_wit_in: &impl Fn(WitnessId) -> T,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The arguments to this function are getting quite involved, I wonder whether we should make a struct to hold all the arguments.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far, it doesn't seem to need other arguments yet.

@@ -59,7 +59,11 @@ impl<T: Sized + Sync + Clone + Send + Copy> RowMajorMatrix<T> {
}

pub fn num_instances(&self) -> usize {
self.values.len() / self.num_col - self.num_padding_rows
let mut num = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for mutation:

diff --git a/ceno_zkvm/src/witness.rs b/ceno_zkvm/src/witness.rs
index 88bfdcf5..47d4f2ee 100644
--- a/ceno_zkvm/src/witness.rs
+++ b/ceno_zkvm/src/witness.rs
@@ -59,11 +59,11 @@ impl<T: Sized + Sync + Clone + Send + Copy> RowMajorMatrix<T> {
     }
 
     pub fn num_instances(&self) -> usize {
-        let mut num = 0;
-        if self.num_col != 0 {
-            num = self.values.len() / self.num_col - self.num_padding_rows
+        if self.num_col == 0 {
+            0
+        } else {
+            self.values.len() / self.num_col - self.num_padding_rows
         }
-        num
     }
 
     pub fn num_padding_instances(&self) -> usize {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@matthiasgoergens
Copy link
Collaborator

Please resolve the merge conflicts.

ceno_zkvm/src/tables/ram/ram_impl.rs Outdated Show resolved Hide resolved
ceno_zkvm/src/tables/ram/ram_impl.rs Outdated Show resolved Hide resolved
ceno_zkvm/src/scheme/prover.rs Outdated Show resolved Hide resolved
ceno_zkvm/src/scheme/verifier.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@hero78119 hero78119 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall LGTM! 👍 thanks for the effort!

.all_equal();
// in table proof, we always skip same point sumcheck for now
// as tower sumcheck batch product argument/logup in same length
let is_skip_same_point_sumcheck = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related to respective "prover.rs", an advice to make thing consistent:

diff --git a/ceno_zkvm/src/scheme/prover.rs b/ceno_zkvm/src/scheme/prover.rs
index daaa1099..1a690fa0 100644
--- a/ceno_zkvm/src/scheme/prover.rs
+++ b/ceno_zkvm/src/scheme/prover.rs
@@ -965,12 +965,9 @@ impl<E: ExtensionField, PCS: PolynomialCommitmentScheme<E>> ZKVMProver<E, PCS> {
         );
         exit_span!(tower_span);

-        // same point sumcheck is optional when all witin + fixed are in same num_vars
-        let is_skip_same_point_sumcheck = witnesses
-            .iter()
-            .chain(fixed.iter())
-            .map(|v| v.num_vars())
-            .all_equal();
+        // in table proof, we always skip same point sumcheck for now
+        // as tower sumcheck batch product argument/logup in same length
+        let is_skip_same_point_sumcheck = true;

         let (input_open_point, same_r_sumcheck_proofs, rw_in_evals, lk_in_evals) =
             if is_skip_same_point_sumcheck {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is required that all the lengths are equal, right?

If yes, an assertion would be nice (restore the formula and add assert!(is_skip_same_point_sumcheck)).

@hero78119
Copy link
Collaborator

Hey @naure would kindly request you to have a quick review on this design, see whether any frontend/backend information leaked in between

@hero78119 hero78119 requested a review from naure December 26, 2024 02:19
Inspired by reviewing scroll-tech#740
@@ -75,12 +67,13 @@ pub struct DynamicAddr {

#[derive(Clone, Debug)]
pub struct SetTableSpec {
pub addr_type: SetTableAddrType,
pub len: usize,
pub len: Option<usize>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does Some(0) differ from None?

@matthiasgoergens matthiasgoergens added this pull request to the merge queue Dec 26, 2024
Merged via the queue into scroll-tech:master with commit f1de609 Dec 26, 2024
4 checks passed
@naure
Copy link
Collaborator

naure commented Jan 2, 2025

Hey @naure would kindly request you to have a quick review on this design, see whether any frontend/backend information leaked in between

Yes! I did review this and the follow-up #797. See the discussion there which mostly apply to both witness and fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants