Skip to content

feat: add preprocessing support #2

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

Merged
merged 22 commits into from
May 8, 2024
Merged

feat: add preprocessing support #2

merged 22 commits into from
May 8, 2024

Conversation

shuklaayush
Copy link
Contributor

@shuklaayush shuklaayush commented May 6, 2024

  • Added a setup phase that generates a ProvingKey and a VerifyingKey. The ProvingKey stores all the preprocessed traces involved when proving multiple AIRs and information on how they're committed. The VerifyingKey stores the commitments.
  • Updated the prover/verifier to accommodate preprocessed traces
  • Added a check_constraints function for debugging RAP constraints

@shuklaayush shuklaayush requested a review from jonathanpwang May 7, 2024 00:17
Copy link
Contributor

@jonathanpwang jonathanpwang left a comment

Choose a reason for hiding this comment

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

The per-air modifications look good, most comments are nits.

But right now the prover / verifier is only taking partitions[0].airs for preprocessed - is that because you were still iterating?

Also as discussed, the proving key for multi AIRs should either keep a separate preprocessed commit per AIR, or a nice-to-have is to allow a list of commits and arbitrary assignment of single AIR preprocessed trace to commit.

We can save the latter to a coming-soon refactor: I'm starting to think that is a better structure than the partition structure.

Recording off-line conversation about motivation: if we have a single machine with fixed chips, then it makes sense to share a preprocessed commit across matrices. However if we have a machine where some chips (precompiles) are only added some of the time, then we don't want to rebuild the global machine proving key for each subset of chips.

@shuklaayush
Copy link
Contributor Author

But right now the prover / verifier is only taking partitions[0].airs for preprocessed - is that because you were still iterating?

Yes, I'm still trying to understand the structure and need some clarification. This is how I'm thinking about this:

We have a machine with a fixed set of AIRs that can be a part of the execution. We divide the execution into partitions and prove them independently. If each partition contained traces for all the machine AIRs, you could store a global proving/verifying key that includes all the preprocessed traces and a single commitment to each.

But I guess what you're saying is that a partition might only contain a subset of the machine AIRs:

// ------------------------------------------
// Partition1
// Prep[0] | Main[0][0] | Permutation[0][1] |
// Prep[1] | Main[0][1] | Permutation[0][1] |
// Prep[2] | Main[0][2] | Permutation[0][2] |
// ...
// ------------------------------------------
// Partition2
// Prep[0] | Main[1][0] | Permutation[1][1] |
// Prep[2] | Main[1][2] | Permutation[1][2] |
// ...
// ------------------------------------------
// ...

Since each partition is heterogeneous, you only want to include and commit to preprocessed traces of AIRs that are part of this partition. In that case, should I store the commitment to each preprocessed trace separately in the proving/verifying keys? I'll also need to store a mapping from the partition AIRs to "global" AIRs.
Another option could be to have separate proving/verifying keys for each partition that only contain preprocessed traces involved in this partition

@jonathanpwang
Copy link
Contributor

The partition logic was only for the main traces, so I think it needs some rework.
Basically the preprocessed are partitioned separately from main, which is partitioned separately from permutation. And I think permutation always only needs 1 singleton partition.

So what I envision for the trace is that you have separate lists of commitments for:

  • preprocessed
  • main
  • permutation (single commit)

Then for each RAP matrix, you will have:

  • preprocessed submatrix
  • partition of main submatrices
  • permutation submatrix
    Each submatrix will below to one of the commits in their respective list, and we can record a pointer to which one. But again the partitions are different for each phase.

Comment on lines +28 to +30
// For each preprocessed trace commitment, the prover data and
// the domain of the matrix, in order
preprocessed: Vec<(&PcsProverData<SC>, Domain<SC>)>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed this from Vec<Domain<SC>> to Domain<SC> since each preprocessed trace is committed separately

