Commit graph

554 commits

Author SHA1 Message Date
2415173510 change mutationset commit to use impl IntoIterator 2024-09-09 17:11:17 -06:00
d182138844 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.
2024-09-09 17:08:56 -06:00
1554eba3ee call out construct_prospective_leaf invariant 2024-09-05 15:39:24 -06:00
4dc276a1d2 feat(smt): export get_value() in the trait 2024-09-05 15:39:05 -06:00
f0eaf046e2 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 15:39:05 -06:00
e7c36fd4fc 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 15:39:05 -06:00
d8da407d4a rename get_prospective_leaf -> construct_prospective_leaf 2024-09-05 15:26:24 -06:00
394b8db006 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 15:23:30 -06:00
de19e0e052 feat(smt): export get_value() in the trait 2024-09-05 15:23:14 -06:00
ca3c79e818 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 15:23:14 -06:00
d3731d13d9 fix link in SimpleSmt::mutate() 2024-09-05 15:12:30 -06:00
534a32ce0f 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 15:12:20 -06:00
b01814ac27 clarify docs on mutate() 2024-09-05 15:07:23 -06:00
84aed72205 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 15:07:06 -06:00
5332b49bbb rustfmt 2024-09-05 14:13:45 -06:00
965c3f3c16 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 14:13:35 -06:00
1410ee4afa add docs to CompletedMutationSet's fields 2024-09-05 14:07:33 -06:00
d7f50821f1 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 14:07:20 -06:00
63a4b50837 tweak comments in insertion commit 2024-09-05 13:38:02 -06:00
f7ed4881d6 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:37:46 -06:00
cb7bcfdd65 rename DoneMutationSet -> CompletedMutationSet 2024-09-05 13:37:30 -06:00
597968e6c5 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:37:19 -06:00
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