58 Commits

Author SHA1 Message Date
Thibaut Schaeffer
3ae17c7fcb Remove halo2 (#2740)
Remove halo2 from the backends, as well as the tutorials which heavily
reference it.
2025-05-21 12:08:50 +00:00
Thibaut Schaeffer
aafe2570be Remove estark (#2739)
Following #2735 , remove all of estark
2025-05-20 17:50:33 +00:00
Steve Wang
1b49df5aa6 Powdr PIL runs witgen with mock backend by default (#2601)
Now that witgen depends on backend type, `powdr pil` requires a backend
type to run through witgen. It only runs till optimized pil if
`--prove-with` is not provided.

To match the description, this PR defaults backend to Mock if
`--prove-with` is not provided, so `powdr pil` can still run till
witgen. To prove with any backend, `--prove-with` is still required.
2025-03-28 12:35:20 +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
Steve Wang
4c1ca2b43b PoC for two passes of pilopt (#2535)
After discussing with @Schaeff, we formulated a plan:
1. Currently, our pipeline is `compile pilopt tune pilopt witgen0 prove0
witgen1 prove1 finalize`, where `prove0 witgen1 prove1 finalize` is
backend aware.
2. In this PR, `tune pilopt witgen0 prove0 witgen1 prove1 finalize` are
all backend aware, meaning that a backend argument is required for these
steps to run.

I made some specific implementation decisions:
3. In this PR, the `tune` step is a `BackendFactory` API, while all
other APIs remain the same places as before. For example, `witgen0` is
backend aware because it requires a `backend_tuned_pil` to run. However,
`witgen0` only runs differently because different backend tuned pil's
are provided by different backend, not *directly* because of the
different backend (it has the same algorithm regardless of the backend).
Therefore, while `witgen0` requires a backend to run, I didn't put it
under `BackendFactory`. Design choices like this should ensure maximum
backward compatibility.

Summary of all other changes on the high level, mostly fixing pipeline
test and CI incompatibilities:

CLI changes:
4. `powdr-rs` requires a backend for witgen.
5. `powdr pil` only runs witgen if a backend is provided.

Test crates changes:
6. For tests that don't require a backend but require witgen, use the
mock backend to run witgen.
7. For tests that require a backend and also require witgen but runs
witgen before setting the backend, modify the test to set the backend
before running witgen.
2025-03-21 11:18:31 +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
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
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
chriseth
b2a48d7965 Test runner. (#1999)
Simple command line utility that can run tests in a `.asm` file.
2024-10-31 18:37:35 +00:00
Leandro Pacheco
bcc7374ef9 fix --export-csv and skip witgen when full witness is provided (#1973)
This PR does two things:
- make `--export-csv` not export fixed columns, so it can be directly
used as external witness
- skip witness generation when all witness columns are provided
externally
2024-10-29 15:39:27 +00:00
Leo
0a59d8f1f1 change cli/cli-rs crates to only depend on the powdr crate (#1965)
Depends on https://github.com/powdr-labs/powdr/pull/1961
2024-10-28 14:50:30 +00:00
Leo
51bcef591c split simd features in backend (#1961)
Unfortunately, cargo weirdness attacks again. Even with
`estark-starky-simd = ["starky?/avx512"]` enabling the feature only if
`starky` is being used, cargo still selects `starky` for compilation.

Then, because `starky` itself doesn't check the architecture being used
at compile time to enable AVX and only checks the features, compilation
fails for https://github.com/powdr-labs/powdr-template with `simd` if
AVX is not available.

Therefore, we can't group both p3 and starky's simd features in the same
backend `simd` feature, and need one simd feature per prover. This is
what this PR does. The result has been tested with the template repo and
starky is correctly *not* selected for compilation both with and without
the `simd` feature of the template crate.
2024-10-28 12:55:58 +00:00
Leo
20024812ba make starky optional (#1951)
Currently the users end up always compiling starky as well. This removes
that.

I think the CI tests should not change here because we run it with
`--all-features`.

I also made p3 default in the cli and cli-rs crates.
2024-10-25 12:30:47 +00:00
Leo
8595b4e54a User facing prover session (#1936)
The idea of this PR is to add the most commonly used workflow to the
outer facing `powdr` crate so that users have quick access to the prover
functionalities for Rust programs.

The changes to `powdr/src/lib.rs` wrap those common functionalities
(compiling Rust to powdr-asm, compiling powdr-asm to PIL, witgen, proof
generation with continuations) into simple function calls and hide the
Pipeline type a bit by using the new `Session` trait.

The end result is that a user can do the following:

```rust
use powdr::Session;
use std::path::Path;

fn main() {
    env_logger::init();

    let some_data = vec![1, 2, 3, 4, 5];

    let out_path = Path::new("powdr-target");
    let mut session = Session::new("./guest", out_path).write(1, &some_data);

    // Dry run to test execution
    session.run();

    // Compute the proof
    session.prove();
}
```

TODO:
- [x] Decide on the abstraction
- [x] Try to remove some clones from the continuations setup
- [x] Make sure the `prove` function re-uses artifacts if available
(like setup), and re-runs if needed
- [x] Should we have a separate `setup` call? I feel like it should be
automatic with the item above.
2024-10-23 17:30:23 +00:00
Leo
75c73ae58a SIMD feature for backends (#1924)
Depends on https://github.com/powdr-labs/powdr/pull/1923

Now that we use nightly, we can more easily enable AVX, Neon etc in
backends that support it.

Not sure why fmt added some formatting changes.

---------

Co-authored-by: Lucas Clemente Vella <lvella@powdrlabs.com>
2024-10-18 18:00:10 +00:00
Georg Wiese
bc419bf805 Add KoalaBear field (#1923)
The KoalaBear prime ($2^{31} - 2^{24} + 1$) is very similar to the
BabyBear prime ($2^{31} - 2^{27} + 1$), but allows for a more efficient
S-Box in Poseidon2 ($x^3$ instead of $x^7$). It should be slightly
faster to evaluate and significantly faster to prove recursively. For
some reason, I [saw a much more significant
advantage](https://gist.github.com/georgwiese/211d14c860c16cc4e1fbde7dc374af35)
when running the Plonky3 examples.

One downside of BabyBear is that it supports smaller traces, e.g. up to
$2^{23}$ rows with a degree bound of 3. For example,
`test_data/pil/fibonacci.pil` fails for larger instances.

This PR supports KoalaBear end-to-end:
```bash
cargo run -r --bin powdr-rs compile riscv/tests/riscv_data/keccak -o output --field kb
cargo run -r --features plonky3,halo2 pil output/keccak.asm -o output -f --field kb --prove-with plonky3
```
2024-10-18 14:18:28 +00:00
ShuangWu121
57d3c83459 Stwobackend prover skeleton (#1898)
### **Progress on Integrating `Stwo`**

This PR makes incremental progress towards integrating the `stwo`
prover, refer to issue #1833 . It includes the following changes:

- **Add `stwo` feature to `Cargo.toml`:**  
The `Cargo.toml` files for the `cli`, `pipeline`, and `backend`
components have been updated to include the `stwo` feature.

- **Implement `StwoProverFactory`:**  
A skeleton structure for `StwoProverFactory` has been introduced. This
structure implements the `BackendFactory` trait.

- **Implement `StwoProver`:**  
Similarly, a skeleton implementation of `StwoProver` has been created,
implementing the `Backend` trait. .



### **Commands to run:**

```bash


# Run the project with the `stwo` feature
cargo run --features stwo pil test_data/pil/fibonacci.pil -o output -f --field m31 --prove-with stwo

---------

Co-authored-by: Thibaut Schaeffer <schaeffer.thibaut@gmail.com>
Co-authored-by: Georg Wiese <georgwiese@gmail.com>
2024-10-18 12:03:31 +00:00
Lucas Clemente Vella
83e2c841e6 Trying buildjet CI runner (#1777) 2024-09-11 08:53:12 +00:00
Georg Wiese
41a61b1638 Add Mersene31Field (#1781)
Adds Plonky3's implementation of the Mersenne-31 field.

To test:
```
cargo run pil test_data/pil/fibonacci.pil -o output -f --field m31
```

The implementation is basically the same wrapper as for BabyBear, so I
moved the code to a macro and used it for both fields.
2024-09-10 16:24:12 +00:00
Georg Wiese
831edf3412 Print tracing profiling log (for Plonky3) (#1753)
With this change, we also print profiling logs for crates that are
instrumented using the `tracing` crate (if we're at least in the `DEBUG`
log level).

For example, for:
```bash
cargo run -r --bin powdr-rs compile riscv/tests/riscv_data/keccak -o output
RUST_LOG=debug cargo run -r --features plonky3,halo2 pil output/keccak.asm -o output -f --field gl --prove-with plonky3-composite
```

This prints:
```
== Proving machine: main (size 131072), stage 0
INFO     prove_with_key [ 1.84s | 0.23% / 100.00% ]
INFO     ┝━ infer log of constraint degree [ 141µs | 0.01% ]
INFO     ┝━ commit to trace data [ 458ms | 19.13% / 24.94% ]
INFO     │  ┕━ coset_lde_batch [ 107ms | 5.81% ] dims: 74x131072
INFO     ┝━ compute quotient polynomial [ 1.16s | 62.90% ]
INFO     ┝━ commit to quotient poly chunks [ 58.7ms | 2.14% / 3.19% ]
INFO     │  ┝━ coset_lde_batch [ 10.6ms | 0.58% ] dims: 2x131072
INFO     │  ┕━ coset_lde_batch [ 8.86ms | 0.48% ] dims: 2x131072
INFO     ┝━ compute_inverse_denominators [ 26.3ms | 1.43% ]
INFO     ┝━ reduce matrix quotient [ 10.9ms | 0.00% / 0.59% ] dims: 4x262144
INFO     │  ┝━ compute opened values with Lagrange interpolation [ 8.46ms | 0.46% ]
INFO     │  ┕━ reduce rows [ 2.42ms | 0.13% ]
INFO     ┝━ reduce matrix quotient [ 10.9ms | 0.00% / 0.59% ] dims: 4x262144
INFO     │  ┝━ compute opened values with Lagrange interpolation [ 8.91ms | 0.48% ]
INFO     │  ┕━ reduce rows [ 2.01ms | 0.11% ]
INFO     ┝━ reduce matrix quotient [ 20.4ms | 0.00% / 1.11% ] dims: 74x262144
INFO     │  ┝━ compute opened values with Lagrange interpolation [ 14.0ms | 0.76% ]
INFO     │  ┕━ reduce rows [ 6.35ms | 0.35% ]
INFO     ┝━ reduce matrix quotient [ 17.6ms | 0.00% / 0.96% ] dims: 74x262144
INFO     │  ┝━ compute opened values with Lagrange interpolation [ 11.2ms | 0.61% ]
INFO     │  ┕━ reduce rows [ 6.44ms | 0.35% ]
INFO     ┝━ reduce matrix quotient [ 7.55ms | 0.00% / 0.41% ] dims: 2x262144
INFO     │  ┝━ compute opened values with Lagrange interpolation [ 6.63ms | 0.36% ]
INFO     │  ┕━ reduce rows [ 913µs | 0.05% ]
INFO     ┝━ reduce matrix quotient [ 8.74ms | 0.00% / 0.48% ] dims: 2x262144
INFO     │  ┝━ compute opened values with Lagrange interpolation [ 7.92ms | 0.43% ]
INFO     │  ┕━ reduce rows [ 817µs | 0.04% ]
INFO     ┕━ FRI prover [ 57.8ms | 0.00% / 3.15% ]
INFO        ┝━ commit phase [ 56.0ms | 3.05% ]
INFO        ┝━ grind for proof-of-work witness [ 654µs | 0.04% ]
INFO        ┕━ query phase [ 1.09ms | 0.06% ]
INFO     verify_with_key [ 42.6ms | 99.63% / 100.00% ]
INFO     ┕━ infer log of constraint degree [ 158µs | 0.37% ]
==> Proof stage computed in 1.934923926s
```
2024-09-05 13:45:55 +00:00
Leo
c7fdc6cb2b baby bear field only (#1696)
Most minimal attempt at adding BabyBear, only adds the field and field
tests, but no powdr tests using the field.
2024-08-16 13:40:26 +00:00
Leo
2ecb5e578b add prover features to cli-rs (#1668) 2024-08-08 12:52:31 +00:00
Thibaut Schaeffer
01acfd736e Add plonky3 support (#1158)
plonky3 backend integration for witness columns only
2024-06-26 20:05: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
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
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
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
Lucas Clemente Vella
5063ad670c Restore outputing commits and constants in the pipeline. (#1325) 2024-04-30 10:02:40 +00:00
Lucas Clemente Vella
ac9dcfda87 zkEVM prover backend (#1211)
Similar to #1193, but in here I am just interested in having it working
end-to-end, at least for a few cases, so that everybody can try it and
build upon.

<!--

Please follow this protocol when creating or reviewing PRs in this
repository:

- Leave the PR as draft until review is required.
- When reviewing a PR, every reviewer should assign themselves as soon
as they
start, so that other reviewers know the PR is covered. You should not be
discouraged from reviewing a PR with assignees, but you will know it is
not
  strictly needed.
- Unless the PR is very small, help the reviewers by not making forced
pushes, so
that GitHub properly tracks what has been changed since the last review;
use
  "merge" instead of "rebase". It can be squashed after approval.
- Once the comments have been addressed, explicitly let the reviewer
know the PR
  is ready again.

-->

---------

Co-authored-by: Leo <leo@powdrlabs.com>
2024-04-18 09:16: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
001bd9a753 expose publics in CLI (#1236) 2024-04-04 11:29:27 +00:00
Leandro Pacheco
50eaab464e Coprocessors refactor (#1224)
- Refactor `CoProcessors` into a `Runtime` with submachines and syscalls
- Calls into prover functionality and submachines done via `ecall`
instead of "call symbol replacement"
- Call `poseidon_gl` machine with riscv registers by using the stack
(~50% speedup in many_chunks benchmark)
- New `riscv-syscalls` crate keeps the list of syscalls and related
constants
2024-04-03 18:37:32 +00:00
Vu Vo
6d6b4c9e14 Add log option in powdr command line (#1212)
# Context 
Now powdr can allow handle log in cli option. 

Example 

```bash
powdr --log DEBUG pil test_data/asm/book/hello_world.asm --field bn254 --force --inputs 0
``` 

--log value is LevelFilter 

```rust
pub enum LevelFilter {
    /// A level lower than all log levels.
    Off,
    /// Corresponds to the `Error` log level.
    Error,
    /// Corresponds to the `Warn` log level.
    Warn,
    /// Corresponds to the `Info` log level.
    Info,
    /// Corresponds to the `Debug` log level.
    Debug,
    /// Corresponds to the `Trace` log level.
    Trace,
} 
```

Fixes #164
2024-04-02 08:31:43 +00:00
Leandro Pacheco
02c52b5cb3 Remove support for running stand-alone rust files (#1220)
Change both tests and CLI to only support running rust crates
2024-04-01 18:45:40 +00:00
Leo Alt
2908938726 simplify coprocessors 2024-03-22 19:58:44 +01:00
Georg Wiese
80fafbe19c Spell-check 2024-03-20 16:12:55 +01:00
Leo Alt
b9b1d24455 allow riscv_executor::execute to take in the initial memory state 2024-03-19 20:49:21 +01:00
Georg Wiese
06866e4408 Fix soundness bug in mul instruction of RISC-V machine 2024-03-19 12:32:54 +01:00
Leo Alt
efe11f40fc enum declarations 2024-03-18 22:09:44 +01:00
schaeff
2378a2498e remove unused dependencies 2024-03-13 18:23:39 +01:00
chriseth
349f9aa461 Parse numbers as integers. 2024-03-08 15:48:49 +01:00
Leo Alt
18ddc65ef9 refactor pipeline to be a DAG instead of a linear path 2024-02-23 16:41:37 +01:00
Leo Alt
ef663bc649 make pilo output opt in 2024-02-22 14:19:06 +01:00
Georg Wiese
eb2f59aab3 Set default binary to powdr 2024-02-15 15:27:35 +01:00
Champii1
0cf2b977dc Add versioning for the analyzed types and schema validation
Remove dangling function in  macro

Fix variable name in schema_update.rs

Read the version number at runtime instread of compile time

Fix version_number parsing and write new schema after it

Add schemars feature `preserve_order`

Change unwrap for expect in schema_update.rs

Moved schema binary in its own crate

Graceful error management in powdr-schema instead of panic

Better graceful error handling in the pipeline and the cli

Fix clippy

Put the magic number at the start of the serialized data

Revert magic at the start of the file

Moved the SerializedAnalyzed to the schemas crate

Changed serialized.rs to analyzed.rs

Changed the magic number to be the ASCII `powdr`
2024-02-15 13:48:16 +01:00
Champii1
0c6ac7d2c2 Add serialization for Analyzed<T> and pipeline resume
Fix pipeline name from file name with suffix

Variable naming

Replace `splitted` with `split`

Co-authored-by: Leo <leo@ethereum.org>

Fix clippy

Add test for serde of PIL

Changed the optimized PIL file extension to .pilo

Changed function names to reflect the operation on pil object
2024-02-13 20:41:40 +01:00
Lucas Clemente Vella
390f3a191f New backend interface. 2024-02-13 11:24:47 +00:00
Lucas Clemente Vella
40950a9feb Cleanup on file reads and writes. 2024-02-09 11:04:08 +00:00
Lucas Clemente Vella
07835e0fec Updating rust version from 1.72 to 1.74. 2024-02-08 19:17:40 +00:00
Leo Alt
45069c968b Add verification key to Halo2 and support to vkey generation and proof
verification in CLI.
2024-02-06 14:50:53 +01:00