Skip to content

Commit

Permalink
Merge branch 'main' into remove-goerli
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-zimnoch committed Jan 29, 2024
2 parents aeef5c1 + fe5180c commit 7e243df
Show file tree
Hide file tree
Showing 60 changed files with 5,277 additions and 897 deletions.
700 changes: 700 additions & 0 deletions solidity/.openzeppelin/mainnet.json

Large diffs are not rendered by default.

24 changes: 19 additions & 5 deletions solidity/contracts/bridge/BitcoinTx.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ library BitcoinTx {
/// @notice Single byte-string of 80-byte bitcoin headers,
/// lowest height first.
bytes bitcoinHeaders;
/// @notice The sha256 preimage of the coinbase tx hash
/// i.e. the sha256 hash of the coinbase transaction.
bytes32 coinbasePreimage;
/// @notice The merkle proof of the coinbase transaction.
bytes coinbaseProof;
// This struct doesn't contain `__gap` property as the structure is not
// stored, it is used as a function's calldata argument.
}
Expand Down Expand Up @@ -186,6 +191,10 @@ library BitcoinTx {
txInfo.outputVector.validateVout(),
"Invalid output vector provided"
);
require(
proof.merkleProof.length == proof.coinbaseProof.length,
"Tx not on same level of merkle tree as coinbase"
);

txHash = abi
.encodePacked(
Expand All @@ -196,15 +205,20 @@ library BitcoinTx {
)
.hash256View();

bytes32 root = proof.bitcoinHeaders.extractMerkleRootLE();

require(
txHash.prove(
proof.bitcoinHeaders.extractMerkleRootLE(),
proof.merkleProof,
proof.txIndexInBlock
),
txHash.prove(root, proof.merkleProof, proof.txIndexInBlock),
"Tx merkle proof is not valid for provided header and tx hash"
);

bytes32 coinbaseHash = sha256(abi.encodePacked(proof.coinbasePreimage));

require(
coinbaseHash.prove(root, proof.coinbaseProof, 0),
"Coinbase merkle proof is not valid for provided header and hash"
);

evaluateProofDifficulty(self, proof.bitcoinHeaders);

return txHash;
Expand Down
8 changes: 4 additions & 4 deletions solidity/contracts/maintainer/MaintainerProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ contract MaintainerProxy is Ownable, Reimbursable {
constructor(Bridge _bridge, ReimbursementPool _reimbursementPool) {
bridge = _bridge;
reimbursementPool = _reimbursementPool;
submitDepositSweepProofGasOffset = 27000;
submitRedemptionProofGasOffset = 0;
submitDepositSweepProofGasOffset = 30000;
submitRedemptionProofGasOffset = 4000;
resetMovingFundsTimeoutGasOffset = 1000;
submitMovingFundsProofGasOffset = 15000;
submitMovingFundsProofGasOffset = 20000;
notifyMovingFundsBelowDustGasOffset = 3500;
submitMovedFundsSweepProofGasOffset = 22000;
submitMovedFundsSweepProofGasOffset = 26000;
requestNewWalletGasOffset = 3500;
notifyWalletCloseableGasOffset = 4000;
notifyWalletClosingPeriodElapsedGasOffset = 3000;
Expand Down
24 changes: 24 additions & 0 deletions solidity/contracts/test/TestBitcoinTx.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity 0.8.17;

import "../bridge/BitcoinTx.sol";
import "../bridge/BridgeState.sol";
import "../bridge/IRelay.sol";

contract TestBitcoinTx {
BridgeState.Storage internal self;

event ProofValidated(bytes32 txHash);

constructor(address _relay) {
self.relay = IRelay(_relay);
}

function validateProof(
BitcoinTx.Info calldata txInfo,
BitcoinTx.Proof calldata proof
) external {
emit ProofValidated(BitcoinTx.validateProof(self, txInfo, proof));
}
}
50 changes: 45 additions & 5 deletions solidity/deployments/mainnet/Bridge.json
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,16 @@
"internalType": "bytes",
"name": "bitcoinHeaders",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "coinbasePreimage",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "coinbaseProof",
"type": "bytes"
}
],
"internalType": "struct BitcoinTx.Proof",
Expand Down Expand Up @@ -1915,6 +1925,16 @@
"internalType": "bytes",
"name": "bitcoinHeaders",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "coinbasePreimage",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "coinbaseProof",
"type": "bytes"
}
],
"internalType": "struct BitcoinTx.Proof",
Expand Down Expand Up @@ -2044,6 +2064,16 @@
"internalType": "bytes",
"name": "bitcoinHeaders",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "coinbasePreimage",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "coinbaseProof",
"type": "bytes"
}
],
"internalType": "struct BitcoinTx.Proof",
Expand Down Expand Up @@ -2128,6 +2158,16 @@
"internalType": "bytes",
"name": "bitcoinHeaders",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "coinbasePreimage",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "coinbaseProof",
"type": "bytes"
}
],
"internalType": "struct BitcoinTx.Proof",
Expand Down Expand Up @@ -2610,15 +2650,15 @@
"status": 1,
"byzantium": true
},
"numDeployments": 2,
"numDeployments": 3,
"libraries": {
"Deposit": "0x1Ac1841a47054E070236F1664991e52c30C04dC5",
"DepositSweep": "0xE6F919e62c370Ef04EDF4cA5E2a901Ea1aa87085",
"Redemption": "0xfa4FC53BEB5B7721d173342FfC24058e9D47a1Ff",
"DepositSweep": "0x53f26BfE896CC4267720cDAf64E9A0c8Fa8f13c2",
"Redemption": "0x7D807e9CE1ef73048FEe9A4214e75e894ea25914",
"Wallets": "0xC67913137429985416DbCe28D9fa9ec960BA47BF",
"Fraud": "0xd040Def4bC6372Cd27b433288008aDCe7c9de71C",
"MovingFunds": "0xB857117ae7639255d7305DdbC7346b4a644CA432"
"MovingFunds": "0x3106675EDE4A64d70131247466FD8704A3d42123"
},
"implementation": "0x8D014903BF7867260584d714e11809fea5293234",
"implementation": "0x3A4a6919F70e5b0aA32401747C471eCfe2322C1b",
"devdoc": "Contract deployed as upgradable proxy"
}
28 changes: 14 additions & 14 deletions solidity/deployments/mainnet/DepositSweep.json

