mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 12:20:38 +00:00
WIP: BIP460: CISA for Taproot key path spends #36122
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36122
Loading…
Reference in a new issue
No description provided.
Delete branch "bip460"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Reference implementation of BIP460 Cross-Input Signature Aggregation for Taproot key path spends. Implements witness v2 outputs whose key path spends can be aggregated with BIP458 half-aggregation or BIP459 full-aggregation, or opt out with a plain BIP341 signature.
Draft to accompany the BIPs, not intended for merge:
Further notes:
src/test/data/and run insrc/test/cisa_tests.cpp. Additional functional tests cover relay and block validation.The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.
Conflicts
Reviewers, this pull request conflicts with the following ones:
-Wunusedby fanquake)If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
LLM Linter (✨ experimental)
Possible places where named args for integral literals may be used (e.g.
func(x, /*named_arg=*/0)in C++, andfunc(x, named_arg=0)in Python):src/test/cisa_tests.cpp:key.Set(privkey.begin(), privkey.end(), true)src/test/cisa_tests.cpp:tweaked_key.Set(tweaked_privkey.begin(), tweaked_privkey.end(), true)test/functional/feature_cisa.py:TaprootSignatureHash(tx, spent, 0, input_index=0)(explicit-default test)test/functional/feature_cisa.py:TaprootSignatureHash(tx, spent, 0, input_index=0)(marker-byte test)test/functional/feature_cisa.py:TaprootSignatureHash(tx, spent, 0, input_index=6)test/functional/feature_cisa.py:TaprootSignatureHash(tx, spent, 0, input_index=0, scriptpath=True, ...)test/functional/feature_cisa.py:TaprootSignatureHash(tx, spent, 0, input_index=idx)Possible places where comparison-specific test macros should replace generic comparisons:
test/functional/test_framework/cisa.py:assert len(pk) == 32 and len(msg) == 32 and len(sig) == 64→ Preferassert_equalchecks for each length.test/functional/test_framework/cisa.py:assert u == len(seckeys) > 0→ Preferassert_equal(u, len(msgs))andassert_greater_than(u, 0).2026-11-27 18:51:49
The latest commits, prefixed with
draft-bip:go further than BIP460 itself. They implement two companion BIPs necessary for adoption that have not been reviewed and I don't think they are worth sharing on the mailing list yet either:cisa()andrawcisa(): https://github.com/fjahr/cisa-playground/blob/main/bip_cisa_descriptor.mediawikiThey are included so that wallets and protocols, like payjoin or coinjoin for example, can build proofs of concept on top of this branch and exercise CISA end-to-end through the their already common descriptor, wallet and PSBT RPCs flows. Expect these commits to change as these drafts evolve. Review of the consensus and policy commits does not depend on them and I would prefer if review is focused on those unless you are building a PoC and depend on these later changes.
🐙 This pull request conflicts with the target branch and needs rebase.
🐙 This pull request conflicts with the target branch and needs rebase.
Hey Fabian, Hope you don't mind if I add a review here. I built this locally and ran
feature_cisa.pyandwallet_cisa.pyfrom commit 224e15f. Both passed, and the consensus/policy test coverage looks great. I did hit three wallet/PSBT issues while reviewing the changes.You already reject conflicting full-agg nonces and partial sigs.
wallet_cisa.pycovers that (PSBTs not compatible). Half-agg signatures do not get checked the same way. Merge keeps the firstm_cisa_halfagg_sigit sees.I took two otherwise identical half-agg PSBTs and flipped one bit in input 0’s sig.
combinepsbt([A, B])succeeded and kept A. Swapping the order kept B.We can fix this issue if you treat
m_cisa_halfagg_siglike the full-agg partial sig (both present and unequal means incompatible). I only mention it because the full-agg side already worksFinalizeCISAInputsskips any input that is already signed. This skip on already-signed inputs can leave you with two separate groups of the same mode. Consensus then fails the tx withSCRIPT_ERR_CISA_GROUP_INVALID, because once it has seen a group’s final it will not accept another member.The problem is basically when input 0 already has a final, and you then put input 1 into the same mode with a signature. The loop walks past input 0 and builds a brand new 1-input group on input 1.
Working example:
I signed a 2-input half-agg PSBT without finalizing, cleared input 1’s mode and sig, and ran
finalizepsbt. That put a 65-byte final on input 0 and reportedcomplete=false. I put input 1’s mode and sig back and finalized again. That time it reportedcomplete=true, both witnesses were 65 bytes, andtestmempoolacceptfailed with aInvalid CISA aggregation group structureerror.For a marked v2 keypath,
VerifyScriptreturning success afterParseCISAWitnessseems correct for a per-input structure check.ProduceSignatureandDataFromTransactionthen treat that success as complete, so a dummy member looks fully signed.I made a 2-input v2 spend and put 32 zero bytes on both witnesses (half-agg members, no final).
signrawtransactionwithwalletcame backcomplete=truewith no errors.testmempoolacceptthen failed withmempool-script-verify-flag-failed(Invalid CISA aggregation group structure). So CISACheck is doing its job. Anyone who only looks atVerifyScript / completewill think the input is done.Would it be reasonable to run
VerifyCISATransactionon the full tx before setting complete when the parse yields a marker?Right, good catch. The finalizer should treat a group as closed once any input of that mode has a final witness and I have changed
FinalizeCISAInputsto do that, so the remaining input stays unfinalized instead of forming a second group. I also updated the psbt bip draft with a small sentence to clarify this.This is intended, halfagg has no signing session so two different signatures for the same input can both be valid and either one aggregates fine. It matches the behavior of BIP 174/371 for
PSBT_IN_PARTIAL_SIGandPSBT_IN_TAP_KEY_SIG, which also keep the first. The flipped bit is an invalid signature rather than a conflict, and the Finalizer verifies every signature before aggregating, so it fails withcomplete=falseinstead of producing an invalid tx. I added an explicit test here.The per-input success is intentional so existing aggregation data is not overwritten by a following opted-out signature, but nothing ran the tx-level check afterwards.
SignTransactionnow runsVerifyCISATransactiononce all inputs are processed and reports the error on the aggregated inputs, so complete should now befalsefor your example. I also added a test for this inwallet_cisa.py.🚧 At least one of the CI tasks failed.
Task
32 bit ARM: https://github.com/bitcoin/bitcoin/actions/runs/35590888385/job/106304773630LLM reason (✨ experimental): CI failed during compilation because
cisa_tests.cpptriggered-Werror=array-bounds(array subscript 64 out of bounds instd::vector/construction).Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
17 additional verified findings in the Review report.
Earlier concerns neither republished nor resolved: 4 suggestions. See the Run archive linked from the Review report for their assessments.
🔴 Major · Witness-v2 policy is enabled on networks without CISA consensus rules
Although this draft activates consensus only on regtest, non-regtest wallets with active
cisa()descriptors can receive funds that any miner can spend without a signature.Location:
src/policy/policy.h:105(head).🟠 Minor · PSBT completion skips verification of finalized CISA aggregates
finalizepsbt,walletprocesspsbt,descriptorprocesspsbtand the GUI can report completion for a corrupted or unterminated aggregation group.Location:
src/psbt.cpp:941(head).🟠 Minor · Full-aggregation signing snapshots unfinished group metadata
Interleaving per-input metadata updates with signing can make an earlier input sign the wrong group and consume its reserved nonce.
Location:
src/psbt.cpp:765(head).🟠 Minor ·
descriptorprocesspsbtpublishes nonces it cannot later sign withdescriptorprocesspsbtadvertisesfullaggbut lacks a secret-nonce store, producing an unusable signing session or an abort in builds enforcingAssume.Location:
src/rpc/rawtransaction.cpp:2145(head).🟠 Minor ·
finalizepsbtreports incomplete after building valid half-aggregation witnessesAn external 65-byte half-aggregation signature without
PSBT_IN_SIGHASH_TYPEyields valid witnesses but initially returnscomplete=false; no current caller producing this state was found.Location:
src/psbt.cpp:733(head).🟠 Minor ·
sendallvalidatescisa_modeafter locking its inputsWith
lock_unspents=true, mistypingcisa_modeleaves the selectedsendallcoins locked after the RPC returns an error.Location:
src/wallet/rpc/spend.cpp:121(head).Review coverage was incomplete.
Reviewed:
de966331a285· Review report · Previous reportspermalink
Tested
07addd3748: the consensus code agrees with BIP460's vectors and with 35 extra edge cases, checked against libraries I maintain.I recomputed the wallet vectors of bips#2212 at ca1312e from the BIP text and checked its consensus vectors, using btclib's taproot sighash with the agg_mode byte added and ecc's BIP458 and BIP459 modules, both still in open pull requests. All 56 wallet values match, including both aggregates and the signed transactions, and so do all 53 consensus verdicts. On this head
cisa_tests,feature_cisa.pyandwallet_cisa.pypass. I then put the BIP's vectors and my 35 cases incisa_consensus_vectors.json, and Core returned the expected verdict on each. They cover one-input groups of both kinds together, interleaved groups, an annex on every input, every sighash type in both modes, invalid sighash bytes, aggregates built in the wrong input order, s at or above n, duplicate keys, and P2SH-wrapped or 33-byte v2 inputs whose elements look like group members.The vendored
cisa_consensus_vectors.jsonis older than the BIP's copy. Itsmarker-undefinedcase isoptout-sighash-undefinedthere, with the same transaction, now an opted-out signature with an undefined sighash type, which is how the BIP text reads 0xbb. Copying the BIP's file over fixes it.The scripts and the 35 cases are in https://gist.github.com/fametrano/2a66f0b0064f4bf754edaf48bda44cdc. P2SH-wrapped inputs, s at or above n, and valid full aggregation with NONE, SINGLE or ANYONECANPAY are not in the BIP's vectors yet, and I can add them there if you want.
🐙 This pull request conflicts with the target branch and needs rebase.
Updated in the latest push.
I added two test vectors with multiple sighash types to the BIP vectors and added them here. I left out the s/n suggestion because this would belong in BIP458 and BIP459 and there are already vectors for it there, maybe I will add more as noted in the response there but I think it's not that important.
The updated consensus vectors check out: at
02239232f1cisa_consensus_vectors.jsonis byte-identical to BIP460's as merged in bitcoin/bips (d5ca385c8e). With the setup of my earlier comment, where btclib computes the messages and btclib-org/ecc's BIP458 and BIP459 modules build and verify the aggregates, all 56 verdicts match, and Core'scisa_testspasses on this head.cisa_wallet_vectors.jsonis unchanged since07addd3748, still identical to the BIP's copy I already matched.The new cases are
program-p2sh-wrappedand the two whose groups mix sighash types. In those two I changed each member's sighash byte in turn to another valid type, and checked each result with btclib and btclib-org/ecc: all eight altered transactions fail aggregate verification. So the two vectors catch an implementation that does not hash a member's sighash type. Ralph's report on this head says the vendored vectors were not diffed against the BIPs and that agreement between independent implementations is unverified. For the consensus and wallet vectors, this does both.Scripts and output: https://gist.github.com/fametrano/2a66f0b0064f4bf754edaf48bda44cdc/c4fea95b9d10bd7e79ec25ce2709043655db80fa
🐙 This pull request conflicts with the target branch and needs rebase.
🐙 This pull request conflicts with the target branch and needs rebase.
🐙 This pull request conflicts with the target branch and needs rebase.
🐙 This pull request conflicts with the target branch and needs rebase.