Commit Graph

78 Commits

Author SHA1 Message Date
Georg Wiese
a22065ee2d Refactor QuadraticSymbolicExpression (#2923)
This PR refactors `QuadraticSymbolicExpression`: I removed the reference
to
[`SymbolicExpression`](f60e9d9f69/constraint-solver/src/quadratic_symbolic_expression.rs (L70)).
It can represent values that are known at runtime, represented as an
expression. We don't need this in the context of APC: Variables are
either unknown or known at compile time, and therefore can be
represented as a `FieldElement` instead.

The idea is to introduce [this
trait](4989be08f3/constraint-solver/src/runtime_constant.rs (L11)),
which is implemented by `SymbolicExpression` and any `T: FieldElement`.
This way, we can continue to use the solver with
`QuadraticSymbolicExpression<SymbolicExpression<T, V>, V>` (equivalent
to the current `QuadraticSymbolicExpression<T, V>`) in the old JIT
pipeline and use the simpler `QuadraticSymbolicExpression<T, V>` in the
APC pipeline.

---------

Co-authored-by: chriseth <chriseth.github@gmail.com>
2025-06-30 15:47:12 +00:00
Georg Wiese
340b532619 FieldElement: Require MulAssign (#2924)
Pulled out of #2923
2025-06-20 11:38:37 +00:00
chriseth
1b011343e3 Remove equal constraints. (#2777) 2025-05-27 14:46:11 +00:00
chriseth
3876fc2226 Solve bit decomposition with negative coefficients. (#2554)
Co-authored-by: Georg Wiese <georgwiese@gmail.com>
2025-03-26 13:57:04 +00:00
Thibaut Schaeffer
8496fa7617 Fix try_into_i32 (#2348)
`try_into_i32` is wrong for small fields, it always returns a positive
number.
I checked where it's used, and I think it makes more sense to have
`to_signed_integer`, so I changed that.
The only place it's used now is in the mock prover: negative values are
interpreted as receives, positive as sends. This would break if we
sent/received more than p/2 times, which seems fine for now.

Update: now also used in the riscv executor
2025-01-16 18:09:46 +00:00
ShuangWu121
2e978667b2 Update stwo dependency to the latest version (#2264)
### PR: Update Powdr's `stwo` Dependency and Align Toolchain

This PR updates Powdr's `stwo` dependency to the latest version, which
now uses the `nightly-2024-12-17` Rust toolchain. To ensure
compatibility, Powdr's toolchain has also been aligned with this new
nightly version.

As part of this update:
- Several modifications were made to address stricter rules and lints
introduced by the newer version of Clippy.
- System dependencies, including `uuid-dev` and `libgrpc++-dev`, were
added to resolve build and runtime issues brought about by updated
dependencies and toolchain requirements.
2024-12-23 11:48:52 +00:00
chriseth
18f6da0c47 Specialized code for goldilocks. (#2253)
This is mostly a reduced copy of the goldilocks implementation we
already have with the main difference that the division tries to perform
integer division first if it can be done without remainder.
2024-12-18 19:09:51 +00:00
chriseth
12aca0e136 Various preparatory changes. (#2228) 2024-12-12 17:56:54 +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
Leo
b1bdec55b6 fix i64 (#2202)
Copied from the GL impl
2024-12-06 11:08:56 +00:00
Thibaut Schaeffer
c0fefae3e7 Introduce workspace-level lints (#2166)
Reduce the cost of adding a lint from O(#workspace_crates) to 1.
2024-11-29 14:02:53 +00:00
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
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
Lucas Clemente Vella
612a0f972a Pinning git dependencies to git revision. (#1917)
Tag is also acceptable. Branch is not.

Solves #1914
2024-10-18 10:53:56 +00:00
Leo
44beb1745b RISCV BabyBear machine (#1889)
Replaces https://github.com/powdr-labs/powdr/pull/1790

This PR:
- [X] implements the basic RISCV BB machine without precompiles
- [X] runs the instruction tests with BB as well
- [x] runs the Rust tests except for continuations and tests that
require keccak, poseidon, ec ops
- [x] Missing: inputs and outputs with 2 limbs. There is already a
failing test that covers that.

---------

Co-authored-by: Leo Alt <leo@ethereum.org>
2024-10-16 16:49:38 +00:00
Leo
0f0eae47d5 compiler options and codegen split (#1879)
Extracted from https://github.com/powdr-labs/powdr/pull/1790.

This PR:
- creates the new `CompilerOptions` that encapsulate precompiles and
common options, needed by both cli-rs and tests
- splits codegen, runtime and bootloader into an outer facing dispatcher
based on the compiler options, and internal versions that currently are
just copies of the previous implementation that is specific to
Goldilocks and larger modulus.

After this PR, the riscv-bb PR will simply add analogous 17-bit codegen,
runtime and bootloader files.
2024-10-10 21:21:31 +00:00
Thibaut Schaeffer
d96c59095f Import p3 implementation (#1845)
This PR is only a copy paste from https://github.com/powdr-labs/plonky3
with the following exceptions:
- only the files that differ from uni-stark are copied over. Any
references to other modules are targeting upstream uni-stark
- the `preprocessed_width` function is moved to the `MultiStageAir`
trait from `BaseAir` to avoid changes to `p3-air`
- upstream uni-stark is nostd. Our wrapper uses things like hashmaps and
mutexes, so for now I commented out `nostd`
- `lib.rs` is a merge of the existing lib.rs and that of our uni-stark
fork
- the `prove` function is removed, as it is only there for compatibility
with uni-stark tests
- `FieldMerkleTreeMmcs` was
[renamed](84a13454ea)
to `MerkleTreeMmcs` in plonky3 since we forked it. Our configs use this
type and the name is updated accordingly

TODO:
- [x] extract rust update to separate PR due to the new ways clippy
complains
2024-09-30 21:09:53 +00:00
topanisto
1b0bb9d041 Plonky3 challenges (#1737)
Plonky3 challenges implementation:

- implements the relevant traits from our uni-stark fork to support
challenges
- public inputs are only supported in the first stage
- the p3 dependency is pinned to a specific commit rather than `main`
because of a possible issue with buildjet which @lvella is investigating

---------

Co-authored-by: schaeff <thibaut@schaeff.fr>
2024-09-26 12:58:18 +00:00
Thibaut Schaeffer
a1b1447a6e Point plonky3 to previous version (#1824)
We merged plonky3 challenges in our fork.
This breaks main.
Point plonky3 to the commit before the merge.
This will be removed by #1737
2024-09-23 15:04:08 +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
topanisto
277edbf5dd BabyBear with only Plonky3 changes (#1693)
Adding BabyBear params to Plonky3 crate.

---------

Co-authored-by: Thibaut Schaeffer <schaeffer.thibaut@gmail.com>
Co-authored-by: Lucas Clemente Vella <lvella@powdrlabs.com>
Co-authored-by: schaeff <thibaut@schaeff.fr>
Co-authored-by: Leo Alt <leo@powdrlabs.com>
2024-09-06 13:33:40 +00:00
Thibaut Schaeffer
55afe60662 Make csv export work with multiple fixed column sizes (#1744) 2024-09-03 12:55:30 +00:00
Leo
18ccb2fe81 remove unsafe in const bb traits (#1738) 2024-08-30 15:06:02 +00:00
Leandro Pacheco
fb74fc1034 point baby-bear to our p3 fork (#1715)
point `p3-baby-bear` to our `p3` fork (like the other `p3` dependencies
in the project)
2024-08-23 18:27:51 +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
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
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
898de40813 Fix clippy on non-x86_64 architectures (#1474) 2024-06-27 09:31:05 +00:00
chriseth
99d35a3719 Use goldilocks from plonky2 (#1438) 2024-06-26 21:35:07 +00:00
chriseth
a24aa1dbb6 Reduce trait interface. (#1433) 2024-06-17 11:19:48 +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
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
Leandro Pacheco
9d3f3707b6 bugfix: read_polys_file with 0 columns
also added related tests
2024-03-13 10:36:28 -03:00
chriseth
349f9aa461 Parse numbers as integers. 2024-03-08 15:48:49 +01:00
chriseth
4024698b2a Use ibig crate. 2024-03-08 07:31:27 +01:00
Lucas Clemente Vella
08ace88416 Nightly fix: ignoring env_logger on cargo udeps.
cargo udeps doesn't undertand why env_logger is needed on development
dependencies
2024-03-05 18:54:10 +00:00
chriseth
9f4f4776e8 Use powder_number::BigInt / BigUint everywhere instead of num_bigint. 2024-03-05 15:32:39 +01:00
chriseth
ba64512321 Rename AbstractNumberType to BigUint. 2024-03-05 15:24:21 +01:00
chriseth
57df2918d0 Rename number::BigInt to LargeInt. 2024-03-05 15:11:49 +01:00
Leandro Pacheco
861e576da7 inlining 2024-02-24 23:06:44 -03:00
Leo
0a34dd4913 Merge pull request #1072 from powdr-labs/field-registers
Registers in the riscv-executor can hold fields.
2024-02-22 08:17:33 +00: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
Lucas Clemente Vella
c5e305a6f9 Adding support for FieldElement conversion into int types. 2024-02-14 17:35:19 +00: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
40950a9feb Cleanup on file reads and writes. 2024-02-09 11:04:08 +00:00
Leandro Pacheco
cbec66e130 fix impl Display for ASMProgram
- have `FieldElement` printed as non-negative
- print constrained machine arguments
- fix related tests
2024-02-05 18:40:00 -03:00
Leo Alt
3daf9d90be add package info 2024-01-29 18:35:32 +01:00