DSS 2026 / Day 2 / Pearl Hall
Bitcoin DeFi (BTCFi) Auditing Is Its Own Discipline
Haoran Xu
Source: YouTube automatic caption track · Exported 2026-11-16. Timestamps link to the source video. Cue end times were not supplied.
Transcript
0:01Hi everyone, and thanks for joining. I'm
0:03Hao Ran, a security engineer at CertiK.
0:06This talk comes from our experience
0:08auditing Bitcoin DeFi protocols and
0:10applications.
0:11Today I will explain why Bitcoin DeFi or
0:14BTC Fi needs its own security approach.
0:18We will look at the component this
0:20application rely on, the attackers, the
0:22attack surface they introduced, and walk
0:25through a case study from our audits.
0:28Let's start what BTC Fi is and how it
0:31emerged.
0:33BTC Fi brings trading, lending, asset
0:36insurance, and yield to the Bitcoin
0:38ecosystem. Developers want this
0:41financial services, but Bitcoin's base
0:43layer did not provide them natively.
0:46Trading and lending needs rules for
0:49managing collateral, debt, and trades.
0:52Developer implement this rules in smart
0:54contract on programmable layer built
0:56around Bitcoin. Another approach use BTC
1:00backed tokens such as pegged BTC in DeFi
1:03applications on other chains.
1:06For asset insurance, developers
1:08introduced protocols such as Ordinals,
1:11BRC-20, and Runes.
1:13This define how assets are created and
1:16transferred through Bitcoin
1:17transactions. Those protocol use
1:19indexers to interpret transaction and
1:22track ownership or token balances.
1:24User can also earn interest by learning
1:27or providing liquidity in staking
1:29systems such as Babylon protocol.
1:32Holders lock BTC on Bitcoin to help
1:34secure proof of stakes on other
1:37networks and receive rewards from that
1:39network. To understand the security of
1:42this application, we need to look at how
1:44this component works.
1:48Bitcoin represents funds as unspent
1:50transaction outputs or UTXOs. Uh it's
1:55each output has a value and spending
1:57conditions. Bitcoin checks the input are
1:59unspent that their spending conditions
2:02are satisfied, but it does not track
2:04application stats.
2:06The BTC 5 protocol itself has to
2:09maintain that state.
2:11So let's start with how this protocol
2:13controls who can spend funds and under
2:16what conditions.
2:19Bitcoin script defines a condition for
2:21spending an output. It can require the
2:24signature, knowledge of a secret, or a
2:27time lock period. In this staking
2:30example, Taproot provides two ways to
2:32spend funds.
2:34The upper branch is the key pass. The
2:36spender provides a valid signature and
2:38the output tweaked public key.
2:40The lower branch is the script script
2:43pass. The spender reveals one script and
2:45satisfies its condition. Here the
2:48withdraw script require Alice signature
2:50and a wait period. The slashing script
2:53require Alice and committed signature on
2:56a pre-signed penalty transaction.
2:58The OR lab the OR labels means that the
3:01spender spender only needs to satisfy
3:03one pass. That's how
3:05spending conditions work in the Taproot
3:08output.
3:11Next, let's look at programmable layers
3:14where smart contracts run the DeFi logic
3:17and maintain the application financial
3:19state.
3:20In this example, Alice deposits one
3:22Bitcoin through a bridge or pack.
3:25Bridge bridge signers control that
3:27output on Bitcoin. After verified
3:31deposit,
3:32the bridge mint Alice with a BTC backed
3:34token on the programmable layer.
3:37Alice can then use the token as
3:39collateral in a lending contract.
3:41When Alice borrows or repays, her
3:44lending position changes on the contract
3:46layer. The original BTC state untouched
3:49on Bitcoin. Those contract update do not
3:52move or modify the original BTC.
3:55Releasing the original BTC requires a
3:57separate withdraw request through the
3:59bridge.
4:02We have seen how
4:04manage financial states. Now let's look
4:06at how user authorized Bitcoin
4:08transactions, especially when several
4:10participants help build the same
4:12transaction.
4:14In a marketplace, the seller may sign
4:16first, leaving the buyer to add funds
4:19and complete the purchase. This is where
4:22the PSBT are used.
4:24PSBT stands for partially signed Bitcoin
4:27transaction. It's a package that carries
4:30the proposed transaction, the
4:31information needed to sign it, and the
4:34signature from different participants.
4:37Follow the workflow across the top. The
4:40application prepares the input, output,
4:43and signing information.
4:44Each participant wallet reviews the
4:47transaction and adds adds its own
4:49signatures. A combiner brings those
4:52signatures together. Once the required
4:54signatures are available, the
4:56transaction is finalized and then
4:58extracted for broadcast.
5:00The lower row shows what happened during
5:03the signing. The wallet does not sign
5:05the entire PSBT package. The C hash mode
5:08determines which transaction field goes
5:11into the hash, and the wallet signs the
5:13hash with the appropriate private key.
5:16Changing a field covered by a signature
5:18invalidates it, but field outside of
5:21that coverage is still editable.
5:24That's why transaction can already
5:26contain a valid signature and still
5:28allows another participant to change
5:30part of it.
5:34Once the transaction confirms, how does
5:36the application know who received the
5:38asset?
5:39The top row show Bitcoin raw transaction
5:41on chain, and the bottom row shows that
5:45the application indexer off chain.
5:47On the left, the reveal transaction
5:50include the
5:51inscription content in its witness.
5:54Ordinal rules associated
5:57that inscription with a particular
5:59Satoshi. Here the set is in Alice's
6:02output.
6:04On the right, Alice that output in a new
6:07transaction.
6:08The indexer tracks whether the
6:11inscribed set goals.
6:12And here it reads Bob's output. So the
6:15indexer record Bob as new
6:18inscription holder.
6:19The inscription data stays in the
6:21original reveal transaction. What move
6:23is
6:25is the Satoshi associated with that
6:27inscription data.
6:29Bitcoin itself does not track
6:31inscription ownership or asset balances.
6:34It is the indexer who applies the asset
6:36rules and interprets those transactions.
6:39For a BRC 20 the indexer process valid
6:43token operations and update its balance
6:45ledger according to
6:47protocol rules.
6:50Now let's look at how this component can
6:53fill.
6:54Based on our auditing experience, we
6:56have grouped the common attack vectors
6:58in BTC 5 into four categories.
7:03The first attack vector is incomplete
7:05transaction authorization.
7:07An attacker change a payment or
7:08recipient after the user have signed
7:11without invalidating that user's
7:13signature.
7:14So this the authorization is
7:16managed by the C Cash mode.
7:19Let's use a marketplace purchase as an
7:21example. The seller sites input one.
7:24This table shows the buyer's receiving
7:27output, the seller's payment and change.
7:29Blue means fixed by this signature and
7:31red means open to change. With C Cash
7:34all area output amount and destinations
7:37are fixed. Changing any of them will
7:39invalidate the signature. With C Cash
7:42none, no output is fixed. Anyone can
7:45redirect the payments.
7:47C Cash single fixed only its output at
7:49the same index and signed input. Here it
7:53protects the signer's payment at output
7:55one, but leaves the rest output open to
7:58edit.
7:59C Cash anyone can pay. Let's let another
8:03buyer supply their own funding input
8:05without invalidating seller's signature.
8:08Combined with Ccash single, it keeps
8:11sellers payment fixed but leaves the
8:13asset destination open.
8:16Developer needs to ensure that the
8:18signature
8:20the Ccash properly enforce the intended
8:22payment amount and recipient. Otherwise,
8:26attacker can redirect an unprotected
8:28payment output to their own address or
8:32or replace the intended asset recipient.
8:37The next attack vector is that is about
8:39UTXO ownership versus asset ownership.
8:42UTXO ownership means being able to spend
8:45a Bitcoin output. For inscription, asset
8:48ownership depends on which output
8:50contains its associated set and whoever
8:53can spend that output is the asset
8:55owner.
8:56So these two ownership are different. A
8:58valid spend does not guarantee that the
9:01asset reach the intended destination.
9:03Let's look at the orange mark in the
9:05sellers input.
9:07That's the inscription set.
9:10Here, the set from the first two input
9:12all go all go to the output zero
9:15including that
9:17orange set.
9:18Whoever controls output zero now holds
9:21the inscription.
9:24And both output are part of the same
9:26transaction. Paying the seller does not
9:28guarantee that the intended buyer
9:31receive this inscription.
9:34The third attack vector represent using
9:37an unintended or hidden
9:39spending path that bypass protocols
9:41restrictions.
9:42Here in this example, the withdraw the
9:45withdraw script enforces the lock up and
9:47the stash script allows a penalty.
9:50The developer expect expect this two
9:53script to control how the stakes can be
9:56spent.
9:57But they use stickers own public key as
10:00a taproot internal key.
10:02The sticker already know its private key
10:04so they can calculate the tricked
10:06private key and sign a key path spent.
10:09That's the right branch on left.
10:11The transaction never runs the withdraw
10:13or slashing script.
10:15The
10:16the sticker can move funds before the
10:18lockup ends
10:19or before the penalty transaction
10:21confirm.
10:22So this is
10:23unintended spend path of this
10:26script.
10:28The attacker does not break the lockup
10:30or forge a signature. They use another
10:32path where those restrictions do not
10:34apply.
10:37The first attack vector is about
10:39confirmation window. It targets the gap
10:41between broadcasting a transaction and
10:43getting it confirmed.
10:45In this example, Alice is swapping BTC
10:47for Bob's token on another chain. She
10:50claimed Bob's tokens revealing the
10:52secret Bob need to claim her BTC.
10:55Bob broadcast his claim but it's but it
10:58is still waiting for confirmation. The
11:00red dash line marks when Alice become
11:03allowed to reclaim the BTC he locked for
11:05the swap.
11:07Bob can still claim those claim those
11:08funds after that point but Alice can now
11:11broadcast a refund request spending the
11:14same output and only one of these
11:16transactions can be confirmed.
11:19Here Alice refund confirmed first.
11:22She recovers her BTC and keep Bob's
11:24token. Bob's claim can no longer confirm
11:27because output has already been spent by
11:30Alice.
11:32The issue here is Bob has too little
11:34time learning the secret before Alice
11:37refund get confirmed. Bob's confirm
11:39still pending still in pending status
11:42when Alice start competing for the same
11:45funds.
11:47Now let's work through a BTC order
11:50sniping case from our audits.
11:56This marketplace let user buy and sell
11:58BRC-20 tokens for BTC.
12:00Here a seller has list tokens at a great
12:03price. The transfers inscription on the
12:05left is used to deliver those token to
12:08the buyer.
12:09The seller submit a signed PSBT to the
12:12marketplace which reserves the listing
12:14for Bob. Bob then add his fund, set sign
12:18his input and broadcast the purchase.
12:22The marketplace sets output zero to Bob
12:25to Bob's address in the PSBT, so that
12:28Bob will receive these tokens.
12:30Because the seller seller signs with C
12:33Cash
12:34uh C Cash Single plus anyone can pay,
12:36their signature protects the payment at
12:39output one, which means the seller can
12:41receive the correct payment, but it
12:44leaves output zero, the inscription
12:46inscription status nation open to
12:48change.
12:51In this diagram, the blue row is Bob's
12:54purchase and the red row is attacker's
12:56competing transaction. The attacker
12:58reuse seller's signature from Bob's
13:01pending transaction. They keep the
13:02seller's input and payment unchanged,
13:05but supply their own BTC and seller send
13:07their inscription to their own address
13:09to replace the original output zero.
13:13Sig C Cash Single plus anyone can pay
13:15allow these changes to happen without
13:17breaking the signature. Both two
13:19purchases notes spend the same uh spend
13:23the same seller output, but only one can
13:25confirm. The attacker offers a high
13:28higher fee so that their transaction are
13:30more likely to be confirmed first.
13:32Therefore, even though marketplace order
13:34matching selected Bob, the transaction
13:36still allow someone else to front run
13:39this purchase.
13:41This finding helps redefine how the
13:43backend order matching works.
13:46To protect the order matching, the
13:48marketplace must bind delivery to Bob
13:51through a required signature or spending
13:53conditions. Changing the recipient must
13:55require a new authorization.
13:58This is the
14:00uh our case about our case study of BTC
14:03Sniping.
14:05Based on our past auditing experience,
14:07we have turned the checklist we use in
14:09our BTC file audits into a library of
14:12skills.
14:13The skill library covers Clarity smart
14:15contract, PSBT signing, BTC
14:18marketplaces, BTC staking and lightning
14:20application security. You can find the
14:23library on GitHub at the link below.
14:25Feel free to try it try it on your own
14:27projects.
14:29That's the end of my talk. Thank you for
14:31listening. My email is on the slide if
14:33you
14:34if you'd like to discuss the work or
14:36share the feedback on the skills with
14:38me.
Source and accuracy details
- Names, organizations, technical terms, code and numbers may be misrecognized.
- Source wording and disfluencies are preserved; no editorial corrections were applied.
- Export contains whole-second cue starts only; cue ends and subsecond timing are unavailable.
- A full caption-track export does not establish that every spoken word is represented.
- Automatic YouTube captions; not human-verified against the audio.
Source export SHA256: bd642084634d2050c68fa5770242e8d992cf5d97e723d1699b2955494a1e731b