106 Commits

Author SHA1 Message Date
Steve Wang
de718d96dc Create bus.asm call to expose native BusInteraction to the backend (#2510)
Currently just the bus.asm call is created. Next step will be editing
`bus.rs` linker to do this call for backends that needs the native bus
interaction.

A key quesiton remains whether we need to import the backend crate or
create another linker mode in the linker crate in order to distinguish
which cases to pass down the native bus interaction vs which cases to
call `bus_multi_linker`.

A third solution is to make both `bus_multi_linker` and
`bus_native_linker` call in `bus.rs`, and this will create both
`BusInteraction` and `PhantomBusInteraction` for all backends, and some
backends can just ignore the native `BusInteraction`, similar to what
we've done for native lookup and permutation.
2025-03-26 16:45:47 +00:00
Lucas Clemente Vella
0ed9db7fb6 Fix lint on log calls. (#2589)
Log crate now has clippy enabled for its arguments
2025-03-25 18:46:26 +00:00
Thibaut Schaeffer
bb86aefc8f Skip dispatcher for main VM (#2504)
To simplify witgen, avoid using a dispatcher for the main VM

---------

Co-authored-by: chriseth <chriseth.github@gmail.com>
Co-authored-by: Leandro Pacheco <contact@leandropacheco.com>
Co-authored-by: chriseth <chris@ethereum.org>
2025-03-12 15:38:05 +00:00
ShuangWu121
aa8c656c65 build bus using counter (#2523)
changing the bus_id build from hash to constant
2025-03-06 12:29:37 +00:00
Steve Wang
59c1effcc1 Bus interaction linker single accumulator (#2486)
Depends on #2484. Implements task number 1 in issue #2485. Create one
bus interaction for each object (machine).
2025-02-17 15:50:43 +00:00
Steve Wang
ee650efc8e Bus interaction simplify API (#2483)
Ready for review. Depends on #2479 merged, which is currently in a chain
of 3 PRs that need merging.

Inspired by Chris' comment here:
https://github.com/powdr-labs/powdr/pull/2465#discussion_r1954166247

This PR will remove anything in the like of
`bus_send(BusInteraction::Send(...))`, because the "send" is duplicated
information. Instead, it will just be `bus` or `bus_multi` that handles
both the send and the receive cases.

Linker and tests that depend on these APIs are also updated.
2025-02-17 09:06:22 +00:00
Steve Wang
187c79631d 30-bit bus interaction ID (#2474)
Solves #2470. Depends on #2465. Approval will only works after merging
#2465.

The following is a response to #2470 and motivation of this PR: 

Chance of collission:
For 24-bits:
100 interactions: 0.000295000053831429
1000 interactions: 0.02933425835911685
10000 interactions: 0.9492338975723106

For 30-bits (theoretically the largest we could get to without changing
pil code due to field prime of bb and m31):
100 interactions: 4.610036260510597e-06
1000 interactions: 0.0004650875835883195
10000 interactions: 0.04549425469529611

Neither look ideal, but I think after
https://github.com/powdr-labs/powdr/pull/2469, bus linker mode should
always have 2 bus interactions only. For user defined bus interactions,
they can intentionally input IDs that don't clash, so I think just using
30-bit interaction id should be good enough for 29 bits of security
(under 2 interactions linker case).
2025-02-14 12:57:51 +00:00
Steve Wang
7671334ed2 Bus Interaction Enum (#2465)
Ready for review. Solves #2460. Depends on #2469. Prior bug fixed (due
to an error in the `bus.asm` code update when unwrapping the new
`BusInteraction` enum type.
2025-02-14 09:45:16 +00:00
Steve Wang
27ce67a6f2 Bus multi interaction batch lookup and permutation receives (#2469)
Ready for review. Depends on #2468. Implements bullet point number 2
mentioned in #2468.

The biggest challenge would be adding the multiplicity columns and an
additional constraint `(1 - selector) * multiplicity = 0` for the lookup
case, and this can be achieve by two methods:
1. Adding the array of column and array of constraints at the linker
level.
2. Create another PIL function that batch permutation receives and
lookup receives to the same bus multi interaction.

I'm opting for method 2 because method 1 likely requires lots of
processing of numerous lower level ast `Expression` types, which would
likely look a lot messier than method 2.

---------

Co-authored-by: schaeff <thibaut@powdrlabs.com>
2025-02-13 04:37:40 +00:00
Steve Wang
b391f362a3 Bus multi interaction linker (#2468)
Ready for review. Depends on #2459, which depends on #2457.

1. Added `lookup_multi_receive` and `permutation_multi_receive` APIs for
the linker and test files to use.
2. Modified linker to use the multi version by default. This in practice
reduces the number of bus interactions to 2 or 3 (depending if we only
have permutation, only have lookup, or have both). This can be furthur
optimized by directly using `bus_multi_receive` function in the linker,
but requires more processing of lower level expressions, which I'd leave
to another PR. In practice, this would reduce the number of bus
interactions from 2 or 3 to always 2. This is currently being
implemented in #2469.
3. Added test cases to the pipeline.
2025-02-12 13:58:26 +00:00
Thibaut Schaeffer
8fb9153754 Make interaction ids 16 bits (#2446)
cc @leonardoalt 

32 bit interaction ids are too large for small fields. Switch to 16 bit.
2025-02-05 15:25:16 +00:00
Thibaut Schaeffer
6bb6690a8a Single receive in bus linker (#2359)
- separate the native and bus linker as two implementations of a
`LinkerBackend` trait
- refactor the object data structures to simplify linker implementation
- change the bus linker to use the bus directly and use a single receive
per operation, with the `interaction_id` being hash based
- pull the permutation selector array treatment into the linker, since
it should be linker specific (per link for native, per operation for
bus)

---------

Co-authored-by: Georg Wiese <georgwiese@gmail.com>
Co-authored-by: chriseth <chris@ethereum.org>
Co-authored-by: Leo <leo@powdrlabs.com>
2025-01-29 13:19:21 +00:00
Georg Wiese
d382a38f22 Make latch semantic clearer (#2358)
Depends on #2360

Changes the semantics of the `PhantomBusInteraction.latch` field
slightly, to make my life easier with #2351. Basically, we want it to be
exactly what the RHS selector would have been in a lookup / permutation:
A fixed column latch for a lookup, and equal to the multiplicity for the
permutation. This way, witgen can treat it just like it treats selectors
now.

Eventually, I think we should remove the latch again. The permutation
latch is equal to the multiplicity anyway, and the lookup latch should
be detectable by looking for a constraint like `(1 - latch) *
multiplicity = 0;`.
2025-01-20 11:07:25 +00:00
Thibaut Schaeffer
28ad2d8801 Add latch to phantom bus interaction (#2258)
We need this for witness generation.
This propagates to `bus_interaction`, `bus_receive`, `lookup_receive`
and `permutation_receive` also taking a latch.
2025-01-02 23:07:39 +00:00
Georg Wiese
816e8c742c Enable Bus in tests (#2289)
This PR uses `LinkerMode::Bus` in all tests which:
- Are on Goldilocks or BN254 (the bus is not implemented for smaller
fields), AND
- Are tested with the mock prover or Plonky3 (while Halo2 does support
the bus in principle, its runtime is exponential, because it inlines
intermediate polynomials)

This is true for most tests.

Doing so, I came across a few bugs. I added comments for them below.
2024-12-30 17:44:15 +00:00
Thibaut Schaeffer
ad858a1d7d Run cargo bench in PR CI tests and report result to PR and Github Pages (#2198)
Run benchmarks in PRs, fail and warn on the PR if we got more than 20%
slower, add benchmark results to https://docs.powdr.org/dev/bench/
2024-12-09 14:51:20 +00:00
Thibaut Schaeffer
c0fefae3e7 Introduce workspace-level lints (#2166)
Reduce the cost of adding a lint from O(#workspace_crates) to 1.
2024-11-29 14:02:53 +00:00
Thibaut Schaeffer
c9a5058c41 Remove monolithic inference in the linker (#2093)
- Replace the rule which sets all degrees to that of main if it is
static and use a CLI flag instead: `--degrees-mode`
- Adjust tests to run mostly on vadcop
- Tweak tests to reduce wasted rows
2024-11-26 10:41:05 +00:00
Leo
82798c8d76 fix nightly tests (#2115) 2024-11-20 09:42:00 +00:00
Thibaut Schaeffer
f3c6c86ed6 Linker bus support (#2073)
Refactor of the linker to enable creating statements both in the source
and in the target of a link. Instead of creating a vector of statements,
we create a (name=>namespace) map.

The linker mode is exposed in the CLI, and currently defaults to the
native lookup/permutation statements.

Bus linking can be activated the following way:

```console
cargo run pil test_data/asm/vm_to_block_unique_interface.asm --force --linker-mode bus
```

TODO:
- [x] absolute names
2024-11-18 10:36:25 +00:00
Leo
a3474c3174 Remove env var MAX_DEGREE_LOG (#2092) 2024-11-15 19:25:09 +00:00
chriseth
a3f7eac204 Rename PILGraph to MachineInstanceGraph. (#2001) 2024-10-31 14:32:53 +00:00
Leandro Pacheco
718c333ff9 Query input/output rework (#1828)
This PR does a few things:
- unify `Input/DataIdentifier` into a single `Input` query that takes
(channel,idx) and returns a field element
- Output query takes (channel, fe)
- change the related prover functions to reflect this
This interface is used by, but not the same, as the input/output for the
riscv machine.
How to use these to input/output bytes or serialized data is a job of
the runtime implementation.
2024-09-24 13:58:38 +00:00
Thibaut Schaeffer
64e7bf1402 Refactor asm ast (#1736) 2024-09-24 12:54:20 +00:00
chriseth
6789fe0271 Remove query functions from asm processing (#1746)
Co-authored-by: Lucas Clemente Vella <lvella@powdrlabs.com>
2024-09-13 13:56:06 +00:00
Gastón Zanitti
945d613f15 Remove lookups from PilStatement (#1782)
Co-authored-by: chriseth <chris@ethereum.org>
2024-09-12 10:02:46 +00:00
Lucas Clemente Vella
83e2c841e6 Trying buildjet CI runner (#1777) 2024-09-11 08:53:12 +00:00
Gastón Zanitti
4f190b9bf9 Lookups as Binary ops (#1770)
Co-authored-by: chriseth <chris@ethereum.org>
2024-09-10 15:15:58 +00:00
Thibaut Schaeffer
7f259b43c7 Support degree ranges (#1667)
We currently hardcode the range of degrees that variable degree machines
are preprocessed for. Expose that in machines instead.

This changes pil namespaces to accept a min and max degree:
```
namespace main(123..456);
namespace main(5); // allowed for backward compatibility, translates to `5..5`
```

It adds two new builtins:
```
std::prover::min_degree
std::prover::max_degree
```

And sets the behavior of the `std::prover::degree` builtin to only
succeed if `min_degree` and `max_degree` are equal.
2024-09-03 12:37:44 +00:00
Gastón Zanitti
ea2f06df16 LambdaExpression formatting (#1733)
This PR fixes issue #1728.
1) Removes the blank space that was printed even if the body of the
blocks was empty.
2) Adds the Precedence trait to LambdaExpressions to correctly handle
the use of parentheses.
2024-09-02 09:27:05 +00:00
Gastón Zanitti
0dc3ae762f Depreciation of . by :: in paths (#1694) 2024-08-23 07:39:50 +00:00
chriseth
440e555c8f Change display for witness columns. (#1665) 2024-08-15 08:56:58 +00:00
Thibaut Schaeffer
6637bba4db Set ROM degree (#1666)
When creating the ROM machine, give it a degree:
- if the VM has a degree, pass the same degree to its ROM machine (this
is required to support the monolithic case where all degrees must match)
- otherwise, pass the length of the ROM

---------

Co-authored-by: Georg Wiese <georgwiese@gmail.com>
2024-08-13 11:51:11 +00:00
Thibaut Schaeffer
bda1b8f29a Enable the linker to output dynamic namespaces (#1640)
What we can have after this PR:
- only dynamic namespaces
- dynamic main, others dynamic or static

What we still cannot have:
- static main and another machines dynamic

The change to `_linker_first_step` can be reverted after #1565
2024-08-01 13:22:53 +00:00
onurinanc
bc5f71e109 fix sub implementation in link_merging.asm test (#1600)
The previous version of link_merging.asm is not working correctly since
the `operation sub<1>` implementation is wrong. With this PR, `operation
sub<1>` implementation is fixed.
2024-07-29 11:05:27 +00:00
chriseth
ac3b96eecf Even more quick tests (#1613) 2024-07-26 08:16:45 +00:00
chriseth
67742879ed Speed up quick tests (#1611) 2024-07-25 17:42:20 +00:00
Leo
8f72dd436a reduce the degree of compiled asm to pil so it works with P3 (#1596)
Depends on https://github.com/powdr-labs/powdr/pull/1594

---------

Co-authored-by: schaeff <thibaut@schaeff.fr>
2024-07-23 12:11:04 +00:00
Thibaut Schaeffer
8b32dcaa50 Extract ROM machine (#1555)
This PR continues the task to replace lookups by links. The advantages
of this approach are:
- with a link, the two machines can have different degrees and be proven
separately
- with a lookup, only a monolithic proof works
- some backends such as Plonky3 do not support lookups
- this is backwards compatible, since in the monolithic setting, links
are turned into lookups

In the compiler, we currently reduce each machine to another machine
which has only pil code and links. To this end, in the case of virtual
machines, we encode the program in fixed columns. This change introduces
a separate machine to store the ROM. Therefore, each VM gets turned into
not one, but two machines:

```
machine MyVM {
}
```

becomes

```
machine MyVM {
   MyVMROM _rom;
}

machine MyVMROM {
}
```

We introduce a new name alongside the original name, which pollutes the
module. When raised, it was decided that we should not currently allow
defining the ROM machine *inside* the VM.

A better long term solution would be to have a generic `ROM` machine in
the stdlib which can be instantiated with the fixed columns which encode
the program, using them in the `get_line` operation. There are a few
missing pieces in the asm language to enable that.
2024-07-22 10:42:32 +00:00
Lucas Clemente Vella
8bc4d4b937 Updating and uniformizing itetools. (#1547) 2024-07-08 14:32:36 +00:00
Thibaut Schaeffer
dfa84e9933 Visit instructions and links in canonicalizer (#1513) 2024-07-08 12:15:42 +00:00
Thibaut Schaeffer
ccef995406 Relax linker degree requirements (#1532)
Before: all machines must have the same degree, no degree gets replaced
with the main degree
After: machines can have different degrees, no degree gets replaced with
the main degree

We'll probably need another change to support dynamic degree but this
should be enough for machines of different, static, degree.
2024-07-05 15:01:33 +00:00
Leandro Pacheco
72b4d739d7 merge compatible links from different instructions (#1467)
Merge compatible `link`s into a single permutation/lookup.
We only consider merging links from different instructions, as a single
instruction can be active at a time.
Links with next references are ignored due to a limitation in witgen
(left a TODO so its easily fixed upon witgen support)
2024-07-02 10:53:07 +00:00
Gastón Zanitti
91d41df9a0 Allow blocks to be empty (#1435)
This PR builds on top of #1393.
It mainly modifies the grammar by changing the way SelectedExpressions
are declared, to allow blocks to be empty.

---------

Co-authored-by: chriseth <chris@ethereum.org>
2024-07-01 15:05:32 +00:00
Leandro Pacheco
abbe26618f Instructions with link statements (#1439)
Allow VM instructions to use the `link` notation, unifying the way
machines are linked from VMs and block machines.
Previous syntax for "external instructions" not allowed anymore, and
should use the new `link` syntax.
2024-06-18 17:31:38 +00:00
chriseth
adee683796 Refactor error to use SourceRef (#1398) 2024-05-31 14:47:05 +00:00
Leo
34d04ed873 move internal dependencies to shared version (#1379)
Trying this out which will make releases much easier
2024-05-15 10:46:34 +00:00
Gastón Zanitti
3f2792f98f Number struct in Expressions (#1353)
This PR is part of issue https://github.com/powdr-labs/powdr/pull/1345.
In particular, it adds the struct Number to Expressions to homogenize
the structure before including source references.
2024-05-10 08:06:01 +00:00
Amin Latifi
9472671b9b Reduce Number of Expression Parentheses (#1289)
Adds binary operation precedence support to avoid unnecessary
parentheses in expression printed format

- #962

---------

Co-authored-by: chriseth <chris@ethereum.org>
2024-05-09 07:33:26 +00:00
chriseth
62c3eadc4c Re-enable non-inlined format args (#1362)
Fixes https://github.com/powdr-labs/powdr/issues/1360
2024-05-08 16:27:22 +00:00