Commit Graph

246 Commits

Author SHA1 Message Date
Leo
1608312fa2 update openvm and stark-backend hashes (#2811) 2025-06-02 19:51:56 +00:00
Georg Wiese
4ac9378a82 BusMap: Use BTreeMap (#2815)
Makes this code deterministic, which leads to deterministic PIL outputs:

867097fbc1/openvm/src/utils.rs (L210-L216)
2025-06-02 19:23:40 +00:00
Leo
867097fbc1 add bigint branching opcodes as well (#2810)
This came up in the Reth benchmarks. Without this our basic blocks
collection fails to see these extension branch instructions. These don't
come up in the ELF file because they're extensions.
2025-06-02 13:49:45 +00:00
Georg Wiese
350e7def2e Cache Plonk Gates & Refactor (#2805)
With this PR, we don't allocate PlonK gates to compute the same
expression twice anymore, and instead just re-use the existing variable.

I also couldn't resist to refactor the code: Rather than adding yet
another `&mut ...` to `air_to_plonkish`, I introduced a
`CircuitBuilder`. I recommend reviewing this code with the "Hide
whitespace" setting, as most line changes are due to existing code being
indented differently.

Reduces the number of gates for Keccak from 21747 to 11466, as printed
by:
`RUST_LOG=powdr_openvm::powdr_extension::plonk=debug cargo test -r
keccak_plonk_small_prove_mock -- --nocapture`
2025-06-02 12:33:37 +00:00
Steve Wang
062c2a2699 Refactor tests for PGO (#2808)
All changes explained in comments. Prerequisite for
https://github.com/powdr-labs/powdr/pull/2781/
2025-06-02 11:14:19 +00:00
ShuangWu121
9b8616f61f Add bus in plonk circuit builder (#2803)
Add bus interactions' gate in plonk circuit builder

---------

Co-authored-by: Georg Wiese <georgwiese@gmail.com>
2025-05-30 11:57:54 +00:00
Georg Wiese
d6071358d1 Add Option to compile an APC to a PlonK circuit + tests (#2788)
Building on #2787, this PR adds an option to compile a precompile into a
PlonK circuit. It also adds tests, which are currently marked as
`should_fail`, because we don't implement bus interactions yet and
therefore have an imbalanced bus.

Example:
```
$ RUST_LOG=powdr_openvm::powdr_extension::plonk::chip=debug cargo test -r keccak_plonk_small_prove_mock -- --nocapture
...
Generating air proof input for PlonkChip PowdrAutoprecompile_0
   Number of calls: 240
   Plonk gates: 10124
   Trace width: 8
   Trace height: 4194304
...
LogUp multiset equality check failed.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test tests::keccak_plonk_small_prove_mock - should panic ... ok
```
2025-05-30 11:04:18 +00:00
Georg Wiese
0b7976e5e1 PlonK compiler: Get entire machine (#2800)
This should be a good entrypoint for #2779.
2025-05-30 08:25:18 +00:00
Georg Wiese
2afcf93474 Improve Gate display (#2796)
Builds on #2787

Leads to much more readable tests, see [this
discussion](https://github.com/powdr-labs/powdr/pull/2787#discussion_r2112958723).
2025-05-29 17:32:02 +00:00
Georg Wiese
54543b49b0 Connect PlonK chip to circuit generator (#2787)
This PR implements everything needed for the `PlonkChip` to actually
implement validating the algebraic constraints (no bus interactions
yet):
- I changed the implementation to assert zero, see comment below.
- Added a `build_circuit` function that takes a list of constraints,
rather than a single constraint.
- The chip now calls this function, passing the algebraic constraints.
- Some fixes in the PlonK witness generation, see comment below.

With this PR, none of this code is run yet, but #2788 does run it and
adds tests.
2025-05-29 13:46:32 +00:00
chriseth
0e140dc1a1 Remove equal bus interactions (#2790)
Co-authored-by: Leo <leo@powdrlabs.com>
2025-05-29 08:17:37 +00:00
Thibaut Schaeffer
4240af53a9 Tweaks for reth benchmark (#2792) 2025-05-28 17:01:25 +00:00
chriseth
1052c220a4 Run optimization in loop. (#2774)
Co-authored-by: Leo <leo@powdrlabs.com>
2025-05-28 16:01:36 +00:00
Leo
84b2855f3d make degree bound part of config (#2789) 2025-05-28 14:22:34 +00:00
Thibaut Schaeffer
8d27539adf Update openvm dep (#2786)
Updated because the version changed to 1.1.2
2025-05-28 14:19:21 +00:00
chriseth
96a27406d4 Remove bus interaction kind. (#2784) 2025-05-28 12:55:33 +00:00
Georg Wiese
c0df3043c9 Implement Display for Gate (#2783) 2025-05-28 12:23:04 +00:00
Georg Wiese
a63a1690a8 Find guest block that is actually executed (#2782)
Fixes a TODO in the tests.
2025-05-28 11:53:17 +00:00
Steve Wang
fbba7198bb Removed unwanted basic block (#2780)
Moved over from https://github.com/powdr-labs/powdr-openvm/pull/119. All
changes reviewed and ready for merge.
2025-05-28 10:06:06 +00:00
chriseth
1b011343e3 Remove equal constraints. (#2777) 2025-05-27 14:46:11 +00:00
chriseth
5bdb442ddb Refactor autoprecompiles (#2773)
Except for the removal of `collect_basic_blocks`, this just moves code
around and renames.
2025-05-27 13:02:13 +00:00
ShuangWu121
340fa97101 Set temp to be unused in zero assertion (#2775)
When q_o is zero, set temp to be Unused, to not break the plonk circuit
witness generation
[here](fd00f930bd/openvm/src/powdr_extension/plonk/chip.rs (L232))
2025-05-27 12:45:25 +00:00
Georg Wiese
fd00f930bd Plonk witness generation (#2767)
Builds on #2765 (already approved)

Implements a basic algorithm for PlonK witness generation.

Has a lot of TODOs and the code isn't actually run yet, but I'd suggest
to merge it already and iterate on that.

The general algorithm is:
- Call `Executor::generate_witness()` to get all the values of the
variables in the original constraint systems (= what would have been
trace cells in `PowdrChip`)
- For each call:
  - For each gate:
- Set the selector columns (which are currently witness columns, should
eventually be preprocessed columns)
- Solve for temporary variables on the fly, assuming that there is at
most unknown when processing gates in order
- Set the witness columns (`a`, `b`, `c`), with their values either
coming from the result of `Executor::generate_witness()` or a temporary
variable.
2025-05-27 10:00:25 +00:00
ShuangWu121
c26d04763d Make plonk expression evaluated to be zero (#2771)
Current plonk compiler transfer an air expression to plonk gate, but it
doesn't evaluate the expression.
for example: 

`a * b * c = 0`

it will compile it to 

```
a * b = temp0
temp0 * c = temp1
```
This PR set the last gate output, which is the output of the expression
(temp1 in the above example) to be zero

---------

Co-authored-by: Georg Wiese <georgwiese@gmail.com>
2025-05-27 09:16:44 +00:00
Leo
a76e8c415f Configuration bus map instead of constant (#2766) 2025-05-26 14:08:40 +00:00
Leandro Pacheco
3fc558338b couple of new unsupported APC instructions (#2770)
these were hit in scroll APCs
2025-05-26 13:30:44 +00:00
Georg Wiese
fd191411fe Implement more Plonk Chip functions (#2765)
Continuing implementing the Plonk Chip, now only
`generate_air_proof_input` is missing! Everything should be analogous to
`PowdrChip`.
2025-05-26 12:45:53 +00:00
ShuangWu121
a579cbfd97 Add air to plonk air circuit compiler (#2769)
Synchronise this
[PR](https://github.com/powdr-labs/powdr-openvm/pull/116) in
powdr-openvm
2025-05-26 10:12:15 +00:00
Thibaut Schaeffer
8911044ffb Witgen: improve tracegen (#2754)
- Following the insight by @georgwiese that `eval` is actually not
called many times, this PR changes `PowdrAir` to store the AST nodes
based on `AlgebraicExpression` (as opposed to openvm
SymbolicExpression).
- During trace generation, we do work on each row of the table, which
currently includes some table lookups in the table of airs. Move as much
as possible out of the part which runs for each row, saving map lookups.
- Avoid collecting into a vector when processing bus interactions
2025-05-24 07:58:14 +00:00
chriseth
a9cc344c9c Implement range constraint transfer for bus interactions with complex expressions (#2761)
Depends on #2758
2025-05-23 15:12:17 +00:00
Leo
9084ac4fc3 api features option (#2763)
This allows users of the `powdr-openvm` lib to pass build features.
2025-05-23 14:00:29 +00:00
chriseth
0ffa16ecec Count columns properly. (#2762) 2025-05-23 13:43:29 +00:00
chriseth
c526b9283c Baseline test (#2755) 2025-05-22 15:36:48 +00:00
Georg Wiese
97645d5f52 Executor: Generate AIR proof input (#2752)
Continuing #2733, this PR moves most of
`PowdrChip::generate_air_proof_input` into the `Executor`. As a result,
it is more encapsulated (all its fields are private now), and the
interface is such that we should be able to use it in the `PlonkChip` as
well: `Executor::generate_witness` returns a matrix of all variable
values, for each call to the APC. In the `PowdrChip`, this is the
witness directly; in the `PlonkChip`, we can compute the witness from
this matrix.

This PR *mostly* moves code. I would prefer to leave any bigger changes
to a different PR, so that it doesn't get too entangled.
2025-05-22 09:17:42 +00:00
Leo
7647c67482 split riscv modules in crates so other crates can have minimal deps (#2747) 2025-05-21 15:37:42 +00:00
Georg Wiese
485cc0388b Remove evm-verify feature (#2748)
Reduces the number of the `openvm` crate from 550 to 377.
(measured by `cargo tree --edges=normal -q | sed 's/.*── //' | cut -d' '
-f1 | sort -u | wc -l`.)

We no longer create the root proof and the last Halo2 proof that can be
verified on chain. These proofs tend to take a long time that is largely
independent of the statement being proven (and with which chips), so it
just adds a constant overhead.

To test, run this from the `cli-openvm`:
```
$ RUST_LOG=powdr_openvm=info cargo run -r prove $(pwd)/../openvm/guest-keccak --autoprecompiles 1 --pgo --input 10 --recursion
...
INFO     i [info]: Generating app proof...
INFO     i [info]: App proof took 1.378542917s
INFO     i [info]: Public values: [155, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
INFO     i [info]: App proof verification done.
INFO     i [info]: Generating aggregation proving key...
INFO     i [info]: Generating aggregation proof...
INFO     i [info]: Agg proof (inner recursion) took 22.166544083s
INFO     i [info]: All done. 
```
2025-05-21 12:27:04 +00:00
Leo
1d6a12b1b8 update openvm rev (#2741) 2025-05-21 07:54:51 +00:00
Leo
1cc2536da9 reduce deps in powdr-openvm (#2743)
The goal here is to make more explicit which powdr crates are needed for
powdr-openvm.
After this PR, next concrete steps are:

- Extract the elf stuff from powdr-riscv into another crate so that this
new crate can be used by powdr-openvm instead of powdr-riscv, since that
one has tons of other dependencies
- constraint-solver only depends on powdr-number which is great!
- powdr-autoprecompiles depends on a bunch of other powdr crates.
Ideally we'd eventually be able to remove from the dep list: ast,
parser, parser-util, pil-analyzer, pilopt
2025-05-21 05:56:54 +00:00
Leo
184d8a2fd9 use optimized openvm features (#2736) 2025-05-20 15:40:40 +00:00
Georg Wiese
0fc33b6618 Extract executor (#2733)
Extracts (one of the two...) `PowdrExecutor` into its own file. I just
moved the code (the only change is that I made the fields public for
now, to minimize code change).

I think the next steps should be:
- Make it do most of what `generate_air_proof_input` does as well
- Refactor (so the behavior is more encapsulated)
- Re-use it for witness generation of the PlonK chip
2025-05-20 10:37:21 +00:00
Georg Wiese
34b59516a1 Add PlonK chip (#2732)
Bootstrapping a chip that implements a PlonK circuit. Implements the
AIR, but leaves all other chip methods with `todo!()`.
2025-05-20 08:47:15 +00:00
Georg Wiese
73bb984816 Bug fix: constrain the entire data to be equal (#2729)
This bug was both a soundness bug and a performance bug, leading to
fewer columns being removed (although also too many bus interactions
being removed, see below).
2025-05-19 16:25:04 +00:00
Leandro Pacheco
c390627ccf openvm apc: ignore opcodes PHANTOM and TERMINATE (#2728) 2025-05-19 13:54:10 +00:00
Georg Wiese
81659e5c8a Remove disconnected columns (#2724)
This PR is an alternative to #2721, also fixing the regression of #2717.
It actually leads to benefits beyond that.

The idea is to only keep columns that are connected to *stateful* bus
interactions (i.e., memory and the execution bridge), because this is
the only way to affect the state of the VM. This is actually a special
case of the `remove_trivial_bus_interactions` step (trivial bus
interactions are connected to no columns, and therefore removed), so I
removed that (and simplified the `ConcreteBusInteractionHandler`).


[This](https://gist.github.com/georgwiese/56d768e86bbf6def28260ca92f0b5180)
is a diff of the generated PIL of the Keccak APC. I spot-checked a few
instances of removed columns and there were often columns that were
range-checked but otherwise un-constrained.
2025-05-19 13:02:36 +00:00
Thibaut Schaeffer
76bbebb53c Move patch to workspace cargo toml (#2726) 2025-05-18 08:46:48 +00:00
Thibaut Schaeffer
2d6708bbc5 Add openvm crates (#2714)
Based on commit 1dbe4db
- Split into two crates, lib and cli
- upgrade stwo, marked one stwo test `should_panic` @ShuangWu121 
- various clippy and fmt fixes linked to the rust version update
- bring all rust versions to 2025-05-14. CI still installs other
versions for openvm which uses them internally. The stable rust version
we test on is bumped to 1.85
- remove `examples` and related tests, which test the powdr crate on the
previous version of powdr (since it uses another nightly). Happy to
discuss this if it's important @leonardoalt
2025-05-16 14:30:09 +00:00