0(Zero) UTXOs bug

Hey @Support,

For a while, I couldn’t consolidate one of my accounts. I was getting an error like “something is not quite right”. My wallet was getting slower. Finally, I’ve found the bug. The bug is in both the client side and server side. If the value of the first 30 UTXOs of an account is zero, the total UTXO value becomes 0. At that point, the bug starts. Consolidate feature of the app does not allow zero total and becomes unsuccessful. Using go-incognito-sdk, I canceled those zero checks at the client side but this time, the server side (full node) raises an error since it has some checks too. Modifying the server’s code and syncing the chain would be costly for me. So, I applied the workaround below in calculateOutputCoinsByMinValue() of https://github.com/incognitochain/go-incognito-sdk/blob/master/rpcserver/rpcservice/defragmentservice.go file (please follow the pass variable) and this new code does not allow zero total. However, as you may guess, it does not solve the problem if all remaining UTXO values are zero. FYI.

func (txService TxService) calculateOutputCoinsByMinValue(outCoins []*privacy.OutputCoin, maxVal uint64, maxDefragmentQuantityTemp int) ([]*privacy.OutputCoin, uint64) {
        outCoinsTmp := make([]*privacy.OutputCoin, 0)
        amount := uint64(0)
       // Abduraman: pass variable newly introduced
        pass := true
        for _, outCoin := range outCoins {
                if outCoin.CoinDetails.GetValue() <= maxVal && (pass ||  outCoin.CoinDetails.GetValue() > 0) {
                        fmt.Println(outCoin.CoinDetails.GetValue())

                        outCoinsTmp = append(outCoinsTmp, outCoin)
                        amount += outCoin.CoinDetails.GetValue()

                        if len(outCoinsTmp) == maxDefragmentQuantityTemp - 1 && amount == 0 {
                                pass = false
                        }

                        if len(outCoinsTmp) >= maxDefragmentQuantityTemp {
                                break
                        }
                }
        }
        return outCoinsTmp, amount
}
3 Likes

Hey @abduraman Thanks for bringing this up, let me pass this down and someone will get back to you shortly.

2 Likes

I hope @Chucky, I hope :joy:

1 Like

Thanks, @abduraman helps us found this issue.

You met this issue because there were many zero uxtos (value = 0) in your account.
When defragmenting utxos with our released app, we get the first 30 utxos that have the smallest value to create the defragment transaction with the network fee. But unfortunately, the total value of the chosen utxos is zero so it isn’t enough for paying the network fee. Therefore, Incognito chain rejected your transaction.
We will fix this issue in the next release app soon. Thanks again.

5 Likes

Hey @0xkraken

There are two more bugs on this issue.

1- If the last utxo of PRV coin is zero, that account cannot initiate any transaction (at least trade transaction for my case) since {‘Id’: 1, ‘Result’: None, ‘Error’: {‘Code’: -1, ‘Message’: ‘Unexpected error’, ‘StackTrace’: '-1: -1016: not enough coin for native fee\nReject invalid fee …} error is raised.

2- If the last utxo of PRV coin (maybe same for others too) is zero, PRV balance of that account returns 0. To fix this, I had to defrag the account many times.

Probably, these two are related. Btw, why are these “zero” utxos created? Cannot be prevented? or how can I avoid creating zero utxos?

Edit: I’m not sure about the bugs. I need to study a little bit on utxo mechanism. That’s why I crossed them out. However, my questions are still valid :slight_smile:

1 Like

Hey @0xkraken,

Is there any progress on fixing this bug? And I think you missed my questions :slight_smile:

Thanks.

Hah, I think Hien is being busy with some shopping and leave Abduraman all alone :joy:
Anw, I pinged her for you. She will pop up soon.

2 Likes

Hi @abduraman,
Sorry because I missed your question. We are fixing this issue. And I’ll update the process later.
About “zero” utxos, they are maybe created when someone sent you output coins with zero amount. Because our transactions are privacy (hiding the value of output coins), so we can’t recognize “zero” utxos to reject them.
In privacy v2, we will try to prevent creating “zero” utxos (if possible).

2 Likes

Hi @0xkraken,

I think I’ve found why these zero utxos are created: Refunded trades. When a trade is refunded, Incognito Chain creates 2 transactions: one for the sent amount, one for the trading fee. Since I usually prefer “zero trading fee”, if my trade request is rejected, the zero amount created from the refunded trade returns to my account, and a new zero utxo is created. Am I right?

Maybe preventing all zero utxos are not possible but I think these meaningless transactions can be prevented in the validators. Moreover, this will reduce the network traffic.

1 Like

Thanks, @abduraman.
Your idea is totally right. We also accidentally found this error a few days ago. We have been fixing it and will deploy it on mainnet soon. And the fixing will prevent creating “zero” utxos when trading.
Thanks again.

3 Likes

Hi @Support @0xkraken,

This is not a bug for the consolidation feature anymore. However, I sometimes see zero-value UTXOs when I list utxos of a token. What is the reason for zero-valued utxos?

Btw, I can send an amount of zero value to someone via RPC. So these txs also create zero-valued utxos. However, this is not the case for what I wrote in the previous paragraph.

Thanks.