464 Commits

Author SHA1 Message Date
Daniel Lubarov
e4a5c2c968
Merge pull request #857 from mir-protocol/non_tight_degree_bound
Allow non-tight degree bound
2023-01-03 22:29:45 -08:00
Daniel Lubarov
0ca308400a
Merge pull request #855 from mir-protocol/fixed_stark_recursion
Shrink STARK proofs to a constant degree
2023-01-03 11:31:14 -08:00
Daniel Lubarov
1ecdb96a6b Power of two length 2023-01-03 11:03:20 -08:00
Daniel Lubarov
2e59ceccc4 import 2023-01-03 10:40:05 -08:00
Daniel Lubarov
40aecc8e95 Allow non-tight degree bound
Reverts the degree adjustment part of #436. As @jimpo pointed out, the adjustment complicates security by allowing rational functions of the form `poly(x) / x`.

A tight degree bound shouldn't be necessary. Ultimately we want to check that some witness function `f(x)` exists satisfying (simplified) `c(f(x)) = Z_H(x) q(x)`.  We only need `f(x)` to be low-degree because that allows us to use polynomial identity testing. With PIT we don't care about exact degree bounds; a negligible degree change will have a negligible effect on PIT soundness.
2023-01-03 10:19:55 -08:00
Daniel Lubarov
595e751ac1 Shrink STARK proofs to a constant degree
The goal here is to end up with a single "root" circuit representing any EVM proof. I.e. it must verify each STARK, but be general enough to work with any combination of STARK sizes (within some range of sizes that we chose to support). This root circuit can then be plugged into our aggregation circuit.

In particular, for each STARK, and for each initial `degree_bits` (within a range that we choose to support), this adds a "shrinking chain" of circuits. Such a chain shrinks a STARK proof from that initial `degree_bits` down to a constant, `THRESHOLD_DEGREE_BITS`.

The root circuit then combines these shrunk-to-constant proofs for each table. It's similar to `RecursiveAllProof::verify_circuit`; I adapted the code from there and I think we can remove it after. The main difference is that now instead of having one verification key per STARK, we have several possible VKs, one per initial `degree_bits`. We bake the list of possible VKs into the root circuit, and have the prover indicate the index of the VK they're actually using.

This also partially removes the default feature of CTLs. So far we've used filters instead of defaults. Until now it was easy to keep supporting defaults just in case, but here maintaining support would require some more work. E.g. we couldn't use `exp_u64` any more, since the size delta is now dynamic, it can't be hardcoded. If there are no concerns, I'll fully remove the feature after.
2023-01-01 23:11:39 -08:00
Sladuca
403e239250
use doc comment 2022-12-28 12:20:08 -05:00
Sladuca
350b902998
add or gadget 2022-12-28 11:30:24 -05:00
Daniel Lubarov
92974aa105 A few more cyclic recursion changes
In preparation for adding the zkEVM aggregation circuit. Mainly,

- Adds a `WitnessWrite` trait, a sub-trait of `Witness`, and move the write methods to it. `GeneratedValues` impls `WitnessWrite`, which lets generators like `DummyProofGenerator` access all our write methods like `set_proof_with_pis_target`. Also removes some duplication.

- Remove `set_cyclic_recursion_data_target` - now that dummy proof data is automatically populated, all that remains is populating `condition` and the cyclic proof + VK. I think it's easy enough for callers to do this; the steps are the same as with `conditionally_verify_proof`. This way there's no cyclic-recursion-specific API to learn about.

