Commit graph

532 commits

Author SHA1 Message Date
e78d5e4f4c add messages for prospective insertion asserts 2024-09-05 13:26:32 -06:00
94e1ef0aa3 feat(smt): implement generic prospective insertions
This commit adds a type, MutationSet, which represents a 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.

Additionally, as MutationSet is a generic type
which works on any type that implements SparseMerkleTree, but is
intended for public API use, the SparseMerkleTree trait and InnerNode
type have been made public so MutationSet can be used outside of this
crate.
2024-09-05 13:26:04 -06:00
c90b619c6e fix docstrings for generic prospective insertions commit 2024-09-05 13:04:44 -06:00
95a164fcf4 feat(smt): implement generic prospective insertions
This commit adds a type, MutationSet, which represents a 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.

Additionally, as MutationSet is a generic type
which works on any type that implements SparseMerkleTree, but is
intended for public API use, the SparseMerkleTree trait and InnerNode
type have been made public so MutationSet can be used outside of this
crate.
2024-09-05 13:04:20 -06:00
9ac8f2e9f7 add messages for prospective hash asserts 2024-09-05 13:01:55 -06:00
e430c3096e feat(smt): export get_value() in the trait 2024-09-05 13:01:42 -06:00
6f24007657 feat(smt): implement generic prospective insertions
This commit adds a type, MutationSet, which represents a 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.

Additionally, as MutationSet is a generic type
which works on any type that implements SparseMerkleTree, but is
intended for public API use, the SparseMerkleTree trait and InnerNode
type have been made public so MutationSet can be used outside of this
crate.
2024-09-05 13:01:42 -06:00
affbcf30ed 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.
2024-09-05 13:01:42 -06:00
89fe857ccf fix nostd build 2024-09-05 12:30:08 -06:00
862d995b11 feat(smt): implement generic prospective insertions
This commit adds a type, MutationSet, which represents a 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.

Additionally, as MutationSet is a generic type
which works on any type that implements SparseMerkleTree, but is
intended for public API use, the SparseMerkleTree trait and InnerNode
type have been made public so MutationSet can be used outside of this
crate.
2024-09-05 12:30:00 -06:00
6ae3536fc3 split the prospective hash and prospective insert tests 2024-09-04 17:57:37 -06:00
8f8ab4eef5 feat(smt): implement generic prospective insertions
This commit adds a type, MutationSet, which represents a 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.

Additionally, as MutationSet is a generic type
which works on any type that implements SparseMerkleTree, but is
intended for public API use, the SparseMerkleTree trait and InnerNode
type have been made public so MutationSet can be used outside of this
crate.
2024-09-04 17:36:46 -06:00
e7f53e8c04 give test_prospective_hash() a docstring 2024-09-04 16:55:10 -06:00
7e81a00291 feat(smt): export get_value() in the trait 2024-09-04 16:52:56 -06:00
4630093e94 WIP: feat(smt): implement generic prospective insertions
This commit adds a type, MutationSet, which represents a 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.

Additionally, as MutationSet is a generic type
which works on any type that implements SparseMerkleTree, but is
intended for public API use, the SparseMerkleTree trait and InnerNode
type have been made public so MutationSet can be used outside of this
crate.
2024-09-04 16:52:56 -06:00
1cea08c2ff 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.
2024-09-04 16:52:43 -06:00
e03ad4e2b1 give prospective leaf commit a real commit message 2024-09-04 16:42:19 -06:00
23f8077e05 WIP: feat(smt): implement generic prospective insertions
This commit adds a type, MutationSet, which represents a 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.

Additionally, as MutationSet is a generic type
which works on any type that implements SparseMerkleTree, but is
intended for public API use, the SparseMerkleTree trait and InnerNode
type have been made public so MutationSet can be used outside of this
crate.
2024-09-04 16:42:01 -06:00
8139cf3034 feat(smt): export get_value() in the trait 2024-09-04 16:42:01 -06:00
e05cb382b7 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.
2024-09-04 16:41:10 -06:00
a7f9b701ce fix docstring on get prospective leaf 2024-09-04 15:36:09 -06:00
a3f6f3c24f WIP: feat(smt): implement generic prospective insertions
This commit adds a type, MutationSet, which represents a 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.

Additionally, as MutationSet is a generic type
which works on any type that implements SparseMerkleTree, but is
intended for public API use, the SparseMerkleTree trait and InnerNode
type have been made public so MutationSet can be used outside of this
crate.
2024-09-04 15:30:21 -06:00
b99402258b feat(smt): export get_value() in the trait 2024-09-04 15:30:21 -06:00
aa9da0bcad feat(smt): impl constructing leaves that don't yet exist (WIP) 2024-09-04 15:30:21 -06:00
6e93028387 implement generic prospective insertions 2024-09-04 15:27:44 -06:00
2d9317ead1 WIP: feat(smt): implement generic prospective insertions
This commit adds a type, MutationSet, which represents a 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.

