Commit graph

30 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Ahmad Afuni
aa4d0a2670
Wrap up ETHDoS example (#121) 2025-03-11 00:03:39 +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
Ahmad Afuni
9d60b0ec3a
Frontend work (#109) 2025-03-05 21:02:28 +10: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
Rob Knight
bcfad307e7
ZuKYC example: get the sanctions list from a SignedPod (#98)
* Get the sanctions list from a SignedPod

* Formatting
2025-02-28 12:15:18 +01:00
tideofwords
a2bcb501e8
Improve formatting of SignedPods: show keys as strings (#95)
* Improve formatting of SignedPods: show keys as strings

* Cargo fmt
2025-02-27 19:23:23 +01:00
arnaucube
423605f867
Featurize middleware types that are actually defined by the backend (#94)
At the middleware we were defining some types that actually are dependant on the
backend no matter how we define them in the middleware.

For example, we were hardcoding the `Hash` and `Value` types and their related
behaviour (eg. `.to_fields()`) to be based on the length of 4 field elements,
but that's not a choice of the middleware, and in fact this is determined by the
backend itself. On the same time, those types and related methods do not belong
to the backend, since conceptually they are part of the middleware reasoning.

The intention of this PR is not to prematurely abstract the library, but to
avoid inconsistencies where a type or parameter is defined in the middleware to
have certain carachteristic and later in the backend it gets used differently.
The idea is that those types and parameters (eg. lengths) have a single source
of truth in the code; and in the case of the "base types" (hash, value, etc)
this is determined by the backend being used under the hood, not by a choice of
the middleware parameters.

The idea with this approach, is that the frontend & middleware should not need
to import the proving library used by the backend (eg. plonky2, plonky3, etc).

As mentioned earlier, the `Hash` and `Value` types are types belonging at the
middleware, and is the middleware who reasons about them, but depending on the
backend being used, the `Hash` and `Value` types will have different sizes. So
it's the backend being used who actually defines their nature under the hood.
For example with a plonky2 backend, these types will have a length of 4 field
elements, whereas with a plonky3 backend they will have a length of 8 field
eleements.

Note that his approach does not introduce new traits or abstract code, just
makes use of rust features to define 'base types' that are being used in the
middleware.
2025-02-27 14:15:31 +01:00
tideofwords
a37b96ab4f
Serialize and hash custom predicates (#90)
* Print pods from SignedPodBuilder

* Add additional print to test printing SignedPodBuilder

* Mock-prove and print MainPod

* Implement ToFields for custom predicates and dependencies

* Test: print serialization of a recursive batch

* Rearrange serialization of CustomPredicate so args_len is always in the same position

* Serialize predicates with first entry nonzero to avoid collision with padding

* Off by one error in ethdos test BatchSelf(2)

* cargo fmt

* not a typo

* Typos, trying again
2025-02-26 20:28:27 +01:00
Ahmad Afuni
05c21ebe6a
feat: partial incorporation of custom predicates into statement and operation structures in middleware (#84)
* Add custom predicates to middleware Statement enum

* Add custom op enum variant and wildcard matching procedures
2025-02-25 15:44:27 +01:00
arnaucube
538353a701
Frontend: simplify custom predicates interfaces (#83)
* add comments detailing logic, migrate middleware::custom::tests to frontend::custom

* simplify custom predicate's frontend interfaces, making it less verbose to define Statement Template arguments

The main idea is that when defining the arguments at a statement
template, it can be done from 3 different inputs:
i. `(&str, literal)`: this is to set a POD and a field, ie. `(POD, literal("field")`)
ii. `(&str, &str)`: this is to define a origin-key wildcard pair, ie. `(src_origin, src_dest)`
iii. `Value`: this is to define a literal value, ie. `0`
2025-02-25 14:15:08 +10:00
arnaucube
c101d94530
implement the specified sparse merkletree (#82)
* wip

* prototype custom predicates 1b

* feat: implement custom pred recursion

* files reorg, add github CI for rustfmt checks

* start sparsemerkletree. impl add_leaf method, initial Leaf & Intermediate types with methods

* mt: add hash computation of all the nodes in the tree, add method to print the tree to visualize it as a graphviz

* mt: add  (till the leaf) method which is used by get,contains,prove methods

* mt: add verify (of inclusion) method

* mt: update 'down' method to reuse siblings, update get,contains,prove methods (the three use 'down' under the hood)

* Add nonexistence proofs and iterator

* Add iterator test

* migrate usage of old merkletree to the new merkletree impl in POD2 code

---------

Co-authored-by: Eduard S. <eduardsanou@posteo.net>
Co-authored-by: Ahmad <root@ahmadafuni.com>
2025-02-21 11:13:58 +10:00
2e9719a1ca
Prototype custom predicates (#74)
* wip

* prototype custom predicates 1b

* feat: implement custom pred recursion

* files reorg, add github CI for rustfmt checks

---------

Co-authored-by: arnaucube <git@arnaucube.com>
2025-02-21 10:55:36 +10:00
Ahmad Afuni
c2d23b0b1b
chore: enums for statement and op types (#69)
* Experiment with statement & op enums

* Clean-up & fixes

* More clean-up

* Add argument length checks

* More clean-up

* Place statement and operation logic in submodules
2025-02-20 10:08:29 +01:00