Commit Graph

343 Commits

Author SHA1 Message Date
Lucas Clemente Vella
e58ddac313 Aggregating challenges of all proofs (#1603)
Co-authored-by: Georg Wiese <georgwiese@gmail.com>
2024-07-29 21:06:04 +00:00
Georg Wiese
5c31155a7e Add dynamic VADCOP witness generation (for block machines) (#1595)
Another step towards #1572
Builds on #1574

I modified witness generation as follows:
- Each machine keeps track of its current size; whenever a fixed column
value is read, it has to pass the requested size as well.
- If fixed columns are available in several sizes, witness generation
starts out by using the largest size, as before
- When finalizing a block machine, it "downsizes" the machine to the
smallest possible value

Doing this for other machine types (e.g. VM, memory, etc) should be done
in another PR.

In the `vm_to_block_dynamic_length.pil` example, witness generation now
pics the minimum size instead of the maximum size for `main_arith`

```
$ cargo run pil test_data/pil/vm_to_block_dynamic_length.pil -o output -f --field bn254 --prove-with halo2-mock-composite
...
== Proving machine: main (size 256)
==> Machine proof of 256 rows (0 bytes) computed in 60.174583ms
size: 256
Machine: main__rom
== Proving machine: main__rom (size 256)
==> Machine proof of 256 rows (0 bytes) computed in 33.310292ms
size: 32
Machine: main_arith
== Proving machine: main_arith (size 32)
==> Machine proof of 32 rows (0 bytes) computed in 2.766541ms
```
2024-07-23 12:21:33 +00:00
Georg Wiese
7a1ccfcead Add dynamic VADCOP proving (no witgen yet) (#1574)
Fixes #1496
Also, a step towards #1572

This PR implements the steps needed in `CompositeBackend` to implement
dynamic VADCOP.

In summary:
- If a machines size (a.k.a. "degree") is set to `None`, fixed columns
are computed in all powers of too in some hard-coded range. This fixes
#1572. As a result, machines with a size set to `None` are available in
multiple sizes. If the size is explicitly set by the user, the machine
is only available in that one size.
- Note that the ASM linker still sets the size of machines without a
size. So, currently, this can only happen when coming from PIL directly.
- `CompositeBackend` instantiates a new backend for each machine *and
size*:
  - The verification key contains a key for each machine and size.
- When proving, it it uses the backend of whatever size the witness has.
The size chosen is also stored in the proof.
  - When verifying, the verification key of the reported size is used.
- Witness generation currently chooses the largest available size. This
will change in a future PR.

This is an example:
```
$ cargo run pil test_data/pil/vm_to_block_dynamic_length.pil -o output -f --field bn254 --prove-with halo2-mock-composite
...
== Proving machine: main (size 256)
==> Machine proof of 256 rows (0 bytes) computed in 209.101166ms
== Proving machine: main__rom (size 256)
==> Machine proof of 256 rows (0 bytes) computed in 226.87175ms
== Proving machine: main_arith (size 1024)
==> Machine proof of 1024 rows (0 bytes) computed in 432.807583ms
```
2024-07-23 09:41:44 +00:00
Georg Wiese
de2905de69 Add data structures for variably-sized fixed columns (#1542)
This PR adds `number::VariablySizedColumns`, which can store several
sizes of the same column. Currently, we always just have one size, but
as part of #1496, we can relax that.
2024-07-22 16:10:23 +00:00
Georg Wiese
9483a26f41 Block machine: report side effect (fixes TODO) (#1563)
Since #1385 is resolved, we can fix this TODO.
2024-07-17 09:51:10 +00:00
Georg Wiese
ff8f81e8ce Block machine witgen: Always run default sequence after the cached sequence (#1562)
Fixes #1559 (alternative to #1560)

With this PR, we always run the "default" sequence iterator, even if we
have a cached sequence (which is still run before). This way, if the
cached sequence was not sufficient to solve the entire block, the
default solving sequence will have another attempt.

The reason this doesn't lead to a dramatic performance degradation is
because since #1528, we skip identities that have been completed. In the
typical case, the cached sequence will have completed most identities.

The reason this is better than #1560 is because the cached sequence
typically makes progress with every identity, whereas the default
iterator does not.

## Benchmark

I ran the RISC-V Keccak example 3 times. It looks like the time spent in
block machines increases by roughly 20%. Given that this fixes a bug and
the overall time spent in block machines is small (even in the
bitwise-heavy Keccak example), I think it's worth it!

### Main

```
 == Witgen profile (1766802 events)
   44.5% (    4.4s): FixedLookup
   36.3% (    3.6s): Main Machine
    9.7% ( 964.7ms): Secondary machine 0: main_binary (BlockMachine)
    6.8% ( 669.3ms): witgen (outer code)
    2.4% ( 236.0ms): Secondary machine 2: main_shift (BlockMachine)
    0.3% (  32.6ms): Secondary machine 1: main_memory (DoubleSortedWitnesses)
    0.0% ( 183.7µs): Secondary machine 3: main_split_gl (BlockMachine)
  ---------------------------
    ==> Total: 9.907174375s

 == Witgen profile (1766802 events)
   41.0% (    3.8s): FixedLookup
   39.0% (    3.6s): Main Machine
   10.2% ( 951.7ms): Secondary machine 0: main_binary (BlockMachine)
    6.9% ( 644.2ms): witgen (outer code)
    2.5% ( 231.5ms): Secondary machine 2: main_shift (BlockMachine)
    0.3% (  32.1ms): Secondary machine 1: main_memory (DoubleSortedWitnesses)
    0.0% ( 183.4µs): Secondary machine 3: main_split_gl (BlockMachine)
  ---------------------------
    ==> Total: 9.295457333s

 == Witgen profile (1766802 events)
   43.7% (    4.2s): FixedLookup
   37.0% (    3.6s): Main Machine
   10.0% ( 963.6ms): Secondary machine 0: main_binary (BlockMachine)
    6.6% ( 636.3ms): witgen (outer code)
    2.4% ( 234.7ms): Secondary machine 2: main_shift (BlockMachine)
    0.3% (  29.0ms): Secondary machine 1: main_memory (DoubleSortedWitnesses)
    0.0% ( 190.8µs): Secondary machine 3: main_split_gl (BlockMachine)
  ---------------------------
    ==> Total: 9.677017958s
```

### This branch

```
 == Witgen profile (1986686 events)
   43.3% (    4.3s): FixedLookup
   36.2% (    3.6s): Main Machine
   11.5% (    1.1s): Secondary machine 0: main_binary (BlockMachine)
    6.0% ( 600.2ms): witgen (outer code)
    2.7% ( 273.3ms): Secondary machine 2: main_shift (BlockMachine)
    0.3% (  28.6ms): Secondary machine 1: main_memory (DoubleSortedWitnesses)
    0.0% ( 203.4µs): Secondary machine 3: main_split_gl (BlockMachine)
  ---------------------------
    ==> Total: 9.975125084s

 == Witgen profile (1986686 events)
   40.4% (    3.9s): FixedLookup
   37.2% (    3.6s): Main Machine
   12.1% (    1.2s): Secondary machine 0: main_binary (BlockMachine)
    7.1% ( 687.7ms): witgen (outer code)
    2.9% ( 276.7ms): Secondary machine 2: main_shift (BlockMachine)
    0.3% (  30.3ms): Secondary machine 1: main_memory (DoubleSortedWitnesses)
    0.0% ( 197.3µs): Secondary machine 3: main_split_gl (BlockMachine)
  ---------------------------
    ==> Total: 9.619824375s

 == Witgen profile (1986686 events)
   42.4% (    4.2s): FixedLookup
   36.1% (    3.6s): Main Machine
   11.9% (    1.2s): Secondary machine 0: main_binary (BlockMachine)
    6.6% ( 654.9ms): witgen (outer code)
    2.8% ( 276.6ms): Secondary machine 2: main_shift (BlockMachine)
    0.3% (  29.1ms): Secondary machine 1: main_memory (DoubleSortedWitnesses)
    0.0% ( 202.3µs): Secondary machine 3: main_split_gl (BlockMachine)
  ---------------------------
    ==> Total: 9.957052209s
```
2024-07-15 14:44:06 +00:00
chriseth
e1169a7a4b Do not add a constraint for the empty tuple. (#1568) 2024-07-12 19:04:53 +00:00
Gastón Zanitti
70e4f7c39b Trait parsing (#1489)
This PR splits from the main Trait implementation PR #1450 to simplify
the review process.

It includes only the parsing of the traits (not impls) and some
functionality necessary for the code to compile.

---------

Co-authored-by: chriseth <chris@ethereum.org>
2024-07-09 13:25:39 +00:00
Lucas Clemente Vella
8bc4d4b937 Updating and uniformizing itetools. (#1547) 2024-07-08 14:32:36 +00:00
chriseth
48b206037f Remove constants. (#1526)
Co-authored-by: schaeff <thibaut@schaeff.fr>
2024-07-08 11:43:39 +00:00
Thibaut Schaeffer
49ffd47008 Allow different degrees in witgen (#1460)
Fixes #1494

- use cbor for witness and constant files (moving polygon serialisation
to the relevant backend)
- add `degree` field on `Symbol`, inherited from the namespace degree
- have each machine in witgen operate over its own degree
- fail in the backend if we have many degrees
2024-07-04 17:23:50 +00:00
Georg Wiese
c4ded73433 Block machines: Skip complete identities (#1528)
Just like the `VmProcessor`, with this PR the `BlockProcessor` never
processes an identity again that has been completed.

This should be a slight performance optimization (when the "default"
sequence iterator is used), but more importantly it:
- Fixes #1385 
- Allows us to remove error-prone code (see below)
- Helps with witgen for stateful machines, like those who access memory
2024-07-03 16:35:00 +00:00
Georg Wiese
c26ca455cb CompositeBackend: Create proofs for each machine (working with Halo2) (#1470)
Another step towards VadCoP (#1495)

With this PR, the `CompositeBackend` splits the given PIL into multiple
machines and creates a proof for each machine.

The rough algorithm is as follows:
1. The PIL is split into namespaces
2. Any lookups or permutations that reference multiple namespaces are
removed.
3. Any other constraints that reference multiple namespaces lead to the
two namespaces being merged.

This is an example:
```
$ RUST_LOG=debug cargo run pil test_data/asm/block_to_block.asm -o output -f --prove-with halo2-composite --field bn254
...
Skipping connecting identity: main.instr_add { main.x, main.y, main.z } in 1 { main_arith.x, main_arith.y, main_arith.z };
== Proving machine: main
PIL:
namespace main(8);
    col fixed x(i) { i / 4 };
    col fixed y(i) { i / 4 + 1 };
    col witness z;
    col witness res;
    col fixed latch = [0, 0, 0, 1]*;
    main.res' = (1 - main.latch) * (main.res + main.z);
    (1 - main.instr_add) * (main.x + main.y - main.z) = 0;
    col fixed instr_add = [0, 1]*;

Starting proof generation...
Generating PK for snark...
Generating proof...
Time taken: 149.459458ms
Proof generation done.
== Proving machine: main_arith
PIL:
namespace main_arith(8);
    col witness x;
    col witness y;
    col witness z;
    main_arith.z = main_arith.x + main_arith.y;

Starting proof generation...
Generating PK for snark...
Generating proof...
Time taken: 150.752125ms
Proof generation done.
Writing output/block_to_block_proof.bin.
```

Seems seems to work across the entire codebase and allows us to create
Halo2 proofs by machine!

For STARK backends, we typically expect that IDs (e.g. Polynomial IDs,
constraint IDs, ...) are re-assigned, which is not yet happening in this
implementation. As mentioned in the comment, the easiest way to fix that
would be to fix #1488 and re-parse the PIL file.
2024-07-03 14:09:51 +00:00
chriseth
ddfac8bcb6 Remove lifetime parameter (#1514) 2024-07-03 10:34:52 +00:00
chriseth
bb4412656a Create row struct (#1510) 2024-07-02 16:48:35 +00:00
chriseth
69c3131942 Refactor rows a little. (#1481)
The main goal here is to hide the inner structure of a Row so that it
can be more easily optimized later.
2024-07-01 17:10:16 +00:00
Georg Wiese
ade87fa24d Witgen: Bug fixes in Block machine witness generation (#1509)
Some witness generation fixes needed to make #1508 work:
- When we check whether we already answered the query, we assumed that
the latch row is the last row; now, we use the actual latch row.
- That same check might access any row in the last block, so now we
never finalize the last block.
2024-07-01 16:30:01 +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
Thibaut Schaeffer
01acfd736e Add plonky3 support (#1158)
plonky3 backend integration for witness columns only
2024-06-26 20:05:05 +00:00
chriseth
924b9b0660 Avoid creating an intermediate vector (#1457) 2024-06-26 16:42:10 +00:00
chriseth
9c4b3e92f9 Optimize queries. (#1455) 2024-06-18 16:43:27 +00:00
Thibaut Schaeffer
2708a63d1f Avoid parentheses in AlgebraicExpression display (#1444)
- Introduce structs in the analysed AST
- Port parenthesis minimisation from parsed AST to analysed AST 

Closes #1429
2024-06-17 10:05:28 +00:00
Georg Wiese
7a851317bc Implement permutation argument using extension field (#1306)
Makes the permutation argument sound on the Goldilocks field by
evaluating polynomials on the extension field introduced in #1310.

I also used the new `Constr::Permutation` variant!

A few test cases (also tested in CI):

#### No extension field
`cargo run pil test_data/std/permutation_via_challenges.asm -o output -f
--field bn254 --prove-with halo2-mock`

This still works and produces the same output as before, thanks to the
PIL evaluator removing multiplications by 0 etc:

```
    col witness stage(1) z;
    (std::protocols::permutation::is_first * (main.z - 1)) = 0;
    ((((1 - main.first_four) * ((std::protocols::permutation::beta1 - ((std::protocols::permutation::alpha1 * main.b1) + main.b2)) - 1)) + 1) * main.z') = (((main.first_four * ((std::protocols::permutation::beta1 - ((std::protocols::permutation::alpha1 * main.a1) + main.a2)) - 1)) + 1) * main.z);
```

#### With extension field
`cargo run pil test_data/std/permutation_via_challenges_ext.asm -o
output -f --field bn254 --prove-with halo2-mock`

The constraints are significantly more complex but seem correct to me:

```
    col witness stage(1) z1;
    col witness stage(1) z2;
    (std::protocols::permutation::is_first * (main.z1 - 1)) = 0;
    (std::protocols::permutation::is_first * main.z2) = 0;
    (((((1 - main.first_four) * ((std::protocols::permutation::beta1 - ((std::protocols::permutation::alpha1 * main.b1) + main.b2)) - 1)) + 1) * main.z1') + ((7 * ((1 - main.first_four) * (std::protocols::permutation::beta2 - (std::protocols::permutation::alpha2 * main.b1)))) * main.z2')) = ((((main.first_four * ((std::protocols::permutation::beta1 - ((std::protocols::permutation::alpha1 * main.a1) + main.a2)) - 1)) + 1) * main.z1) + ((7 * (main.first_four * (std::protocols::permutation::beta2 - (std::protocols::permutation::alpha2 * main.a1)))) * main.z2));
    ((((1 - main.first_four) * (std::protocols::permutation::beta2 - (std::protocols::permutation::alpha2 * main.b1))) * main.z1') + ((((1 - main.first_four) * ((std::protocols::permutation::beta1 - ((std::protocols::permutation::alpha1 * main.b1) + main.b2)) - 1)) + 1) * main.z2')) = (((main.first_four * (std::protocols::permutation::beta2 - (std::protocols::permutation::alpha2 * main.a1))) * main.z1) + (((main.first_four * ((std::protocols::permutation::beta1 - ((std::protocols::permutation::alpha1 * main.a1) + main.a2)) - 1)) + 1) * main.z2));
```

#### On Goldilocks

Running the first example on GL fails, because using the permutation
argument without the extension field would not be sound. The second
example works, but because we don't support challenges on GL yet, it
doesn't actually run the second-phase witness generation.

---------

Co-authored-by: chriseth <chris@ethereum.org>
2024-06-12 11:15:50 +00:00
chriseth
4ab45dc302 Process pc lookup first. (#1427) 2024-06-10 10:47:22 +00:00
Georg Wiese
f2457f2573 Witgen: Pass range constraints to callee (#1389)
*Cherry-picked b1a07bd9a7 from #1380, and
extended on it.*

Fixes #1382.

With this PR, a lookup like `selector { byte_lower + 256 * byte_upper }
in { <some other machine> }` works, even if the range constraints on
`byte_lower` and `byte_upper` are not "global". For example, they could
be implemented as `selector { byte_lower } in { BYTES }` (i.e.,
`byte_lower` is only range constrained when the machine call is active).

To make this work, I changed the `Machine::process_plookup` interface
like this:
```diff
    fn process_plookup<'b, Q: QueryCallback<T>>(
        &mut self,
        mutable_state: &'b mut MutableState<'a, 'b, T, Q>,
        identity_id: u64,
-       args: &[AffineExpression<&'a AlgebraicReference, T>],
+       caller_rows: &'b RowPair<'b, 'a, T>,
    ) -> EvalResult<'a, T>;
```

The `RowPair` passed by the caller contains all range constraints known
at runtime. The LHS of the lookup (or permutation) is no longer
evaluated by the caller but by the callee. For this, the callee needs to
remember the identity associated with the `identity_id` (before this PR,
most machines just remembered the RHS, not the full identity). I don't
expect there to be any performance implications, because we only invoke
one machine (since #1154).

### Benchmark results

```
executor-benchmark/keccak
                        time:   [14.609 s 14.645 s 14.678 s]
                        change: [-2.5984% -2.3127% -2.0090%] (p = 0.00 < 0.05)
                        Performance has improved.

executor-benchmark/many_chunks_chunk_0
                        time:   [39.299 s 39.380 s 39.452 s]
                        change: [-3.9505% -3.6909% -3.4063%] (p = 0.00 < 0.05)
                        Performance has improved.
```

---------

Co-authored-by: Leo <leo@powdrlabs.com>
2024-05-28 18:40:30 +00:00
chriseth
9ee58fe7d0 Store contents in SourceRef and change to offset instead of line/col. (#1396) 2024-05-28 15:33:38 +00:00
Gastón Zanitti
0d9669e26c SourceRef in expressions (#1357)
This PR solves issue https://github.com/powdr-labs/powdr/issues/1293.

Includes PRs that modify some Expression in order to match fields. It is
recommended to review/merge those first:
- #1351 
- #1352
- #1353
- #1354
- #1355


All comments are welcome :)

---------

Co-authored-by: chriseth <chris@ethereum.org>
2024-05-26 16:52:07 +00:00
Georg Wiese
a3087ea364 Witgen: Handle machine calls with side effects (#1388)
Cherry-picked ef6a72fcfa from #1380.

With this PR, we track whether a call to a machine led to some side
effect (e.g. added a block). In that case, the processed identity should
count has having led to some progress, even if no values were returned
to the calling machine. An example would be writing values to memory,
which does not return any values and hence does not change the state of
the caller.
2024-05-21 16:09:06 +00:00
Georg Wiese
cb8969368b BlockMachine: Don't look into other fixed columns for period detection (#1383)
Fixes an issue that @leonardoalt had on his `binary-mux2` branch.

There are two ways to have a block machine that is connected via a
permutation:
1. Use permutations `<sel> { ... } is (sub.sel * sub.LATCH) { ... }`.
This makes sure only rows where `sub.LATCH` is `1` can be selected. This
is what we do when we compile from ASM to PIL.
2. Use permutations `<sel> { ... } is sub.sel { ... }`, but also a
constraint `(1 - sub.LATCH) * sub.sel = 0`. This achieves something
similar.

The problem is that in the second case, detecting the block size is
harder, because the latch doesn't appear anywhere in the selector. So we
used to look into *all* fixed columns to detect the period. But this
includes fixed columns that might have a larger period (as is the case
for the multiplexer machine).

This PR simply removes support for the second approach. I think this is
fine in practice, as I don't see a disadvantage of the first approach
and when you come from ASM everything works as expected. I did need to
adjust `test_data/pil/block_lookup_or_permutation.pil`, which used the
second approach.
2024-05-17 16:24:08 +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
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
Georg Wiese
f307f513ad Fix accessing challenges from hints (#1331)
This PR attempts various issues around using challenges in hints, which
is blocking #1306:
1. Hints of later-phase witness columns are now removed in witgen, as
these columns don't need to be computed yet anyway and the hint might be
accessing a challenge that does not exist.
2. The query callback is now cloned for each phase of witness generation
(because otherwise it was only available in the first phase).
3. `SymbolicEvaluator` no longer panics when encountering challenges,
but returns an error. This evaluator is used to detect patterns in
identities, like `A' - A = 0`. This means that we can't detect patterns
in identities that involve challenges, but at least it doesn't panic.
4. `witgen::query_processor::Symbols` can now evaluate challenges.
5. `witgen::query_processor::Symbols` now also looks up intermediate
"polynomials" (which includes challenges). This is necessary because we
don't currently inline intermediate polynomials in hints (which we do
for identities).

I added a test that demonstrates that challenges can now be used in
hints.
2024-05-07 14:34:05 +00:00
chriseth
ed064f8821 Connection identity test. (#1258) 2024-05-07 14:04:07 +00:00
Georg Wiese
34cdaae63e Evaluate nested expressions (#1346)
Something I came across in #1306. This let's us do something like `let
foo: fe = eval(some_column * some_challenge)`.
2024-05-07 10:12:18 +00:00
Georg Wiese
98275f827f Witness generation with copy constraints (#1276)
This PR adds witness generation support for copy constraints: Whenever a
cell value is determined, this value is copied to all cells in its
equivalence class. This allows us to do witgen for arbitrary Plonkish
circuits (which would be detected as block machines) *as long as the
circuit is topologically sorted* (because otherwise, our row-by-row
solving strategy does not work.

Copy constraints are currently only supported in the language as
`connect` identities, as opposed to lists of cell pairs that belong to
the same equivalence class. Connecting this to the PIL input should be
part of another PR.
2024-04-30 18:01:33 +00:00
chriseth
88946edfa5 Make query functions enum-exhaustive. (#1327) 2024-04-30 17:59:41 +00:00
chriseth
2b63dd8032 Add degree builtin. (#1259) 2024-04-29 12:08:26 +00:00
Georg Wiese
d67eda4300 Improve error message if the machine rows are exhausted (#1292)
@leonardoalt got a failing assertion in one of his tests because the
rows in the Poseidon machine where exhausted. With this PR, this
situation is detected earlier, leading to a better error message:

```
=> Error: Table rows exhausted for machine Secondary machine 3: main_poseidon_gl (BlockMachine)
```
2024-04-19 16:00:47 +00:00
Georg Wiese
5e125ff765 Refactor: Make global range constraints part of FixedData (#1279)
The global range constraints are now part of `FixedData`. Also, I got
rid of the row factory, anyone with a reference to `FixedData` can now
just call `Row::fresh(fixed_data, row_index)`. This simplifies things
and should help with #1276.
2024-04-18 13:46:10 +00:00
chriseth
b2e0beef36 Enum pattern (#1216) 2024-04-17 13:11:09 +00:00
Lucas Clemente Vella
9d104c2088 Removing pub and "test_" from test functions. (#1274)
One is unecessary, the other is redundant.

Co-authored-by: Lucas Clemente Vella <lucas.vella@powdrlabs.com>
2024-04-15 20:01:47 +00:00
Leo
5d162d8fda remove unaligned memory check in double sorted memory machine in witgen (#1271)
This is only needed for RISCV, but witgen is more general than RISCV and
should allow memory accesses anywhere, especially since we have the std
memory machine.

The RISCV executor also checks this so it won't go unchecked.
2024-04-15 12:44:20 +00:00
Thibaut Schaeffer
ef2409b008 Upgrade rust to 1.77 (#1253)
Required for #1158
2024-04-04 20:17:48 +00:00
chriseth
99d25fd74f Rename generic args. (#1230) 2024-04-03 13:05:23 +00:00
chriseth
f46d59dfe1 Basic version of patterns. (#1205)
Depends on #1187 

Implements part of https://github.com/powdr-labs/powdr/issues/982

Will document in https://github.com/powdr-labs/powdr/pull/1214
2024-04-03 09:30:42 +00:00
chriseth
28f0bb9c1d Statements in blocks and function annotations (#1187)
Adds statements at block level and introduces function kinds to be
either pure, constr or query.

closes https://github.com/powdr-labs/powdr/issues/960

---------

Co-authored-by: Leo <leo@powdrlabs.com>
2024-04-02 08:23:39 +00:00
chriseth
989087634c Some dependency cleanup. (#1209) 2024-03-28 12:23:35 +00:00
Georg Wiese
96893cc143 Add Write-once memory to STD (#1202)
Fixes #844

This PR adds a new machine to the STD: `WriteOnceMemory`. This can be
used in our RISC-V machine for bootloader inputs (#1203).

Most of the issues mentioned in the issue were fixed in the meantime or
had a simple workaround (like defining `let LATCH = 1`). The only
remaining issues were in the machine detection, which I fixed here.

I also re-factor two existing tests.
2024-03-26 18:50:30 +00:00
Georg Wiese
c1bc7184ed Witgen: Remember which machine answers to which lookup / permutation (#1154)
With this PR, we remember the mapping from Lookup / Permutation Identity
to Machine. This is cleaner, lets us save some work when calling a
machine and allows us to fail earlier if no machine can answer the call
(at machine extraction time, rather than runtime.

Changes:
- `Machine::process_plookup()`: Instead of passing in `right` and
`kind`, machines now only receive an `IdentityId`. If the machine needs
to access any of the expressions, references to it have to be stored
with the machine.
- `Machine::identities()`: New function that lets us ask the machine for
which identities it feels respondible.
- The `Machines` struct now stores the mapping from `IdentityId` to
machine index, allowing us to replace the loop of trying all machines
with a simple call to `Machines::call()`.
- The identity kind is now also stored in `Identity::id`. Previously,
this only stored a `usize` which is not necessarily unique. As mentioned
above, this change could be merged as part of a separate PR.

#### Benchmark Results:

```
executor-benchmark/keccak
                        time:   [8.7242 s 8.9755 s 9.3876 s]
                        change: [-4.7814% +0.8652% +7.4252%] (p = 0.79 > 0.05)
                        No change in performance detected.

executor-benchmark/many_chunks_chunk_0
                        time:   [38.731 s 39.313 s 40.081 s]
                        change: [-5.6906% -3.9986% -1.8421%] (p = 0.00 < 0.05)
                        Performance has improved.
```
2024-03-25 19:27:09 +00:00