Skip to content

Conversation

ffranr
Copy link
Contributor

@ffranr ffranr commented Sep 9, 2025

Closes #1782


This PR strengthens the supply commitment verification process by enforcing that initial supply commitments must spend pre-commitment outputs. This requirement ties the first supply commitment transaction directly to a mint anchor transaction.

Key changes:

  • Verification logic

    • In supplyverifier, added an assertion that initial supply commitments must spend pre-commitment outputs. This ties the first supply commitment transaction directly to a mint anchor transaction, ensuring the chain of authentication is enforced for both local and remote issuances.
  • Database queries and schema

    • Renamed existing queries to clearly distinguish between pre-commitments created by the local issuer (FetchUnspentMintSupplyPreCommits) and those created by remote issuers (FetchUnspentSupplyPreCommits).
    • Added conditional upsert logic so that supply pre-commitments can be recorded when syncing issuance proofs for assets not issued locally.
  • tapdb enhancements

    • Extended SupplyCommitMachine.UnspentPrecommits to return both local and remote issuer pre-commitments.

This change is Reviewable

Rename SQL query to better align with "supply" terminology.
Rename SQL query UpsertMintAnchorUniCommitment to
UpsertMintSupplyPreCommit.

This gives room to add UpsertSupplyPreCommit in a later commit. Also,
better align with "supply" terminology.
Rename SQL query FetchUnspentPrecommits to
FetchUnspentMintSupplyPreCommits. This adds the term "Mint" to indicate
that these supply pre-commitment entries relate to the local node's
minting process. The rename also allows room to add
FetchUnspentSupplyPreCommits in a subsequent commit.
Rename SQL query MarkPreCommitmentSpentByOutpoint to
MarkMintPreCommitSpentByOutpoint. This adds the term "Mint" to indicate
that these supply pre-commitment entries relate to the local node's
minting process. The rename also allows room to add
MarkPreCommitSpentByOutpoint in a subsequent commit.
Rename SQL table mint_anchor_uni_commitments to mint_supply_pre_commits.
This aligns with the "supply" terminology and provides room to add a new
supply pre-commits table for assets issued by a remote peer in a
subsequent commit.
Extend FetchMintSupplyPreCommits to also return the supply pre-commit
outpoint.
@ffranr ffranr added this to the v0.7 milestone Sep 9, 2025
@ffranr ffranr self-assigned this Sep 9, 2025
@ffranr ffranr added database supply commit Work on the supply commitment feature, enabling issuers to attest to total asset supply on-chain. labels Sep 9, 2025
@ffranr ffranr moved this from 🆕 New to 👀 In review in Taproot-Assets Project Board Sep 9, 2025
@coveralls
Copy link

coveralls commented Sep 9, 2025

Pull Request Test Coverage Report for Build 17626735389

Details

  • 192 of 274 (70.07%) changed or added relevant lines in 12 files are covered.
  • 97 unchanged lines in 14 files lost coverage.
  • Overall coverage decreased (-0.01%) to 56.974%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tapdb/burn_tree.go 5 8 62.5%
tapdb/supply_tree.go 3 6 50.0%
universe/supplycommit/env.go 6 11 54.55%
universe/supplyverifier/verifier.go 5 10 50.0%
tapdb/sqlc/supply_commit.sql.go 24 32 75.0%
tapdb/supply_commit.go 43 66 65.15%
tapdb/universe.go 74 109 67.89%
Files with Coverage Reduction New Missed Lines %
fn/context_guard.go 1 91.94%
asset/asset.go 2 79.97%
tapdb/addrs.go 2 78.23%
tapdb/sqlc/universe.sql.go 2 75.78%
tapdb/universe.go 2 79.86%
tapgarden/custodian.go 2 77.02%
commitment/tap.go 3 85.19%
proof/verifier.go 3 87.54%
mssmt/compacted_tree.go 4 77.19%
tapdb/assets_store.go 7 79.7%
Totals Coverage Status
Change from base Build 17562325369: -0.01%
Covered Lines: 63308
Relevant Lines: 111118

💛 - Coveralls

