Commit Graph

366 Commits

Author SHA1 Message Date
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
Georg Wiese
fbc8c8c927 Introduce AlgebraicVariable (#1755)
(First 4 commits of #1650)

This PR prepares witness generation for scalar publics (#1756). Scalar
publics are similar to cells in the trace, but are global (i.e.,
independent on the row number).

With this PR, affine expressions use a new `AlgebraicVariable` enum,
that can be either a column reference (`&'a AlgebraicReference`, which
was used previously), or a reference to a public.
2024-09-23 14:44:04 +00:00
chriseth
06abb2a28a Simplify parsed identities and introduce the concept of proof item. (#1820)
At the on-site, we introduced operators for all lookup-like constraints.
This means that `[x, y] in s $ [a, b];` is not parsed as a lookup
identity any more, but just as a regular expression with binary
operators. The whole concept of a lookup or identity as a rust type is
now only present after the condenser has run. Because of that, we can
remove a lot of code that was concerned with parsed identities.

Since prover functions were introduced, we can have both constraints and
prover functions at statement level. Because of that I extended the
concept of "identity" (which we partly renamed to "constraint" already)
to "proof item". A proof item is either a constraint or a prover
function. Later on, we might also include fixed columns, challenges,
etc.

Co-authored-by: chriseth <chriseth.github@gmail.com>
2024-09-23 12:53:25 +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
chriseth
48d7d90d9b Return errors from pil analyzer. (#1758) 2024-09-12 10:04:42 +00:00
chriseth
efd93482e3 Prover functions (#1717) 2024-09-11 10:51:56 +00:00
Gastón Zanitti
73f49a4553 Traits unification (#1625)
Co-authored-by: chriseth <chris@ethereum.org>
2024-09-09 13:37:42 +00:00
chriseth
42d998c1cf Introduce machine parts. (#1743) 2024-09-04 13:08:34 +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
chriseth
14d710c56c Refactor double sorted witness. (#1735) 2024-08-30 12:43:16 +00:00
chriseth
69ae0b69e7 Extract build_machine. (#1729) 2024-08-28 17:47:50 +00:00
Gastón Zanitti
0dc3ae762f Depreciation of . by :: in paths (#1694) 2024-08-23 07:39:50 +00:00
Thibaut Schaeffer
b1431e5034 Use degree type where applicable (#1690)
Small one extracted from #1667
2024-08-15 17:03:47 +00:00
Georg Wiese
34fdbd1ccd RISC-V machine: Use dynamic VADCOP (#1683)
Builds on #1687
Fixed #1572 

With this PR, we are using dynamic VADCOP in the RISC-V zk-VM.

There were a few smaller fixes needed to make this work. In summary, the
changes are as follows:
- We set the degree the main machine to `None`, and all fixed lookup
machines to the appropriate size. As a consequence, the CPU, all block
machines & memory have a dynamic size.
- As a consequence, I had to adjust some tests (set the size of all
machines, so they can still be run with monolithic provers) *and* was
able to remove the `Memory_<size>` machines 🎉
- With the main machine being of flexible size, the prover can chose for
how long to run it. We run it for `1 << (MAX_DEGREE_LOG - 2)` steps and
compute the bootloader inputs accordingly. With this choice, we can
guarantee that the register memory (which can be up to 4x larger than
the main machine) does not run out of rows.

Note that while we do access `MAX_DEGREE_LOG` in a bunch of places now,
this will go away once #1667 is merged, which will allow us to configure
the degree range in ASM and for each machine individually.

### Example:
```bash
export MAX_LOG_DEGREE=18
cargo run -r --bin powdr-rs compile riscv/tests/riscv_data/many_chunks -o output --continuations
cargo run -r --bin powdr-rs execute output/many_chunks.asm -o output --continuations -w
cargo run -r --features plonky3,halo2 prove output/many_chunks.asm -d output/chunk_0 --field gl --backend plonky3-composite
```

This leads to the following output:
```
== Proving machine: main (size 65536), stage 0
==> Proof stage computed in 1.918317417s
== Proving machine: main__rom (size 8192), stage 0
==> Proof stage computed in 45.847375ms
== Proving machine: main_binary (size 1024), stage 0
==> Proof stage computed in 27.718416ms
== Proving machine: main_bit2 (size 4), stage 0
==> Proof stage computed in 15.280667ms
== Proving machine: main_bit6 (size 64), stage 0
==> Proof stage computed in 17.449875ms
== Proving machine: main_bit7 (size 128), stage 0
==> Proof stage computed in 20.717834ms
== Proving machine: main_bootloader_inputs (size 262144), stage 0
==> Proof stage computed in 524.013375ms
== Proving machine: main_byte (size 256), stage 0
==> Proof stage computed in 17.280167ms
== Proving machine: main_byte2 (size 65536), stage 0
==> Proof stage computed in 164.709625ms
== Proving machine: main_byte_binary (size 262144), stage 0
==> Proof stage computed in 504.743917ms
== Proving machine: main_byte_compare (size 65536), stage 0
==> Proof stage computed in 169.881542ms
== Proving machine: main_byte_shift (size 65536), stage 0
==> Proof stage computed in 146.235916ms
== Proving machine: main_memory (size 32768), stage 0
==> Proof stage computed in 326.522167ms
== Proving machine: main_poseidon_gl (size 16384), stage 0
==> Proof stage computed in 1.324662625s
== Proving machine: main_regs (size 262144), stage 0
==> Proof stage computed in 2.009408667s
== Proving machine: main_shift (size 32), stage 0
==> Proof stage computed in 13.71825ms
== Proving machine: main_split_gl (size 16384), stage 0
==> Proof stage computed in 108.019334ms
Proof generation took 7.364567s
Proof size: 8432928 bytes
Writing output/chunk_0/many_chunks_proof.bin.
```

Note that `main_bootloader_inputs` is still equal to the maximum size,
we should fix that in a following PR!
2024-08-15 11:27:52 +00:00
Georg Wiese
aea2e036b8 Witgen: Recognize range constraints in more cases (#1685)
When making fixed lookup machines smaller in the RISC-V VM (#1683), I
came across the issue that range-constraint lookups (e.g. `[two_bits] in
[TWO_BITS]` where `TWO_BITS = [0, 1, 2, 3]`) where not recognized as
such if the fixed column was *just* the right size (in the above
example, `TWO_BITS = [0, 1, 2, 3, 0]` would have worked).
2024-08-14 14:01:36 +00:00
Georg Wiese
5e0ae179f9 Memory machine: Only use the necessary size (#1680)
Builds on #1666 

Now, the memory machine is downsized to the smallest possible size:
```
$ MAX_DEGREE_LOG=10 cargo run -r pil test_data/asm/dynamic_vadcop.asm -o output -f --field bn254 --prove-with halo2-mock-composite
...
Running main machine for 1024 rows
[00:00:00 (ETA: 00:00:00)] ░░░░░░░░░░░░░░░░░░░░ 0% - Starting...                         Found loop with period 1 starting at row 100
[00:00:00 (ETA: 00:00:00)] ████████████████████ 100% - 280269 rows/s, 4205k identities/s, 94% progress
Resizing variable length machine 'Secondary machine 0: main_arith (BlockMachine)': 1024 -> 32 (rounded up from 3)
Resizing variable length machine 'Secondary machine 1: main_memory (DoubleSortedWitnesses)': 1024 -> 32 (rounded up from 4)
Witness generation took 0.005317875s
Writing output/commits.bin.
Instantiating a composite backend with 5 machines:
...
== Proving machine: main (size 1024), stage 0
==> Proof stage computed in 15.581958ms
== Proving machine: main__rom (size 16), stage 0
==> Proof stage computed in 800.708µs
== Proving machine: main_arith (size 32), stage 0
==> Proof stage computed in 506.25µs
== Proving machine: main_byte2 (size 65536), stage 0
==> Proof stage computed in 84.450916ms
== Proving machine: main_memory (size 32), stage 0
==> Proof stage computed in 719.375µs
Proof generation took 0.102423415s
Proof size: 88 bytes
Writing output/dynamic_vadcop_proof.bin.
```
2024-08-14 10:57:02 +00:00
Georg Wiese
88785a83a5 Downsize VMs when they reach a loop (#1676)
Builds on #1666

With this PR, Witgen choses the minimum possible size of VMs (rounding
to the next power of two after first detecting a loop):

```
$ MAX_DEGREE_LOG=10 cargo run -r pil test_data/asm/vm_to_block_different_length.asm -o output -f --field bn254 --prove-with halo2-composite
...
== Proving machine: main (size 128), stage 0
Starting proof generation...
Generating PK for snark...
Generating proof...
Time taken: 59.970083ms
Proof generation done.
==> Proof stage computed in 81.618417ms
== Proving machine: main__rom (size 8), stage 0
Starting proof generation...
Generating PK for snark...
Generating proof...
Time taken: 12.319334ms
Proof generation done.
==> Proof stage computed in 29.754417ms
== Proving machine: main_arith (size 32), stage 0
Starting proof generation...
Generating PK for snark...
Generating proof...
Time taken: 20.056834ms
Proof generation done.
==> Proof stage computed in 32.017167ms
Proof generation took 0.14349297s
Proof size: 8296 bytes
```
2024-08-13 15:05:34 +00:00
Georg Wiese
d87a33cd2c Make MAX_DEGREE_LOG configurable (#1677)
Pulled out of #1676, where it helps making the tests run faster.

I think this could possibly be removed by #1667 again.
2024-08-12 11:36:06 +00:00
Georg Wiese
f3a238c28f Turn FixedLookup into proper Machine (#1654)
This PR turns the `FixedLookup` into a "normal" machine, i.e., it
implements the `Machine` trait. This removes special handling of the
fixed lookup in various places.

Changes:
- `Machine::take_witness_col_values` now takes a reference to
`MutableState`, similar to `Machine::process_plookup`. With this,
machines can still call other machines machines while finalizing. This
is needed because some machines appear to call the fixed lookup when
finalizing.
- To handle this correctly, I changed the code such that:
- Machines are finalized in the order in which they appear in the
machines list (`FixedLookup` is the last machine)
- When finalizing, machines can access all *following* machines, but not
the once before, as they are already finalized.

`FixedLookup` is still a weird machine, which is responsible to many
sets of fixed columns (i.e., several ASM-machines) which might not even
have the same length. But that can be fixed in a separate PR.
2024-08-09 09:38:17 +00:00
Leo
98acbdd037 Use poseidon with memory in the riscv machine (#1599)
Depends on https://github.com/powdr-labs/powdr/pull/1655

This PR is based on https://github.com/powdr-labs/powdr/pull/1533 on top
of registers in memory and the new links.
2024-08-09 08:53:49 +00:00
Thibaut Schaeffer
76806b5a62 Delay array expression solving until constant evaluator (#1653)
Equivalent to #1623  but in Rust

Closes #1570

@georgwiese I wanted to add a test but everything I try either panics
(we sometimes assume the fixed columns to be available in a single size)
or runs forever (when I add fixed columns to a machine, I assume witgen
keeps increasing the degree and never stops? or it picks the largest
size and just takes time?) any thoughts?
2024-08-08 06:48:43 +00:00
Georg Wiese
f77c0a798e Fix witgen for bus accumulators (#1628)
Fixes #1604

With this PR, we bypass machine detection during witness generation of
stages > 0. See [this
comment](https://github.com/powdr-labs/powdr/issues/1604#issuecomment-2257059636)
for a motivation.

This currently needs to be tested manually, as follows:
```
$ RUST_LOG=trace cargo run pil test_data/asm/block_to_block_with_bus.asm -o output -f --field bn254 --prove-with halo2-mock
...
===== Summary for row 7:
    main.acc1 = 20713437912485111384541749944547180564950035591542371144095269313127123163196
    main.acc2 = 5162472027861336027760332823162682203738251621730423286600997430635718406729
    main.z = 3
    main.res = 9
    main_arith.acc1 = 1174804959354163837704655800710094523598328808873663199602934873448685332421
    main_arith.acc2 = 16725770843977939194486072922094592884810112778685611057097206755940090088888
    main_arith.acc1_next = 463668501342879563405020640323131794083013726819708055681247370540753473777
    main_arith.acc2_next = 20043340305711842349747334022818855888193664738087810292789887394167185113571
    main_arith.y = 1
    main_arith.z = 1
    main.dummy = 0
    main.acc1_next = 0
    main.acc2_next = 0
    main_arith.x = 0
    main_arith.sel[0] = 0
---------------------
...
```

Computing `main.acc1 + main_arith.acc1` and `main.acc2 +
main_arith.acc2` both yields
`21888242871839275222246405745257275088548364400416034343698204186575808495617`,
which is the BN254 scalar field prime! In other words, the partial
accumulators sum to 0.

---------

Co-authored-by: Leo <leo@powdrlabs.com>
2024-08-05 12:14:27 +00:00
chriseth
10be8ab355 Improve evaluator (#1648)
Extracted from @Schaeff `s https://github.com/powdr-labs/powdr/pull/1623

---------

Co-authored-by: schaeff <thibaut@schaeff.fr>
2024-08-02 21:18:45 +00:00
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