- Split `cyclic_recursion` into two variants, one which checks the current circuit or a dummy, and a more general one which checks the current circuit or some other circuit. We can use the latter to build a more efficient aggregation circuit, where we check another aggregation proof or an EVM proof, with no dummy proofs involved.
2022-12-11 22:43:26 -08:00
Nicholas Ward
f0e144bb9b removed confusing grammatical exclamation point from factorial example 2022-12-09 17:29:09 -08:00
Daniel Lubarov
fbb26546dd Jemalloc for EVM
Also update the version used elsewhere.
2022-12-04 10:15:28 -08:00
Daniel Lubarov
05ab3d7933 Fixes 2022-12-01 16:23:39 -08:00
Daniel Lubarov
73de231e34
Merge pull request #827 from mir-protocol/cyclic_recursion_tweaks
Cyclic recursion tweaks
2022-11-29 13:19:18 -08:00
Daniel Lubarov
3515fbddac fix 2022-11-29 12:39:53 -08:00
Daniel Lubarov
ad58dcbc0e fix 2022-11-29 12:39:17 -08:00
Daniel Lubarov
c3ae52f5b0 fix 2022-11-29 12:19:40 -08:00
Daniel Lubarov
b23193ba8d use hashmap 2022-11-29 12:17:33 -08:00
Daniel Lubarov
319d9b5a52 Feedback 2022-11-29 12:02:54 -08:00
Daniel Lubarov
644a8a2336 Make proof_with_pis a reference 2022-11-28 22:18:42 -08:00
Daniel Lubarov
c528da4e66 Cyclic recursion tweaks
- Have the caller to `cyclic_recursion` create and pass in the virtual proof
- Split `dummy_proof` into preprocessing and proving, so that we don't need to redo the preprocessing work in each `set_cyclic_recursion_data_target` call
- Have the caller update `num_public_inputs` instead of doing it in `cyclic_recursion`. This is a little less convenient but I think it's best not to modify the caller's config (principle of least surprise)
- Have `set_cyclic_recursion_data_target` take a sparse set of public inputs. Taking some PIs with the lowest indices didn't seem very general. I still have some reservations about this part of the API - I think it would seem cleaner if PIs of a proof which wasn't selected for verification were simply ignored - but perhaps there are some optimization reasons to keep using them.
2022-11-28 21:02:41 -08:00
Daniel Lubarov
964d2bc373 Fix test 2022-11-22 22:33:41 -08:00
Daniel Lubarov
4048107892 Cyclic recursion tweaks 2022-11-22 20:09:10 -08:00
Daniel Lubarov
7ec14029c6 Fix comment 2022-11-22 08:04:01 -08:00
Daniel Lubarov
af1b6680e8 Switch to Vec 2022-11-22 08:02:22 -08:00
Daniel Lubarov
108cb83621 Domain separator option 2022-11-21 13:24:46 -08:00
Daniel Lubarov
05f4d2be4e Remove conversion 2022-11-20 09:43:16 -08:00
Daniel Lubarov
b0be6d7e8a Serialization refactor
Followup to #806.

A few goals here
- Zero dependencies on std. (Previously deserialization depended on std for `Cursor`.)
- Provide a single (memory buffering) impl of `Write` to make sure there's no confusion. (Previously `Buffer` and `Vec<u8>` both implemented it.)
- Move closer to the `std::io` APIs. Hopefully they will be available without std at some point (there have been some discussions...).

More specifically, this
- Changes `Buffer` to not use std's `Cursor`.
- Removes `impl Write` for `Buffer`, since it's implemented for `Vec<u8>`.
- Adds a concrete I/O error type to mimic `std::io`'s.
- Combines `Position` and `Size` into `Remaining`.
2022-11-20 09:37:18 -08:00
Daniel Lubarov
9a43084f94 Merge branch 'feat/no-std-support' of https://github.com/openzklib/plonky2 into openzklib-feat/no-std-support 2022-11-17 12:17:22 -08:00
Daniel Lubarov
1732399f05 Remove comment 2022-11-17 12:08:33 -08:00
Daniel Lubarov
e22da77b34 Include the FRI prover's PoW witness in the transcript
We don't think this is required for soundness, but just to remove any doubt.

Old protocol:
```
...
P sends final_poly
V samples random r
P sends pow_witness (not in transcript)
V computes pow_response = H(r, pow_witness)
V asserts pow_response has N leading 0s
...
```

New protocol:
```
...
P sends final_poly
P sends pow_witness
V samples random pow_response
V asserts pow_response has N leading 0s
...
```
2022-11-17 12:08:11 -08:00
Brandon H. Gomes
65d106bc31
chore: remove derivative dependency as non-crucial
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
2022-11-15 16:26:43 -05:00
Brandon H. Gomes
2520bd62c6
chore: match hashbrown ahash dependency
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
2022-11-15 16:14:07 -05:00
Brandon H. Gomes
812a5d468a
chore: merge branch main
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
2022-11-15 01:54:30 -05:00
Brandon H. Gomes
289498e854
fix: address review comments
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
2022-11-15 01:52:27 -05:00
Brandon H. Gomes
14c2a6dd1f
Fork Update (#3)
* Use static `KERNEL` in tests

* Print opcode count

* Update criterion

* Combine all syscalls into one flag (#802)

* Combine all syscalls into one flag

* Minor: typo

* Daniel PR comments

* Check that `le_sum` won't overflow

* security notes

* Test reverse_index_bits

Thanks to Least Authority for this

* clippy

* EVM shift left/right operations (#801)

* First parts of shift implementation.

* Disable range check errors.

* Tidy up ASM.

* Update comments; fix some .sum() expressions.

* First full draft of shift left/right.

* Missed a +1.

* Clippy.

* Address Jacqui's comments.

* Add comment.

* Fix missing filter.

* Address second round of comments from Jacqui.

* Remove signed operation placeholders from arithmetic table. (#812)

Co-authored-by: wborgeaud <williamborgeaud@gmail.com>
Co-authored-by: Daniel Lubarov <daniel@lubarov.com>
Co-authored-by: Jacqueline Nabaglo <jakub@mirprotocol.org>
Co-authored-by: Hamish Ivey-Law <426294+unzvfu@users.noreply.github.com>
2022-11-15 01:51:29 -05:00
Daniel Lubarov
7eb0c74166 Randomize unused wires of PublicInputGate 2022-11-14 14:53:06 -08:00
Daniel Lubarov
cab6c18ed6 Check that le_sum won't overflow 2022-11-08 11:55:02 -08:00
Daniel Lubarov
3dcc0c257e Update criterion 2022-11-07 11:28:24 -08:00
Brandon H. Gomes
9431fd7448
chore: add missing documentation in serialization trait
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
2022-11-05 10:59:46 -07:00
Brandon H. Gomes
7e432bd6cc
feat: add serialization documentation
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
2022-11-04 16:47:02 -07:00
Brandon H. Gomes
fc3f63398d
wip: start moving starky to no-std
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
2022-11-03 12:17:03 -07:00
Brandon H. Gomes
38e467f1c0
chore: fix serde-cbor and run cargo-sort
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
2022-11-03 11:41:12 -07:00
Brandon H. Gomes
703d2c3c95
wip: start plonky2_u32 and plonky2_ecdsa no-std impl
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
2022-11-03 10:58:55 -07:00
Brandon H. Gomes
e2cdd5a954
feat: upgrade Sampling APIs
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
2022-11-03 08:26:03 -07:00
Brandon H. Gomes
4aaf57e9a9
feat: separate reading and writing to get infallible writers
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
2022-11-02 21:07:51 -07:00
Brandon H. Gomes
7a81c5d46a
feat: move to alloc for Vec/String/Box
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
2022-11-02 19:59:12 -07:00
Brandon H. Gomes
6fd0da216a
fix: remove unstable features from plonky2
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
2022-11-02 17:50:31 -07:00
Brandon H. Gomes
11600b93c0
fix: do a first round of a core replacement
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
2022-11-02 16:54:41 -07:00
wborgeaud
c47f767fc5 PR feedback 2022-10-27 15:45:14 +02:00
wborgeaud
8a60fe19ea Cyclic recursion gadget doesn't move circuit builder 2022-10-26 15:04:47 +02:00