Large diffs are not rendered by default.

144 changes: 92 additions & 52 deletions solidity/deployments/mainnet/MaintainerProxy.json

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions solidity/deployments/mainnet/MovingFunds.json

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions solidity/deployments/mainnet/Redemption.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

88 changes: 84 additions & 4 deletions solidity/export.json
Original file line number Diff line number Diff line change
Expand Up @@ -2331,6 +2331,16 @@
"internalType": "bytes",
"name": "bitcoinHeaders",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "coinbasePreimage",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "coinbaseProof",
"type": "bytes"
}
],
"internalType": "struct BitcoinTx.Proof",
Expand Down Expand Up @@ -2455,6 +2465,16 @@
"internalType": "bytes",
"name": "bitcoinHeaders",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "coinbasePreimage",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "coinbaseProof",
"type": "bytes"
}
],
"internalType": "struct BitcoinTx.Proof",
Expand Down Expand Up @@ -2584,6 +2604,16 @@
"internalType": "bytes",
"name": "bitcoinHeaders",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "coinbasePreimage",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "coinbaseProof",
"type": "bytes"
}
],
"internalType": "struct BitcoinTx.Proof",
Expand Down Expand Up @@ -2668,6 +2698,16 @@
"internalType": "bytes",
"name": "bitcoinHeaders",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "coinbasePreimage",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "coinbaseProof",
"type": "bytes"
}
],
"internalType": "struct BitcoinTx.Proof",
Expand Down Expand Up @@ -6249,7 +6289,7 @@
]
},
"DepositSweep": {
"address": "0xE6F919e62c370Ef04EDF4cA5E2a901Ea1aa87085",
"address": "0x53f26BfE896CC4267720cDAf64E9A0c8Fa8f13c2",
"abi": [
{
"anonymous": false,
Expand Down Expand Up @@ -7166,7 +7206,7 @@
]
},
"MaintainerProxy": {
"address": "0xcF29Ff894674775841F60Aa2a3c373DE27A8df2b",
"address": "0x535E01F948458E0b64F9dB2A01Da6F32E240140f",
"abi": [
{
"inputs": [
Expand Down Expand Up @@ -7812,6 +7852,16 @@
"internalType": "bytes",
"name": "bitcoinHeaders",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "coinbasePreimage",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "coinbaseProof",
"type": "bytes"
}
],
"internalType": "struct BitcoinTx.Proof",
Expand Down Expand Up @@ -7909,6 +7959,16 @@
"internalType": "bytes",
"name": "bitcoinHeaders",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "coinbasePreimage",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "coinbaseProof",
"type": "bytes"
}
],
"internalType": "struct BitcoinTx.Proof",
Expand Down Expand Up @@ -8001,6 +8061,16 @@
"internalType": "bytes",
"name": "bitcoinHeaders",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "coinbasePreimage",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "coinbaseProof",
"type": "bytes"
}
],
"internalType": "struct BitcoinTx.Proof",
Expand Down Expand Up @@ -8098,6 +8168,16 @@
"internalType": "bytes",
"name": "bitcoinHeaders",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "coinbasePreimage",
"type": "bytes32"
},
{
"internalType": "bytes",
"name": "coinbaseProof",
"type": "bytes"
}
],
"internalType": "struct BitcoinTx.Proof",
Expand Down Expand Up @@ -8300,7 +8380,7 @@
]
},
"MovingFunds": {
"address": "0xB857117ae7639255d7305DdbC7346b4a644CA432",
"address": "0x3106675EDE4A64d70131247466FD8704A3d42123",
"abi": [
{
"anonymous": false,
Expand Down Expand Up @@ -8432,7 +8512,7 @@
]
},
"Redemption": {
"address": "0xfa4FC53BEB5B7721d173342FfC24058e9D47a1Ff",
"address": "0x7D807e9CE1ef73048FEe9A4214e75e894ea25914",
"abi": [
{
"anonymous": false,
Expand Down
Loading

0 comments on commit 7e243df

Please sign in to comment.