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