Commit graph

31 commits

Author SHA1 Message Date
polydez
7ee6d7fb93
feat: add support for hashmaps in Smt and SimpleSmt (#363) 2025-01-02 10:23:12 -08:00
Bobbin Threadbare
d470a5087b
chore: fix lints 2024-12-26 23:12:49 -08:00
Bobbin Threadbare
43b2954d60
Merge branch 'main' into next 2024-12-26 23:10:26 -08:00
polydez
589839fef1
feat: reverse mutations generation, mutations serialization (#355)
* feat: revert mutations generation, mutations serialization
* tests: check both `apply_mutations` and `apply_mutations_with_reversion`
* feat: add `num_leaves` method for `Smt`
* refactor: improve ad-hoc benchmarks
* chore: update crate version to v0.13.1
2024-12-26 18:16:38 -08:00
Bobbin Threadbare
8db71b66d9
chore: fix typo 2024-12-22 00:25:58 -08:00
crStiv
1444bbc0f2
fix: typos of different importance (#359) 2024-12-16 10:27:51 -08:00
b151773b0d
feat: implement concurrent Smt construction (#341)
* merkle: add parent() helper function on NodeIndex
* smt: add pairs_to_leaf() to trait
* smt: add sorted_pairs_to_leaves() and test for it
* smt: implement single subtree-8 hashing, w/ benchmarks & tests

This will be composed into depth-8-subtree-based computation of entire
sparse Merkle trees.

* merkle: add a benchmark for constructing 256-balanced trees

This is intended for comparison with the benchmarks from the previous
commit. This benchmark represents the theoretical perfect-efficiency
performance we could possibly (but impractically) get for computing
depth-8 sparse Merkle subtrees.

* smt: test that SparseMerkleTree::build_subtree() is composable

* smt: test that subtree logic can correctly construct an entire tree

This commit ensures that `SparseMerkleTree::build_subtree()` can
correctly compose into building an entire sparse Merkle tree, without
yet getting into potential complications concurrency introduces.

* smt: implement test for basic parallelized subtree computation w/ rayon

Building on the previous commit, this commit implements a test proving
that `SparseMerkleTree::build_subtree()` can be composed into itself not
just concurrently, but in parallel, without issue.

* smt: add from_raw_parts() to trait interface

This commit adds a new required method to the SparseMerkleTree trait,
to allow generic construction from pre-computed parts.

This will be used to add a generic version of `with_entries()` in a
later commit.

* smt: add parallel constructors to Smt and SimpleSmt

What the previous few commits have been leading up to: SparseMerkleTree
now has a function to construct the tree from existing data in parallel.
This is significantly faster than the singlethreaded equivalent.
Benchmarks incoming!

---------

Co-authored-by: krushimir <krushimir@reilabs.co>
Co-authored-by: krushimir <kresimir.grofelnik@reilabs.io>
2024-12-04 10:54:41 -08:00
Philipp Gackstatter
a27f9ad828
refactor: use thiserror to derive errors and update error messages (#344) 2024-11-21 15:52:20 -08:00
Bobbin Threadbare
689cc93ed1
chore: update crate version to v0.11.0 and set MSRV to 1.82 2024-10-17 23:16:41 -07:00
Bobbin Threadbare
7970d3a736
Merge branch 'main' into next 2024-10-17 20:53:09 -07:00
Andrey Khmuro
940cc04670
feat: add Smt::is_empty (#337) 2024-10-17 14:27:50 -07:00
Philipp Gackstatter
8adc0ab418
feat: implement get_size_hint for Smt (#331) 2024-09-26 09:13:50 -07:00
Qyriad
ae807a47ae
feat: implement transactional Smt insertion (#327)
* feat(smt): impl constructing leaves that don't yet exist

This commit implements 'prospective leaf construction' -- computing
sparse Merkle tree leaves for a key-value insertion without actually
performing that insertion.

For SimpleSmt, this is trivial, since the leaf type is simply the value
being inserted.

For the full Smt, the new leaf payload depends on the existing payload
in that leaf. Since almost all leaves are very small, we can just clone
the leaf and modify a copy.

This will allow us to perform more general prospective changes on Merkle
trees.

* feat(smt): export get_value() in the trait

* feat(smt): implement generic prospective insertions

This commit adds two methods to SparseMerkleTree: compute_mutations()
and apply_mutations(), which respectively create and consume a new
MutationSet type. This type represents as set of changes to a
SparseMerkleTree that haven't happened yet, and can be queried on to
ensure a set of insertions result in the correct tree root before
finalizing and committing the mutation.

This is a direct step towards issue 222, and will directly enable
removing Merkle tree clones in miden-node InnerState::apply_block().

As part of this change, SparseMerkleTree now requires its Key to be Ord
and its Leaf to be Clone (both bounds which were already met by existing
implementations). The Ord bound could instead be changed to Eq + Hash,
if MutationSet were changed to use a HashMap instead of a BTreeMap.

* chore(smt): refactor empty node construction to helper function
2024-09-11 16:49:57 -07:00
Paul-Henry Kajfasz
ad0f472708
Updated Makefile and Readme 2024-08-16 15:07:27 -07:00
Augusto Hack
c0743adac9
Rpo256: Add RpoDigest conversions (#311) 2024-05-12 03:09:21 +08:00
Dominik Schmid
2a0ae70645 feature: adding serialization to the SMT (#304) 2024-04-21 01:14:18 -07:00
Bobbin Threadbare
4bf087daf8
fix: decrement leaf count in simple SMT when inserting empty value (#303) 2024-04-02 13:01:00 -07:00
polydez
b4dc373925
feat: add leaf count to SimpleSmt (#302) 2024-04-02 12:07:00 -07:00
Paul Schoenfelder
999a64fca6 chore: handle deprecations in winterfell 0.8.3 release 2024-03-17 16:18:23 -04:00
Augusto Hack
dbab0e9aa9
fix: clippy warnings (#280) 2024-02-21 20:55:02 -08:00
Andrey Khmuro
cd4525c7ad refactor: update repo to be compatible with Winterfell 0.8 (#275) 2024-02-14 11:52:40 -08:00
Philippe Laferrière
119c7e2b6d SmtProof: add accessors (#276)
* add accessors

* fmt

* comments
2024-02-14 11:52:40 -08:00
Philippe Laferrière
45e7e78118 Clone (#274) 2024-02-14 11:52:40 -08:00
Philippe Laferrière
a9475b2a2d reexport (#273) 2024-02-14 11:52:40 -08:00
Philippe Laferrière
e55b3ed2ce Introduce SmtProof (#270)
* add conversion for `SmtLeaf`

* introduce `SmtProof` scaffolding

* implement `verify_membership()`

* SmtLeaf: knows its index

* `SmtLeaf::index`

* `SmtLeaf::get_value()` returns an Option

* fix `verify_membership()`

* impl `SmtProof::get`

* impl `into_parts()`

* `SmtProof::compute_root`

* use `SmtProof` in `Smt::open`

* `SmtLeaf` constructors

* Vec

* impl `Error` for `SmtLeafError`

* fix std Error

* move Word/Digest conversions to LeafIndex

* `SmtProof::new()` returns an error

* `SparseMerkleTree::path_and_leaf_to_opening`

* `SmtLeaf`: serializable/deserializable

* `SmtProof`: serializable/deserializable

* add tests for SmtLeaf serialization

* move `SmtLeaf` to submodule

* use constructors internally

* fix docs

* Add `Vec`

* add `Vec` to tests

* no_std use statements

* fmt

* `Errors`: make heading

* use `SMT_DEPTH`

* SmtLeaf single case: check leaf index

* Multiple case: check consistency with leaf index

* use `pub(super)` instead of `pub(crate)`

* use `pub(super)`

* `SmtLeaf`: add `num_entries()` accessor

* Fix `SmtLeaf` serialization

* improve leaf serialization tests
2024-02-14 11:52:40 -08:00
Philippe Laferrière
3d71a9b59b Smt: remove inner nodes when removing value (#269) 2024-02-14 11:52:40 -08:00
Philippe Laferrière
da12fd258a Add missing methods to Smt (#268) 2024-02-14 11:52:40 -08:00
Philippe Laferrière
1cdd3dbbfa Add methods to Smt necessary for VM tests (#264)
* Smt::inner_nodes

* Add conversion Smt -> MerkleStore

* add docstring to `Smt`

* add to docstring

* fmt

* add `leaves()` method to `Smt`

* add `kv_pairs` functions

* rewrite `into_elements()` in terms of `into_kv_pairs()`

* change docstring
2024-02-14 11:52:40 -08:00
Philippe Laferrière
5596db7868 Implement Smt struct (replacement to TieredSmt) (#254) 2024-02-14 11:52:40 -08:00
Bobbin Threadbare
a933ff2fa0 refactor: remove obsolete traits 2024-02-14 11:52:40 -08:00
Philippe Laferrière
8ea37904e3 Introduce SparseMerkleTree trait (#245) 2024-02-14 11:52:40 -08:00