Commit graph

520 commits

Author SHA1 Message Date
e7f53e8c04 give test_prospective_hash() a docstring 2024-09-04 16:55:10 -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
7e81a00291 feat(smt): export get_value() in the trait 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
731afe30ec feat(smt): impl hashing 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. Since almost all leaves are very
small, we can just clone the leaf and modify a copy.

Future work could optimize the uncommon SmtLeaf::Multiple case and
avoid a heap clone by combining the normal insertion logic and the
normal hash logic without an intermediate leaf value.
2024-08-27 16:59:15 -06:00
119bb80aac feat(smt): export get_value() in the trait 2024-08-27 16:59:15 -06:00
da2856af6c 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 16:59:15 -06:00
afe32aa444 the parent node can be handled not specially 2024-08-27 16:02:40 -06:00
f471ee4086 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 16:01:41 -06:00
1402b8dcf7 leaf cloning is acceptable! 2024-08-27 14:32:43 -06:00
2696e4884c feat(smt): export get_value() in the trait 2024-08-27 14:27:39 -06:00
113832d6a4 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 14:27:39 -06:00
a00a3c3974 feat(smt): impl hashing 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. Since almost all leaves are very
small, we can just clone the leaf and modify a copy.

Future work could optimize the uncommon SmtLeaf::Multiple case and
avoid a heap clone by combining the normal insertion logic and the
normal hash logic without an intermediate leaf value.
2024-08-27 14:27:39 -06:00
78e08626fb fixup SimpleSmt get_value per review 2024-08-27 14:10:43 -06:00
52c35b12c3 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 14:10:27 -06:00
448e59884f feat(smt): export get_value() in the trait 2024-08-27 14:10:27 -06:00