Commit graph

192 commits

Author SHA1 Message Date
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
tideofwords
c9f7427967
Organize docs: front and back end; custom predicates. (#96)
* Organize docs: front and back end; custom predicates.

* Whoops forgot to hit save before git commit last time -- delete stuff moved out of values.md

* Update book/src/values.md

---------

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>
2025-03-03 02:26:29 +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
Ahmad Afuni
af46ab7a8d
feat: implement custom op check (#92)
* Implement custom op check

* Example
2025-02-27 13:53:23 +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
tideofwords
d3bc892906
Aard custom (#49)
* Merge changes to docs

* Fix typo

* Correct SUMMARY so it compiles; update .gitignore

* Clean up statements.md

Make syntax and notation consistent with Rust source code.

* Fix statements for Merkle trees and compound types

* First draft of custom statements and small updates to signedpod.md

* Update book/src/merkletree.md

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

* merklestatements correct typo

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

* add todo for gadget ids

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

* Separate out custom statements version 1

* More details on custom statements version 1

* new file custom2

* Partial draft of version 2

* First draft of version 2 spec, it's kind of a mess

* Another version of the custom predicates spec

* Update book/src/custom2.md

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

* Simple example of deduction rule applied in circuit

* Implement Edu's comments on custom predicates

* Backend predicates must be defined in groups

* Add more examples

* Two diff statements using same constant

* Remove deprecated example

---------

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>
Co-authored-by: Eduard S. <eduardsanou@posteo.net>
2025-02-24 09:05:30 -08: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
Richard Liu
83a4f8969f
feat: add bool frontend type (#63) 2025-02-18 10:16:46 -08:00
2d4d31dce9
feat: add architecture doc (#73)
* feat: add architecture doc

* fix: typos
2025-02-18 16:31:39 +01:00
1b6e0c9395
feat: unify SignedPod and MainPod traits (#64)
* feat: unify SignedPod and MainPod traits

* fix: test

* feat: enable workflows after draft
2025-02-18 13:00:54 +01:00
Richard Liu
452bda8087
small fixes for various todos (#62)
* todos for frontend

* mock_main todos

* have OperationArgError bubble up

* revert frontend.rs
2025-02-17 10:54:37 -08:00
arnaucube
bb865a4fea
Implement Containers (Dictionary,Set,Array) on top of MerkleTree. And restructure the code. (#55)
* Implement Containers (Dictionary,Set,Array) on top of MerkleTree. And restructure the code.

- Reorganize the code grouping backends, middleware, frontend, (crypto) primitives.
- Add types Dictionary,Set,Array at the middleware layer, so that
  it can be used both by the backend and frontend. The Dictionary, Set,
  Array use the merkletree differently as specified at
f2575d1524/book/src/values.md (dictionary-array-set)
	- The containers introduce the trait Container, which has the
	  method 'cm()'. At the current version this uses a merkletree
	  under the hood, and the method 'cm' returns the merkle root.
- Ideally neither frontend nor backend use the MerkleTree type, and they
  use the wrappers {Dictionary,Set,Array}. Note that the current commit
  the MerkleTree is used at the mock-backend to check internal values, but
  not at the struct types.
- updated the spec's merkletree section updating the defined interface
- add github ci to run the tests

---------

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>
Co-authored-by: Eduard S. <eduardsanou@posteo.net>
2025-02-12 12:06:40 +01:00
f2575d1524
Add great boy example (#48)
* Progress towards mock MainPod verification

* add MockMainPod.pub_statements logic so that when originid==SELF it is replaced by self.id()

* Basic op checking for mock MainPOD

* More op checking

* wip

* feat: add great boy example

* feat: put examples under cfg(test)

---------

Co-authored-by: Ahmad <root@ahmadafuni.com>
Co-authored-by: arnaucube <git@arnaucube.com>
2025-02-11 13:54:26 +01:00
Ahmad Afuni
90e9782e62
feat: Basic verification logic for mock MainPOD (#43)
* Progress towards mock MainPod verification

* add MockMainPod.pub_statements logic so that when originid==SELF it is replaced by self.id()

* Basic op checking for mock MainPOD

* More op checking

* Add TODO notes

---------

Co-authored-by: arnaucube <git@arnaucube.com>
2025-02-10 19:07:41 +01:00
tideofwords
dc6b5553e8
Merge changes to docs (#41)
* Merge changes to docs

* Fix typo

* Correct SUMMARY so it compiles; update .gitignore

* Clean up statements.md

Make syntax and notation consistent with Rust source code.

* Fix statements for Merkle trees and compound types

* First draft of custom statements and small updates to signedpod.md

* Update book/src/merkletree.md

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

* merklestatements correct typo

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

* add todo for gadget ids

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

* Remove custom statements, will do on separate branch

* Restore Merkle examples and statements table

---------

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>
2025-02-10 19:06:45 +01:00
arnaucube
34a223ac76
add mdbook compilation check to CI (#45)
Reasoning: till now we're only compiling it when the changes land at the
`main` branch, which allows invalid changes to the mdbook to pass the PR
check. With the update at this commit we ensure that the new PRs pass
the mdbook compilation check.
2025-02-10 12:39:56 +01:00
arnaucube
5236b46214
Migrate fmt to use Display trait (#44)
Migrate fmt to use Display trait to simplify the usage of it.

Also with this, in the same snipped of code we can print types from
backend, middleware and frontend; which before needed to import the two
different `Printer` structs (frontend::Printer and mock_main::Printer).

Before:
```
let printer = mock_main::Printer { skip_none: false };
let mut w = io::stdout();
printer.fmt_mock_main_pod(&mut w, &pod).unwrap();

let printer = frontend::Printer { skip_none: false };
printer.fmt_main_pod_builder(&mut w, &pod_builder).unwrap();
```

now:
```
println!("{:#}", pod);
println!("{:#}", pod_builder);
```

And the equivalent to the old `skip_none: true`, now is done by just
using `println!("{}", pod);
2025-02-10 12:37:11 +01:00
Ahmad Afuni
f23a78dcb8
Add Plonky2 string hash definition (#32)
Co-authored-by: tideofwords <tideofwords@gmail.com>
2025-02-06 10:55:38 -08:00
arnaucube
ca1be65b85
compute MainPod.id from pub_statements; and introduce the trait ToFields (#35)
* compute MainPod.id from pub_statements; and introduce the trait `ToFields`

Compute MainPod.id from pub_statements hash; for it, introduce the trait
`ToFields` at the middleware and implement it for the Statement related
types.

* cleaner statements tofield iter

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

---------

Co-authored-by: Ahmad Afuni <root@ahmadafuni.com>
2025-02-06 11:35:57 +01:00
8945d7f8a1
Partial implementation of the MockMainPod (#33)
* wip

* wip

* feat: handle public statements

* fix: remove old backend module
2025-02-05 16:50:00 +01:00
arnaucube
e074d34078
Extend merkletree spec, init SignedPod section, add typos checker in CI (#31)
Extend merkletree spec, init SignedPod section, add typos checker in CI

- extend merkletree spec, converting old hand-drawn diagrams to drawio
  diagrams, and adding new diagrams (related: #6)
- init SignedPod section (related: #2)
- initial draft of the types dictionary, set, array (related: #26)
- add typos checker in CI (and correct the ones that were detected)

Note on drawio diagrams: each image file contains the metadata to edit the diagram in the draw.io website.
2025-02-05 16:37:16 +01:00
Ahmad Afuni
d85e1b7c78
docs: add native operation table (#22)
* Add native operation table

* Code review

* Add NewEntry footnote
2025-02-05 12:25:34 +01:00
085d5fff2c
feat: integrate mt in mock_sign (#23)
* feat: integrate mt in mock_sign

* fix: handle compile error

* fix: use PodClass::Main in MainPod origin
2025-02-05 11:24:35 +01:00
Ahmad Afuni
4d16647d10
docs: add native statement table (#21)
* Add native statement table

* Code review
2025-02-05 12:02:44 +10:00
3445bd98bd
feat: add middleware and signer traits (#18)
* feat: add middleware and signer traits

* wip

* wip

* feat: MainPod traits
2025-02-04 12:35:32 +01:00
Ahmad Afuni
caa91cb615
docs: add POD value types (#19)
* Add value type documentation

* Modify footnote
2025-02-04 21:33:43 +10:00
arnaucube
aafebfbcd5
add SignerPod.id computation (integrate kvs with MerkleTree) (#17)
- Add SignerPod.id computation (integrate kvs with MerkleTree).
- Updates frontend::SignerPod to be a wrapper on top of
  backend::SignerPod with extra metadata (a keymap between hashes and
  their strings).
- Get's rid of SignerPod.compile() since now the frontend::SignerPod
  uses the method `::new()` which internally calls
  backend::SignerPod::new which constructs the merkletree to use it's root
  as PodID.
2025-02-03 18:22:18 +01:00
arnaucube
5b455acbd6
add initial MerkleTree implementation (#13)
Add initial MerkleTree implementation, which is a wrapper on top of
Plonky2's MerkleTree, with the idea that the future iteration will
replace it by the MerkleTree specified at
https://0xparc.github.io/pod2/merkletree.html .
2025-02-03 18:03:45 +01:00
gubsheep
bf2fa090a3
change println to writeln (#14) 2025-02-03 23:08:13 +10:00
arnaucube
62a140569e
add initial spec of the merkletree (#10)
* add initial spec of the merkletree

* update gh workflow to work with the new book path

* rephrase non-inclusion section
2025-01-31 17:21:18 +01:00
ef3dd308e8
feat: move code here (#11) 2025-01-31 16:20:57 +01:00
arnaucube
5bb98e2645 add gh-pages action to autodeploy rendered site 2025-01-31 10:33:38 +01:00
arnaucube
f8cd1ed0b6
Merge pull request #9 from 0xPARC/edu
feat: add examples
2025-01-31 10:21:01 +01:00
3c6ccd7c31 feat: add examples 2025-01-30 20:39:10 +01:00
arnaucube
ceeddba2b5 init repo, add initial structure 2025-01-30 17:32:09 +01:00