A suggestion about updating the Merkle Tree by replacement instead of deletions & insertions #268
Replies: 3 comments
-
As a flow of thoughts when I was thinking that this approach could help tracing how certain amount of cryptocurrency got spent by putting them in the same Merkle subtree, I connected that thought to: I noticed that these r the different cases I have to deal with in my replacement algorithm.
3-Connecting this to Andrew Miller response about my idea
»»»The point is if it's bad to use the same public key, I don't think it's bad for the Merkle Tree branches structure, ie we can have an idea (predict how the tree will look like) from those days Merkle Trees when the same address were reused and the tree was BST indexed on the key |
Beta Was this translation helpful? Give feedback.
-
Yes the idea of doing additions and deletions at the same time has been floating around. While it can work, we're not looking to go in that direction at the moment as hashing is not the bottleneck, bandwidth is. In this picture, you'll notice that there's vertical stripes in many places. These are where the new leaves get placed. But as they are deleted, it gets replaced by a new leaf. This causes an increase in proof sizes and Tadge has detailed an accumulator design where we can avoid this problem. #249 (comment) While the design where additions and deletions happen at the same time would help a bit, hash savings would be limited and wouldn't help with the real bottleneck, the proof size. Maybe later down the road when proof sizes are less of a concern, we could visit this idea again but for now, we likely won't be heading this way. |
Beta Was this translation helpful? Give feedback.
-
Neglecting the effect on the proof size (which depends on the tree height)at least for now, I think replacement reduces the size/amount of "change" in proofs. When less branches r modified, less internal nodes change their concatenated hashes. This could be helpful, especially when u r caching some of them. |
Beta Was this translation helpful? Give feedback.
-
I hesitated in discussing my idea here in Utreexo, but those words from one of the authors of "Merkle Trees Optimized for Stateless Clients in Bitcoin" encouraged me to.
.
Replacing old UTXOS with new one in place: an idea/suggested complexity reduction"
.
This is a suggestion that, I think, will introduce a significant complexity reduction in the process of adding/removing UTXOS from the proofs Merkle Tree...
.
Intuition/ Rationale:
Since any transaction somehow follows the Energy Law from the point that SUM of inputs = SUM of outputs, a lot of unnecessary overhead could be avoided if deletions & insertions happened simultaneously in a replacement manner.
.
Summary:
When processing a transaction, replace the old TXOs that became input with the new ones; ie if they're the same number there will be no actual deletions/a and thus no tree swaps.. just modify the corresponding values& hashes along the proof path.
-If one old TXO led to more than one change the value of the old leaf node to be the root of a corresponding subtree of the new TXOs.
-Only if n1 inputs created n2 outputs where n1>n2 u will have to choose (n1-n2) leaves to delete according to some criteria/heuristics
-Then deletions will this way definitely happen much less often, and a suitable heuristic could be thought of later according to some data analysis of existing blocks.
.
Examples:
I traced some inputs and outputs in 2 consecutive blocks Block 1973321,1973322 from the site:
https://blockstream.info/testnet/block/000000000000001eedf8cd0e358a0ca6144e82f5c3da263769f7ad208b8e07ba
You will find that
57.64177548 tBTC=⟩
0.01322037 tBTC
Then in the next block
57.62838604 tBTC=⟩
57.61015944 tBTC
-So, in my method a subtree evolves in place of the original leaf that represented the UTXO 57.64177548 tBTC, and no other branch of the tree get modified.
.
-If u traced a number of blocks u'll find that the situation where the number of inputs n1 is larger than the number of outputs n2 (n1›n2) is a very rare event. Even if it is not, we still guaranteed to have less deletions
.
(More details & discussions
https://bitcointalk.org/index.php?topic=5334763.0)
.
I think it would be better to test this idea starting with a regular Merkle first to exclude the correlated effect of other enhancements, then with a Utreexo forest maybe, but I think with no cache at first?
Beta Was this translation helpful? Give feedback.
All reactions