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

[Backport] Add coinbase transaction proof to SPV proof #770

Merged

Conversation

lukasz-zimnoch
Copy link
Member

@lukasz-zimnoch lukasz-zimnoch commented Jan 16, 2024

Refs: #769

This pull request backports changes developed as part of GHSA-wg2x-rv86-mmpx to the releases/mainnet/solidity/v1.5.2 branch corresponding to the solidity/v1.5.2 release.

Release solidity/v1.5.2 is a patch branched off from the currently deployed solidity/v1.5.1 version. Version solidity/v1.5.2 could not be branched off directly from main because main contains some features that are not ready for release yet (e.g. removed WalletCoordinator, added deposits with extra data). Those features will be released as solidity/v1.6.0 when the time comes.

lukasz-zimnoch and others added 6 commits January 16, 2024 11:17
Here we cover the `BitcoinTx.validateProof` function
with a test scenario that checks gas consumed during
validation of long SPV proofs. This will help
assessing the cost impact of the additional coinbase
checks.

(cherry picked from commit a8f3b44)
An unusual but valid 64-byte Bitcoin transaction can be used to produce
SPV proofs for different, invalid transactions by treating the
transaction as another node in the merkle tree of the fraudulent
transaction's proof. This exploit can be prevented by checking that the
merkle proof of the coinbase transaction has the same length as the
proof of the transaction of interest.

All transactions in a valid Bitcoin block are on the same level of the
merkle tree, and it is prohibitively difficult to produce a hash
preimage that matches the first 32 bytes of a valid coinbase
transaction. Thus, if such a preimage can be provided, we can trust that
the merkle tree of the coinbase transaction is legitimate, and that the
transaction of interest is valid because it is on the same level of the
tree as the coinbase transaction.

(cherry picked from commit cfdd0b9)
The SPV proof verifier requires coinbase's preimage and
merkle proof from now on. Here we enrich existing test
vectors with this information to make existing unit test
working again.

(cherry picked from commit 381adb9)
The gas cost of `submit*Proof` functions went up
due to the recent changes made in the SPV proof
verifier. This has an impact on the reimbursement
values as gas offsets are no longer accurate.
Here we adjust them to fit into the unit test
boundaries again. Values were determined by
trial and error.

(cherry picked from commit b31abfc)
Here we extend existing unit tests by adding additional
assertions stressing the new coinbase checks added to
the SPV proof verifier.

(cherry picked from commit 742cce3)
The SPV proof verifier requires coinbase's data from now on. Here
we adjust existing integration tests to that requirement.

(cherry picked from commit 664b434)
@lukasz-zimnoch lukasz-zimnoch self-assigned this Jan 16, 2024
@lukasz-zimnoch lukasz-zimnoch added the ⛓️ solidity Solidity contracts label Jan 16, 2024
Copy link

Solidity API documentation preview available in the artifacts of the https://github.com/keep-network/tbtc-v2/actions/runs/7540322442 check.

@lukasz-zimnoch lukasz-zimnoch added this to the solidity/v1.5.2 milestone Jan 16, 2024
@tomaszslabon tomaszslabon merged commit 20a6fb1 into releases/mainnet/solidity/v1.5.2 Jan 16, 2024
36 of 38 checks passed
@tomaszslabon tomaszslabon deleted the backport-GHSA-wg2x-rv86-mmpx branch January 16, 2024 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⛓️ solidity Solidity contracts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants