Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaf-Node weakness in Bitcoin Merkle Tree Design #1073

Closed
nud3l opened this issue May 29, 2023 · 0 comments · Fixed by #1112
Closed

Leaf-Node weakness in Bitcoin Merkle Tree Design #1073

nud3l opened this issue May 29, 2023 · 0 comments · Fixed by #1112
Assignees
Labels
bug Something isn't working

Comments

@nud3l
Copy link
Member

nud3l commented May 29, 2023

Describe the bug
The Bitcoin protocol has a flaw when validating consensus in SPV mode. There is a potential type confusion between Merkle tree middle and leaf nodes. This can lead to two kinds of attacks: leaf transactions that are incorrectly parsed as middle nodes, and middle nodes that are incorrectly parsed as transactions. The vulnerability was made public and analyzed in this post: https://bitslog.com/2018/06/09/leaf-node-weakness-in-bitcoin-merkle-tree-design/

To Reproduce
It seems that InterBTC has no protection against the Bitcoin vulnerability of considering a transaction to be a middle node, creating a vulnerability in the bridge. The cost of the attack is estimated in 2^70 hashing operations, which is very high, but not prohibitive. In fact, if the attacker can peg-in tens of million of dollars in fake BTCs, and then peg-out real BTCs, the cost of pre-processing may be minor, specially for well-funded hacking groups. For comparison, the Bitcoin network performs 2^70 hashes every 10 seconds, and 1% of the Bitcoin hashing network performs 2^70 operations in only 15 minutes. Since we don't have the resources to perform the pre-processing, we can't demonstrate an exploit for this vulnerability in the InterBTC flaw. However, code inspection of the InterBTC code shows no protection measure against this attack.

Since the impact on interBTC is dependent on the economic damage on the system, we first need to determine potential damage. This is where it gets a little bit tricky. Technically, all of the iBTC in the system is currently at risk. However, we would argue that unless the exploit is economically feasible, the likelihood of the exploit is low. When assessing whether or not the exploit is profitable, it is important to note that a transaction is required per vault. The maximum amounts they could steal in a single transaction are currently:

  • Max. damage if we consider iBTC issuable in a single request: Interlay: 19.567 BTC Kintsugi: 0.368 BTC
  • Max. damage if we consider iBTC redeemable in a single request: Interlay: 18.24 BTC Kintsugi: 5.831 kBTC

So the maximum amount an attacker could steal with one transaction is less than 20 BTC. It is difficult to estimate the cost it would take to run this exploit - we'd have to make some assumptions. However, if we use this estimate: the total amount of iBTC stored in the vaults is currently 66 iBTC, which is probably similar to the cost of the attack pre-processing; then the cost is more than the potential gain of running the exploit. On top of that, if we understand correctly, there is the significant amount of bitcoin that the attacker needs to hold, plus the hashing power needed to produce a bitcoin block as a miner. Taking all of this into account, it seems to us that the attack is not currently economically feasible.

As such, we would argue that the current economic damage is zero.

Workaround
A mitigation for this attack is to limit issue, redeem, and replace requests and execution to at most 20 Bitcoin per request.

Expected behavior
The code should check that no tree node in the Merkle tree is a valid Bitcoin transaction. The Rootstock sidechain is protected from this attack by checking that no tree node built during the Merkle tree inclusion proof is a valid Bitcoin transaction. The code for this check can be found here: https://github.com/rsksmart/bitcoinj-thin/blob/ab624f09a77e48e04542a06d4a392c952b86aff2/src/main/java/co/rsk/bitcoinj/core/PartialMerkleTree.java#L230

@nud3l nud3l added the bug Something isn't working label May 29, 2023
@nud3l nud3l added this to the Interlay De-Fi Hub milestone May 29, 2023
@nud3l nud3l added this to Backlog May 29, 2023
@github-project-automation github-project-automation bot moved this to New 🆕 in Backlog May 29, 2023
@nud3l nud3l changed the title Restrict issues to be 20 BTC max Leaf-Node weakness in Bitcoin Merkle Tree Design May 29, 2023
@nud3l nud3l moved this from New 🆕 to Todo ⏳ in Backlog May 29, 2023
@nud3l nud3l moved this from Todo ⏳ to New 🆕 in Backlog May 29, 2023
@nud3l nud3l moved this from New 🆕 to Todo ⏳ in Backlog Jun 5, 2023
@tomjeatt tomjeatt removed this from the Interlay De-Fi Hub milestone Jun 28, 2023
@github-project-automation github-project-automation bot moved this from Todo ⏳ to Done ✅ in Backlog Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants