Commit graph

179 commits

Author SHA1 Message Date
arnaucube
e1775d8578
add eq & partial_eq for RecursivePod, Pod traits and VDSet struct (for usage from introduction-pods) (#309)
* add eq & partial_eq for VDSet (for usage from introduction-pods)

* add eq & partial_eq impls for Pod & RecursivePod traits
2025-06-24 17:41:46 +02:00
arnaucube
256d76ae34
add zk config, enabled by a feature (on by default) (#306)
* add zk config, enabled by a feature (on by default)

* Update src/backends/plonky2/recursion/circuit.rs

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>

---------

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>
2025-06-24 17:28:58 +02:00
d5da9d8593
Display point in base58 (#305)
* Compress EC subgroup points before serialising

* serialize and display point in base58

* Use Display for Points

---------

Co-authored-by: Ahmad <root@ahmadafuni.com>
2025-06-24 00:18:58 +10:00
Ahmad Afuni
151419ec88
feat: compress EC subgroup points before serialising (#304)
* Compress EC subgroup points before serialising

* Code review
2025-06-20 23:01:11 +10:00
b7ac54d972
Add some top-level examples (#303)
The examples show:
- Building a Signed Pod with different types of values
- Building a MainPod
- Input SignedPod to MainPod
- Input MainPod to MainPod
- Using MainPod or MockMainPod
- Using custom predicates
2025-06-19 19:31:54 +02:00
6249406cb2
Complete the verification in MainMockPod (#302)
- Update the `RecursivePod` trait to return `vd_set` instead of `vds_root`
  - A native verifier requires the entire set to reason about the circuits that have been used in the recursive tree
- Implement serialization/deserialization for `VDSet`
- Remove `DynError` and use `BackendError` instead for middleware functions that wrap or define trait functions implemented in the backend.  This is based on the fact that we will only have a single backend enabled at a time, so there's no need for a `dyn Error`
  - Move the implementations of `_verify` functions to `verify` and similarly for `_prove`
- Complete the verification of a MockMainPod: the verification of input pods was missing.  The inclusion of these input pods in the serialization was also missing.  With this change a `MockMainPod` will grow after each recursion.  This was expected from the design but was not the case because of the missing recursive native verification implementation.

* apply feedback from @arnaucube
2025-06-19 16:28:25 +02:00
df8fce76d6
better measuring (#295) 2025-06-18 17:23:32 +02:00
arnaucube
0541817116
move pod data's deserialization to RecursivePod trait (#294), expose get_common_data (#300) 2025-06-18 11:13:29 +02:00
arnaucube
6ab0bc52fc
recursion circuit's verifier_data_hash include constant_sigmas_cap in the hash, and add explanation (#288) 2025-06-17 10:49:04 +02:00
Rob Knight
462aaee061
Fix incorrect output statement types on operation check (#292) 2025-06-17 01:40:52 -07:00
3c6930dfe6
Allow literals in statement templates (#287)
This PR is a continuation of the work done in #276 
- Fix PodType in MainPod (we were using `MockMain` instead of `Main`)
- Update anchored keys in statement template arguments to only support wildcards in the origin and literal keys as the key.
  - Update the pest grammar accordingly
  - Update the parser accordingly
- Rewrite the eth_dos example in a recursive manner so that we use one recursive pod for every distance increment of 1.
  - I've also used the podlang to define the eth_dos custom predicates.  Currently all predicates are in a single batch (previously `eth_friend` was in a different batch).  With #286 we could define `eth_friend` in a different batch again.
    - I was feeling a bit creative and used a format macro to pass `Value`s from rust to the podlang code.
  - The eth_dos is now written using literals.  This resolves https://github.com/0xPARC/pod2/issues/255
- Remove `StatementArg::WildcardValue` in favor of `StatementArg::Literal`.  The `WildcardValue` was just a way to have some kind of typing for values that would be used as arguments in custom predicates.  Now that we can have literals in any statement this value can be anything, so I just removed the `WildcardValue` and use `Literal` instead.  On the backend it was already the case that both cases were treated the same way (after all, `WildcardValue` and `Literal` were 4 fields in the backend).
  - Added a new type for Value: `PodId` so that we can use it for custom predicates that take a pod id to be used in a wildcard
- Add a mock vd_set that is empty for tests that don't use plonky2; this allows running those tests individually without paying for the expensive work of calculating the vd for various circuits.
- rename StatementTmplArg::WildcardValue to StatementTmplArg::Wildcard
2025-06-16 16:38:38 +02:00
Daniel Gulotta
7d0d3ad769
Allow literals in statements (#276)
Implements #229 and #261.
2025-06-13 10:27:19 -07:00
Rob Knight
21ab3c2d0d
Basic 'use' syntax for importing custom predicates (#286)
* Basic 'use' syntax for importing custom predicates

* Add extra test for unknown batches

* Fix unused import

* Enforce that imports must match number of predicates in a batch
2025-06-13 10:09:08 -07:00
arnaucube
f7bb6af219
docs: add initial docs of Introduction PODs section, with some diagrams (#285) 2025-06-13 11:26:12 +02:00
3b4edab1f5
remove NonePod and use dummy signed pods (#272)
* remove NonePod and use dummy signed pods

* apply suggestion by @arnaucube
2025-06-13 10:14:15 +02:00
03485d6fd3
fix anchored keys syntax (#283) 2025-06-12 18:15:02 +02:00
Rob Knight
3ea0d5be71
Better Hash and PartialEq for Keys and AnchoredKeys (#277) 2025-06-11 04:25:08 -07:00
arnaucube
273d803ebd
Add verifier-datas tree (set) & in-circuit verification (#274)
* containers: add method to create new {Dict,Set,Array} with custom max_depth

* add vds_tree computation, update tree circuit interface

* add VDTree struct, add DEFAULT_VD_TREE, integrate it with MainPod,EmptyPod,frontend,etc.

* adapt frontend/serialization tests to new containers field (max_depth)

* adapt interfaces to allow using custom vd_tree in frontend & backend constructors

* rename VDTree to VDSet (and derivate namings too)

* containers 'new' always with param 'max_depth', use params.max_depth_mt_containers instead of the global constant MAX_DEPTH

* adapt after rebasing the branch to main latest changes

* apply review suggestions from @ed255

* use emptypod vd_mt_proofs (using vd_set as circuit input), merge the two existing set_targets methods of MainPodVerifyTarget

* document VDSet & vds_root
2025-06-11 13:08:39 +02:00
6258e52e1a
update docs to use pod lang v1 (#268) 2025-06-10 15:08:45 +02:00
6feff2ae69
display statement/statement_tmpl as in pod lang v1 (#269)
* display statement/statement_tmpl as in pod lang v1

* fix tests
2025-06-10 15:06:57 +02:00
Ahmad Afuni
77c96d5dbe
chore(backend): add flags to PointTarget struct (#270)
* Add flags to PointTarget struct

* Code review
2025-06-10 21:47:51 +10:00
9c709094e5
adjust recursive calculation using standard gates (#251)
* adjust recursive calculation using standard gates

* document gate constraints on zero-witness
2025-06-10 12:35:13 +02:00
621f8be6b5
Implement generic serialization/deserialization (#260)
* complete general serialization

* bump default params temporarily

* disable recursion in great_boy_pod example
2025-06-10 12:17:30 +02:00
Ahmad Afuni
c66506c048
feat(backend): Use Schnorr signatures for signed PODs (#236)
* Implement non-native extension field arithmetic

* Schnorr signature verification (#221)

* Use Schnorr signatures for signed PODs

* add custom gates (#237)

* Clippy

* Formatting

* Apply suggestions from code review

Co-authored-by: Eduard S. <eduardsanou@posteo.net>

* Fix typo

* Fix tests

* Point -> PublicKey

* Remove default nnf_div implementation for clarity

* Code review & edits for clarity

* Remove suspicious mutation

* Simplify computation

* Fix division

* Fix

* Update src/backends/plonky2/primitives/ec/curve.rs

Co-authored-by: Eduard S. <eduardsanou@posteo.net>

* Update src/backends/plonky2/primitives/ec/curve.rs

Co-authored-by: Eduard S. <eduardsanou@posteo.net>

* Fixes

* Add public key to signed POD struct

* Style

* Elaborate on in-circuit field->biguint conversion

* Add missing gates

* Comments

* Add bits to biguint struct

* Comments

* Comment

---------

Co-authored-by: Daniel Gulotta <dgulotta@alum.mit.edu>
Co-authored-by: Eduard S. <eduardsanou@posteo.net>
2025-06-10 00:24:16 +10:00
Rob Knight
541c264586
Podlog language v1 (#225)
* Initial commit for Podlog language

* Spell-checker thinks that 'lits' is a bad abbreviation for 'literals'

* Enable SetContains/SetNotContains

* Update language based on review feedback

* Typo/comment fix

* Make native predicates case-sensitive

* Enforce max batch size in CustomPredicateBatchBuilder

* Remove some unnecessary checks for things handled by the grammar

* Clean up more unnecessary error-checking

* Typo

* Simplify hex processing

* Replace various errors with unreachable!()

* Translate from big-endian hex string to little-endian RawValue

* Update hex en/decoding functions
2025-06-06 22:17:23 -07:00
Sunghyeon Jo
e8edbbc1c5
Feat/add exp gate (#257)
* add exponentiation gate to common_data_for_recursion

* fix: use new_from_config

Co-authored-by: Eduard S. <eduardsanou@posteo.net>

---------

Co-authored-by: Eduard S. <eduardsanou@posteo.net>
2025-06-06 11:37:15 +02:00
arnaucube
7bc0bd08d2
expose some interfaces for external usage (from introduction-pods) (#256)
* expose some interfaces for external usage (from introduction-pods)

* add From<MainPod> for OperationArg, add copy op!

Co-authored-by: Eduard S. <eduardsanou@posteo.net>

---------

Co-authored-by: Eduard S. <eduardsanou@posteo.net>
2025-06-05 11:37:43 +02:00
tideofwords
5d13ac32ce
update docs (#242)
* Update docs: Statements, operations, syntactic sugar

* Update docs: Remove low-level Merkle tree statements

* Update docs: typo

* Update book/src/operations.md

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>

* Eq -> Equal

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>

* Eq -> Equal, again

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>

* Eq -> Equal, yet again

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>

---------

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>
2025-06-03 10:49:33 +10:00
88a75986b8
Integrate recursion into MainPod (#243)
* calculate MainPod id in a dynamic-friendly way

The MainPod id is now calculated with front padding and a fixed size
independent of max_public_statements so that introduction gadgets can be
verified by a MainPod while paying only for the number of statements
they use.  This is because with front padding of none-statements we can
precompute the poseidon state corresponding to absorbing all the padding
statements and only pay constraints for the non-padding statements.

The id is calculated as follows:
`id = hash(serialize(reverse(statements || none-statements)))`

* add time feature and disable timing by default

* apply suggestions from @arnaucube

* link issues in todos
2025-05-29 17:10:19 +02:00
d3fef8392e
calculate MainPod id in a dynamic-friendly way (#241)
* calculate MainPod id in a dynamic-friendly way

The MainPod id is now calculated with front padding and a fixed size
independent of max_public_statements so that introduction gadgets can be
verified by a MainPod while paying only for the number of statements
they use.  This is because with front padding of none-statements we can
precompute the poseidon state corresponding to absorbing all the padding
statements and only pay constraints for the non-padding statements.

The id is calculated as follows:
`id = hash(serialize(reverse(statements || none-statements)))`

* fix test
2025-05-23 10:12:28 +02:00
82481e88d7
allow SELF in st_tmpl (#240)
* allow SELF in st_tmpl

* add some tests

* Update src/backends/plonky2/circuits/mainpod.rs

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>

---------

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>
2025-05-22 15:13:02 +02:00
arnaucube
b4a4c72328
Add RecursiveCircuit (#204)
* Add RecursiveCircuit

The RecursiveCircuit verifies N proofs of itself (N=arity), together with
the logic defined at the InnerCircuit (in our case, used for the
MainPodCircuit logic).

The arity defines the maximum amount of proofs of itself that the
RecursiveCircuit verifies. When arity>1, using the RecursiveCircuit has the
shape of a tree of the same arity.

                     π_root
                       ▲
               ┌───────┴────────┐
               │RecursiveCircuit│
               └─▲───▲───▲────▲─┘
         ┌───────┘  ┌┘   └┐   └──────┐
         │π''_1     │ ... │     π''_N│
┌────────┴───────┐ ┌┴┐┌─┐┌┴┐ ┌───────┴────────┐
│RecursiveCircuit│ │.││.││.│ │RecursiveCircuit│
└──▲─────────▲───┘ └─┘└─┘└─┘ └──▲─────────▲───┘
   │         │                  │         │
  π_1  ...  π_N               π'_1 ...  π'_N

where
N: arity of the RecursiveCircuit
π_i: plonky2 proof of the RecursiveCircuit

* add different inner-circuits in the test, reusing the same verifier_data; polish recursion interfaces

* add InnerCircuit::Params

* rm non_base_node

* WIP refactor RecursiveCircuit

* wip. change approach on verifier_data of circuits used in recursivecircuit. arity=1 works

* recursion works fine without registering verifierdatas as publicinputs

* add hashing of verifier_data (out & in-circuit) methods with test

* connect previous and current verifier_datas hashes

* polish

* add InnerCircuit's public_inputs to the RecursiveCircuit

* extend recursive test

* polish & review suggestions
2025-05-21 13:15:22 +02:00
c3c9e7f99c
add gate count metrics (#238)
* add gate count metrics

* tweak params

* move metrics to its own file
2025-05-21 12:45:51 +02:00
Rob Knight
de9b206852
Serialization for Plonky2 Signed and Main PODs (#234)
* WIP

* WIP

* Working serialization for both Mock and Plonky2 versions of Signed and Main Pods

* Restore useful comment about serialized_proof()

* Use plonky2 serialization for signatures and proofs

* Add schema renames for Serialized SignedPod/MainPod types

* Break out utility function for generating common circuit data

* Review feedback fixes
2025-05-19 02:22:38 -07:00
def0730462
Fix custom predicate circuits and add tests for them (#235)
* add tests, fix custom predicates

* wip

* wip

* fix custom predicates

* modularize code

* fix typos

* remove scratch file

* update

* Update src/backends/plonky2/circuits/mainpod.rs

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>

---------

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>
2025-05-16 13:17:14 +02:00
Ahmad Afuni
f5a1aa7523
chore: workaround for #230 (#231)
* Workaround for debug panic

* Use Rust exception handler 💀
2025-05-14 00:22:11 +10:00
cd40219ba6
Use id as public inputs in MainPod verify (#233) 2025-05-13 16:19:51 +02:00
024ed8bd04
Constraints for custom predicates (#227)
* add target types for custom predicates

* simplify

* fix clippy

* fix typo

* don't use ref for NativePredicate

* fix wrong len

* precalculate CustomPredicateBatch id

* wip

* wip

* move code back

* great progress

* wip

* code complete, hopefully; missing tests

* fill aux for custom predicate op

* fix clippy warnings

* fix typos

* fix test import

* fix missing assignment in lt_mask, test custom_operation_verify_gadget

* fix mistake

* wip

* fix

* debug revert except for let entry = CustomPredicateVerifyEntryTarget

* fix batch_id calculation by fixing padding

* oops

* remove completed TODOs
2025-05-13 11:00:45 +02:00
Ahmad Afuni
4fa9e20ecd
feat(backend): implement gadgets for remaining ops (#228)
* Implement gadgets for remaining ops

* Use overflowing arithmetic ops

* Code review

* Formatting
2025-05-13 07:34:35 +10:00
Rob Knight
b2cb563eb6
Desugar statement templates (#226)
* Desugar statement templates

* Support desugaring of SetContains statement templates

* Update the book
2025-05-09 05:48:18 -07:00
726f95483d
add target types for custom predicates (#223)
* add target types for custom predicates

* simplify

* fix clippy

* fix typo

* don't use ref for NativePredicate

* fix wrong len

* apply feedback from @ax0
2025-05-07 11:09:38 +02:00
Ahmad Afuni
bf394eada3
feat(backend): implement more ops (#222)
* Implement more ops

* Split up op verification tests

* Code review
2025-05-07 10:37:05 +10:00
Ahmad Afuni
8cc090c5e0
Implement HashOf statement and op (#217) 2025-05-06 19:14:53 +10:00
Ahmad Afuni
53ade6ea26
chore: implement Gt and GtEq as syntactic sugar (#216)
* Implement Gt and GtEq as syntactic sugar

* Update src/backends/plonky2/circuits/mainpod.rs

Co-authored-by: Eduard S. <eduardsanou@posteo.net>

* Op verification circuit refactor

* Code review

* Add range check to Eq case of LtEq

* Style

* Factor out ValueOf statement argument type checks

* Formatting

* Clean-up

* Safety

* Take sign into account

* Simplify sign check

---------

Co-authored-by: Eduard S. <eduardsanou@posteo.net>
2025-05-06 06:59:59 +10:00
Ahmad Afuni
e420aa7b32
Make Plonky2 config more explicit (#209) 2025-04-30 07:15:20 +10:00
arnaucube
29545f03fc
migrate from anyhow to thiserror (#197)
* migrate from anyhow to thiserror (#190). pending polish error msgs

* Add backtrace and compartmentalize errors

- Include backtraces in the errors we generate.  To get this we can't
  just return a literal enum, because the backtrace requires a call.
- Related to the previous point: add methods to create errors so
  we can include the backtrace conveniently without changing too much
  the syntax.  So instead of `Err(Error::KeyNotFound(key))` (literal
  enum) it will be `Err(Error::key_not_found(key))` (method call)
- Each error should be local to its scope, and each scope should
  only return its own error.
  - The merkle tree should return `TreeError` and not Error
  - The middleware should return `MiddlewareError` and not Error
- With a global Error we can't easily include backend/frontend types in
  the error fields, so declare a `BackendError` and a `FrontendError`
  and follow the pattern from the previous point
- The Pod traits should be able to return backend errors and will be
  used in the frontend; for that we change them to use trait object
  Error: `dyn std::error::Error`

* fix error

* apply suggestions from @arnaucube

* rename XError and XResult to Error and Result

* reorg signature

* make frontend custom error more ergonomic

* remove unnecessary feature

---------

Co-authored-by: Eduard S. <eduardsanou@posteo.net>
2025-04-22 15:07:04 +02:00
Daniel Gulotta
58d3c6a236
make Pod derive from Any (#205) 2025-04-22 14:06:23 +02:00
Rob Knight
bf6d8aee8b
Re-implement serialization (#201)
* Serialization tests now pass again

* Tidy up and test more edge-cases

* Use attributes rather than custom serializer for arrays

* Add JSON Schema support

* Tests for JSON Schema generation and validation

* Add comments

* Support custom predicates

* Clippy fixes

* Make deserialization/constructor functions pub(crate)
2025-04-22 04:19:20 -07:00
26a6b2d143
Padding in set target (#200)
* feat: handle padding in set_target

* remove enable from MerkleClaimAndProof

* Update src/backends/plonky2/circuits/mainpod.rs

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>

---------

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>
2025-04-21 17:27:29 +02:00
Ahmad Afuni
17e6c2a092
chore(frontend): make Merkle proofs optional (#198)
* Make frontend Merkle proofs optional

* Code review

* Clippy
2025-04-17 21:51:02 +10:00