@@ -145,8 +235,9 @@ impl<SC: StarkGenericConfig> PartitionProver<SC> {
// Prepare the proven RAP trace views
let (raps, trace_views): (Vec<_>, Vec<_>) = rap_mains
.into_iter()
.zip(std::iter::repeat(preps).flatten())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs to be handled in a better way. Since AIRs from different partitions can refer to the same preprocessed trace, we need to store a global AIR index along with each AIR in a partition

@shuklaayush shuklaayush requested a review from jonathanpwang May 7, 2024 22:25
Copy link
Contributor

@jonathanpwang jonathanpwang left a comment

Choose a reason for hiding this comment

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

LGTM

@jonathanpwang jonathanpwang merged commit 8822068 into main May 8, 2024
@jonathanpwang jonathanpwang deleted the feat/preprocessing branch May 8, 2024 02:36
luffykai pushed a commit that referenced this pull request Dec 13, 2024
* chore: add gitignore

* feat: add basic pk/vk

* fix: move pk/vk to setup

* feat: add wip preprocessing

* fix: reuse ProverTraceData

* fix: ordering

* fix: consume verifying key

* fix: preprocessed trace in interactions

* feat(test): add check_constraints for debugging

* fix: preprocessed before main

* fix: more preprocessed before main

* chore: rename var

* refactor: move check_constraints to debug dir

* docs: add proper docsstring for pk, vk

* chore: add mock prover note

* fix: use as_view and remove clones

* chore: fix fib conditional air comment

* fix: separate commitments for each preprocessed trace

* fix: simplify proving key

* chore: remove comment

* fix: open preprocessed traces at single point

* chore: reverse order
Avaneesh-axiom pushed a commit that referenced this pull request Jan 10, 2025
* chore: add gitignore

* feat: add basic pk/vk

* fix: move pk/vk to setup

* feat: add wip preprocessing

* fix: reuse ProverTraceData

* fix: ordering

* fix: consume verifying key

* fix: preprocessed trace in interactions

* feat(test): add check_constraints for debugging

* fix: preprocessed before main

* fix: more preprocessed before main

* chore: rename var

* refactor: move check_constraints to debug dir

* docs: add proper docsstring for pk, vk

* chore: add mock prover note

* fix: use as_view and remove clones

* chore: fix fib conditional air comment

* fix: separate commitments for each preprocessed trace

* fix: simplify proving key

* chore: remove comment

* fix: open preprocessed traces at single point

* chore: reverse order
jonathanpwang pushed a commit that referenced this pull request Mar 9, 2025
* fix p256-generator

* add host tests for ecc
jonathanpwang added a commit that referenced this pull request Mar 9, 2025
* [fix] Fix P256 `GENERATOR` and `double_impl` (#2)

* fix p256-generator

* add host tests for ecc

* fix: loadstore sign of immediate

* fix: prints and test

* fix: load_sign_extend tests

* Update docs/specs/ISA.md

* clarify notation and sign extension in ISA spec

* fix reveal transpiler spec

---------

Co-authored-by: Manh Dinh <[email protected]>
Co-authored-by: Jonathan Wang <[email protected]>
jonathanpwang added a commit that referenced this pull request Mar 9, 2025
…ications (#29)

* [fix] Fix P256 `GENERATOR` and `double_impl` (#2)

* fix p256-generator

* add host tests for ecc

* Use private repo for stark-backend (#11)

* temp(ci): switch riscv AMI for runner (#14)

* [chore] Update DSL verify to match plonky3 (#5)

* Update DSL verify to match plonky3

* fix: transpose state for p3-keccak tracegen

* chore: add comment linking plonky3 issue

* Update stark-backend commit

---------

Co-authored-by: Jonathan Wang <[email protected]>

* Use full commit in openvm-stark-backend revision (#18)

* chore: update `stark-backend` commit (#19)

* [fix] `Rv32BaseAluAdapterAir` unconstrained register reads (#25)

* Create pull_request_template.md (#26)

* [fix] Poseidon2 verify_batch opcode can send to execution bus for invalid rows (#17)

* [fix] Rust memory allocation overflow (#13)

* Fix and add test

* Fix lint error

* Update crates/toolchain/platform/src/memory.rs

---------

Co-authored-by: Jonathan Wang <[email protected]>

* [fix] Constrain `final_hash` in sha256 air to address audit finding (#12)

* [fix] properly constrain final_hash in sha256 air

* Add negative test for underconstrained final_hash. It was manually checked that this new test would have passed before the change.

* [fix] IsLtArraySubAir (#9)

* add fix

* add tests

* remove diff_val

* chore: update comment

* chore: no try_inverse

---------

Co-authored-by: Jonathan Wang <[email protected]>

* [fix] `Rv32BaseAluAdapterAir` immediate limbs not range-checked (#8)

* fix local_as2

* range check imm limbs

* add count for range check

* add test for unconstrained imm limb

* fix MemoryTester chip trace height

* add test for unconstrained rs2 read

* Revert "fix local_as2"

This reverts commit ef83121bf1796874affaca4682dbb4f9f051b079.

* Revert "add count for range check"

This reverts commit 5252444dfeaf41e7c336648ad92c4736f48ead9d.

* Revert "range check imm limbs"

This reverts commit 2e2937536069ae66849fdf7bba9ea509065d17fe.

* fix unconstrained imm limbs

* fix local_rs2_as test

* fix lint

* Update extensions/rv32im/circuit/src/base_alu/tests.rs

---------

Co-authored-by: Jonathan Wang <[email protected]>

* fix: fixed SHA2 subair trace generation and the testing (#28)

* fix: loadstore sign of immediate (#4)

* [fix] Fix P256 `GENERATOR` and `double_impl` (#2)

* fix p256-generator

* add host tests for ecc

* fix: loadstore sign of immediate

* fix: prints and test

* fix: load_sign_extend tests

* Update docs/specs/ISA.md

* clarify notation and sign extension in ISA spec

* fix reveal transpiler spec

---------

Co-authored-by: Manh Dinh <[email protected]>
Co-authored-by: Jonathan Wang <[email protected]>

* fix transpiler

* fix loadstore adapter

* fix store transpiler

* fix tests

* add e2e test

* fix docs

* fix: jalr imm_sign (#30)

* optimize record struct packing

* chore: use from_bool

* chore: derive_more feature in bench

* fix bench

* fix

---------

Co-authored-by: Xinding Wei <[email protected]>
Co-authored-by: Jonathan Wang <[email protected]>
Co-authored-by: Golovanov399 <[email protected]>
Co-authored-by: Avaneesh-axiom <[email protected]>
Co-authored-by: Arayi Khalatyan <[email protected]>
jonathanpwang added a commit that referenced this pull request Mar 9, 2025
* [fix] Fix P256 `GENERATOR` and `double_impl` (#2)

* fix p256-generator

* add host tests for ecc

* fix: hintstore mem_ptr and rem_words overflow

* fix: is_buffer_start constrain

* Use private repo for stark-backend (#11)

* temp(ci): switch riscv AMI for runner (#14)

* [chore] Update DSL verify to match plonky3 (#5)

* Update DSL verify to match plonky3

* fix: transpose state for p3-keccak tracegen

* chore: add comment linking plonky3 issue

* Update stark-backend commit

---------

Co-authored-by: Jonathan Wang <[email protected]>

* Use full commit in openvm-stark-backend revision (#18)

* chore: update `stark-backend` commit (#19)

* [fix] `Rv32BaseAluAdapterAir` unconstrained register reads (#25)

* Create pull_request_template.md (#26)

* [fix] Poseidon2 verify_batch opcode can send to execution bus for invalid rows (#17)

* [fix] Rust memory allocation overflow (#13)

* Fix and add test

* Fix lint error

* Update crates/toolchain/platform/src/memory.rs

---------

Co-authored-by: Jonathan Wang <[email protected]>

* [fix] Constrain `final_hash` in sha256 air to address audit finding (#12)

* [fix] properly constrain final_hash in sha256 air

* Add negative test for underconstrained final_hash. It was manually checked that this new test would have passed before the change.

* [fix] IsLtArraySubAir (#9)

* add fix

* add tests

* remove diff_val

* chore: update comment

* chore: no try_inverse

---------

Co-authored-by: Jonathan Wang <[email protected]>

* [fix] `Rv32BaseAluAdapterAir` immediate limbs not range-checked (#8)

* fix local_as2

* range check imm limbs

* add count for range check

* add test for unconstrained imm limb

* fix MemoryTester chip trace height

* add test for unconstrained rs2 read

* Revert "fix local_as2"

This reverts commit ef83121bf1796874affaca4682dbb4f9f051b079.

* Revert "add count for range check"

This reverts commit 5252444dfeaf41e7c336648ad92c4736f48ead9d.

* Revert "range check imm limbs"

This reverts commit 2e2937536069ae66849fdf7bba9ea509065d17fe.

* fix unconstrained imm limbs

* fix local_rs2_as test

* fix lint

* Update extensions/rv32im/circuit/src/base_alu/tests.rs

---------

Co-authored-by: Jonathan Wang <[email protected]>

* fix: fixed SHA2 subair trace generation and the testing (#28)

* fix: loadstore sign of immediate (#4)

* [fix] Fix P256 `GENERATOR` and `double_impl` (#2)

* fix p256-generator

* add host tests for ecc

* fix: loadstore sign of immediate

* fix: prints and test

* fix: load_sign_extend tests

* Update docs/specs/ISA.md

* clarify notation and sign extension in ISA spec

* fix reveal transpiler spec

---------

Co-authored-by: Manh Dinh <[email protected]>
Co-authored-by: Jonathan Wang <[email protected]>

* seperate the fixes

* fix naming

* fix: lints

---------

Co-authored-by: Manh Dinh <[email protected]>
Co-authored-by: Xinding Wei <[email protected]>
Co-authored-by: Jonathan Wang <[email protected]>
Co-authored-by: Golovanov399 <[email protected]>
Co-authored-by: Avaneesh-axiom <[email protected]>
jonathanpwang pushed a commit that referenced this pull request Mar 9, 2025
* fix p256-generator

* add host tests for ecc
jonathanpwang added a commit that referenced this pull request Mar 9, 2025
* [fix] Fix P256 `GENERATOR` and `double_impl` (#2)

* fix p256-generator

* add host tests for ecc

* fix: loadstore sign of immediate

* fix: prints and test

* fix: load_sign_extend tests

* Update docs/specs/ISA.md

* clarify notation and sign extension in ISA spec

* fix reveal transpiler spec

---------

Co-authored-by: Manh Dinh <[email protected]>
Co-authored-by: Jonathan Wang <[email protected]>
jonathanpwang added a commit that referenced this pull request Mar 9, 2025
…ications (#29)

* [fix] Fix P256 `GENERATOR` and `double_impl` (#2)

* fix p256-generator

* add host tests for ecc

* Use private repo for stark-backend (#11)

* temp(ci): switch riscv AMI for runner (#14)

* [chore] Update DSL verify to match plonky3 (#5)

* Update DSL verify to match plonky3

* fix: transpose state for p3-keccak tracegen

* chore: add comment linking plonky3 issue

* Update stark-backend commit

---------

Co-authored-by: Jonathan Wang <[email protected]>

* Use full commit in openvm-stark-backend revision (#18)

* chore: update `stark-backend` commit (#19)

* [fix] `Rv32BaseAluAdapterAir` unconstrained register reads (#25)

* Create pull_request_template.md (#26)

* [fix] Poseidon2 verify_batch opcode can send to execution bus for invalid rows (#17)

* [fix] Rust memory allocation overflow (#13)

* Fix and add test

* Fix lint error

* Update crates/toolchain/platform/src/memory.rs

---------

Co-authored-by: Jonathan Wang <[email protected]>

* [fix] Constrain `final_hash` in sha256 air to address audit finding (#12)

* [fix] properly constrain final_hash in sha256 air

* Add negative test for underconstrained final_hash. It was manually checked that this new test would have passed before the change.

* [fix] IsLtArraySubAir (#9)

* add fix

* add tests

* remove diff_val

* chore: update comment

* chore: no try_inverse

---------

Co-authored-by: Jonathan Wang <[email protected]>

* [fix] `Rv32BaseAluAdapterAir` immediate limbs not range-checked (#8)

* fix local_as2

* range check imm limbs

* add count for range check

* add test for unconstrained imm limb

* fix MemoryTester chip trace height

* add test for unconstrained rs2 read

* Revert "fix local_as2"

This reverts commit ef83121bf1796874affaca4682dbb4f9f051b079.

* Revert "add count for range check"

This reverts commit 5252444dfeaf41e7c336648ad92c4736f48ead9d.

* Revert "range check imm limbs"

This reverts commit 2e2937536069ae66849fdf7bba9ea509065d17fe.

* fix unconstrained imm limbs

* fix local_rs2_as test

* fix lint

* Update extensions/rv32im/circuit/src/base_alu/tests.rs

---------

Co-authored-by: Jonathan Wang <[email protected]>

* fix: fixed SHA2 subair trace generation and the testing (#28)

* fix: loadstore sign of immediate (#4)

* [fix] Fix P256 `GENERATOR` and `double_impl` (#2)

* fix p256-generator

* add host tests for ecc

* fix: loadstore sign of immediate

* fix: prints and test

* fix: load_sign_extend tests

* Update docs/specs/ISA.md

* clarify notation and sign extension in ISA spec

* fix reveal transpiler spec

---------

Co-authored-by: Manh Dinh <[email protected]>
Co-authored-by: Jonathan Wang <[email protected]>

* fix transpiler

* fix loadstore adapter

* fix store transpiler

* fix tests

* add e2e test

* fix docs

* fix: jalr imm_sign (#30)

* optimize record struct packing

* chore: use from_bool

* chore: derive_more feature in bench

* fix bench

* fix

---------

Co-authored-by: Xinding Wei <[email protected]>
Co-authored-by: Jonathan Wang <[email protected]>
Co-authored-by: Golovanov399 <[email protected]>
Co-authored-by: Avaneesh-axiom <[email protected]>
Co-authored-by: Arayi Khalatyan <[email protected]>
jonathanpwang added a commit that referenced this pull request Mar 9, 2025
* [fix] Fix P256 `GENERATOR` and `double_impl` (#2)

* fix p256-generator

* add host tests for ecc

* fix: hintstore mem_ptr and rem_words overflow

* fix: is_buffer_start constrain

* Use private repo for stark-backend (#11)

* temp(ci): switch riscv AMI for runner (#14)

* [chore] Update DSL verify to match plonky3 (#5)

* Update DSL verify to match plonky3

* fix: transpose state for p3-keccak tracegen

* chore: add comment linking plonky3 issue

* Update stark-backend commit

---------

Co-authored-by: Jonathan Wang <[email protected]>

* Use full commit in openvm-stark-backend revision (#18)

* chore: update `stark-backend` commit (#19)

* [fix] `Rv32BaseAluAdapterAir` unconstrained register reads (#25)

* Create pull_request_template.md (#26)

* [fix] Poseidon2 verify_batch opcode can send to execution bus for invalid rows (#17)

* [fix] Rust memory allocation overflow (#13)

* Fix and add test

* Fix lint error

* Update crates/toolchain/platform/src/memory.rs

---------

Co-authored-by: Jonathan Wang <[email protected]>

* [fix] Constrain `final_hash` in sha256 air to address audit finding (#12)

* [fix] properly constrain final_hash in sha256 air

* Add negative test for underconstrained final_hash. It was manually checked that this new test would have passed before the change.

* [fix] IsLtArraySubAir (#9)

* add fix

* add tests

* remove diff_val

* chore: update comment

* chore: no try_inverse

---------

Co-authored-by: Jonathan Wang <[email protected]>

* [fix] `Rv32BaseAluAdapterAir` immediate limbs not range-checked (#8)

* fix local_as2

* range check imm limbs

* add count for range check

* add test for unconstrained imm limb

* fix MemoryTester chip trace height

* add test for unconstrained rs2 read

* Revert "fix local_as2"

This reverts commit ef83121bf1796874affaca4682dbb4f9f051b079.

* Revert "add count for range check"

This reverts commit 5252444dfeaf41e7c336648ad92c4736f48ead9d.

* Revert "range check imm limbs"

This reverts commit 2e2937536069ae66849fdf7bba9ea509065d17fe.

* fix unconstrained imm limbs

* fix local_rs2_as test

* fix lint

* Update extensions/rv32im/circuit/src/base_alu/tests.rs

---------

Co-authored-by: Jonathan Wang <[email protected]>

* fix: fixed SHA2 subair trace generation and the testing (#28)

* fix: loadstore sign of immediate (#4)

* [fix] Fix P256 `GENERATOR` and `double_impl` (#2)

* fix p256-generator

* add host tests for ecc

* fix: loadstore sign of immediate

* fix: prints and test

* fix: load_sign_extend tests

* Update docs/specs/ISA.md

* clarify notation and sign extension in ISA spec

* fix reveal transpiler spec

---------

Co-authored-by: Manh Dinh <[email protected]>
Co-authored-by: Jonathan Wang <[email protected]>

* seperate the fixes

* fix naming

* fix: lints

---------

Co-authored-by: Manh Dinh <[email protected]>
Co-authored-by: Xinding Wei <[email protected]>
Co-authored-by: Jonathan Wang <[email protected]>
Co-authored-by: Golovanov399 <[email protected]>
Co-authored-by: Avaneesh-axiom <[email protected]>
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.

2 participants