Commit graph

128 commits

Author SHA1 Message Date
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
281f57f0a0
move MainPod layouting to mainpod (#196)
* move MainPod layouting to mainpod

* wip

* use MerkleClaimAndProof in merkle circuit set_targets

* fix empty mt proof
2025-04-17 13:31:44 +02:00
Ahmad Afuni
0b5d4dd802
Remove output statement logic in middleware (#199) 2025-04-17 21:15:46 +10:00
c232c8dae5
Refactor frontend/middleware types (#194)
* unify fe/be NativeOp and NativePred

* remove Origin in favour of PodId

* Combine string and hash in Key

* use middleware::AnchoredKey in frontend

* merge frontend/middleware types

* refactor custom predicates

* clean up a bit

* fix middleware custom tests

* clean up

* clean up 2

* add acronyms in typos list
2025-04-16 11:59:30 +02:00
Rob Knight
9e860ef262
Use the sanctions set passed in as arg to builder function (#193) 2025-04-10 10:07:40 -07:00
0759d6e165
Add clippy (#191)
* Organize imports

Use rustfmt to organize imports.  Resolve #162

* remove unused imports

* Fix clippy complaints

* add clippy github action

* remove comment for @arnaucube
2025-04-08 11:52:02 -07:00
24ff82dd3d
Organize imports (#188)
* Organize imports

Use rustfmt to organize imports.  Resolve #162

* remove unused imports

* cargo fmt
2025-04-07 16:19:13 -07:00
Rob Knight
a6cd02ec2f
Add extra front-end types and make MainPodBuilder emit these (#166)
* All test pass on middleware->frontend type refactor

* Convert frontend CustomPredicateRef to a named field struct

* Minor serialization improvements

* Set appropriate titles in JSON schemas

* Add names for custom predicates

* Remove PodClass from front-end Origin type

* Simplify value conversion

---------

Co-authored-by: Ahmad <root@ahmadafuni.com>
2025-04-07 14:27:20 -07:00
Ahmad Afuni
6528914366
chore(backend): implement more circuit op logic (#173)
* Add backend MerkleProof type

* Add eval_not_contains

* Remove print statement

* Handle some edge cases

* Add test

* Add missing ?

* Optimisation and stylistic changes

* Code review
2025-04-08 02:15:46 +10:00
ce26a316a1
MainPod implementation (#168)
* Initial circuit op work

* Fix copy op

* Add more ops

* add mainpod boilerplate

* pass basic test of mainpod

* fix duplicate imports

* WIP

* fixes

* wip

* fix test

* wip

* clean up

* address feedback from @ax0

* oops

---------

Co-authored-by: Ahmad <root@ahmadafuni.com>
2025-04-01 11:23:45 -07:00
arnaucube
4a94b34792
Add SignedPod verification circuit (SignedPodVerifyGadget) (#170)
* add boolean selector to the MerkleProofGadget, to allow skipping proof verifications when all the slots are not used (eg. in the SignedPod circuit)

* move existing signedpod's circuits draft to its own file

* implement SignedPodVerify circuit
2025-04-01 18:20:28 +02:00
arnaucube
0637f52573
add circuit to verify signatures (SignatureVerifyGadget) (#167)
* implement circuit to verify signature (proof-based signature), ie. a 1-level recursion verification

* as agreed in the call, rename Gate -> Gadget when it's not a 'gate'

* make SignatureVerifyGadget conditional on the selector input

* small naming polish

* sigverifygadget: add s computation in-circuit, connect pk,msg,s to internalproof's public_inputs

* optimize signature verify

---------

Co-authored-by: Eduard S. <eduardsanou@posteo.net>
2025-03-31 16:36:37 -07:00
tideofwords
d00ff95f41
Fe contains (#145)
* Contains should take three arguments (root, key, value)

* Add a test for frontend Dictionaries

* Separate frontend and middleware operations

* Make tests pass: add arg to contains

* Cargo fmt

* Merkleproof verify circuit (#143)

* merkletree: add keypath circuit

* merkletree-circuit: implement proof of existence verification in-circuit

* parametrize max_depth at the tree circuit

* Constrain selectors in-circuit

* implement merketree nonexistence proof circuit, and add edgecase tests

* add non-existence proofs documentation in the mdbook, mv EMPTY->EMPTY_VALUE & NULL->EMPTY_HASH, dependency clean and public exposure methods

* review comments, some extra polishing and add a test that expects wrong proofs to fail

* Add circuit to check only merkleproofs-of-existence

With this, the merkletree_circuit module offers two different circuits:
- `MerkleProofCircuit`: allows to verify both proofs of existence and proofs
non-existence with the same circuit.
- `MerkleProofExistenceCircuit`: allows to verify proofs of existence only.

In this way, if only proofs of existence are needed,
`MerkleProofExistenceCircuit` should be used, which requires less amount
of constraints than `MerkleProofCircuit`.

* Code review

---------

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

* Towards Contains/NotContains in middleware and backend

* Fix build

* Adding error handling to deal with op compile introduce extra ops

* Incorporate Merkle proofs into MockMainPod

* Merkleproof verify circuit (#143)

* merkletree: add keypath circuit

* merkletree-circuit: implement proof of existence verification in-circuit

* parametrize max_depth at the tree circuit

* Constrain selectors in-circuit

* implement merketree nonexistence proof circuit, and add edgecase tests

* add non-existence proofs documentation in the mdbook, mv EMPTY->EMPTY_VALUE & NULL->EMPTY_HASH, dependency clean and public exposure methods

* review comments, some extra polishing and add a test that expects wrong proofs to fail

* Add circuit to check only merkleproofs-of-existence

With this, the merkletree_circuit module offers two different circuits:
- `MerkleProofCircuit`: allows to verify both proofs of existence and proofs
non-existence with the same circuit.
- `MerkleProofExistenceCircuit`: allows to verify proofs of existence only.

In this way, if only proofs of existence are needed,
`MerkleProofExistenceCircuit` should be used, which requires less amount
of constraints than `MerkleProofCircuit`.

* Code review

---------

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

* Towards Contains/NotContains in middleware and backend

* Frontend compound types -- allow one frontend operation to produce multiple middleware statements (in progress)

* Incorporate Merkle proofs into MockMainPod

* Incorporate Merkle proof op arg into frontend

* Compile one statement to many, in progress

* Fix remaining tests

* Minor clean-up

* Oops I did a bunch of work in the middle of a rebase, committing

* Incorporate Merkle proof op arg into frontend

* still working on frontend compound types, refactor compile() to output multiple statements

* Contains statements for frontend types: code compiles

* Tests pass

* Examples use front-end compound types

* Remove old Contains and NotContains from frontend

* Add nin to typos

* Code review

---------

Co-authored-by: arnaucube <git@arnaucube.com>
Co-authored-by: Ahmad <root@ahmadafuni.com>
2025-03-27 10:54:58 +10:00
arnaucube
d6033b7090
implement SignedPod (non-mock) using proof-based signatures (#160) 2025-03-25 22:17:14 +01:00
Ahmad Afuni
30f26a94ef
chore(backend): implement some circuit op logic (#165)
* Initial circuit op work

* Fix copy op

* Add more ops

* Fixes

* Code review
2025-03-26 03:40:23 +10:00
arnaucube
3b2860beeb
organize files & dirs (mostly backend structure) (#158) 2025-03-24 12:34:45 +01:00
b93187c9bb
Progress on the MainPod circuit (#159)
* feat: add SignedPodVerify test

* unify circuits style

* more clear sizes

* get operation_verify test working

* be consistent with names
2025-03-21 16:53:03 +01:00
Rob Knight
9afc43675d
Serialization of Signed and Main Pods (#128) 2025-03-21 13:42:16 +00:00
tideofwords
fee70af12b
Print debugging info if a pod does not verify (#141)
* Print debugging info if a pod does not verify

* Use logging for incorrect pods; add additional test
2025-03-20 10:36:26 -07:00
22db6ce4c6
MainPod circuit skeleton (#151)
* feat: add MainPod circuit skeleton

* feat: use ValueTarget in mt, verify SignedPod type

* wip

* feat: match structure with mock

* apply feedback from @arnaucube

* add 2 operations

* fix test compilation

* Add missing todo
2025-03-20 13:32:12 +01:00
2a2628ccbf
chore: simplify ToFields trait (#154) 2025-03-20 09:38:46 +01:00
arnaucube
b1689c5b37
Merkleproof verify circuit (#143)
* merkletree: add keypath circuit

* merkletree-circuit: implement proof of existence verification in-circuit

* parametrize max_depth at the tree circuit

* Constrain selectors in-circuit

* implement merketree nonexistence proof circuit, and add edgecase tests

* add non-existence proofs documentation in the mdbook, mv EMPTY->EMPTY_VALUE & NULL->EMPTY_HASH, dependency clean and public exposure methods

* review comments, some extra polishing and add a test that expects wrong proofs to fail

* Add circuit to check only merkleproofs-of-existence

With this, the merkletree_circuit module offers two different circuits:
- `MerkleProofCircuit`: allows to verify both proofs of existence and proofs
non-existence with the same circuit.
- `MerkleProofExistenceCircuit`: allows to verify proofs of existence only.

In this way, if only proofs of existence are needed,
`MerkleProofExistenceCircuit` should be used, which requires less amount
of constraints than `MerkleProofCircuit`.

* Code review

---------

Co-authored-by: Ahmad <root@ahmadafuni.com>
2025-03-18 19:34:01 +01:00
Ahmad Afuni
abce0af675
chore(frontend): expose literal method in MainPod builder + more op macros (#127)
* Expose literal builder method

* Add additional macros
2025-03-12 14:30:11 +01:00
arnaucube
12ec220de6
add initial counter setup (#130)
* add initial counter setup

We can extend it to also count the POD operations or other kind of logic
that we might want to count.


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

---------

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>
2025-03-12 14:29:55 +01:00
Ahmad Afuni
1b53e3b693
Replace leaf hash function (#129) 2025-03-12 00:00:27 +10:00
Ahmad Afuni
aa4d0a2670
Wrap up ETHDoS example (#121) 2025-03-11 00:03:39 +10:00
arnaucube
ef3bf26533
implement proof-based signatures using plonky2 proofs (#112)
* implement proof-based signatures using plonky2 proofs

* proof-based sigs: polish & document
2025-03-08 00:27:14 +10:00
tideofwords
42c1f0b0f7
Replace constant 4 with HASH_SIZE (#119)
* Replace constant 4 with HASH_SIZE

* cargo fmt

* More 4 change to HASH_SIZE

---------

Co-authored-by: Ahmad <root@ahmadafuni.com>
2025-03-08 00:10:09 +10:00
tideofwords
2864ef22d4
Implement more frontend ops (#111)
* middleware operation output statement?

* small refactor to op() on frontend

* Implement op()

* cargo fmt

* Clippy

* Code review

---------

Co-authored-by: Ahmad <root@ahmadafuni.com>
2025-03-07 21:15:01 +10:00
Ahmad Afuni
6627b46819
chore: add statement and KV metadata to frontend PODs (#117)
* Add statement and KV metadata to frontend PODs

* Code review
2025-03-07 14:35:25 +10:00
arnaucube
02ec7c311b
sync spec & code (#107)
* sync spec & code

* move primitives (merkletree) into the backend

* comment on the ops spec and link to issue #108

* typo

* fix github-ci mdbook-publish pages
2025-03-05 11:35:23 -08:00
Rob Knight
77f3f347e0
Fix i64 conversion (#110)
* Failing test

* Fixed implementation
2025-03-05 15:46:27 +01:00
Ahmad Afuni
9d60b0ec3a
Frontend work (#109) 2025-03-05 21:02:28 +10:00
tideofwords
7eeb595dc2
Backend support for custom statements and deductions (#105)
* Custom statements on backend

* Add support for custom statements and deductions on backend

* typo checker smh

* clean up match statement

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

* clean up more match statement

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

* delete done todo

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

---------

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>
2025-03-03 15:55:30 -08:00
tideofwords
5092149f9f
Check statement correctness on compile (#104)
* Check statement correctness on compile

* format

* Update src/frontend/mod.rs

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

* clean error handling

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

* clean coding style

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

* don't need to return ()

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

* Update github workflow for mdbook

* Resolve issue from merge: pass params to check()

---------

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>
2025-03-03 15:12:09 -08:00
arnaucube
c92839d897
limit the number of StatementTmpl in CustomPredicate: (#101)
* limit the number of StatementTmpl in CustomPredicate:

- add constructor method for CustomPredicate
- make size checks at the CustomPredicate creation, so that once instantiated we can assume that contains valid data

This resolves #79

* Update tests to use new interface

---------

Co-authored-by: Ahmad <root@ahmadafuni.com>
2025-03-03 14:38:51 +10:00
Ahmad Afuni
7373b959f6
feat: custom predicates in frontend statement and operation types (#97)
* Modify frontend statement type

* Modify frontend operation type

* Add exception to typos.toml
2025-02-28 22:03:44 +10:00