I don't quite understand your approach but I have another approach for this problem. Not sure if they are effectively the same.
I believe it's mathematically correct, but not sure about its computational efficiency
For every block, there will be a Merkle sum tree for the number of spent UTXO and new UTXO. For example, if we have 4 txs:
Tx1 (coinbase): 0 spent UTXO, 2 new UTXO
Tx2: 1 spent UTXO, 4 new UTXO
Tx3: 5 spent UTXO, 1 new UTXO
Tx4: 6 spent UTXO, 8 new UTXO
sum_hash_1 = hash(tx1_hash|0|2)
sum_hash_2 = hash(tx2_hash|1|4)
sum_hash_3 = hash(tx3_hash|5|1)
sum_hash_4 = hash(tx4_hash|6|8)
sum_hash_5 = hash(hash_1|hash_2|1|6)
sum_hash_6 = hash(hash_3|hash_4|11|9)
root_merkle_sum_tree = hash(hash_5|hash_6|12|15)
UTXO is presented as (txid|txoutindex|scriptPubkey|value|minimum_height_to_spend)
(For normal tx, minimum_height_to_spend is the block height. For coinbase tx, it is block height + 100)
Two UTXO Merkle roots are calculated:
1. All UTXO sorted alphanumerically (root_all_utxo)
2. Spent UTXO in this block, sorted alphanumerically (root_spent_utxo)
Any one of the following proofs is sufficient to invalidate an illegal UTXO commitment, and an illegal UTXO commitment will necessarily produce at least one of the following proofs. (In other words, these conditions are collectively exhaustive for an illegal UTXO commitment)
---------------
Proof of wrong UTXO order: Merkle path of 2 misplaced UTXO records.
---------------
Proof of incorrect # of UTXO in root_all_utxo: # of UTXO in the last block + # of new UTXO - # of spent UTXO != # of UTXO in this block
---------------
Proof of incorrect # of UTXO in root_spent_utxo: # of UTXO in root_spent_utxo != record in root_merkle_sum_tree
---------------
Spending of a UTXO not documented in root_spent_utxo:
- A transaction with its Merkle path to the root_merkle_sum_tree
- Merkle path of the 2 adjacent UTXOs in the root_spent_utxo, proving the lack of record
---------------
New UTXO not documented in root_all_utxo:
- A transaction with its Merkle path to the root_merkle_sum_tree
- Merkle path of the 2 adjacent UTXOs in the root_all_utxo, proving the lack of record
---------------
Proof of illegal deletion of an existing UTXO in root_all_utxo:
- Merkle path of the deleted UTXO in last block
- Merkle path of the 2 adjacent UTXOs in the root_all_utxo of this block, proving the UTXO is deleted
- Merkle path of the 2 adjacent UTXOs in the root_spent_utxo of this block, proving the lack of spending record of this UTXO
Explanation:
By 1, we show that a UTXO exists in the last block
By 2, we show that the UTXO is removed in this block
By 3, we show that the removal of this UTXO is not documented in root_spent_utxo
If the removal is indeed documented in root_spent_utxo, some other spent UTXO must not be documented, given that the number of UTXO in root_spent_utxo matches the record in root_merkle_sum_tree. In that case, we could just prove with "Removal of UTXO not documented in root_spent_utxo"
---------------
Proof of illegal addition of UTXO in root_all_utxo / Spent UTXO not removed from root_all_utxo:
This could be indirectly proved by the proofs mentioned. There will be either too many UTXO in root_all_utxo, or some existing UTXOs got illegally deleted, or some new UTXOs are not documented