add tapret tweak only when necessary #158
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've found a bug while doing transfers between an opret wallet (using rgb-lib) and a tapret wallet (using rgb-wallet). In detail I've:
The second transfer will have in input an opret seal and will define 2 seals, one opret (for the receiver) and one tapret (for the RGB change), therefore it will need to create an opret anchor.
This transfer fails (when calling the
pay
method) with the errorCompletion(TapretKey(NoCommitment))
.Investigating this, I've noticed that the call to
psbt.dbc_output::<TapretProof>()
returns an p2tr output and currently it's used to decide if a tapret tweak needs to be added. But when it tries to extract the tapret commitment from that output (let tapret_commitment = output.tapret_commitment()?;
) it fails because it's not there (since the call torgb_commit
created just an opret commitment). I think the issue is that the call todbc_output
is not enough to decide whether there is a tapret commitment that needs a tapret tweak to be added, in this case for example the method is seeing the p2tr output for the bitcoin change.Therefore with this fix I'm protecting that code with an extra check, inspecting the
AnchorSet
of theFascia
to see if there's a tapret anchor. As an alternative fix I think thergb_commit
method could return theCloseMethodSet
it used and then protect the addition of the tapret tweak callinghas_tapret_first
.