Additionally, as MutationSet is a generic type
which works on any type that implements SparseMerkleTree, but is
intended for public API use, the SparseMerkleTree trait and InnerNode
type have been made public so MutationSet can be used outside of this
crate.
2024-09-04 15:12:04 -06:00
32d96f0dce feat(smt): export get_value() in the trait 2024-09-03 19:54:00 -06:00
04ef7205d5 feat(smt): make leaf-emptiness knowable at the trait level 2024-09-03 19:54:00 -06:00
eb407cd8fc feat(smt): impl constructing leaves that don't yet exist (WIP) 2024-09-03 19:54:00 -06:00
d3ae0a25f6 that rebase had way more conflicts than it needed to 2024-08-29 18:26:49 -06:00
a02754d94f feat(smt): export get_value() in the trait 2024-08-29 18:25:45 -06:00
72662c7e09 feat(smt): make leaf-emptiness knowable at the trait level 2024-08-29 18:25:43 -06:00
e69f7b6973 feat(smt): impl constructing leaves that don't yet exist (WIP) 2024-08-29 18:18:32 -06:00
63068b165e about to give up on this branch lol 2024-08-29 17:56:53 -06:00
2573f050a3 feat(smt): implement root-checked insertion
This commit implements SparseMerkleTree::insert_ensure_root(), a version
of SparseMerkleTree::insert() that prevents modification of the tree if
the insert turns out to not result in the correct tree root (i.e., the
transaction is not valid).

This is an initial step towards issue 222.

As a logical next step, generalizing this to validation of inserting
multiple values at once will directly enable removing Merkle tree clones
in miden-node InnerState::apply_block().

For further work, as we generalize pre-validation for mutations we will
want a separate type to represent an arbitrary set of prospective
mutations on the Merkle tree and their validity, like the `ChangeSet`
type suggested in the issue.
2024-08-29 17:38:20 -06:00
42d7f6384c change hash pros to get pros as separate commit 2024-08-29 17:37:13 -06:00
77511e3a76 WIP: change hash pros to get pros 2024-08-29 17:28:50 -06:00
46bd03d329 add is_leaf_empty commit 2024-08-29 16:34:33 -06:00
4369743b63 feat(smt): export get_value() in the trait 2024-08-29 16:31:04 -06:00
c16b747a73 feat(smt): implement root-checked insertion
This commit implements SparseMerkleTree::insert_ensure_root(), a version
of SparseMerkleTree::insert() that prevents modification of the tree if
the insert turns out to not result in the correct tree root (i.e., the
transaction is not valid).

This is an initial step towards issue 222.

As a logical next step, generalizing this to validation of inserting
multiple values at once will directly enable removing Merkle tree clones
in miden-node InnerState::apply_block().

For further work, as we generalize pre-validation for mutations we will
want a separate type to represent an arbitrary set of prospective
mutations on the Merkle tree and their validity, like the `ChangeSet`
type suggested in the issue.
2024-08-29 16:31:04 -06:00
4f17c1deb1 feat(smt): make leaf-emptiness knowable at the trait level 2024-08-29 16:31:04 -06:00
9b9d2d3a42 reset back to public state 2024-08-29 14:26:06 -06:00
76ea4ed6cb cleaned up working state 2024-08-29 13:01:46 -06:00
411354fbec cleaned up working state 2024-08-29 13:01:41 -06:00
43f19f5933 MULTI INSERTION WORKING STATE 2024-08-28 17:21:00 -06:00
a86faf68b5 MULTI INSERTION WORKING STATE 2024-08-28 17:18:55 -06:00
032e14c0ca feat(smt): implement root-checked insertion
This commit implements SparseMerkleTree::insert_ensure_root(), a version
of SparseMerkleTree::insert() that prevents modification of the tree if
the insert turns out to not result in the correct tree root (i.e., the
transaction is not valid).

This is an initial step towards issue 222.

As a logical next step, generalizing this to validation of inserting
multiple values at once will directly enable removing Merkle tree clones
in miden-node InnerState::apply_block().

For further work, as we generalize pre-validation for mutations we will
want a separate type to represent an arbitrary set of prospective
mutations on the Merkle tree and their validity, like the `ChangeSet`
type suggested in the issue.
2024-08-27 17:37:56 -06:00
1cc9ef892f fix more typos 2024-08-27 17:36:35 -06:00
31da24fff3 feat(smt): implement root-checked insertion
This commit implements SparseMerkleTree::insert_ensure_root(), a version
of SparseMerkleTree::insert() that prevents modification of the tree if
the insert turns out to not result in the correct tree root (i.e., the
transaction is not valid).

This is an initial step towards issue 222.

As a logical next step, generalizing this to validation of inserting
multiple values at once will directly enable removing Merkle tree clones
in miden-node InnerState::apply_block().

For further work, as we generalize pre-validation for mutations we will
want a separate type to represent an arbitrary set of prospective
mutations on the Merkle tree and their validity, like the `ChangeSet`
type suggested in the issue.
2024-08-27 17:36:20 -06:00
2ae39fc36b tweak comment in hash_prospective_leaf 2024-08-27 16:59:31 -06:00