@keep-network/tbtc-v2 0.1.1-dev.42 → 0.1.1-dev.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/TBTC.json +3 -3
- package/artifacts/TBTCToken.json +3 -3
- package/artifacts/VendingMachine.json +10 -10
- package/artifacts/solcInputs/{002940e9cc8128f6629e90620c66cba5.json → f2c15d3cf1bd9566483f595c5ed30ccc.json} +10 -10
- package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
- package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
- package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +1 -1
- package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +2 -2
- package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
- package/build/contracts/bridge/Bridge.sol/Bridge.json +123 -185
- package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +1 -1
- package/build/contracts/bridge/BridgeState.sol/BridgeState.json +2 -2
- package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +1 -1
- package/build/contracts/bridge/Deposit.sol/Deposit.json +2 -2
- package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +1 -1
- package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.json +2 -2
- package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +1 -1
- package/build/contracts/bridge/Fraud.sol/Fraud.json +2 -54
- package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +1 -1
- package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +1 -1
- package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +2 -2
- package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +4 -0
- package/build/contracts/bridge/{Redeem.sol → Redemption.sol}/OutboundTx.json +3 -3
- package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +4 -0
- package/build/contracts/bridge/Redemption.sol/Redemption.json +92 -0
- package/build/contracts/bridge/Sweep.sol/Sweep.dbg.json +1 -1
- package/build/contracts/bridge/Sweep.sol/Sweep.json +2 -2
- package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
- package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +1 -1
- package/build/contracts/bridge/Wallets.sol/Wallets.json +2 -2
- package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
- package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
- package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
- package/contracts/bridge/BitcoinTx.sol +19 -26
- package/contracts/bridge/Bridge.sol +466 -486
- package/contracts/bridge/BridgeState.sol +5 -23
- package/contracts/bridge/Deposit.sol +22 -0
- package/contracts/bridge/EcdsaLib.sol +15 -0
- package/contracts/bridge/Fraud.sol +17 -14
- package/contracts/bridge/MovingFunds.sol +13 -5
- package/contracts/bridge/{Redeem.sol → Redemption.sol} +13 -6
- package/contracts/bridge/Sweep.sol +13 -5
- package/package.json +1 -1
- package/build/contracts/bridge/Redeem.sol/OutboundTx.dbg.json +0 -4
- package/build/contracts/bridge/Redeem.sol/Redeem.dbg.json +0 -4
- package/build/contracts/bridge/Redeem.sol/Redeem.json +0 -92
|
@@ -18,11 +18,13 @@ pragma solidity ^0.8.9;
|
|
|
18
18
|
import {BTCUtils} from "@keep-network/bitcoin-spv-sol/contracts/BTCUtils.sol";
|
|
19
19
|
import {ValidateSPV} from "@keep-network/bitcoin-spv-sol/contracts/ValidateSPV.sol";
|
|
20
20
|
|
|
21
|
+
import "./BridgeState.sol";
|
|
22
|
+
|
|
21
23
|
/// @title Bitcoin transaction
|
|
22
24
|
/// @notice Allows to reference Bitcoin raw transaction in Solidity.
|
|
23
25
|
/// @dev See https://developer.bitcoin.org/reference/transactions.html#raw-transaction-format
|
|
24
26
|
///
|
|
25
|
-
/// Raw
|
|
27
|
+
/// Raw Bitcoin transaction data:
|
|
26
28
|
///
|
|
27
29
|
/// | Bytes | Name | BTC type | Description |
|
|
28
30
|
/// |--------|--------------|------------------------|---------------------------|
|
|
@@ -80,12 +82,12 @@ library BitcoinTx {
|
|
|
80
82
|
/// @notice Represents Bitcoin transaction data.
|
|
81
83
|
struct Info {
|
|
82
84
|
/// @notice Bitcoin transaction version
|
|
83
|
-
/// @dev `version` from raw
|
|
85
|
+
/// @dev `version` from raw Bitcoin transaction data.
|
|
84
86
|
/// Encoded as 4-bytes signed integer, little endian.
|
|
85
87
|
bytes4 version;
|
|
86
88
|
/// @notice All Bitcoin transaction inputs, prepended by the number of
|
|
87
89
|
/// transaction inputs.
|
|
88
|
-
/// @dev `tx_in_count | tx_in` from raw
|
|
90
|
+
/// @dev `tx_in_count | tx_in` from raw Bitcoin transaction data.
|
|
89
91
|
///
|
|
90
92
|
/// The number of transaction inputs encoded as compactSize
|
|
91
93
|
/// unsigned integer, little-endian.
|
|
@@ -120,17 +122,6 @@ library BitcoinTx {
|
|
|
120
122
|
bytes bitcoinHeaders;
|
|
121
123
|
}
|
|
122
124
|
|
|
123
|
-
/// @notice Determines the difficulty context for a Bitcoin SPV proof.
|
|
124
|
-
struct ProofDifficulty {
|
|
125
|
-
/// @notice Difficulty of the current epoch.
|
|
126
|
-
uint256 currentEpochDifficulty;
|
|
127
|
-
/// @notice Difficulty of the previous epoch.
|
|
128
|
-
uint256 previousEpochDifficulty;
|
|
129
|
-
/// @notice The number of confirmations on the Bitcoin chain required
|
|
130
|
-
/// to successfully evaluate an SPV proof.
|
|
131
|
-
uint256 difficultyFactor;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
125
|
/// @notice Represents info about an unspent transaction output.
|
|
135
126
|
struct UTXO {
|
|
136
127
|
/// @notice Hash of the transaction the output belongs to.
|
|
@@ -156,12 +147,11 @@ library BitcoinTx {
|
|
|
156
147
|
/// Reverts in case the validation or proof verification fail.
|
|
157
148
|
/// @param txInfo Bitcoin transaction data
|
|
158
149
|
/// @param proof Bitcoin proof data
|
|
159
|
-
/// @param proofDifficulty Bitcoin proof difficulty context.
|
|
160
150
|
/// @return txHash Proven 32-byte transaction hash.
|
|
161
151
|
function validateProof(
|
|
152
|
+
BridgeState.Storage storage self,
|
|
162
153
|
Info calldata txInfo,
|
|
163
|
-
Proof calldata proof
|
|
164
|
-
ProofDifficulty memory proofDifficulty
|
|
154
|
+
Proof calldata proof
|
|
165
155
|
) internal view returns (bytes32 txHash) {
|
|
166
156
|
require(
|
|
167
157
|
txInfo.inputVector.validateVin(),
|
|
@@ -190,7 +180,7 @@ library BitcoinTx {
|
|
|
190
180
|
"Tx merkle proof is not valid for provided header and tx hash"
|
|
191
181
|
);
|
|
192
182
|
|
|
193
|
-
evaluateProofDifficulty(proof.bitcoinHeaders
|
|
183
|
+
evaluateProofDifficulty(self, proof.bitcoinHeaders);
|
|
194
184
|
|
|
195
185
|
return txHash;
|
|
196
186
|
}
|
|
@@ -200,20 +190,23 @@ library BitcoinTx {
|
|
|
200
190
|
/// Reverts in case the evaluation fails.
|
|
201
191
|
/// @param bitcoinHeaders Bitcoin headers chain being part of the SPV
|
|
202
192
|
/// proof. Used to extract the observed proof difficulty
|
|
203
|
-
/// @param proofDifficulty Bitcoin proof difficulty context.
|
|
204
193
|
function evaluateProofDifficulty(
|
|
205
|
-
|
|
206
|
-
|
|
194
|
+
BridgeState.Storage storage self,
|
|
195
|
+
bytes memory bitcoinHeaders
|
|
207
196
|
) internal view {
|
|
197
|
+
IRelay relay = self.relay;
|
|
198
|
+
uint256 currentEpochDifficulty = relay.getCurrentEpochDifficulty();
|
|
199
|
+
uint256 previousEpochDifficulty = relay.getPrevEpochDifficulty();
|
|
200
|
+
|
|
208
201
|
uint256 requestedDiff = 0;
|
|
209
202
|
uint256 firstHeaderDiff = bitcoinHeaders
|
|
210
203
|
.extractTarget()
|
|
211
204
|
.calculateDifficulty();
|
|
212
205
|
|
|
213
|
-
if (firstHeaderDiff ==
|
|
214
|
-
requestedDiff =
|
|
215
|
-
} else if (firstHeaderDiff ==
|
|
216
|
-
requestedDiff =
|
|
206
|
+
if (firstHeaderDiff == currentEpochDifficulty) {
|
|
207
|
+
requestedDiff = currentEpochDifficulty;
|
|
208
|
+
} else if (firstHeaderDiff == previousEpochDifficulty) {
|
|
209
|
+
requestedDiff = previousEpochDifficulty;
|
|
217
210
|
} else {
|
|
218
211
|
revert("Not at current or previous difficulty");
|
|
219
212
|
}
|
|
@@ -234,7 +227,7 @@ library BitcoinTx {
|
|
|
234
227
|
);
|
|
235
228
|
|
|
236
229
|
require(
|
|
237
|
-
observedDiff >= requestedDiff *
|
|
230
|
+
observedDiff >= requestedDiff * self.txProofDifficultyFactor,
|
|
238
231
|
"Insufficient accumulated difficulty in header chain"
|
|
239
232
|
);
|
|
240
233
|
}
|