Repository navigation
Conversation
cursor
Bot
force-pushed
the
satscrip/supplycommit-anchor-fix-upstream-main
branch
2 times, most recently
from
October 11, 2026 15:32
7a2b70f to
3cca212
Compare
Author
|
@macroscope-app review this PR |
|
Manual reviews triggered for commit All prior checks · these links stay valid even if you push more commits. |
|
Review started; results will be posted as check runs. |
SadiqJaf
marked this pull request as ready for review
October 11, 2026 20:21
Author
|
/review-security |
SadiqJaf
changed the base branch from
cursor/upstream-main-mirror-ad51
to
main
October 12, 2026 07:12
Port the v0.8.5 genesis-anchor repair onto current main. Main's latest migration is 73, so this lands as migration 74. A proof updates genesis_points.anchor_tx_id only when its anchor transaction spends the genesis outpoint. Migration 74 retargets a pointer a transfer already moved, and abandons a never-confirmed commitment only when its inputs match neither a real pre-commit nor a confirmed commitment outpoint. A restarted manager then rebuilds and broadcasts a commitment that spends the caller-selected pre-commit, including a custom-genesis mint at output index 1. Signed-off-by: Sadiq Jaffer <sadiq.jaffer@satscryption.io>
startAssetSM copies a parked transition onto UpdatesPendingState, so the restart tick commits that batch without fetching the record a second time. The restart test expected the old empty-memory fetch. Signed-off-by: Sadiq Jaffer <sadiq.jaffer@satscryption.io>
Mint, transfer, and only then publish the supply commitment. The commitment must spend the mint pre-commit, not the transfer outpoint at the same index. Signed-off-by: Sadiq Jaffer <sadiq.jaffer@satscryption.io>
Signed-off-by: Sadiq Jaffer <sadiq.jaffer@satscryption.io>
SadiqJaf
force-pushed
the
satscrip/supplycommit-anchor-fix-upstream-main
branch
from
October 12, 2026 08:39
6e5b6ca to
bd9f47f
Compare
…ycommit-anchor-fix-upstream-main # Conflicts: # docs/release-notes/release-notes-0.9.0.md # tapdb/sqlc/querier.go
Use a type conversion instead of a struct literal in the genesis anchor rebuild test (staticcheck S1016), and add the missing testCaseSeconds entry for the "supply commit send before commit" itest case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Draft for review in Satscryption/taproot-assets only. This is not filed on lightninglabs/taproot-assets: no upstream issue, pull request, comment, or push.
Base is the fork's
main, fast-forwarded to lightninglabs/taproot-assetsmainat9db270f988fc359233fe09f15ed2d041aea3c1f0(Merge pull request lightninglabs#2329, 2026-10-09). Headsatscrip/supplycommit-anchor-fix-upstream-mainis3cca2127415dd9332a5fdb23ff3eddcbc5685da5. It carries the anchor-retarget write guard and migration 74, a supply-commit manager hydration fix for pending updates before the restart tick, and the regression tests.The issue text below is the upstream-ready draft. It is in this pull request body and is not part of the code commits.
Title
Supply commitment spends the transfer outpoint after a transfer proof retargets the genesis anchor
Affected versions
upsertAssetGenpath callsAnchorGenesisPointon every proof, including a transfer proof.bb3f1c6b552109dcd3f24c2fb3939ec051bfd9e6, tagv0.8.5). Reproduced with the newsupply commit send before commititest on a tree that has that test and no write guard.mainat9db270f988fc359233fe09f15ed2d041aea3c1f0.upsertAssetGenstill callsAnchorGenesisPointunconditionally (tapdb/universe.go:643).LatestMigrationVersionis 73.lightninglabs#2331 does not fix this. Its diff does not change
tapdb/universe.go,AnchorGenesisPoint, orFetchUnspentMintSupplyPreCommits. On v0.8.5, a tree with lightninglabs#2331's cherry-picks and the v0.8.5 adaptations, and without the write guard (9f72c9e5), failssupply_commit_send_before_committhe same way stock v0.8.5 does.Summary
UpdateSupplyCommitcan build a commitment whose input 0 spends a transfer output instead of the mint supply pre-commit. The pre-commit output index is still the mint's index, so the commitment spends<transfer txid>:<pre-commit index>and is signed with the mint pre-commit key. The node rejects that transaction. The commitment never confirms, so later supply updates, including burns, wait on a commitment that cannot finalize. Confirming the first supply commitment before any transfer proof is upserted spends<mint txid>:<pre-commit index>and does not hit this. That is whattestSupplyCommitMintBurndoes.Minimal reproduction
UpdateSupplyCommitfor that group key.What the rejection looks like
v0.8.5 itest, stock tree plus only the new test (
0ad85408), no write guard. The send succeeds. The harness then finds no commitment in the mempool:btcd (
output_btcd_chainbackend.log). Commitment input 0 references the transfer at output 1:lnd:
The same test on the lightninglabs#2331-only tree (
9f72c9e5) fails the same way (93.25s). btcd accepts the transfer (f818ead5, 2 inputs, 3 outputs), mines it, and rejects the commitment:lnd:
With the write guard, the same itest passes: 77.46s on the v0.8.5 anchor-fix branch (
ac101ed0), and it is one of the 117 cases in the passingmake itest-parallelon the stacked branch (a307dc0d). On thismain-based branch it passes in ~59s (see verification below).Root cause
On
mainat9db270f9:tapdb/sqlc/assets.sql.goAnchorGenesisPoint(lines 153-170) is an unconditionalUPDATE genesis_points SET anchor_tx_id = $2for the row whoseprev_outis the genesis outpoint.tapdb/universe.gouniverseUpsertProofLeaf(line 1138) callsupsertAssetGen(line 1259) for every proof type.upsertAssetGen(line 572) stores the proof'sAnchorTxand then callsAnchorGenesisPoint(line 643) with that chain-tx row. For an issuance proof that transaction is the mint. For a transfer proof it is the send. The genesis prevout stays the mint's input.FetchUnspentMintSupplyPreCommits(tapdb/sqlc/queries/supply_commit.sql:296) joinschain_txns mint_txn ON gp.anchor_tx_id = mint_txn.txn_id(line 316) and returns that raw transaction withmint_supply_pre_commits.tx_output_index. The pre-commit row is not retargeted. Only the join key is.newRootCommitment(universe/supplycommit/transitions.go:518) adds each pre-commit as an input and sets the witness UTXO topreCommit.MintingTxn.TxOut[preCommit.OutIdx](line 548). After the retarget,MintingTxnis the transfer andOutIdxis still the mint pre-commit index.Relation to other issues
missing asset input(s)/ provenance). supplyverifier: verify burn leaves against their input's provenance lightninglabs/taproot-assets#2331 verifies a burn leaf against its input's provenance. It does not change the genesis-anchor write. A commitment that btcd rejects never reaches burn-leaf publication. supplyverifier: verify burn leaves against their input's provenance lightninglabs/taproot-assets#2331 alone does not fix this retarget.genesis_points.anchor_tx_id.tapcli universe supplycommit fetchmissing a locator (commitment locator must be set). Closed by cmd: add locator args to supplycommit fetch lightninglabs/taproot-assets#1819. It is not this bug.FundBatch/PrepareBatch/FinalizeBatch). It changes how the mint transaction is funded. It does not stop a later transfer proof from overwritinganchor_tx_id.AnchorGenesisPoint, and a send before the first supply commitment did not find an open issue that describes this bug.Proposed fix
On
satscrip/supplycommit-anchor-fix-upstream-main(this pull request), against the forkmainabove:AnchorGenesisPointonly when the proof's anchor transaction spendsasset.Genesis.FirstPrevOut. A transfer is still stored withUpsertChainTx. Re-upserting the issuance proof restores a pointer a transfer previously overwrote, because only the mint spends that outpoint.genesis_points.anchor_tx_idwhen the current pointer does not spend the genesis outpoint and a unique spender is known. It only moves the anchor pointer; it does not move block-confirmation metadata thatConfirmChainTxmay have written onto a retargetedchain_txnsrow (the mint row keeps its block fields; rebuild paths useraw_tx). When several stored chain transactions spend the same genesis outpoint, the migration prefers the mint batch's recorded mint transaction (frommint_supply_pre_commitoutpoints), else the sole confirmed spender, else logs the ambiguity and leaves that genesis unchanged while continuing other rows (it never fails the whole migration for this case). It abandons a never-confirmed supply commitment whose inputs match none of the known pre-commit or confirmed-commitment outpoints, and leaves confirmed commitments and in-mempool spends of a real pre-commit or confirmed commitment outpoint in place.000074_repair_genesis_anchor.down.sqlis comment-only, matching other programmatic migrations (the repair is irreversible). After restart, pending updates are hydrated ontoUpdatesPendingStateand the next tick rebuilds a commitment that spends the mint pre-commit.QuerySyncStatsleavesAnchorPointempty whenanchor_txidis NULL, instead of failingchainhash.NewHashwithinvalid hash length of 0.Regression coverage:
TestTransferProofKeepsCustomGenesisPreCommitupserts a mint proof and then a transfer proof. The genesis anchor andFetchUnspentMintSupplyPreCommitsstill return the mint transaction and the pre-commit index.TestRepairGenesisAnchorcovers mint-batch preference, confirmed-spender preference, and ambiguous multi-spender cases that leave the pointer unchanged.TestMigration74CommitmentSafetyandTestMigration74RebuildsValidCommitmentcover a confirmed commitment, a mempool spend of a confirmed commitment, a custom-genesis pre-commit at caller index 1, and a rebuild that broadcasts a transaction spending that pre-commit.supply commit send before commitis the itest above.Verification on this branch
Head
3cca2127415dd9332a5fdb23ff3eddcbc5685da5.make lintvia the repotaproot-assets-toolsDocker image (upstreammake lint).make lintmake migration-checkmake sqlc-checkmake unit pkg=tapdb nocache=1(SQLite)ok tapdb 89.574s)make unit dbbackend=postgres pkg=tapdb nocache=1ok tapdb 385.228s)make unit pkg=universe/supplycommit nocache=1(SQLite)ok universe/supplycommit 0.251s)make unit dbbackend=postgres pkg=universe/supplycommit nocache=1ok universe/supplycommit 0.228s)make itest icase=supply_commit_send_before_commitok itest 58.936s)The itest minted, sent, published the first commitment, minted a second tranche, sent again, and published the next commitment. Both commitments confirmed. The mempool-empty failure did not occur.