RGB-WG / rgb

RGB smart contracts: command-line tool & wallet runtime library for desktop and mobile integration
https://rgb.tech
Apache License 2.0
123 stars 33 forks source link

wrong balance after witness transfer #212

Open nicbus opened 2 weeks ago

nicbus commented 2 weeks ago

Trying the usual transfer series via rgb-sandbox, using rgb-wallet from master (beta 6 + PR #211 for human-readable values), I run into an issue. After a witness transfer, the balance for the receiving wallet is incorrect.

Here are the steps to reproduce the problem, using 2 opret wallets:

The transfer completes successfully, accept included. Here are the wallets' outpoints and contract states after the transfer:

It looks like wallet 1 doesn't see the UTXO from the transfer's tx (txid: 5f8491a78476b278bb981b2545b890e73847436558a40b69fe9957c2a2f5886b) and thus sees no owned allocations, leading to a balance of 0, instead of the expected 100. Printing the address used by the invoice I get bcrt1qc7huwmgyuq6snsku0papx7grafde9fldhg73rz, which does not appear in the generated PSBT.

Here are the wallets' data dirs: wallet_data.tar.gz

dr-orlovsky commented 2 weeks ago

So basically it doesn't recognize tweak applied to the first tapret output, which is owned by wallet 1...

Well, it can't be recognized by the receiver since it knows nothing about this tweak - it was created by the sender. Thus, the sender had to use the first output for the change, not the second one.

How you specifically used APIs in constructing this transaction on the wallet 0 side?

It seems to me I have somehow to add safety to the API so it should be impossible to construct tapret PSBT where the first output is not a change...

nicbus commented 2 weeks ago

After patching rgb-std to master for https://github.com/RGB-WG/rgb-std/issues/220 I have re-tested for this issue as well and it gone, too.

I don't think it had to do with tweaks, as both wallets are opret in this case and I use no special construction (just the regular CLI invoice/transfer commands). Still, I fail to see how switching to rgb-std master branch should have fixed this problem.

I'll leave this open for now so we can further discuss if needed, but the original problem is solved.

dr-orlovsky commented 2 weeks ago

Sorry, I have somehow read opret as tapret. Indeed, this is very strange...