Commit Graph

32 Commits

Author SHA1 Message Date
chriseth
5c2cc8f126 Add unit test for sha256 optimization (#3186) 2025-08-18 14:47:22 +00:00
Georg Wiese
bdf3a5fefa Low-degree bus interaction optimizer (#3130)
This PR adds a new optimizer: If a stateless bus interaction (a.k.a.
lookup) implements a low-degree function, it is replaced by a polynomial
constraint (and range constraints).

Some examples include:
- `xor(a, 0xff)` (logical `not` on bytes): This is a linear function
(`255 - a`)
- `xor(a, b)`, where `a` and `b` are known to not have the same bits
set: This equals `a + b`
- `xor(a, b)`, where `a` and `b` are known to be bit-valued: This is
equal to `a + b - 2 * a * b`

Doing this replacement has several advantages:
- A bus interaction is replaced with a polynomial constraint (which is
usually much cheaper)
- Because the output is equal to a low-degree expression of the inputs
(often linear), the inliner can inline it, so we don't have to commit to
it

Note that in addition to the linear function, a lookup always *also*
enforces a range constraint. These are added to the system by using the
API added with the range constraint optimizer (#3151). In many cases,
these constraints are redundant and can be removed again by the range
constraint optimizer (e.g. the inputs might come from memory, which can
be assumed to store byte-constrained words.

---------

Co-authored-by: Leo <leo@powdrlabs.com>
Co-authored-by: chriseth <chris@ethereum.org>
2025-08-15 10:47:55 +00:00
Georg Wiese
bb56087791 Use default OpenVM degree bounds (#3167)
Builds on #3166
2025-08-12 15:13:23 +00:00
Georg Wiese
a178517a9d Use expect-test in optimizer test (#3166)
Builds on #3164 (in queue)
2025-08-11 20:39:45 +00:00
Georg Wiese
46100870f5 Bug fix in filter_byte_constraints (#3164)
Fixes a soundness bug @chriseth
[found](https://github.com/powdr-labs/powdr/pull/3151/files#r2267259864)
that was introduced in #3151: I thought we can e.g. check `expr` to be 6
bit by checking `4 * expr` to be a byte. That is incorrect, e.g.
$4^{-1}$ would pass the check but should not.
2025-08-11 19:03:50 +00:00
Georg Wiese
c638bbf081 Read tuple range checker sizes from config (#3154)
We used the default tuple range checker sizes, but it should be read
from the config. For example, in the reth benchmarks, the sizes are
actually different, leading to potential soundness or completeness bugs.
2025-08-08 16:00:57 +00:00
Georg Wiese
71d821c427 Range constraint optimizer (#3151)
Fixes #3128

---------

Co-authored-by: Leo <leo@powdrlabs.com>
2025-08-08 14:05:05 +00:00
chriseth
24ddce250d Prefer inlining last variable. (#3136) 2025-08-05 19:03:23 +00:00
Georg Wiese
d74aaa1a83 Generalize memory (#3065)
This PR generalizes the memory optimizer to not make any specific
assumptions about the structure of memory bus interactions. This is done
by turning `MemoryBusInteraction` into a trait, which is an associated
type in the `Adapter`. Currently, there is one concrete implementation,
`OpenVmMemoryBusInteraction`.
2025-07-22 08:19:13 +00:00
Georg Wiese
caf069eb85 Generalize PC lookup & execution bus handling (#3055)
Generalizations that make fewer assumptions about the structure of bus
interactions like PC lookups and bus interactions. See comments below.

One change is that we know inline the initial PC (because we know it for
any given basic block), which leads to *all* PC lookups being removed,
slightly improving performance (at least reducing one witness column &
one bus interaction).

---------

Co-authored-by: schaeff <thibaut@powdrlabs.com>
2025-07-20 08:09:32 +00:00
Thibaut Schaeffer
3d2d2b756c Use all columns in pgo (#3007)
When looking at metrics to rank apcs, we currently only take into
account main columns (excluding second stage columns)
Fix that.
2025-07-08 14:29:14 +00:00
Thibaut Schaeffer
1418069ea1 Remove option (#2986) 2025-07-03 11:06:19 +00:00
Georg Wiese
69be571b80 Complete clean-up of legacy_expression module (#2905)
Changes:
- Removed `PolyID`, including the polynomial type. Now
`AlgebraicReference` is just an ID with a name (for display purposes)
- Removed the `Column` type, which would have been essentially the same
as `AlgebraicReference`
- Renamed `legacy_expression` -> `expression`
- Because of the type change, I needed to update checked-in CBOR files.
2025-06-16 21:36:51 +00:00
Georg Wiese
a515b323f9 Derive more assignments (#2866)
Implementing the second idea mentioned in #2864.
2025-06-16 09:45:08 +00:00
Georg Wiese
25fcf8df2d Register 0 returns 0 (#2899)
We can actually encode the `x0` semantics in the memory bus interaction
handler.

Note that this still keeps a register access to `x0` that could be
removed, but now at least we're not allocating 4 witness columns for the
value *and* we might be able to derive more values at compile time.
2025-06-14 09:48:52 +00:00
Thibaut Schaeffer
72145fb231 Move openvm default bus map out of apc crate (#2889) 2025-06-13 00:06:30 +00:00
Steve Wang
0a5aaabb5e Move bus map (#2872)
Solves #2856.
2025-06-11 09:41:28 +00:00
Leandro Pacheco
b69ec5ed64 Inliner bus degree (#2799)
depends on #2797
2025-06-09 12:57:23 +00:00
Georg Wiese
18c2d16946 Reapply "Optimize xor." (#2827) (#2846)
Reapplies #2827, reverts commit
48732bd6f0.
2025-06-06 14:09:14 +00:00
Leo
48732bd6f0 Revert "Optimize xor." (#2842)
Reverts powdr-labs/powdr#2827

It leads to a witness bug (OodMismatch, witness does not satisfy the
constraints) in the keccak test with `--inputs 25000 --autoprecompiles
3`
2025-06-05 09:51:40 +00:00
chriseth
53ec187843 Optimize xor. (#2827)
Co-authored-by: Leo <leo@powdrlabs.com>
Co-authored-by: Georg Wiese <georgwiese@gmail.com>
2025-06-04 10:53:24 +00:00
chriseth
a0516a8447 Optimize memory (#2716)
Depends on #2794

---------

Co-authored-by: Leo <leo@powdrlabs.com>
Co-authored-by: Georg Wiese <georgwiese@gmail.com>
2025-06-04 09:42:30 +00:00
Steve Wang
85905f3373 Pgo trace cell (#2781)
Depend on: https://github.com/powdr-labs/powdr/pull/2808

Mostly the same as: https://github.com/powdr-labs/powdr-openvm/pull/121

Differences:
1. Given that we generate apc for all eligible basic blocks, some apc
fail due to some new optimization applied (currently narrowed down to
`exhaustive_search`). Note that previously in powdr-openvm, apc can be
generated for all eligible basic blocks.
2. Remove basic block that fail to generate apc for from the list of
eligible basic blocks, which requires propogating error information all
the way up to `customize`.
2025-06-04 07:55:05 +00:00
chriseth
3a2802042a Fix xor bus (#2798) 2025-06-03 09:59:04 +00:00
chriseth
0e140dc1a1 Remove equal bus interactions (#2790)
Co-authored-by: Leo <leo@powdrlabs.com>
2025-05-29 08:17:37 +00:00
chriseth
1052c220a4 Run optimization in loop. (#2774)
Co-authored-by: Leo <leo@powdrlabs.com>
2025-05-28 16:01:36 +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
Leo
a76e8c415f Configuration bus map instead of constant (#2766) 2025-05-26 14:08:40 +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
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