Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provable asset burning #477

Merged
merged 10 commits into from
Sep 19, 2023
Merged

Provable asset burning #477

merged 10 commits into from
Sep 19, 2023

Conversation

guggero
Copy link
Member

@guggero guggero commented Aug 30, 2023

Fixes #24.

Depends on #482.

Still work in progress, main things missing are:

  • More unit tests
  • CLI command tapcli assets burn
  • Integration tests with 4 test cases:
    • Burn all coins in a commitment (expect error because of edge case)
    • Burn all assets of one ID while there are other (passive) assets (=> expect root asset for burn)
    • Burn some assets, get some change back (=> expect split asset for burn)
    • Burn assets from multiple inputs

rpcserver.go Outdated

// If there is only a single output, it means that we are attempting to
// burn all the assets that were selected and that there are no passive
// assets either. This would mean we'd create a BTC level output with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be the same as the tombstone scenario? With the only difference being this new burn NUMs key is used instead of the existing burn/nums key?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or it's even just a send as "normal", with no need for an anchor at all, as it looks sort of like UTXO consolidation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, true. But I guess that way we'd end up sending 1k sats to a BTC output that can't be spent anymore (at least not with the current RPCs). I can remove that restriction if we want and create an issue that we'll eventually need a "sweep BTC from outputs with empty commitments/tombstones/burns".

@guggero guggero linked an issue Aug 31, 2023 that may be closed by this pull request
@guggero guggero self-assigned this Aug 31, 2023
@guggero guggero force-pushed the provable-asset-burning branch from 2070c37 to a735502 Compare September 1, 2023 17:11
@guggero guggero force-pushed the provable-asset-burning branch from a735502 to 8424ea5 Compare September 4, 2023 14:20
@guggero guggero marked this pull request as ready for review September 4, 2023 14:20
@guggero guggero requested review from Roasbeef and jharveyb September 4, 2023 14:20
@guggero
Copy link
Member Author

guggero commented Sep 4, 2023

Addressed all comments and fixed all TODOs. This is ready for full review.

@guggero guggero force-pushed the provable-asset-burning branch 4 times, most recently from 43eb682 to b9c7662 Compare September 8, 2023 14:45
@lightninglabs-deploy
Copy link

@Roasbeef: review reminder
@jharveyb: review reminder

@Roasbeef
Copy link
Member

Pushed up a rebased version.

@Roasbeef Roasbeef force-pushed the provable-asset-burning branch from b9c7662 to 49f7cda Compare September 13, 2023 02:19
Amount: 0,
Type: tappsbt.TypeSplitRoot,
AnchorOutputIndex: 0,
ScriptKey: asset.NUMSScriptKey,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought tombstones weren't needed for this case? cc @jharveyb

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC the tombstone output is added here so that fundPacketWithInputs handles change calculation on building a valid change output if needed. The branch later on handles the full-value burn situation, so we should never end up with an actual tombstone. I think the comment could be a bit more verbose in nothing that the final result will not be a tombstone.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, they aren't. This is just to give the wallet an asset output it can attach any passive assets to. We remove it again later if there are no passive assets. Added a more explicit comment to it.

// without an actual commitment in it. So if we are not getting any
// change or passive assets in this output, we'll not want to go through
// with it.
changeOut := fundedPkt.VPacket.Outputs[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the above is unchanged though, then doesn't this lead to us just sending those other funds to the NUMs key?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I think from fundPacketWithInputs and the logic right after this, that key will never stay as NUMS if the amount is non-zero; this either becomes a normal split, or the tombstone is removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. We might want to eventually refactor the whole wallet code a bit to either make some of the assumptions less implicit or by just documenting them better.

// assets. Otherwise, for an interactive send we don't
// need a tombstone output and this wouldn't be a two
// output collectible send.
if !rootOut.Type.CanCarryPassive() &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs unit test

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a unit test.

Copy link
Contributor

@jharveyb jharveyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, cool to see how the freighter changes are relatively contained!

Gave my nits offline or in existing threads.

if in.AmountToBurn == 0 {
return nil, fmt.Errorf("amount to burn must be specified")
}
if in.ConfirmationText != AssetBurnConfirmationText {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

scriptKey3, anchorInternalKeyDesc3 := deriveKeys(t.t, t.tapd)
scriptKey4, _ := deriveKeys(t.t, t.tapd)

// We create the following outputs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very helpful for following the flow & cases here!

Because a burn is an interactive send, we don't need to create a
tombstone output if it's a full-value send. So in case there are passive
assets in the same commitment, we don't have a split root output to hook
them to. With the introduction of the new TypeSimplePassiveAssets we
have a new way to signal to the send state machine where to commit
passive assets to if there is no actual split or tombstone output.
We want to be able to show/list burned assets, so we want to re-create
them in the assets table. But to avoid them showing up in any balances,
we also mark burned assets as spent and we'll add an extra is_burn flag
to the asset output as well on the RPC response.
The same way we prune tombstone asset outputs from the input commitment
when spending an anchor output, we also want to remove any burned
assets.
In the case where we have an interactive full-value send of a
collectible, we would normally only expect a single output. But if there
are passive assets to commit to, then there needs to be a second output
just for those.
@guggero guggero force-pushed the provable-asset-burning branch from 49f7cda to 2d15923 Compare September 18, 2023 16:42
@guggero guggero requested a review from Roasbeef September 18, 2023 16:42
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🦜

@Roasbeef Roasbeef added this pull request to the merge queue Sep 19, 2023
@Roasbeef Roasbeef removed this pull request from the merge queue due to a manual request Sep 19, 2023
@Roasbeef Roasbeef merged commit 0c6cf23 into main Sep 19, 2023
@guggero guggero deleted the provable-asset-burning branch September 19, 2023 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[bug]: proof_at_depth is confusing in decode method bip-taro: implement provable burning and verification
4 participants