Commit Graph

1823 Commits

Author SHA1 Message Date
chriseth
adee683796 Refactor error to use SourceRef (#1398) 2024-05-31 14:47:05 +00:00
Steve Wang
fba0ba8d08 modul asm only (#1410)
Only the asm file changes that's ready to merge. To be paired with
another PR that will be updated and merged later: #1404
2024-05-30 15:19:56 +00:00
Lucas Clemente Vella
5f6efaa9ce Implementing a more generic version of jalr. (#1405)
Still not the full generic version: only supports zero offset.
2024-05-30 10:05:03 +00:00
Lucas Clemente Vella
816503d9fc Refactoring instruction processor to be more generic. (#1406)
In preparation for supporting RISC-V from binary.
2024-05-29 15:51:48 +00:00
Georg Wiese
0105da5b4d Add test for parallel memory accesses (#1403)
This simulates one approach we could go for when moving registers to
memory. The memory machine remains completely unchanged, but the step is
increased by more than 1 in each step of the main machine. This way,
from the point of view of memory, all the memory operations happen at
different time steps, which allows for:
- Reading from the same address twice
- Writing to the same address that we read from (which from the point of
view of memory should happen *after* the read)

The only downside I see with this approach is that this makes the
differences of time steps between memory accesses bigger: Before it was
at most the degree, now it is some small constant times the degree (in
this example 3). The way the memory machine is currently built, the
difference can be at most $2^{32} - 1$, so I think this is fine in
practice. E.g., for a degree $2^{30}$ machine we could do up to 4
parallel reads / writes.
2024-05-29 13:18:44 +00:00
Georg Wiese
1be743b641 Add multiple_signatures test (#1397)
This tests that we can re-use operation IDs (if we want the same
constraints), but switching around the inputs and outputs.
2024-05-28 18:41:06 +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
Leo
3579f24202 Generic write syscall that can be read from the host (#1390) 2024-05-28 12:02:25 +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
f04fb8c06d Fix many_chunks benchmark (#1395) 2024-05-24 18:17:55 +00:00
Gastón Zanitti
0757e57e8d BlockExpression struct in Expressions (#1355)
This PR is part of issue https://github.com/powdr-labs/powdr/pull/1345.
In particular, it adds the struct BlockExpression to Expressions to
homogenize the structure before including source references.
2024-05-23 10:56:54 +00:00
Gastón Zanitti
c10ffb1fe1 MatchExpression struct in Expressions (#1354)
This PR is part of issue https://github.com/powdr-labs/powdr/pull/1345.
In particular, it adds the struct MatchExpression to Expressions to
homogenise the structure before including source references.
2024-05-22 18:10:56 +00:00
Gastón Zanitti
98da4955de UnaryExpression struct in Expressions (#1352)
This PR is part of issue https://github.com/powdr-labs/powdr/pull/1345.
In particular, it adds the struct UnaryOperation to Expressions to
homogenise the structure before including source references.
2024-05-22 08:48:29 +00:00
chriseth
b72acfae00 Import EvalError. (#1392) 2024-05-22 07:45:33 +00:00
chriseth
8362be3e3e Provide as_polynomial_identity helper. (#1391) 2024-05-22 07:45:17 +00:00
Gastón Zanitti
29b0ee6672 BinaryExpression struct in Expressions (#1351)
This PR is part of issue #1345.
In particular, it adds the struct BinaryOperation to Expressions to
homogenise the structure before including source references.

---------

Co-authored-by: Thibaut Schaeffer <schaeffer.thibaut@gmail.com>
2024-05-21 17:58:30 +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
cbc5dd118e Fix soundness bug in permutation argument (#1386)
This fixes a soundness bug in the recently added permutation argument:
To fingerprint a list $A = (a_1, ..., a_n)$ with selectors $S = (s_1,
..., s_n)$, we were computing:

$$
\prod_{i = 1}^n (X - s_i \cdot a_i)
$$

As a result, any element $a_i$ can be replaced with $0$, by setting the
selector to $0$!

Now, an element $i$ with $s_i = 0$ does not contribute to the product
anymore:

$$
\prod_{i = 1}^n (s_i \cdot (X - a_i - 1) + 1)
$$
2024-05-18 08:29:09 +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
266d737089 bump version (#1381)
version bump after release
2024-05-15 17:44:46 +00:00
Leo
34d04ed873 move internal dependencies to shared version (#1379)
Trying this out which will make releases much easier
v0.1.0-alpha.1
2024-05-15 10:46:34 +00:00
Georg Wiese
1c9841158c Halo2 backend: use fewer copy constraints (#1376)
In Halo2, we need to simulate the "wrapping" behavior that we expect
from the backend, by copying the first row of witness columns after the
last. This was previously implemented by using copy constraints.
Considering [how the argument
works](https://zcash.github.io/halo2/design/proving-system/permutation.html),
this leads to 1 additional fixed column during setup *per witness
column*, and several additional witness columns (depending on the degree
bound, but linear in the number of witness columns).

But because Halo2 offers rotations of arbitrary offsets, we can instead
constrain this as:
`first_step * (witness_column - witness_column'degree)`

On the `simple_sum` example, this improved the proof time by ~15%
(353.01825ms -> 302.067125ms). The benchmarks on Keccak are still
running...
2024-05-14 18:23:35 +00:00
Leo
bcfee63ae5 Dual license (#1377)
Followed https://github.com/arnavyc/dual-licensed-mit-apache
2024-05-14 16:29:23 +00:00
Leo
dce4f985c7 update readme (#1375) 2024-05-14 12:56:53 +00:00
Leo
07642d056b Add book example that uses publics in asm (#1373)
Fixes https://github.com/powdr-labs/powdr/issues/1225
2024-05-14 12:37:51 +00:00
Georg Wiese
c1f2de0502 Set powdr as the only default binary (#1372)
Now `cargo run` is equivalent to `cargo run --bin powdr`. To run
`powdr-rs`, you can do `cargo run --bin powdr-rs`.
2024-05-13 10:57:26 +00:00
Leo
101829b230 Split Rust compilation into its own CLI bin (#1348)
As suggested by @lvella .
I'm not too sure about this actually. I agree that compiling Rust ->
powdr-asm should have a separate pipeline somewhere, but before we could
do Rust -> proof in a single command, and with this we can't anymore.

- Do we expose the `prove` command and everything else here as well?
That'd be a lot of duplicated code.
- Do we force the user to first run `powdr-rs compile <rust_proj>` then
`powdr pil/prove ...`? That's potentially worse UX than right now.
- Do we keep all the Rust stuff in the `cli` crate?
2024-05-13 08:33:15 +00:00
chriseth
b7f89d9d45 Add degree checks. (#1370)
Co-authored-by: Leo <leo@powdrlabs.com>
2024-05-13 08:32:31 +00:00
Georg Wiese
7617be2b98 Add std::math::fp2 module (#1310)
Depends on #1346

Adds a module to the standard library to implement extension field
arithmetic. This should work and be correct on both the Goldilocks and
BN254 field. Needed for #1306.

---------

Co-authored-by: chriseth <chris@ethereum.org>
2024-05-10 16:17:29 +00:00
chriseth
0e0ebe7451 Improve logging. (#1368) 2024-05-10 13:02:23 +00:00
chriseth
bd422befcf Use true/false from the prelude. (#1367) 2024-05-10 10:52:30 +00:00
chriseth
70e97f8a2e Set syntax hilighting for asm and pil files. (#1366) 2024-05-10 09:10:46 +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
chriseth
dee6693946 Fix feature-dependent compilation. (#1361) 2024-05-08 14:37:51 +00:00
Leo
755b5816c8 Add an example list to docs (#1359) 2024-05-08 13:18:29 +00:00
Lucas Clemente Vella
37586ad7b6 Matching the behavior of hard_link() and create() in case file exists. (#1358) 2024-05-08 12:05:38 +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
Leo
8d627cd1a2 split benches and remove riscv dep from pipeline (#1350)
This PR

- removes the riscv dev dependency from the pipeline crate
- splits the benchmark into riscv and pil benches
- fixes the query callback in the keccak bench
2024-05-06 15:05:53 +00:00
Lucas Clemente Vella
ce751d8ba4 Using starky version that doesn't stack overflow. (#1340) 2024-05-06 11:40:26 +00:00
Leo
141053c026 Move halo2 crate to a backend module (#1347)
Fixes https://github.com/powdr-labs/powdr/issues/1323
2024-05-06 09:37:21 +00:00
Leo
c1f76f9bbf Halo2 single/aggr SNARK with Solidity verifier (#1256)
Co-authored-by: Georg Wiese <georgwiese@gmail.com>
Co-authored-by: Lucas Clemente Vella <lvella@powdrlabs.com>
2024-05-03 18:47:51 +00:00
Leandro Pacheco
98e844c9a8 fix book example (#1344) 2024-05-03 13:27:26 +00:00
Lucas Clemente Vella
5da667894f Gives a meaningful error message on building estark-polygon for non x86. (#1339) 2024-05-03 10:15:08 +00:00
Lucas Clemente Vella
6f4b485147 Enforcing --force on chunk's constants.bin. (#1341) 2024-05-02 21:34:24 +00:00
chriseth
3e43e33796 Constr as user-defined enum (#1252)
Turns some of the built-in types into user types in the prelude.
2024-05-01 10:29:19 +00:00