Commit Graph

136 Commits

Author SHA1 Message Date
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
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
Leandro Pacheco
98e844c9a8 fix book example (#1344) 2024-05-03 13:27:26 +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
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
75968f286a Btree data structure (#1299)
Co-authored-by: Georg Wiese <georgwiese@gmail.com>
2024-04-30 09:40:58 +00:00
Leandro Pacheco
cea207ff3f Machine properties using with syntax (#1267)
This implements issue #1251.
Basically `machine Foo(a,b) { ... }` is now `machine Foo with latch: a,
operation_id: b { ... }`
2024-04-25 16:02:01 +00:00
Georg Wiese
46e8bb8ee5 Move STD machines into submodule (#1201)
Moves all machines in the standard library to `std::machines`. That way,
it is separated from the PIL utilities in STD.
2024-04-25 12:14:33 +00:00
Georg Wiese
a917e4f35a Add permutation to PIL STD (#1297)
First part of #1296 

This PR adds a `permutation()` function to the standard library. The
code is inspired by the `permutation_via_challenges` test (removed now),
[this
comment](https://github.com/powdr-labs/powdr/issues/424#issuecomment-1931686047)
by @chriseth and [this Halo2
implementation](https://github.com/privacy-scaling-explorations/halo2/blob/main/halo2_proofs/examples/shuffle.rs).
2024-04-25 07:32:35 +00:00
Steve Wang
056630049b keccak.asm (#1231)
Adapted from:
https://github.com/Zokrates/ZoKrates/blob/develop/zokrates_stdlib/stdlib/hashes/keccak/keccak.zok

Line reference comments are for the .zok file linked above.
2024-04-24 15:12:58 +00:00
chriseth
6096afb218 Patterns in let statements and function parameters (#1214)
Co-authored-by: Leo <leo@powdrlabs.com>
2024-04-03 18:39:19 +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
Leandro Pacheco
c5b0767fc4 allow PC to be updated in instruction mapping declarations (#1221) 2024-04-01 17:25:49 +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
chriseth
c85eb1e813 Remove all unreferenced definitions. (#1197)
Fixes https://github.com/powdr-labs/powdr/issues/966

---------

Co-authored-by: Leandro Pacheco <contact@leandropacheco.com>
2024-03-26 11:34:40 +00:00
Leandro Pacheco
31343690de test using call_selectors with no incoming permutation (#1198) 2024-03-25 19:10:26 +00:00
Georg Wiese
a18577fed2 Add read/write memory to standard library (#1129)
With the recent changes by @pacheco, we can extract our [memory
machine](https://github.com/powdr-labs/powdr/blob/main/riscv/src/compiler.rs#L687-L841)
as a separate machine and add it to the standard library.

The result should be the same as calling the function linked above with
`with_bootloader=false`, except that the memory alignment stuff is not
inlined. For this reason, the machine is not yet used by the RISC-V
machine, but it could be after #1077 is implemented.

[This](eb320dca0c) shows the diff from
what we have in `compiler.rs`.

<!--

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.

-->
2024-03-25 17:33:55 +00:00
Georg Wiese
f9318ba5a8 Implement multi-phase witgen 2024-03-25 10:27:15 +01:00
schaeff
8065794633 allow expression in degree statement 2024-03-22 19:20:29 +01:00
Georg Wiese
d2bd95cfd5 Merge pull request #1179 from powdr-labs/challenges-halo2
Implement challenges in Halo2 backend
2024-03-21 18:30:12 +00:00
Georg Wiese
0036acfa5e Implement challenges in Halo2 backend 2024-03-21 19:06:04 +01:00
Georg Wiese
10aeae6cb5 Allow and use permutation in all std machines 2024-03-21 17:20:18 +01:00
chriseth
ae8f8654b1 Merge pull request #1118 from powdr-labs/challenges
Challenges
2024-03-20 12:07:06 +00:00
chriseth
e1753fd88e Challenges and stages. 2024-03-20 12:40:51 +01:00
Leandro Pacheco
edaf536500 Allow machines to be linked via permutation
by instructions and links using `~` instead of `=`.
Block machines must declare `call_selectors`.
2024-03-20 08:17:21 -03:00
Georg Wiese
be7a48cb84 Witgen: Don't derive non-unique witness when there might be overflow 2024-03-19 14:13:17 +01:00
Leo Alt
efe11f40fc enum declarations 2024-03-18 22:09:44 +01:00
Leandro Pacheco
ff8fda1563 Expressions in instr/link params
allow for `link` and RHS of `instr` params to use full on expressions
2024-03-18 14:04:08 -03:00
Georg Wiese
f87a760071 Hints for arithmetic machine 2024-03-18 11:57:40 +01:00
schaeff
995f1fd4c2 remove ordering assumption on register declarations 2024-03-12 19:23:08 +01:00
Georg Wiese
d4477779a2 Memory machine: Don't use selectors to distinguish operations 2024-03-12 12:13:36 +01:00
chriseth
dc96509070 Make expressions and constraints native values. 2024-03-05 11:22:12 +01:00
Leo
88c9d735b7 Merge pull request #1070 from powdr-labs/link_params
Move `link` params to RHS
2024-03-04 13:40:25 +00:00
Leandro Pacheco
f3e1802787 move link params to RHS and simplify the code
- added more checks for pc machines / constrained machines
- improve example and docs
2024-03-04 09:55:37 -03:00
chriseth
df3d3e285a Implement sqrt 2024-03-04 12:51:34 +01:00
chriseth
97ed14c48b Type checking. 2024-03-01 17:36:54 +01:00
Leo
da66acac0c Merge pull request #1108 from powdr-labs/fix-halo2-soundness-bug
Fix Soundness Bug in Halo2 implementation
2024-03-01 08:40:12 +00:00
Georg Wiese
6ad188ccd3 Fix Soundness Bug in Halo2 implementation 2024-02-29 18:03:27 +01:00
chriseth
2a04e6a916 Merge pull request #1075 from powdr-labs/block-machine-permutation
Witness generation for block machines connected via permutations
2024-02-29 15:47:08 +00:00
Georg Wiese
4eb8644e79 Witness generation for block machines connected via permutations 2024-02-29 16:04:58 +01:00
Georg Wiese
50a181dab3 Add tests with invalid witnesses 2024-02-28 17:49:41 +01:00
Georg Wiese
3ce5a9f98a Add tests for Shift and Binary machines 2024-02-26 11:24:03 +01:00
chriseth
daffb65c0c Add type schemes. 2024-02-22 13:39:39 +01:00
Georg Wiese
668d881057 On (N-1, 0) row pair, only execute identities with next reference 2024-02-19 10:27:50 +01:00
Leandro Pacheco
2e1a8571a7 instr param mapping
allow RHS of `instr` declarations to control the usage of write and assignment
registers.
2024-02-14 13:31:19 -03:00
Georg Wiese
d37116372d Test that proving fails for unsatisfying witness 2024-02-13 11:56:18 +01:00
Georg Wiese
dd81fe014a Fix soundness bug in conversion to Halo2 2024-02-12 11:36:31 +01:00
chriseth
de0e89c313 Ararys of intermediate columns. 2024-02-09 08:17:55 +01:00