Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/release-notes/release-notes-0.8.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@
bytes. A supply commitment verifier re-encodes burn proofs to compute
their universe leaves, and could reject a supply commitment for a burned
asset that spent several inputs. Both are now encoded sorted by key.

* [Universe servers no longer reject supply commitments that carry
burns](https://github.com/lightninglabs/taproot-assets/pull/2331).
A burn leaf's proof is a bare state transition, with no provenance
for the input it consumes, and was verified as if it were
self-contained, so every such commitment failed with `missing asset
input(s)` and the group stopped publishing supply commitments. The
verifier now checks the burn against its input's provenance: a
universe server takes it from its own universe, and a node syncing
supply commitments from the servers it pulls from. The issuer
publishes that provenance to each server before pushing the
commitment.
118 changes: 117 additions & 1 deletion itest/supply_commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ func MintAssetWithSupplyCommit(t *harnessTest,
// 3. Burning assets creates burn leaves in the supply tree with negative
// amounts.
// 4. All operations produce valid inclusion proofs that can be verified.
// 5. The universe server accepts the commitment carrying the burn.
func testSupplyCommitMintBurn(t *harnessTest) {
ctxb := context.Background()

Expand Down Expand Up @@ -955,6 +956,11 @@ func testSupplyCommitMintBurn(t *harnessTest) {
fetchResp.BurnSubtreeRoot,
)

t.Log("Verifying universe server holds the burn commitment")
assertBurnCommit(
t, t.universeServer.service, groupKeyBytes, fetchResp, burnAmt,
)

t.Log("Fetching supply leaves for detailed verification")

// Fetch supply leaves to verify individual entries have all been
Expand Down Expand Up @@ -1552,6 +1558,10 @@ func unmarshalRPCSupplyLeafKey(t *testing.T,
// 8. Primary node mints another asset into the group and publishes the
// third supply commitment.
// 9. Verifies the secondary node can fetch the third supply commitment.
// 10. Primary node burns part of its change from the transfer and
// publishes the fourth supply commitment.
// 11. Verifies the universe server and the secondary node both hold the
// fourth supply commitment.
func testSupplyVerifyPeerNode(t *harnessTest) {
ctxb := context.Background()

Expand Down Expand Up @@ -1813,7 +1823,7 @@ func testSupplyVerifyPeerNode(t *harnessTest) {
firstMintReq.Asset.Amount + secondMintReq.Asset.Amount,
)
var thirdSupplyCommitResp *unirpc.FetchSupplyCommitResponse
thirdSupplyCommitResp, _ = WaitForSupplyCommit(
thirdSupplyCommitResp, supplyOutpoint = WaitForSupplyCommit(
t.t, ctxb, t.tapd, groupKeyBytes, fn.Some(supplyOutpoint),
func(resp *unirpc.FetchSupplyCommitResponse) bool {
actualRootSum :=
Expand Down Expand Up @@ -1863,6 +1873,112 @@ func testSupplyVerifyPeerNode(t *harnessTest) {
// Verify that the secondary node's third supply commitment matches the
// primary's.
assertFetchCommitResponse(t, thirdSupplyCommitResp, peerFetchResp3)

// Step 10: Primary node burns part of its change from the transfer to
// the secondary node. The change output never passed through the
// universe server, so the burn's input provenance reaches it only
// through the commitment push.
t.Log("Burning part of the change from the transfer")

const burnAmt = 500
burnResp, err := t.tapd.BurnAsset(ctxb, &taprpc.BurnAssetRequest{
AssetSpecifier: &taprpc.AssetSpecifier{
Id: &taprpc.AssetSpecifier_AssetId{
AssetId: rpcFirstAsset.AssetGenesis.AssetId,
},
},
AmountToBurn: burnAmt,
ConfirmationText: rpcserver.AssetBurnConfirmationText,
})
require.NoError(t.t, err)

AssertAssetOutboundTransferWithOutputs(
t.t, t.lndHarness.Miner(), t.tapd, burnResp.BurnTransfer,
[][]byte{rpcFirstAsset.AssetGenesis.AssetId},
[]uint64{sendChangeAmount - burnAmt, burnAmt}, 1, 2, 2, true,
)

// The burn's supply-commit event is recorded asynchronously, and a
// tick with nothing pending is a no-op, so tick until the commitment
// transaction is broadcast.
t.Log("Updating supply commitment after burn (creating fourth " +
"supply commitment)")
lndMiner := t.lndHarness.Miner()
updateReq := &unirpc.UpdateSupplyCommitRequest{
GroupKey: &unirpc.UpdateSupplyCommitRequest_GroupKeyBytes{
GroupKeyBytes: groupKeyBytes,
},
}
deadline := time.Now().Add(defaultWaitTimeout)
for len(lndMiner.GetRawMempool()) == 0 {
require.True(
t.t, time.Now().Before(deadline),
"no commitment broadcast after the burn",
)

_, err = t.tapd.UpdateSupplyCommit(ctxb, updateReq)
require.NoError(t.t, err)

time.Sleep(2 * time.Second)
}
MineBlocks(t.t, lndMiner, 1, 1)

burnCommitResp, _ := WaitForSupplyCommit(
t.t, ctxb, t.tapd, groupKeyBytes, fn.Some(supplyOutpoint),
func(resp *unirpc.FetchSupplyCommitResponse) bool {
return resp.BurnSubtreeRoot != nil &&
resp.BurnSubtreeRoot.RootNode.RootSum == burnAmt
},
)

// Step 11: The universe server verifies the burn against the
// provenance the push published to it, and the secondary node
// against the provenance it fetches from the universe server.
t.Log("Verifying universe server holds the fourth supply commitment")
assertBurnCommit(
t, t.universeServer.service, groupKeyBytes, burnCommitResp,
burnAmt,
)

t.Log("Verifying secondary node holds the fourth supply commitment")
assertBurnCommit(t, secondTapd, groupKeyBytes, burnCommitResp, burnAmt)
}

// assertBurnCommit asserts that the given node holds the issuer's supply
// commitment carrying burns, as identified by the commitment it spends, and
// that its burn subtree sums to the expected amount.
func assertBurnCommit(t *harnessTest, node unirpc.UniverseClient,
groupKeyBytes []byte, issuerResp *unirpc.FetchSupplyCommitResponse,
burnSum int64) {

t.t.Helper()

burnPred := func(resp *unirpc.FetchSupplyCommitResponse) error {
if resp.BurnSubtreeRoot == nil {
return fmt.Errorf("burn subtree root is nil")
}

actualSum := resp.BurnSubtreeRoot.RootNode.RootSum
if actualSum != burnSum {
return fmt.Errorf("expected burn RootSum %d, got %d",
burnSum, actualSum)
}

return nil
}
req := unirpc.FetchSupplyCommitRequest{
GroupKey: &unirpc.FetchSupplyCommitRequest_GroupKeyBytes{
GroupKeyBytes: groupKeyBytes,
},
Locator: &unirpc.FetchSupplyCommitRequest_SpentCommitOutpoint{
SpentCommitOutpoint: issuerResp.SpentCommitmentOutpoint,
},
}
resp := rpcassert.FetchSupplyCommitRPC(
t.t, context.Background(), node, burnPred, &req,
)

assertFetchCommitResponse(t, issuerResp, resp)
}

// testSupplyCommitSendBeforeCommit mints a grouped asset, sends some of
Expand Down
12 changes: 12 additions & 0 deletions proof/courier.go
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,18 @@ func FetchProofProvenance(ctx context.Context, localArchive Archiver,
// is a reversal of that found in the proof file.
var reversedProofs []Blob
for {
// The walk follows inputs named by the proofs it fetches, so
// nothing but the source guarantees it reaches a genesis proof.
// Stop once the context ends, or once the chain is longer than
// any proof file may be.
if err := ctx.Err(); err != nil {
return nil, err
}
if len(reversedProofs) >= FileMaxNumProofs {
return nil, fmt.Errorf("%w: provenance exceeds %d "+
"proofs", ErrProofFileInvalid, FileMaxNumProofs)
}

// Before we attempt to fetch the proof from the potentially
// remote universe, we'll check our local archive to see if we
// already have it. This doesn't make sense in all cases, so we
Expand Down
46 changes: 46 additions & 0 deletions proof/courier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,49 @@ func TestCheckUniverseRpcCourierConnection(t *testing.T) {
})
}
}

// TestFetchProofProvenanceStopsOnContext tests that a provenance walk that
// never reaches a genesis proof ends once its context does.
func TestFetchProofProvenanceStopsOnContext(t *testing.T) {
t.Parallel()

testBlocks := readTestData(t)
genesis := asset.RandGenesis(t, asset.Collectible)
scriptKey := test.RandPubKey(t)
transfer := RandProof(t, genesis, scriptKey, testBlocks[0], 0, 1)

// A transfer that names its own output as its input: following its
// inputs back never arrives at a genesis proof.
outPoint := transfer.OutPoint()
transfer.Asset.PrevWitnesses = []asset.Witness{{
PrevID: &asset.PrevID{
OutPoint: outPoint,
ID: genesis.ID(),
ScriptKey: asset.ToSerialized(scriptKey),
},
}}
transferBlob, err := transfer.Bytes()
require.NoError(t, err)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

const cancelAfter = 3
var fetches int
fetchSingleProof := func(context.Context, Locator) (Blob, error) {
fetches++
if fetches == cancelAfter {
cancel()
}

return transferBlob, nil
}

_, err = FetchProofProvenance(ctx, nil, Locator{
AssetID: fn.Ptr(genesis.ID()),
ScriptKey: *scriptKey,
OutPoint: &outPoint,
}, fetchSingleProof)
require.ErrorIs(t, err, context.Canceled)
require.Equal(t, cancelAfter, fetches)
}
69 changes: 69 additions & 0 deletions rpcserver/supplysync_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/lightninglabs/taproot-assets/fn"
"github.com/lightninglabs/taproot-assets/mssmt"
"github.com/lightninglabs/taproot-assets/proof"
"github.com/lightninglabs/taproot-assets/rpcutils"
"github.com/lightninglabs/taproot-assets/taprpc"
unirpc "github.com/lightninglabs/taproot-assets/taprpc/universerpc"
"github.com/lightninglabs/taproot-assets/universe"
Expand Down Expand Up @@ -252,6 +253,74 @@ func (r *RpcSupplySync) FetchSupplyCommit(ctx context.Context,
return result, nil
}

// InsertProof inserts a single issuance or transfer proof into the remote
// universe server.
func (r *RpcSupplySync) InsertProof(ctx context.Context,
p *proof.Proof) error {

rawProof, err := p.Bytes()
if err != nil {
return fmt.Errorf("unable to encode proof: %w", err)
}

var groupKeyBytes []byte
if p.Asset.GroupKey != nil {
groupKey := p.Asset.GroupKey.GroupPubKey
groupKeyBytes = groupKey.SerializeCompressed()
}

assetID := p.Asset.ID()
_, err = r.conn.InsertProof(ctx, &unirpc.AssetProof{
Key: &unirpc.UniverseKey{
Id: rpcutils.MarshalUniverseID(
assetID[:], groupKeyBytes,
),
LeafKey: rpcutils.MarshalAssetKey(
p.OutPoint(), p.Asset.ScriptKey.PubKey,
),
},
AssetLeaf: &unirpc.AssetLeaf{
Proof: rawProof,
},
})
if err != nil {
return fmt.Errorf("unable to insert proof: %w", err)
}

return nil
}

// FetchProof fetches the single issuance or transfer proof at the given
// locator from the remote universe server.
func (r *RpcSupplySync) FetchProof(ctx context.Context,
loc proof.Locator) (proof.Blob, error) {

if loc.AssetID == nil || loc.OutPoint == nil {
return nil, fmt.Errorf("proof locator must specify asset ID " +
"and outpoint")
}

var groupKeyBytes []byte
if loc.GroupKey != nil {
groupKeyBytes = loc.GroupKey.SerializeCompressed()
}

resp, err := r.conn.QueryProof(ctx, &unirpc.UniverseKey{
Id: rpcutils.MarshalUniverseID(loc.AssetID[:], groupKeyBytes),
LeafKey: rpcutils.MarshalAssetKey(
*loc.OutPoint, &loc.ScriptKey,
),
})
if err != nil {
return nil, fmt.Errorf("unable to query proof: %w", err)
}
if resp.AssetLeaf == nil {
return nil, fmt.Errorf("universe returned no asset leaf")
}

return resp.AssetLeaf.Proof, nil
}

// Close closes the RPC connection to the universe server.
func (r *RpcSupplySync) Close() error {
if r.conn != nil && r.conn.ClientConn != nil {
Expand Down
2 changes: 2 additions & 0 deletions tapcfg/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
ClientFactory: rpcserver.NewRpcSupplySync,
Store: supplySyncerStore,
UniverseFederationView: federationDB,
LocalProofs: proofArchive,
},
)

Expand Down Expand Up @@ -681,6 +682,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
SupplyTreeView: supplyTreeStore,
SupplySyncer: supplySyncer,
GroupFetcher: assetMintingStore,
UniverseProofs: multiverse,
IssuanceSubscriptions: universeSyncer,
DaemonAdapters: lndFsmDaemonAdapters,
DisableChainWatch: cfg.Universe.DisableSupplyVerifierChainWatch,
Expand Down
24 changes: 20 additions & 4 deletions tapfreighter/chain_porter.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,6 @@ func (p *ChainPorter) storePackageAnchorTxConf(pkg *sendPackage) error {
}

anchorTxBlockHeight := int32(pkg.TransferTxConfEvent.BlockHeight)
anchorTxBlockHeader := pkg.TransferTxConfEvent.Block.Header

// Now we scan through the VPacket for any burns.
//
Expand Down Expand Up @@ -952,9 +951,26 @@ func (p *ChainPorter) storePackageAnchorTxConf(pkg *sendPackage) error {
OutPoint: op,
}

// Set the block height and header in the burn proof.
b.Proof.BlockHeight = uint32(anchorTxBlockHeight)
b.Proof.BlockHeader = anchorTxBlockHeader
// storeProofs updates a decoded copy of the proof
// suffix, not this virtual-packet suffix. Copy the
// confirmation onto the burn proof, including the
// transaction merkle proof. Burn-leaf verification
// checks that proof.
err := b.Proof.UpdateTransitionProof(
&proof.BaseProofParams{
Block: pkg.TransferTxConfEvent.Block,
BlockHeight: pkg.TransferTxConfEvent.
BlockHeight,
Tx: pkg.TransferTxConfEvent.Tx,
TxIndex: int(
pkg.TransferTxConfEvent.TxIndex,
),
},
)
if err != nil {
return fmt.Errorf("unable to update burn "+
"proof: %w", err)
}

if o.Asset.GroupKey != nil {
groupKey := o.Asset.GroupKey.GroupPubKey
Expand Down
Loading
Loading