func (s SupplySubTree) ToUniverseProofType() (universe.ProofType, error) {
switch s {
case MintTreeType:
return universe.ProofTypeMintSupply, nil
Copy link
Member

Choose a reason for hiding this comment

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

In order to unify things further, perhaps we update the String method of SupplySubTree to just return a call to the String() method of the corresponding ProofType.

This way these strings aren't defined in two palces as they are now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah nice, good idea.

Copy link
Contributor Author

@ffranr ffranr Sep 10, 2025

Choose a reason for hiding this comment

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

hmm ToUniverseProofType() returns an error where as SupplySubTree.String() does not. That's causing some problems. Would you mind if I put up a separate PR to refactor SupplySubTree perhaps?

@@ -326,6 +342,76 @@ func (s *SupplyCommitMachine) UnspentPrecommits(ctx context.Context,
preCommits = append(preCommits, preCommit)
}

// If any pre-commits were found where we acted as the issuer,
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this should just be another method? So one used for remote issuers, and one used for local issuers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ve been considering that option. My reasoning for keeping a single UnspentPrecommits is twofold:

  • There shouldn’t be any overlap between remote- and locally-issued assets, so UnspentPrecommits can be called safely in either context.
  • Splitting into local/remote variants adds naming complexity. Terms like “remote pre-commit” aren’t self-explanatory, and including “issued” in the names makes them cumbersome.

What do you rekon i should do here?

@ffranr ffranr force-pushed the wip/supplyverify/store-nonissuer-supply-pre-commits branch from 8ffa1eb to 306bf35 Compare September 10, 2025 00:30
@ffranr ffranr requested a review from Roasbeef September 10, 2025 00:30
Copy link
Member

@jtobin jtobin left a comment

Choose a reason for hiding this comment

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

This all looks very solid, and I haven't found any obvious issues. LGTM. 👍

@ffranr ffranr force-pushed the wip/supplyverify/store-nonissuer-supply-pre-commits branch from 306bf35 to 48336f5 Compare September 10, 2025 10:11
@ffranr
Copy link
Contributor Author

ffranr commented Sep 10, 2025

Added a fix commit to this PR, originally pointed out by @jtobin here: #1788

Add a table to store mint anchor transaction supply pre-commitment
outputs for assets not issued by the local node. Data from this table
will be used for supply commitment verification.
Adds support for upserting supply pre-commits that are not related to
the minting process. These pre-commits pertain to assets issued by
peer nodes.
Passes the proof type as an argument to universeUpsertProofLeaf rather
than just its string representation. This refactor will simplify
conditional logic based on proof type in a subsequent commit.
Extend universe leaf upsert with a method to conditionally upsert
issuance supply pre-commitment records. This allows a node to record
supply pre-commitments when syncing issuance proofs for assets it did
not issue. These records are essential for verifying supply commitment
transactions.
Introduce query to fetch unspent supply pre-commitment outputs. Each
output originates from a mint anchor transaction and corresponds to an
asset issuance where a peer node, not the local node, acted as the
issuer.

This differs from FetchUnspentMintSupplyPreCommits, which only returns
pre-commitments minted by the local node.
@ffranr ffranr force-pushed the wip/supplyverify/store-nonissuer-supply-pre-commits branch from 48336f5 to c9081c0 Compare September 10, 2025 17:30
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.

@Roasbeef reviewed 26 of 26 files at r1, 1 of 3 files at r3, 23 of 23 files at r4, all commit messages.
Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @ffranr)


universe/supplyverifier/verifier.go line 466 at r4 (raw file):

	}

	if issuanceProof.Asset.GroupKey.GroupPubKey !=

Should this be instead IsEqual?

Update method SupplyCommitMachine.UnspentPrecommits to return
pre-commitment outputs generated by remote issuer nodes, in addition to
those from the local node.
Now that supply pre-commitments are stored for remotely issued assets,
we can assert in the supply verifier that if a supply commitment is the
initial one (i.e., the spent commitment field is None), then the
corresponding transaction must spend some pre-commitment outputs. This
enforces a link between the initial supply commitment transaction and
a mint anchor transaction.
@ffranr ffranr force-pushed the wip/supplyverify/store-nonissuer-supply-pre-commits branch from c9081c0 to e8ea035 Compare September 10, 2025 21:02
@ffranr
Copy link
Contributor Author

ffranr commented Sep 10, 2025

I’ve updated the group_key field in the new pre-commit SQL table to:

    -- The asset group key for this supply pre-commitment.
    -- Stored in canonical 32-byte x-only form as defined in BIP340
    -- (schnorr.SerializePubKey).
    group_key BLOB NOT NULL CHECK(length(group_key) = 32),

@ffranr ffranr requested a review from Roasbeef September 10, 2025 21:14
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 merged commit b25c053 into main Sep 10, 2025
18 of 19 checks passed
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Taproot-Assets Project Board Sep 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database supply commit Work on the supply commitment feature, enabling issuers to attest to total asset supply on-chain.
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[feature]: store and verify peer-issued pre-commitment outputs when syncing asset issuance proofs
4 participants