Commit graph

165 commits

Author SHA1 Message Date
6670b94ba7 WIP: smt: implement root-checked insertion 2024-08-22 13:55:39 -06:00
1307e2c948 WIP: add and implement get_value() to Smt trait 2024-08-22 13:55:39 -06:00
4c19f364ca feat: impl hashing Merkle leaves that don't yet exist
This commit implements 'prospective leaf hashing' -- computing what the
hash of a sparse Merkle tree leaf *would* be for a key-value insertion
without actually performing that insertion.

For SimpleSmt, this is trivial, since the leaf hash and its payload are
the same.

For the full Smt, the new leaf payload (and thus, its hash) depend on
the existing payload in that leaf, making the prospective hash logic a
combination of the normal insertion logic and the normal hash logic. But
because we're only interested in the hash and not the intermediate
value, we can skip allocations and sorts for the payload itself.
2024-08-22 13:55:39 -06:00
Paul-Henry Kajfasz
8bf6ef890d
fmt 2024-08-21 14:04:23 +01:00
Paul-Henry Kajfasz
e2aeb25e01
Updated doc comments 2024-08-21 14:03:43 +01:00
Paul-Henry Kajfasz
790846cc73
Merge next 2024-08-21 09:29:39 +01:00
Bobbin Threadbare
a12e62ff22
feat: improve MMR api (#324) 2024-08-18 09:35:12 -07:00
Paul-Henry Kajfasz
ad0f472708
Updated Makefile and Readme 2024-08-16 15:07:27 -07:00
Bobbin Threadbare
dfdd5f722f
chore: fix lints 2024-08-06 16:52:46 -07:00
Al-Kindi-0
f967211b5a
feat: migrate to new Winterfell (#315) 2024-05-12 03:09:27 +08: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
552d90429b Remove TieredSmt (#277) 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
Bobbin Threadbare
61a0764a61 fix: peak index calculation in MmrProof 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
Bobbin Threadbare
5fcf98669d feat: add PartialMmr::from_parts() constructor 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
Augusto F. Hack
70e39e7b39 partialmmr: Method add with support for a single peak and tracking
fixes: #258
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
Augusto F. Hack
dae9de9068 docs: fix warnings 2024-02-14 11:52:40 -08:00
cristiantroy
260592f8e7 Fix: typos (#249)
* tests: fix typos
* full.rs: fix typo
* CONTRIBUTING: fix typo
2024-02-14 11:52:40 -08:00
Bobbin Threadbare
6b5db8a6db fix: clippy 2024-02-14 11:52:40 -08:00
Bobbin Threadbare
3ebee98b0f feat: add PartialMmr::is_tracked() 2024-02-14 11:52:40 -08:00
Bobbin Threadbare
ac7593a13c chore: update CI jobs 2024-02-14 11:52:40 -08:00
Bobbin Threadbare
004a3bc7a8 docs: update changelog and readme 2024-02-14 11:52:40 -08:00
Bobbin Threadbare
a0f533241f fix: bugfix in PartialMmr apply delta 2024-02-14 11:52:40 -08:00
Bobbin Threadbare
be1d631630 feat: add Clone derive to PartialMmr 2024-02-14 11:52:40 -08:00
Bobbin Threadbare
4d0d8d3058 refactor: return MmrPeaks from PartialMmr::peaks() 2024-02-14 11:52:40 -08:00
Bobbin Threadbare
9baddfd138 feat: implement inner_nodes() iterator for PartialMmr 2024-02-14 11:52:40 -08:00
Augusto F. Hack
7e13346e04 serde: for MerklePath, ValuePath, and RootPath 2024-02-14 11:52:40 -08:00
Philippe Laferrière
9a18ed6749 Implement SimpleSmt::set_subtree (#232)
* recompute_nodes_from_indeX_to_root

* MerkleError variant

* set_subtree

* test_simplesmt_set_subtree

* test_simplesmt_set_subtree_entire_tree

* test

* set_subtree: return root
2024-02-14 11:52:40 -08:00
Augusto F. Hack
df2650eb1f bugfix: TSMT failed to verify empty word for depth 64.
When a prefix is pushed to the depth 64, the entry list includes only
the values different than ZERO. This is required, since each block
represents a 2^192 values.

The bug was in the proof membership code, that failed to handle the case
of a key that was not in the list, because the depth is 64 and the value
was not set.
2024-02-14 11:52:40 -08:00
Philippe Laferrière
18310a89f0 MmrPeaks::hash_peaks() returns Digest (#230) 2024-02-14 11:52:40 -08:00
Philippe Laferrière
d719cc2663 Remove ExactSizeIterator constraint from SimpleSmt::with_leaves() (#228)
* Change InvalidNumEntries error

* max computation

* remove length check

* remove ExactSizeIterator constraint

* fix InvalidNumEntries error condition

* 2_usize
2024-02-14 11:52:40 -08:00
Augusto F. Hack
fa475d1929 simplesmt: simplify duplicate check 2024-02-14 11:52:40 -08:00
Philippe Laferrière
25b8cb64ba Introduce SimpleSmt::with_contiguous_leaves() (#227)
* with_contiguous_leaves

* test
2024-02-14 11:52:40 -08:00
Augusto F. Hack
389fcb03c2 simplesmt: bugfix, index must be validated before modifying the tree 2024-02-14 11:52:40 -08:00
Augusto F. Hack
9f95582654 mmr: add into_parts for the peaks 2024-02-14 11:52:40 -08:00