We adopted the following method.
let’s assume the values are under uint256-2 and the maximum number 2^256-1 = uint256(-1)
To merge
- check the value for the key= tx-hash is 0 (not uint256(-1)) in the User Asset Storage (SMT)
- update the value for the key=tx-hash
To purge
- check the value for the key= tx-hash is not uint256(-1) in the User Asset Storage (SMT)
- if a new purge makes the balance 0 from a number(>0), the balance value will be set to uint256(-1)
We cloud simply introduce the SMT consisting of hashes of merged state-diff to the client-side tree, but it made more constraints.
Only the thing we should do is to distinguish the initial value of 0 and a used (reduced) value of 0.