@keep-network/tbtc-v2 0.1.1-dev.5 → 0.1.1-dev.50

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.
Files changed (95) hide show
  1. package/README.adoc +12 -0
  2. package/artifacts/Bank.json +752 -0
  3. package/artifacts/Bridge.json +3271 -0
  4. package/artifacts/Deposit.json +117 -0
  5. package/artifacts/EcdsaDkgValidator.json +532 -0
  6. package/artifacts/EcdsaInactivity.json +156 -0
  7. package/artifacts/Fraud.json +153 -0
  8. package/artifacts/KeepRegistry.json +99 -0
  9. package/artifacts/KeepStake.json +286 -0
  10. package/artifacts/KeepToken.json +711 -0
  11. package/artifacts/KeepTokenStaking.json +483 -0
  12. package/artifacts/MovingFunds.json +160 -0
  13. package/artifacts/NuCypherStakingEscrow.json +256 -0
  14. package/artifacts/NuCypherToken.json +711 -0
  15. package/artifacts/RandomBeaconStub.json +141 -0
  16. package/artifacts/Redemption.json +161 -0
  17. package/artifacts/ReimbursementPool.json +509 -0
  18. package/artifacts/Relay.json +123 -0
  19. package/artifacts/SortitionPool.json +944 -0
  20. package/artifacts/Sweep.json +76 -0
  21. package/artifacts/T.json +1148 -0
  22. package/artifacts/TBTC.json +27 -26
  23. package/artifacts/TBTCToken.json +27 -26
  24. package/artifacts/TokenStaking.json +2288 -0
  25. package/artifacts/TokenholderGovernor.json +1795 -0
  26. package/artifacts/TokenholderTimelock.json +1058 -0
  27. package/artifacts/VendingMachine.json +30 -29
  28. package/artifacts/VendingMachineKeep.json +400 -0
  29. package/artifacts/VendingMachineNuCypher.json +400 -0
  30. package/artifacts/WalletRegistry.json +2709 -0
  31. package/artifacts/WalletRegistryGovernance.json +2364 -0
  32. package/artifacts/Wallets.json +186 -0
  33. package/artifacts/solcInputs/b0c3ed0992bd570aaaee717425c37538.json +218 -0
  34. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
  35. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.json +2 -2
  36. package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
  37. package/build/contracts/bank/Bank.sol/Bank.json +20 -2
  38. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +4 -0
  39. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +10 -0
  40. package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
  41. package/build/contracts/bridge/Bridge.sol/Bridge.json +2093 -77
  42. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +4 -0
  43. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +166 -0
  44. package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +4 -0
  45. package/build/contracts/bridge/Deposit.sol/Deposit.json +72 -0
  46. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +4 -0
  47. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.json +10 -0
  48. package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +4 -0
  49. package/build/contracts/bridge/Fraud.sol/Fraud.json +86 -0
  50. package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +4 -0
  51. package/build/contracts/bridge/IRelay.sol/IRelay.json +37 -0
  52. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +4 -0
  53. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +81 -0
  54. package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +4 -0
  55. package/build/contracts/bridge/Redemption.sol/OutboundTx.json +10 -0
  56. package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +4 -0
  57. package/build/contracts/bridge/Redemption.sol/Redemption.json +92 -0
  58. package/build/contracts/bridge/Sweep.sol/Sweep.dbg.json +4 -0
  59. package/build/contracts/bridge/Sweep.sol/Sweep.json +30 -0
  60. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
  61. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.json +2 -2
  62. package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +4 -0
  63. package/build/contracts/bridge/Wallets.sol/Wallets.json +112 -0
  64. package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
  65. package/build/contracts/token/TBTC.sol/TBTC.json +2 -2
  66. package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
  67. package/build/contracts/vault/IVault.sol/IVault.json +19 -1
  68. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
  69. package/build/contracts/vault/TBTCVault.sol/TBTCVault.json +36 -18
  70. package/contracts/GovernanceUtils.sol +1 -1
  71. package/contracts/bank/Bank.sol +34 -18
  72. package/contracts/bridge/BitcoinTx.sol +234 -0
  73. package/contracts/bridge/Bridge.sol +1274 -126
  74. package/contracts/bridge/BridgeState.sol +538 -0
  75. package/contracts/bridge/Deposit.sol +266 -0
  76. package/contracts/bridge/EcdsaLib.sol +45 -0
  77. package/contracts/bridge/Fraud.sol +488 -0
  78. package/contracts/bridge/IRelay.sol +28 -0
  79. package/contracts/bridge/MovingFunds.sol +511 -0
  80. package/contracts/bridge/Redemption.sol +846 -0
  81. package/contracts/bridge/Sweep.sol +514 -0
  82. package/contracts/bridge/VendingMachine.sol +1 -1
  83. package/contracts/bridge/Wallets.sol +551 -0
  84. package/contracts/token/TBTC.sol +1 -1
  85. package/contracts/vault/IVault.sol +32 -10
  86. package/contracts/vault/TBTCVault.sol +20 -2
  87. package/deploy/00_resolve_relay.ts +28 -0
  88. package/deploy/04_deploy_bank.ts +27 -0
  89. package/deploy/05_deploy_bridge.ts +64 -0
  90. package/deploy/06_bank_update_bridge.ts +19 -0
  91. package/deploy/07_transfer_ownership.ts +15 -0
  92. package/deploy/08_transfer_governance.ts +20 -0
  93. package/export.json +15173 -472
  94. package/package.json +27 -23
  95. package/artifacts/solcInputs/d71966212a658480bad5748ad85b1396.json +0 -116
@@ -13,109 +13,276 @@
13
13
  // ▐████▌ ▐████▌
14
14
  // ▐████▌ ▐████▌
15
15
 
16
- pragma solidity 0.8.4;
16
+ pragma solidity ^0.8.9;
17
17
 
18
- /// @title BTC Bridge
19
- /// @notice Bridge manages BTC deposit and redemption and is increasing and
18
+ import "@keep-network/random-beacon/contracts/Governable.sol";
19
+
20
+ import {IWalletOwner as EcdsaWalletOwner} from "@keep-network/ecdsa/contracts/api/IWalletOwner.sol";
21
+
22
+ import "./IRelay.sol";
23
+ import "./BridgeState.sol";
24
+ import "./Deposit.sol";
25
+ import "./Sweep.sol";
26
+ import "./Redemption.sol";
27
+ import "./BitcoinTx.sol";
28
+ import "./EcdsaLib.sol";
29
+ import "./Wallets.sol";
30
+ import "./Fraud.sol";
31
+ import "./MovingFunds.sol";
32
+
33
+ import "../bank/Bank.sol";
34
+
35
+ /// @title Bitcoin Bridge
36
+ /// @notice Bridge manages BTC deposit and redemption flow and is increasing and
20
37
  /// decreasing balances in the Bank as a result of BTC deposit and
21
- /// redemption operations.
38
+ /// redemption operations performed by depositors and redeemers.
39
+ ///
40
+ /// Depositors send BTC funds to the most recently created off-chain
41
+ /// ECDSA wallet of the bridge using pay-to-script-hash (P2SH) or
42
+ /// pay-to-witness-script-hash (P2WSH) containing hashed information
43
+ /// about the depositor’s Ethereum address. Then, the depositor reveals
44
+ /// their Ethereum address along with their deposit blinding factor,
45
+ /// refund public key hash and refund locktime to the Bridge on Ethereum
46
+ /// chain. The off-chain ECDSA wallet listens for these sorts of
47
+ /// messages and when it gets one, it checks the Bitcoin network to make
48
+ /// sure the deposit lines up. If it does, the off-chain ECDSA wallet
49
+ /// may decide to pick the deposit transaction for sweeping, and when
50
+ /// the sweep operation is confirmed on the Bitcoin network, the ECDSA
51
+ /// wallet informs the Bridge about the sweep increasing appropriate
52
+ /// balances in the Bank.
53
+ /// @dev Bridge is an upgradeable component of the Bank. The order of
54
+ /// functionalities in this contract is: deposit, sweep, redemption,
55
+ /// moving funds, wallet lifecycle, frauds, parameters.
22
56
  ///
23
- /// Depositors send BTC funds to the most-recently-created-wallet of the
24
- /// bridge using pay-to-script-hash (P2SH) which contains hashed
25
- /// information about the depositor’s minting Ethereum address. Then,
26
- /// the depositor reveals their desired Ethereum minting address to the
27
- /// Ethereum chain. The Bridge listens for these sorts of messages and
28
- /// when it gets one, it checks the Bitcoin network to make sure the
29
- /// funds line up. If they do, the off-chain wallet may decide to pick
30
- /// this transaction for sweeping, and when the sweep operation is
31
- /// confirmed on the Bitcoin network, the wallet informs the Bridge
32
- /// about the sweep increasing appropriate balances in the Bank.
33
- /// @dev Bridge is an upgradeable component of the Bank.
34
- contract Bridge {
35
- struct DepositInfo {
36
- uint64 amount;
37
- address vault;
38
- uint32 revealedAt;
39
- }
40
-
41
- /// @notice Collection of all unswept deposits indexed by
42
- /// keccak256(fundingTxHash | fundingOutputIndex | depositorAddress).
43
- /// This mapping may contain valid and invalid deposits and the
44
- /// wallet is responsible for validating them before attempting to
45
- /// execute a sweep.
46
- mapping(uint256 => DepositInfo) public unswept;
57
+ /// TODO: Revisit all events and look which parameters should be indexed.
58
+ /// TODO: Align the convention around `param` and `dev` endings. They should
59
+ /// not have a punctuation mark.
60
+ contract Bridge is Governable, EcdsaWalletOwner {
61
+ using BridgeState for BridgeState.Storage;
62
+ using Deposit for BridgeState.Storage;
63
+ using Sweep for BridgeState.Storage;
64
+ using Redemption for BridgeState.Storage;
65
+ using MovingFunds for BridgeState.Storage;
66
+ using Wallets for BridgeState.Storage;
67
+ using Fraud for BridgeState.Storage;
68
+
69
+ BridgeState.Storage internal self;
47
70
 
48
71
  event DepositRevealed(
49
- uint256 depositId,
50
72
  bytes32 fundingTxHash,
51
- uint8 fundingOutputIndex,
73
+ uint32 fundingOutputIndex,
52
74
  address depositor,
53
- uint64 blindingFactor,
54
- bytes refundPubKey,
55
75
  uint64 amount,
76
+ bytes8 blindingFactor,
77
+ bytes20 walletPubKeyHash,
78
+ bytes20 refundPubKeyHash,
79
+ bytes4 refundLocktime,
56
80
  address vault
57
81
  );
58
82
 
59
- /// @notice Used by the depositor to reveal information about their P2SH
83
+ event DepositsSwept(bytes20 walletPubKeyHash, bytes32 sweepTxHash);
84
+
85
+ event RedemptionRequested(
86
+ bytes20 walletPubKeyHash,
87
+ bytes redeemerOutputScript,
88
+ address redeemer,
89
+ uint64 requestedAmount,
90
+ uint64 treasuryFee,
91
+ uint64 txMaxFee
92
+ );
93
+
94
+ event RedemptionsCompleted(
95
+ bytes20 walletPubKeyHash,
96
+ bytes32 redemptionTxHash
97
+ );
98
+
99
+ event RedemptionTimedOut(
100
+ bytes20 walletPubKeyHash,
101
+ bytes redeemerOutputScript
102
+ );
103
+
104
+ event WalletMovingFunds(
105
+ bytes32 indexed ecdsaWalletID,
106
+ bytes20 indexed walletPubKeyHash
107
+ );
108
+
109
+ event MovingFundsCommitmentSubmitted(
110
+ bytes20 walletPubKeyHash,
111
+ bytes20[] targetWallets,
112
+ address submitter
113
+ );
114
+
115
+ event MovingFundsCompleted(
116
+ bytes20 walletPubKeyHash,
117
+ bytes32 movingFundsTxHash
118
+ );
119
+
120
+ event MovingFundsTimedOut(bytes20 walletPubKeyHash);
121
+
122
+ event MovingFundsBelowDustReported(bytes20 walletPubKeyHash);
123
+
124
+ event NewWalletRequested();
125
+
126
+ event NewWalletRegistered(
127
+ bytes32 indexed ecdsaWalletID,
128
+ bytes20 indexed walletPubKeyHash
129
+ );
130
+
131
+ event WalletClosing(
132
+ bytes32 indexed ecdsaWalletID,
133
+ bytes20 indexed walletPubKeyHash
134
+ );
135
+
136
+ event WalletClosed(
137
+ bytes32 indexed ecdsaWalletID,
138
+ bytes20 indexed walletPubKeyHash
139
+ );
140
+
141
+ event WalletTerminated(
142
+ bytes32 indexed ecdsaWalletID,
143
+ bytes20 indexed walletPubKeyHash
144
+ );
145
+
146
+ event FraudChallengeSubmitted(
147
+ bytes20 walletPubKeyHash,
148
+ bytes32 sighash,
149
+ uint8 v,
150
+ bytes32 r,
151
+ bytes32 s
152
+ );
153
+
154
+ event FraudChallengeDefeated(bytes20 walletPubKeyHash, bytes32 sighash);
155
+
156
+ event FraudChallengeDefeatTimedOut(
157
+ bytes20 walletPubKeyHash,
158
+ bytes32 sighash
159
+ );
160
+
161
+ event VaultStatusUpdated(address indexed vault, bool isTrusted);
162
+
163
+ event DepositParametersUpdated(
164
+ uint64 depositDustThreshold,
165
+ uint64 depositTreasuryFeeDivisor,
166
+ uint64 depositTxMaxFee
167
+ );
168
+
169
+ event RedemptionParametersUpdated(
170
+ uint64 redemptionDustThreshold,
171
+ uint64 redemptionTreasuryFeeDivisor,
172
+ uint64 redemptionTxMaxFee,
173
+ uint256 redemptionTimeout
174
+ );
175
+
176
+ event MovingFundsParametersUpdated(
177
+ uint64 movingFundsTxMaxTotalFee,
178
+ uint32 movingFundsTimeout,
179
+ uint64 movingFundsDustThreshold
180
+ );
181
+
182
+ event WalletParametersUpdated(
183
+ uint32 walletCreationPeriod,
184
+ uint64 walletMinBtcBalance,
185
+ uint64 walletMaxBtcBalance,
186
+ uint32 walletMaxAge,
187
+ uint64 walletMaxBtcTransfer,
188
+ uint32 walletClosingPeriod
189
+ );
190
+
191
+ event FraudParametersUpdated(
192
+ uint256 fraudSlashingAmount,
193
+ uint256 fraudNotifierRewardMultiplier,
194
+ uint256 fraudChallengeDefeatTimeout,
195
+ uint256 fraudChallengeDepositAmount
196
+ );
197
+
198
+ constructor(
199
+ address _bank,
200
+ address _relay,
201
+ address _treasury,
202
+ address _ecdsaWalletRegistry,
203
+ uint256 _txProofDifficultyFactor
204
+ ) {
205
+ require(_bank != address(0), "Bank address cannot be zero");
206
+ self.bank = Bank(_bank);
207
+
208
+ require(_relay != address(0), "Relay address cannot be zero");
209
+ self.relay = IRelay(_relay);
210
+
211
+ require(
212
+ _ecdsaWalletRegistry != address(0),
213
+ "ECDSA Wallet Registry address cannot be zero"
214
+ );
215
+ self.ecdsaWalletRegistry = EcdsaWalletRegistry(_ecdsaWalletRegistry);
216
+
217
+ require(_treasury != address(0), "Treasury address cannot be zero");
218
+ self.treasury = _treasury;
219
+
220
+ self.txProofDifficultyFactor = _txProofDifficultyFactor;
221
+
222
+ // TODO: Revisit initial values.
223
+ self.depositDustThreshold = 1000000; // 1000000 satoshi = 0.01 BTC
224
+ self.depositTxMaxFee = 10000; // 10000 satoshi
225
+ self.depositTreasuryFeeDivisor = 2000; // 1/2000 == 5bps == 0.05% == 0.0005
226
+ self.redemptionDustThreshold = 1000000; // 1000000 satoshi = 0.01 BTC
227
+ self.redemptionTreasuryFeeDivisor = 2000; // 1/2000 == 5bps == 0.05% == 0.0005
228
+ self.redemptionTxMaxFee = 10000; // 10000 satoshi
229
+ self.redemptionTimeout = 172800; // 48 hours
230
+ self.movingFundsTxMaxTotalFee = 10000; // 10000 satoshi
231
+ self.movingFundsTimeout = 7 days;
232
+ self.movingFundsDustThreshold = 20000; // 20000 satoshi
233
+ self.fraudSlashingAmount = 10000 * 1e18; // 10000 T
234
+ self.fraudNotifierRewardMultiplier = 100; // 100%
235
+ self.fraudChallengeDefeatTimeout = 7 days;
236
+ self.fraudChallengeDepositAmount = 2 ether;
237
+ self.walletCreationPeriod = 1 weeks;
238
+ self.walletMinBtcBalance = 1e8; // 1 BTC
239
+ self.walletMaxBtcBalance = 10e8; // 10 BTC
240
+ self.walletMaxAge = 26 weeks; // ~6 months
241
+ self.walletMaxBtcTransfer = 10e8; // 10 BTC
242
+ self.walletClosingPeriod = 40 days;
243
+
244
+ _transferGovernance(msg.sender);
245
+ }
246
+
247
+ /// @notice Used by the depositor to reveal information about their P2(W)SH
60
248
  /// Bitcoin deposit to the Bridge on Ethereum chain. The off-chain
61
249
  /// wallet listens for revealed deposit events and may decide to
62
250
  /// include the revealed deposit in the next executed sweep.
63
251
  /// Information about the Bitcoin deposit can be revealed before or
64
- /// after the Bitcoin transaction with P2SH deposit is mined on the
65
- /// Bitcoin chain.
66
- /// @param fundingTxHash The BTC transaction hash containing BTC P2SH
67
- /// deposit funding transaction
68
- /// @param fundingOutputIndex The index of the transaction output in the
69
- /// funding TX with P2SH deposit, max 256
70
- /// @param blindingFactor The blinding factor used in the BTC P2SH deposit,
71
- /// max 2^64
72
- /// @param refundPubKey The refund pub key used in the BTC P2SH deposit
73
- /// @param amount The amount locked in the BTC P2SH deposit
74
- /// @param vault Bank vault to which the swept deposit should be routed
75
- /// @dev Requirements:
76
- /// - `msg.sender` must be the Ethereum address used in the P2SH BTC deposit,
77
- /// - `blindingFactor` must be the blinding factor used in the P2SH BTC deposit,
78
- /// - `refundPubKey` must be the refund pub key used in the P2SH BTC deposit,
79
- /// - `amount` must be the same as locked in the P2SH BTC deposit,
252
+ /// after the Bitcoin transaction with P2(W)SH deposit is mined on
253
+ /// the Bitcoin chain. Worth noting, the gas cost of this function
254
+ /// scales with the number of P2(W)SH transaction inputs and
255
+ /// outputs. The deposit may be routed to one of the trusted vaults.
256
+ /// When a deposit is routed to a vault, vault gets notified when
257
+ /// the deposit gets swept and it may execute the appropriate action.
258
+ /// @param fundingTx Bitcoin funding transaction data, see `BitcoinTx.Info`
259
+ /// @param reveal Deposit reveal data, see `RevealInfo struct
260
+ /// @dev Requirements:
261
+ /// - `reveal.walletPubKeyHash` must identify a `Live` wallet
262
+ /// - `reveal.vault` must be 0x0 or point to a trusted vault
263
+ /// - `reveal.fundingOutputIndex` must point to the actual P2(W)SH
264
+ /// output of the BTC deposit transaction
265
+ /// - `reveal.depositor` must be the Ethereum address used in the
266
+ /// P2(W)SH BTC deposit transaction,
267
+ /// - `reveal.blindingFactor` must be the blinding factor used in the
268
+ /// P2(W)SH BTC deposit transaction,
269
+ /// - `reveal.walletPubKeyHash` must be the wallet pub key hash used in
270
+ /// the P2(W)SH BTC deposit transaction,
271
+ /// - `reveal.refundPubKeyHash` must be the refund pub key hash used in
272
+ /// the P2(W)SH BTC deposit transaction,
273
+ /// - `reveal.refundLocktime` must be the refund locktime used in the
274
+ /// P2(W)SH BTC deposit transaction,
80
275
  /// - BTC deposit for the given `fundingTxHash`, `fundingOutputIndex`
81
- /// can be revealed by `msg.sender` only one time.
276
+ /// can be revealed only one time.
82
277
  ///
83
278
  /// If any of these requirements is not met, the wallet _must_ refuse
84
279
  /// to sweep the deposit and the depositor has to wait until the
85
280
  /// deposit script unlocks to receive their BTC back.
86
281
  function revealDeposit(
87
- bytes32 fundingTxHash,
88
- uint8 fundingOutputIndex,
89
- uint64 blindingFactor,
90
- bytes calldata refundPubKey,
91
- uint64 amount,
92
- address vault
282
+ BitcoinTx.Info calldata fundingTx,
283
+ Deposit.DepositRevealInfo calldata reveal
93
284
  ) external {
94
- uint256 depositId =
95
- uint256(
96
- keccak256(
97
- abi.encode(fundingTxHash, fundingOutputIndex, msg.sender)
98
- )
99
- );
100
-
101
- DepositInfo storage deposit = unswept[depositId];
102
- require(deposit.revealedAt == 0, "Deposit already revealed");
103
-
104
- deposit.amount = amount;
105
- deposit.vault = vault;
106
- /* solhint-disable-next-line not-rely-on-time */
107
- deposit.revealedAt = uint32(block.timestamp);
108
-
109
- emit DepositRevealed(
110
- depositId,
111
- fundingTxHash,
112
- fundingOutputIndex,
113
- msg.sender,
114
- blindingFactor,
115
- refundPubKey,
116
- amount,
117
- vault
118
- );
285
+ self.revealDeposit(fundingTx, reveal);
119
286
  }
120
287
 
121
288
  /// @notice Used by the wallet to prove the BTC deposit sweep transaction
@@ -125,52 +292,1033 @@ contract Bridge {
125
292
  /// The function is performing Bank balance updates by first
126
293
  /// computing the Bitcoin fee for the sweep transaction. The fee is
127
294
  /// divided evenly between all swept deposits. Each depositor
128
- /// receives a balance in the bank equal to the amount they have
129
- /// declared during the reveal transaction, minus their fee share.
295
+ /// receives a balance in the bank equal to the amount inferred
296
+ /// during the reveal transaction, minus their fee share.
130
297
  ///
131
298
  /// It is possible to prove the given sweep only one time.
132
- /// @param txVersion Transaction version number (4-byte LE)
133
- /// @param txInputVector All transaction inputs prepended by the number of
134
- /// inputs encoded as a VarInt, max 0xFC(252) inputs
135
- /// @param txOutput Single sweep transaction output
136
- /// @param txLocktime Final 4 bytes of the transaction
137
- /// @param merkleProof The merkle proof of transaction inclusion in a block
138
- /// @param txIndexInBlock Transaction index in the block (0-indexed)
139
- /// @param bitcoinHeaders Single bytestring of 80-byte bitcoin headers,
140
- /// lowest height first
141
- function sweep(
142
- bytes4 txVersion,
143
- bytes memory txInputVector,
144
- bytes memory txOutput,
145
- bytes4 txLocktime,
146
- bytes memory merkleProof,
147
- uint256 txIndexInBlock,
148
- bytes memory bitcoinHeaders
299
+ /// @param sweepTx Bitcoin sweep transaction data
300
+ /// @param sweepProof Bitcoin sweep proof data
301
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
302
+ /// the Ethereum chain. If no main UTXO exists for the given wallet,
303
+ /// this parameter is ignored
304
+ /// @dev Requirements:
305
+ /// - `sweepTx` components must match the expected structure. See
306
+ /// `BitcoinTx.Info` docs for reference. Their values must exactly
307
+ /// correspond to appropriate Bitcoin transaction fields to produce
308
+ /// a provable transaction hash.
309
+ /// - The `sweepTx` should represent a Bitcoin transaction with 1..n
310
+ /// inputs. If the wallet has no main UTXO, all n inputs should
311
+ /// correspond to P2(W)SH revealed deposits UTXOs. If the wallet has
312
+ /// an existing main UTXO, one of the n inputs must point to that
313
+ /// main UTXO and remaining n-1 inputs should correspond to P2(W)SH
314
+ /// revealed deposits UTXOs. That transaction must have only
315
+ /// one P2(W)PKH output locking funds on the 20-byte wallet public
316
+ /// key hash.
317
+ /// - `sweepProof` components must match the expected structure. See
318
+ /// `BitcoinTx.Proof` docs for reference. The `bitcoinHeaders`
319
+ /// field must contain a valid number of block headers, not less
320
+ /// than the `txProofDifficultyFactor` contract constant.
321
+ /// - `mainUtxo` components must point to the recent main UTXO
322
+ /// of the given wallet, as currently known on the Ethereum chain.
323
+ /// If there is no main UTXO, this parameter is ignored.
324
+ function submitSweepProof(
325
+ BitcoinTx.Info calldata sweepTx,
326
+ BitcoinTx.Proof calldata sweepProof,
327
+ BitcoinTx.UTXO calldata mainUtxo
328
+ ) external {
329
+ self.submitSweepProof(sweepTx, sweepProof, mainUtxo);
330
+ }
331
+
332
+ /// @notice Requests redemption of the given amount from the specified
333
+ /// wallet to the redeemer Bitcoin output script.
334
+ /// @param walletPubKeyHash The 20-byte wallet public key hash (computed
335
+ /// using Bitcoin HASH160 over the compressed ECDSA public key)
336
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
337
+ /// the Ethereum chain
338
+ /// @param redeemerOutputScript The redeemer's length-prefixed output
339
+ /// script (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
340
+ /// redeemed BTC
341
+ /// @param amount Requested amount in satoshi. This is also the TBTC amount
342
+ /// that is taken from redeemer's balance in the Bank upon request.
343
+ /// Once the request is handled, the actual amount of BTC locked
344
+ /// on the redeemer output script will be always lower than this value
345
+ /// since the treasury and Bitcoin transaction fees must be incurred.
346
+ /// The minimal amount satisfying the request can be computed as:
347
+ /// `amount - (amount / redemptionTreasuryFeeDivisor) - redemptionTxMaxFee`.
348
+ /// Fees values are taken at the moment of request creation.
349
+ /// @dev Requirements:
350
+ /// - Wallet behind `walletPubKeyHash` must be live
351
+ /// - `mainUtxo` components must point to the recent main UTXO
352
+ /// of the given wallet, as currently known on the Ethereum chain.
353
+ /// - `redeemerOutputScript` must be a proper Bitcoin script
354
+ /// - `redeemerOutputScript` cannot have wallet PKH as payload
355
+ /// - `amount` must be above or equal the `redemptionDustThreshold`
356
+ /// - Given `walletPubKeyHash` and `redeemerOutputScript` pair can be
357
+ /// used for only one pending request at the same time
358
+ /// - Wallet must have enough Bitcoin balance to proceed the request
359
+ /// - Redeemer must make an allowance in the Bank that the Bridge
360
+ /// contract can spend the given `amount`.
361
+ function requestRedemption(
362
+ bytes20 walletPubKeyHash,
363
+ BitcoinTx.UTXO calldata mainUtxo,
364
+ bytes calldata redeemerOutputScript,
365
+ uint64 amount
366
+ ) external {
367
+ self.requestRedemption(
368
+ walletPubKeyHash,
369
+ mainUtxo,
370
+ redeemerOutputScript,
371
+ amount
372
+ );
373
+ }
374
+
375
+ /// @notice Used by the wallet to prove the BTC redemption transaction
376
+ /// and to make the necessary bookkeeping. Redemption is only
377
+ /// accepted if it satisfies SPV proof.
378
+ ///
379
+ /// The function is performing Bank balance updates by burning
380
+ /// the total redeemed Bitcoin amount from Bridge balance and
381
+ /// transferring the treasury fee sum to the treasury address.
382
+ ///
383
+ /// It is possible to prove the given redemption only one time.
384
+ /// @param redemptionTx Bitcoin redemption transaction data
385
+ /// @param redemptionProof Bitcoin redemption proof data
386
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
387
+ /// the Ethereum chain
388
+ /// @param walletPubKeyHash 20-byte public key hash (computed using Bitcoin
389
+ /// HASH160 over the compressed ECDSA public key) of the wallet which
390
+ /// performed the redemption transaction
391
+ /// @dev Requirements:
392
+ /// - `redemptionTx` components must match the expected structure. See
393
+ /// `BitcoinTx.Info` docs for reference. Their values must exactly
394
+ /// correspond to appropriate Bitcoin transaction fields to produce
395
+ /// a provable transaction hash.
396
+ /// - The `redemptionTx` should represent a Bitcoin transaction with
397
+ /// exactly 1 input that refers to the wallet's main UTXO. That
398
+ /// transaction should have 1..n outputs handling existing pending
399
+ /// redemption requests or pointing to reported timed out requests.
400
+ /// There can be also 1 optional output representing the
401
+ /// change and pointing back to the 20-byte wallet public key hash.
402
+ /// The change should be always present if the redeemed value sum
403
+ /// is lower than the total wallet's BTC balance.
404
+ /// - `redemptionProof` components must match the expected structure.
405
+ /// See `BitcoinTx.Proof` docs for reference. The `bitcoinHeaders`
406
+ /// field must contain a valid number of block headers, not less
407
+ /// than the `txProofDifficultyFactor` contract constant.
408
+ /// - `mainUtxo` components must point to the recent main UTXO
409
+ /// of the given wallet, as currently known on the Ethereum chain.
410
+ /// Additionally, the recent main UTXO on Ethereum must be set.
411
+ /// - `walletPubKeyHash` must be connected with the main UTXO used
412
+ /// as transaction single input.
413
+ /// Other remarks:
414
+ /// - Putting the change output as the first transaction output can
415
+ /// save some gas because the output processing loop begins each
416
+ /// iteration by checking whether the given output is the change
417
+ /// thus uses some gas for making the comparison. Once the change
418
+ /// is identified, that check is omitted in further iterations.
419
+ function submitRedemptionProof(
420
+ BitcoinTx.Info calldata redemptionTx,
421
+ BitcoinTx.Proof calldata redemptionProof,
422
+ BitcoinTx.UTXO calldata mainUtxo,
423
+ bytes20 walletPubKeyHash
424
+ ) external {
425
+ self.submitRedemptionProof(
426
+ redemptionTx,
427
+ redemptionProof,
428
+ mainUtxo,
429
+ walletPubKeyHash
430
+ );
431
+ }
432
+
433
+ /// @notice Notifies that there is a pending redemption request associated
434
+ /// with the given wallet, that has timed out. The redemption
435
+ /// request is identified by the key built as
436
+ /// `keccak256(walletPubKeyHash | redeemerOutputScript)`.
437
+ /// The results of calling this function: the pending redemptions
438
+ /// value for the wallet will be decreased by the requested amount
439
+ /// (minus treasury fee), the tokens taken from the redeemer on
440
+ /// redemption request will be returned to the redeemer, the request
441
+ /// will be moved from pending redemptions to timed-out redemptions.
442
+ /// If the state of the wallet is `Live` or `MovingFunds`, the
443
+ /// wallet operators will be slashed.
444
+ /// Additionally, if the state of wallet is `Live`, the wallet will
445
+ /// be closed or marked as `MovingFunds` (depending on the presence
446
+ /// or absence of the wallet's main UTXO) and the wallet will no
447
+ /// longer be marked as the active wallet (if it was marked as such).
448
+ /// @param walletPubKeyHash 20-byte public key hash of the wallet
449
+ /// @param redeemerOutputScript The redeemer's length-prefixed output
450
+ /// script (P2PKH, P2WPKH, P2SH or P2WSH)
451
+ /// @dev Requirements:
452
+ /// - The redemption request identified by `walletPubKeyHash` and
453
+ /// `redeemerOutputScript` must exist
454
+ /// - The amount of time defined by `redemptionTimeout` must have
455
+ /// passed since the redemption was requested (the request must be
456
+ /// timed-out).
457
+ function notifyRedemptionTimeout(
458
+ bytes20 walletPubKeyHash,
459
+ bytes calldata redeemerOutputScript
460
+ ) external {
461
+ self.notifyRedemptionTimeout(walletPubKeyHash, redeemerOutputScript);
462
+ }
463
+
464
+ /// @notice Submits the moving funds target wallets commitment.
465
+ /// Once all requirements are met, that function registers the
466
+ /// target wallets commitment and opens the way for moving funds
467
+ /// proof submission.
468
+ /// @param walletPubKeyHash 20-byte public key hash of the source wallet
469
+ /// @param walletMainUtxo Data of the source wallet's main UTXO, as
470
+ /// currently known on the Ethereum chain
471
+ /// @param walletMembersIDs Identifiers of the source wallet signing group
472
+ /// members
473
+ /// @param walletMemberIndex Position of the caller in the source wallet
474
+ /// signing group members list
475
+ /// @param targetWallets List of 20-byte public key hashes of the target
476
+ /// wallets that the source wallet commits to move the funds to
477
+ /// @dev Requirements:
478
+ /// - The source wallet must be in the MovingFunds state
479
+ /// - The source wallet must not have pending redemption requests
480
+ /// - The source wallet must not have submitted its commitment already
481
+ /// - The expression `keccak256(abi.encode(walletMembersIDs))` must
482
+ /// be exactly the same as the hash stored under `membersIdsHash`
483
+ /// for the given source wallet in the ECDSA registry. Those IDs are
484
+ /// not directly stored in the contract for gas efficiency purposes
485
+ /// but they can be read from appropriate `DkgResultSubmitted`
486
+ /// and `DkgResultApproved` events.
487
+ /// - The `walletMemberIndex` must be in range [1, walletMembersIDs.length]
488
+ /// - The caller must be the member of the source wallet signing group
489
+ /// at the position indicated by `walletMemberIndex` parameter
490
+ /// - The `walletMainUtxo` components must point to the recent main
491
+ /// UTXO of the source wallet, as currently known on the Ethereum
492
+ /// chain.
493
+ /// - Source wallet BTC balance must be greater than zero
494
+ /// - At least one Live wallet must exist in the system
495
+ /// - Submitted target wallets count must match the expected count
496
+ /// `N = min(liveWalletsCount, ceil(walletBtcBalance / walletMaxBtcTransfer))`
497
+ /// where `N > 0`
498
+ /// - Each target wallet must be not equal to the source wallet
499
+ /// - Each target wallet must follow the expected order i.e. all
500
+ /// target wallets 20-byte public key hashes represented as numbers
501
+ /// must form a strictly increasing sequence without duplicates.
502
+ /// - Each target wallet must be in Live state
503
+ function submitMovingFundsCommitment(
504
+ bytes20 walletPubKeyHash,
505
+ BitcoinTx.UTXO calldata walletMainUtxo,
506
+ uint32[] calldata walletMembersIDs,
507
+ uint256 walletMemberIndex,
508
+ bytes20[] calldata targetWallets
509
+ ) external {
510
+ self.submitMovingFundsCommitment(
511
+ walletPubKeyHash,
512
+ walletMainUtxo,
513
+ walletMembersIDs,
514
+ walletMemberIndex,
515
+ targetWallets
516
+ );
517
+ }
518
+
519
+ /// @notice Used by the wallet to prove the BTC moving funds transaction
520
+ /// and to make the necessary state changes. Moving funds is only
521
+ /// accepted if it satisfies SPV proof.
522
+ ///
523
+ /// The function validates the moving funds transaction structure
524
+ /// by checking if it actually spends the main UTXO of the declared
525
+ /// wallet and locks the value on the pre-committed target wallets
526
+ /// using a reasonable transaction fee. If all preconditions are
527
+ /// met, this functions closes the source wallet.
528
+ ///
529
+ /// It is possible to prove the given moving funds transaction only
530
+ /// one time.
531
+ /// @param movingFundsTx Bitcoin moving funds transaction data
532
+ /// @param movingFundsProof Bitcoin moving funds proof data
533
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
534
+ /// the Ethereum chain
535
+ /// @param walletPubKeyHash 20-byte public key hash (computed using Bitcoin
536
+ /// HASH160 over the compressed ECDSA public key) of the wallet
537
+ /// which performed the moving funds transaction
538
+ /// @dev Requirements:
539
+ /// - `movingFundsTx` components must match the expected structure. See
540
+ /// `BitcoinTx.Info` docs for reference. Their values must exactly
541
+ /// correspond to appropriate Bitcoin transaction fields to produce
542
+ /// a provable transaction hash.
543
+ /// - The `movingFundsTx` should represent a Bitcoin transaction with
544
+ /// exactly 1 input that refers to the wallet's main UTXO. That
545
+ /// transaction should have 1..n outputs corresponding to the
546
+ /// pre-committed target wallets. Outputs must be ordered in the
547
+ /// same way as their corresponding target wallets are ordered
548
+ /// within the target wallets commitment.
549
+ /// - `movingFundsProof` components must match the expected structure.
550
+ /// See `BitcoinTx.Proof` docs for reference. The `bitcoinHeaders`
551
+ /// field must contain a valid number of block headers, not less
552
+ /// than the `txProofDifficultyFactor` contract constant.
553
+ /// - `mainUtxo` components must point to the recent main UTXO
554
+ /// of the given wallet, as currently known on the Ethereum chain.
555
+ /// Additionally, the recent main UTXO on Ethereum must be set.
556
+ /// - `walletPubKeyHash` must be connected with the main UTXO used
557
+ /// as transaction single input.
558
+ /// - The wallet that `walletPubKeyHash` points to must be in the
559
+ /// MovingFunds state.
560
+ /// - The target wallets commitment must be submitted by the wallet
561
+ /// that `walletPubKeyHash` points to.
562
+ /// - The total Bitcoin transaction fee must be lesser or equal
563
+ /// to `movingFundsTxMaxTotalFee` governable parameter.
564
+ function submitMovingFundsProof(
565
+ BitcoinTx.Info calldata movingFundsTx,
566
+ BitcoinTx.Proof calldata movingFundsProof,
567
+ BitcoinTx.UTXO calldata mainUtxo,
568
+ bytes20 walletPubKeyHash
569
+ ) external {
570
+ self.submitMovingFundsProof(
571
+ movingFundsTx,
572
+ movingFundsProof,
573
+ mainUtxo,
574
+ walletPubKeyHash
575
+ );
576
+ }
577
+
578
+ /// @notice Notifies about a timed out moving funds process. Terminates
579
+ /// the wallet and slashes signing group members as a result.
580
+ /// @param walletPubKeyHash 20-byte public key hash of the wallet
581
+ /// @dev Requirements:
582
+ /// - The wallet must be in the MovingFunds state
583
+ /// - The moving funds timeout must be actually exceeded
584
+ function notifyMovingFundsTimeout(bytes20 walletPubKeyHash) external {
585
+ self.notifyMovingFundsTimeout(walletPubKeyHash);
586
+ }
587
+
588
+ /// @notice Notifies about a moving funds wallet whose BTC balance is
589
+ /// below the moving funds dust threshold. Ends the moving funds
590
+ /// process and begins wallet closing immediately.
591
+ /// @param walletPubKeyHash 20-byte public key hash of the wallet
592
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known
593
+ /// on the Ethereum chain.
594
+ /// @dev Requirements:
595
+ /// - The wallet must be in the MovingFunds state
596
+ /// - The `mainUtxo` components must point to the recent main UTXO
597
+ /// of the given wallet, as currently known on the Ethereum chain.
598
+ /// If the wallet has no main UTXO, this parameter can be empty as it
599
+ /// is ignored.
600
+ /// - The wallet BTC balance must be below the moving funds threshold
601
+ function notifyMovingFundsBelowDust(
602
+ bytes20 walletPubKeyHash,
603
+ BitcoinTx.UTXO calldata mainUtxo
149
604
  ) external {
150
- // TODO We need to read `fundingTxHash`, `fundingOutputIndex` and
151
- // P2SH script depositor address from `txInputVector`.
152
- // We then hash them to obtain deposit identifier and read
153
- // DepositInfo. From DepositInfo we know what amount was declared
154
- // by the depositor in their reveal transaction and we use that
155
- // amount to update their Bank balance, minus fee.
156
- //
157
- // TODO We need to validate if the sum in the output minus the
158
- // amount from the previous wallet balance input minus fees is
159
- // equal to the amount by which Bank balances were increased.
160
- //
161
- // TODO We need to validate txOutput to see if the balance was not
162
- // transferred away from the wallet before increasing balances in
163
- // the bank.
164
- //
165
- // TODO Delete deposit from unswept mapping or mark it as swept
166
- // depending on the gas costs. Alternativly, do not allow to
167
- // use the same TX input vector twice. Sweep should be provable
168
- // only one time.
169
- }
170
-
171
- // TODO It is possible a malicious wallet can sweep deposits that can not
172
- // be later proved on Ethereum. For example, a deposit with
173
- // an incorrect amount revealed. We need to provide a function for honest
174
- // depositors, next to sweep, to prove their swept balances on Ethereum
175
- // selectively, based on deposits they have earlier received.
605
+ self.notifyMovingFundsBelowDust(walletPubKeyHash, mainUtxo);
606
+ }
607
+
608
+ /// @notice Requests creation of a new wallet. This function just
609
+ /// forms a request and the creation process is performed
610
+ /// asynchronously. Once a wallet is created, the ECDSA Wallet
611
+ /// Registry will notify this contract by calling the
612
+ /// `__ecdsaWalletCreatedCallback` function.
613
+ /// @param activeWalletMainUtxo Data of the active wallet's main UTXO, as
614
+ /// currently known on the Ethereum chain.
615
+ /// @dev Requirements:
616
+ /// - `activeWalletMainUtxo` components must point to the recent main
617
+ /// UTXO of the given active wallet, as currently known on the
618
+ /// Ethereum chain. If there is no active wallet at the moment, or
619
+ /// the active wallet has no main UTXO, this parameter can be
620
+ /// empty as it is ignored.
621
+ /// - Wallet creation must not be in progress
622
+ /// - If the active wallet is set, one of the following
623
+ /// conditions must be true:
624
+ /// - The active wallet BTC balance is above the minimum threshold
625
+ /// and the active wallet is old enough, i.e. the creation period
626
+ /// was elapsed since its creation time
627
+ /// - The active wallet BTC balance is above the maximum threshold
628
+ function requestNewWallet(BitcoinTx.UTXO calldata activeWalletMainUtxo)
629
+ external
630
+ {
631
+ self.requestNewWallet(activeWalletMainUtxo);
632
+ }
633
+
634
+ /// @notice A callback function that is called by the ECDSA Wallet Registry
635
+ /// once a new ECDSA wallet is created.
636
+ /// @param ecdsaWalletID Wallet's unique identifier.
637
+ /// @param publicKeyX Wallet's public key's X coordinate.
638
+ /// @param publicKeyY Wallet's public key's Y coordinate.
639
+ /// @dev Requirements:
640
+ /// - The only caller authorized to call this function is `registry`
641
+ /// - Given wallet data must not belong to an already registered wallet
642
+ function __ecdsaWalletCreatedCallback(
643
+ bytes32 ecdsaWalletID,
644
+ bytes32 publicKeyX,
645
+ bytes32 publicKeyY
646
+ ) external override {
647
+ self.registerNewWallet(ecdsaWalletID, publicKeyX, publicKeyY);
648
+ }
649
+
650
+ /// @notice A callback function that is called by the ECDSA Wallet Registry
651
+ /// once a wallet heartbeat failure is detected.
652
+ /// @param publicKeyX Wallet's public key's X coordinate
653
+ /// @param publicKeyY Wallet's public key's Y coordinate
654
+ /// @dev Requirements:
655
+ /// - The only caller authorized to call this function is `registry`
656
+ /// - Wallet must be in Live state
657
+ function __ecdsaWalletHeartbeatFailedCallback(
658
+ bytes32,
659
+ bytes32 publicKeyX,
660
+ bytes32 publicKeyY
661
+ ) external override {
662
+ self.notifyWalletHeartbeatFailed(publicKeyX, publicKeyY);
663
+ }
664
+
665
+ /// @notice Notifies that the wallet is either old enough or has too few
666
+ /// satoshi left and qualifies to be closed.
667
+ /// @param walletPubKeyHash 20-byte public key hash of the wallet
668
+ /// @param walletMainUtxo Data of the wallet's main UTXO, as currently
669
+ /// known on the Ethereum chain.
670
+ /// @dev Requirements:
671
+ /// - Wallet must not be set as the current active wallet
672
+ /// - Wallet must exceed the wallet maximum age OR the wallet BTC
673
+ /// balance must be lesser than the minimum threshold. If the latter
674
+ /// case is true, the `walletMainUtxo` components must point to the
675
+ /// recent main UTXO of the given wallet, as currently known on the
676
+ /// Ethereum chain. If the wallet has no main UTXO, this parameter
677
+ /// can be empty as it is ignored since the wallet balance is
678
+ /// assumed to be zero.
679
+ /// - Wallet must be in Live state
680
+ function notifyCloseableWallet(
681
+ bytes20 walletPubKeyHash,
682
+ BitcoinTx.UTXO calldata walletMainUtxo
683
+ ) external {
684
+ self.notifyCloseableWallet(walletPubKeyHash, walletMainUtxo);
685
+ }
686
+
687
+ /// @notice Notifies about the end of the closing period for the given wallet.
688
+ /// Closes the wallet ultimately and notifies the ECDSA registry
689
+ /// about this fact.
690
+ /// @param walletPubKeyHash 20-byte public key hash of the wallet
691
+ /// @dev Requirements:
692
+ /// - The wallet must be in the Closing state
693
+ /// - The wallet closing period must have elapsed
694
+ function notifyWalletClosingPeriodElapsed(bytes20 walletPubKeyHash)
695
+ external
696
+ {
697
+ self.notifyWalletClosingPeriodElapsed(walletPubKeyHash);
698
+ }
699
+
700
+ /// @notice Submits a fraud challenge indicating that a UTXO being under
701
+ /// wallet control was unlocked by the wallet but was not used
702
+ /// according to the protocol rules. That means the wallet signed
703
+ /// a transaction input pointing to that UTXO and there is a unique
704
+ /// sighash and signature pair associated with that input. This
705
+ /// function uses those parameters to create a fraud accusation that
706
+ /// proves a given transaction input unlocking the given UTXO was
707
+ /// actually signed by the wallet. This function cannot determine
708
+ /// whether the transaction was actually broadcast and the input was
709
+ /// consumed in a fraudulent way so it just opens a challenge period
710
+ /// during which the wallet can defeat the challenge by submitting
711
+ /// proof of a transaction that consumes the given input according
712
+ /// to protocol rules. To prevent spurious allegations, the caller
713
+ /// must deposit ETH that is returned back upon justified fraud
714
+ /// challenge or confiscated otherwise.
715
+ ///@param walletPublicKey The public key of the wallet in the uncompressed
716
+ /// and unprefixed format (64 bytes)
717
+ /// @param sighash The hash that was used to produce the ECDSA signature
718
+ /// that is the subject of the fraud claim. This hash is constructed
719
+ /// by applying double SHA-256 over a serialized subset of the
720
+ /// transaction. The exact subset used as hash preimage depends on
721
+ /// the transaction input the signature is produced for. See BIP-143
722
+ /// for reference
723
+ /// @param signature Bitcoin signature in the R/S/V format
724
+ /// @dev Requirements:
725
+ /// - Wallet behind `walletPublicKey` must be in Live or MovingFunds
726
+ /// or Closing state
727
+ /// - The challenger must send appropriate amount of ETH used as
728
+ /// fraud challenge deposit
729
+ /// - The signature (represented by r, s and v) must be generated by
730
+ /// the wallet behind `walletPubKey` during signing of `sighash`
731
+ /// - Wallet can be challenged for the given signature only once
732
+ function submitFraudChallenge(
733
+ bytes calldata walletPublicKey,
734
+ bytes32 sighash,
735
+ BitcoinTx.RSVSignature calldata signature
736
+ ) external payable {
737
+ self.submitFraudChallenge(walletPublicKey, sighash, signature);
738
+ }
739
+
740
+ /// @notice Allows to defeat a pending fraud challenge against a wallet if
741
+ /// the transaction that spends the UTXO follows the protocol rules.
742
+ /// In order to defeat the challenge the same `walletPublicKey` and
743
+ /// signature (represented by `r`, `s` and `v`) must be provided as
744
+ /// were used to calculate the sighash during input signing.
745
+ /// The fraud challenge defeat attempt will only succeed if the
746
+ /// inputs in the preimage are considered honestly spent by the
747
+ /// wallet. Therefore the transaction spending the UTXO must be
748
+ /// proven in the Bridge before a challenge defeat is called.
749
+ /// If successfully defeated, the fraud challenge is marked as
750
+ /// resolved and the amount of ether deposited by the challenger is
751
+ /// sent to the treasury.
752
+ /// @param walletPublicKey The public key of the wallet in the uncompressed
753
+ /// and unprefixed format (64 bytes)
754
+ /// @param preimage The preimage which produces sighash used to generate the
755
+ /// ECDSA signature that is the subject of the fraud claim. It is a
756
+ /// serialized subset of the transaction. The exact subset used as
757
+ /// the preimage depends on the transaction input the signature is
758
+ /// produced for. See BIP-143 for reference
759
+ /// @param witness Flag indicating whether the preimage was produced for a
760
+ /// witness input. True for witness, false for non-witness input
761
+ /// @dev Requirements:
762
+ /// - `walletPublicKey` and `sighash` calculated as `hash256(preimage)`
763
+ /// must identify an open fraud challenge
764
+ /// - the preimage must be a valid preimage of a transaction generated
765
+ /// according to the protocol rules and already proved in the Bridge
766
+ /// - before a defeat attempt is made the transaction that spends the
767
+ /// given UTXO must be proven in the Bridge
768
+ function defeatFraudChallenge(
769
+ bytes calldata walletPublicKey,
770
+ bytes calldata preimage,
771
+ bool witness
772
+ ) external {
773
+ self.defeatFraudChallenge(walletPublicKey, preimage, witness);
774
+ }
775
+
776
+ /// @notice Notifies about defeat timeout for the given fraud challenge.
777
+ /// Can be called only if there was a fraud challenge identified by
778
+ /// the provided `walletPublicKey` and `sighash` and it was not
779
+ /// defeated on time. The amount of time that needs to pass after
780
+ /// a fraud challenge is reported is indicated by the
781
+ /// `challengeDefeatTimeout`. After a successful fraud challenge
782
+ /// defeat timeout notification the fraud challenge is marked as
783
+ /// resolved, the stake of each operator is slashed, the ether
784
+ /// deposited is returned to the challenger and the challenger is
785
+ /// rewarded.
786
+ /// @param walletPublicKey The public key of the wallet in the uncompressed
787
+ /// and unprefixed format (64 bytes)
788
+ /// @param sighash The hash that was used to produce the ECDSA signature
789
+ /// that is the subject of the fraud claim. This hash is constructed
790
+ /// by applying double SHA-256 over a serialized subset of the
791
+ /// transaction. The exact subset used as hash preimage depends on
792
+ /// the transaction input the signature is produced for. See BIP-143
793
+ /// for reference
794
+ /// @dev Requirements:
795
+ /// - `walletPublicKey`and `sighash` must identify an open fraud
796
+ /// challenge
797
+ /// - the amount of time indicated by `challengeDefeatTimeout` must
798
+ /// pass after the challenge was reported
799
+ function notifyFraudChallengeDefeatTimeout(
800
+ bytes calldata walletPublicKey,
801
+ bytes32 sighash
802
+ ) external {
803
+ self.notifyFraudChallengeDefeatTimeout(walletPublicKey, sighash);
804
+ }
805
+
806
+ /// @notice Allows the Governance to mark the given vault address as trusted
807
+ /// or no longer trusted. Vaults are not trusted by default.
808
+ /// Trusted vault must meet the following criteria:
809
+ /// - `IVault.receiveBalanceIncrease` must have a known, low gas
810
+ /// cost.
811
+ /// - `IVault.receiveBalanceIncrease` must never revert.
812
+ /// @dev Without restricting reveal only to trusted vaults, malicious
813
+ /// vaults not meeting the criteria would be able to nuke sweep proof
814
+ /// transactions executed by ECDSA wallet with deposits routed to
815
+ /// them.
816
+ /// @param vault The address of the vault
817
+ /// @param isTrusted flag indicating whether the vault is trusted or not
818
+ /// @dev Can only be called by the Governance.
819
+ function setVaultStatus(address vault, bool isTrusted)
820
+ external
821
+ onlyGovernance
822
+ {
823
+ self.isVaultTrusted[vault] = isTrusted;
824
+ emit VaultStatusUpdated(vault, isTrusted);
825
+ }
826
+
827
+ /// @notice Updates parameters of deposits.
828
+ /// @param depositDustThreshold New value of the deposit dust threshold in
829
+ /// satoshis. It is the minimal amount that can be requested to
830
+ //// deposit. Value of this parameter must take into account the value
831
+ /// of `depositTreasuryFeeDivisor` and `depositTxMaxFee` parameters
832
+ /// in order to make requests that can incur the treasury and
833
+ /// transaction fee and still satisfy the depositor
834
+ /// @param depositTreasuryFeeDivisor New value of the treasury fee divisor.
835
+ /// It is the divisor used to compute the treasury fee taken from
836
+ /// each deposit and transferred to the treasury upon sweep proof
837
+ /// submission. That fee is computed as follows:
838
+ /// `treasuryFee = depositedAmount / depositTreasuryFeeDivisor`
839
+ /// For example, if the treasury fee needs to be 2% of each deposit,
840
+ /// the `depositTreasuryFeeDivisor` should be set to `50`
841
+ /// because `1/50 = 0.02 = 2%`
842
+ /// @param depositTxMaxFee New value of the deposit tx max fee in satoshis.
843
+ /// It is the maximum amount of BTC transaction fee that can
844
+ /// be incurred by each swept deposit being part of the given sweep
845
+ /// transaction. If the maximum BTC transaction fee is exceeded,
846
+ /// such transaction is considered a fraud
847
+ /// @dev Requirements:
848
+ /// - Deposit dust threshold must be greater than zero
849
+ /// - Deposit treasury fee divisor must be greater than zero
850
+ /// - Deposit transaction max fee must be greater than zero
851
+ function updateDepositParameters(
852
+ uint64 depositDustThreshold,
853
+ uint64 depositTreasuryFeeDivisor,
854
+ uint64 depositTxMaxFee
855
+ ) external onlyGovernance {
856
+ self.updateDepositParameters(
857
+ depositDustThreshold,
858
+ depositTreasuryFeeDivisor,
859
+ depositTxMaxFee
860
+ );
861
+ }
862
+
863
+ /// @notice Updates parameters of redemptions.
864
+ /// @param redemptionDustThreshold New value of the redemption dust
865
+ /// threshold in satoshis. It is the minimal amount that can be
866
+ /// requested for redemption. Value of this parameter must take into
867
+ /// account the value of `redemptionTreasuryFeeDivisor` and
868
+ /// `redemptionTxMaxFee` parameters in order to make requests that
869
+ /// can incur the treasury and transaction fee and still satisfy the
870
+ /// redeemer.
871
+ /// @param redemptionTreasuryFeeDivisor New value of the redemption
872
+ /// treasury fee divisor. It is the divisor used to compute the
873
+ /// treasury fee taken from each redemption request and transferred
874
+ /// to the treasury upon successful request finalization. That fee is
875
+ /// computed as follows:
876
+ /// `treasuryFee = requestedAmount / redemptionTreasuryFeeDivisor`
877
+ /// For example, if the treasury fee needs to be 2% of each
878
+ /// redemption request, the `redemptionTreasuryFeeDivisor` should
879
+ /// be set to `50` because `1/50 = 0.02 = 2%`.
880
+ /// @param redemptionTxMaxFee New value of the redemption transaction max
881
+ /// fee in satoshis. It is the maximum amount of BTC transaction fee
882
+ /// that can be incurred by each redemption request being part of the
883
+ /// given redemption transaction. If the maximum BTC transaction fee
884
+ /// is exceeded, such transaction is considered a fraud.
885
+ /// This is a per-redemption output max fee for the redemption
886
+ /// transaction.
887
+ /// @param redemptionTimeout New value of the redemption timeout in seconds.
888
+ /// It is the time after which the redemption request can be reported
889
+ /// as timed out. It is counted from the moment when the redemption
890
+ /// request was created via `requestRedemption` call. Reported timed
891
+ /// out requests are cancelled and locked TBTC is returned to the
892
+ /// redeemer in full amount.
893
+ /// @dev Requirements:
894
+ /// - Redemption dust threshold must be greater than zero
895
+ /// - Redemption treasury fee divisor must be greater than zero
896
+ /// - Redemption transaction max fee must be greater than zero
897
+ /// - Redemption timeout must be greater than zero
898
+ function updateRedemptionParameters(
899
+ uint64 redemptionDustThreshold,
900
+ uint64 redemptionTreasuryFeeDivisor,
901
+ uint64 redemptionTxMaxFee,
902
+ uint256 redemptionTimeout
903
+ ) external onlyGovernance {
904
+ self.updateRedemptionParameters(
905
+ redemptionDustThreshold,
906
+ redemptionTreasuryFeeDivisor,
907
+ redemptionTxMaxFee,
908
+ redemptionTimeout
909
+ );
910
+ }
911
+
912
+ /// @notice Updates parameters of moving funds.
913
+ /// @param movingFundsTxMaxTotalFee New value of the moving funds transaction
914
+ /// max total fee in satoshis. It is the maximum amount of the total
915
+ /// BTC transaction fee that is acceptable in a single moving funds
916
+ /// transaction. This is a _total_ max fee for the entire moving
917
+ /// funds transaction.
918
+ /// @param movingFundsTimeout New value of the moving funds timeout in
919
+ /// seconds. It is the time after which the moving funds process can
920
+ /// be reported as timed out. It is counted from the moment when the
921
+ /// wallet was requested to move their funds and switched to the
922
+ /// MovingFunds state.
923
+ /// @param movingFundsDustThreshold New value of the moving funds dust
924
+ /// threshold. It is the minimal satoshi amount that makes sense to
925
+ // be transferred during the moving funds process. Moving funds
926
+ // wallets having their BTC balance below that value can begin
927
+ // closing immediately as transferring such a low value may not be
928
+ // possible due to BTC network fees.
929
+ /// @dev Requirements:
930
+ /// - Moving funds transaction max total fee must be greater than zero
931
+ /// - Moving funds timeout must be greater than zero
932
+ /// - Moving funds dust threshold must be greater than zero
933
+ function updateMovingFundsParameters(
934
+ uint64 movingFundsTxMaxTotalFee,
935
+ uint32 movingFundsTimeout,
936
+ uint64 movingFundsDustThreshold
937
+ ) external onlyGovernance {
938
+ self.updateMovingFundsParameters(
939
+ movingFundsTxMaxTotalFee,
940
+ movingFundsTimeout,
941
+ movingFundsDustThreshold
942
+ );
943
+ }
944
+
945
+ /// @notice Updates parameters of wallets.
946
+ /// @param walletCreationPeriod New value of the wallet creation period in
947
+ /// seconds, determines how frequently a new wallet creation can be
948
+ /// requested
949
+ /// @param walletMinBtcBalance New value of the wallet minimum BTC balance
950
+ /// in satoshi, used to decide about wallet creation or closing
951
+ /// @param walletMaxBtcBalance New value of the wallet maximum BTC balance
952
+ /// in satoshi, used to decide about wallet creation
953
+ /// @param walletMaxAge New value of the wallet maximum age in seconds,
954
+ /// indicates the maximum age of a wallet in seconds, after which
955
+ /// the wallet moving funds process can be requested
956
+ /// @param walletMaxBtcTransfer New value of the wallet maximum BTC transfer
957
+ /// in satoshi, determines the maximum amount that can be transferred
958
+ // to a single target wallet during the moving funds process
959
+ /// @param walletClosingPeriod New value of the wallet closing period in
960
+ /// seconds, determines the length of the wallet closing period,
961
+ // i.e. the period when the wallet remains in the Closing state
962
+ // and can be subject of deposit fraud challenges
963
+ /// @dev Requirements:
964
+ /// - Wallet minimum BTC balance must be greater than zero
965
+ /// - Wallet maximum BTC balance must be greater than the wallet
966
+ /// minimum BTC balance
967
+ /// - Wallet maximum BTC transfer must be greater than zero
968
+ /// - Wallet closing period must be greater than zero
969
+ function updateWalletParameters(
970
+ uint32 walletCreationPeriod,
971
+ uint64 walletMinBtcBalance,
972
+ uint64 walletMaxBtcBalance,
973
+ uint32 walletMaxAge,
974
+ uint64 walletMaxBtcTransfer,
975
+ uint32 walletClosingPeriod
976
+ ) external onlyGovernance {
977
+ self.updateWalletParameters(
978
+ walletCreationPeriod,
979
+ walletMinBtcBalance,
980
+ walletMaxBtcBalance,
981
+ walletMaxAge,
982
+ walletMaxBtcTransfer,
983
+ walletClosingPeriod
984
+ );
985
+ }
986
+
987
+ /// @notice Updates parameters related to frauds.
988
+ /// @param fraudSlashingAmount New value of the fraud slashing amount in T,
989
+ /// it is the amount slashed from each wallet member for committing
990
+ /// a fraud
991
+ /// @param fraudNotifierRewardMultiplier New value of the fraud notifier
992
+ /// reward multiplier as percentage, it determines the percentage of
993
+ /// the notifier reward from the staking contact the notifier of
994
+ /// a fraud receives. The value must be in the range [0, 100]
995
+ /// @param fraudChallengeDefeatTimeout New value of the challenge defeat
996
+ /// timeout in seconds, it is the amount of time the wallet has to
997
+ /// defeat a fraud challenge. The value must be greater than zero
998
+ /// @param fraudChallengeDepositAmount New value of the fraud challenge
999
+ /// deposit amount in wei, it is the amount of ETH the party
1000
+ /// challenging the wallet for fraud needs to deposit
1001
+ /// @dev Requirements:
1002
+ /// - Fraud notifier reward multiplier must be in the range [0, 100]
1003
+ /// - Fraud challenge defeat timeout must be greater than 0
1004
+ function updateFraudParameters(
1005
+ uint256 fraudSlashingAmount,
1006
+ uint256 fraudNotifierRewardMultiplier,
1007
+ uint256 fraudChallengeDefeatTimeout,
1008
+ uint256 fraudChallengeDepositAmount
1009
+ ) external onlyGovernance {
1010
+ self.updateFraudParameters(
1011
+ fraudSlashingAmount,
1012
+ fraudNotifierRewardMultiplier,
1013
+ fraudChallengeDefeatTimeout,
1014
+ fraudChallengeDepositAmount
1015
+ );
1016
+ }
1017
+
1018
+ /// @notice Collection of all revealed deposits indexed by
1019
+ /// keccak256(fundingTxHash | fundingOutputIndex).
1020
+ /// The fundingTxHash is bytes32 (ordered as in Bitcoin internally)
1021
+ /// and fundingOutputIndex an uint32. This mapping may contain valid
1022
+ /// and invalid deposits and the wallet is responsible for
1023
+ /// validating them before attempting to execute a sweep.
1024
+ function deposits(uint256 depositKey)
1025
+ external
1026
+ view
1027
+ returns (Deposit.DepositRequest memory)
1028
+ {
1029
+ return self.deposits[depositKey];
1030
+ }
1031
+
1032
+ /// @notice Collection of all pending redemption requests indexed by
1033
+ /// redemption key built as
1034
+ /// keccak256(walletPubKeyHash | redeemerOutputScript). The
1035
+ /// walletPubKeyHash is the 20-byte wallet's public key hash
1036
+ /// (computed using Bitcoin HASH160 over the compressed ECDSA
1037
+ /// public key) and redeemerOutputScript is a Bitcoin script
1038
+ /// (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
1039
+ /// redeemed BTC as requested by the redeemer. Requests are added
1040
+ /// to this mapping by the `requestRedemption` method (duplicates
1041
+ /// not allowed) and are removed by one of the following methods:
1042
+ /// - `submitRedemptionProof` in case the request was handled
1043
+ /// successfully
1044
+ /// - `notifyRedemptionTimeout` in case the request was reported
1045
+ /// to be timed out
1046
+ function pendingRedemptions(uint256 redemptionKey)
1047
+ external
1048
+ view
1049
+ returns (Redemption.RedemptionRequest memory)
1050
+ {
1051
+ return self.pendingRedemptions[redemptionKey];
1052
+ }
1053
+
1054
+ /// @notice Collection of all timed out redemptions requests indexed by
1055
+ /// redemption key built as
1056
+ /// keccak256(walletPubKeyHash | redeemerOutputScript). The
1057
+ /// walletPubKeyHash is the 20-byte wallet's public key hash
1058
+ /// (computed using Bitcoin HASH160 over the compressed ECDSA
1059
+ /// public key) and redeemerOutputScript is the Bitcoin script
1060
+ /// (P2PKH, P2WPKH, P2SH or P2WSH) that is involved in the timed
1061
+ /// out request. Timed out requests are stored in this mapping to
1062
+ /// avoid slashing the wallets multiple times for the same timeout.
1063
+ /// Only one method can add to this mapping:
1064
+ /// - `notifyRedemptionTimeout` which puts the redemption key
1065
+ /// to this mapping basing on a timed out request stored
1066
+ /// previously in `pendingRedemptions` mapping.
1067
+ function timedOutRedemptions(uint256 redemptionKey)
1068
+ external
1069
+ view
1070
+ returns (Redemption.RedemptionRequest memory)
1071
+ {
1072
+ return self.timedOutRedemptions[redemptionKey];
1073
+ }
1074
+
1075
+ /// @notice Collection of main UTXOs that are honestly spent indexed by
1076
+ /// keccak256(fundingTxHash | fundingOutputIndex). The fundingTxHash
1077
+ /// is bytes32 (ordered as in Bitcoin internally) and
1078
+ /// fundingOutputIndex an uint32. A main UTXO is considered honestly
1079
+ /// spent if it was used as an input of a transaction that have been
1080
+ /// proven in the Bridge.
1081
+ function spentMainUTXOs(uint256 utxoKey) external view returns (bool) {
1082
+ return self.spentMainUTXOs[utxoKey];
1083
+ }
1084
+
1085
+ /// @notice Gets details about a registered wallet.
1086
+ /// @param walletPubKeyHash The 20-byte wallet public key hash (computed
1087
+ /// using Bitcoin HASH160 over the compressed ECDSA public key)
1088
+ /// @return Wallet details.
1089
+ function wallets(bytes20 walletPubKeyHash)
1090
+ external
1091
+ view
1092
+ returns (Wallets.Wallet memory)
1093
+ {
1094
+ return self.registeredWallets[walletPubKeyHash];
1095
+ }
1096
+
1097
+ /// @notice Gets the public key hash of the active wallet.
1098
+ /// @return The 20-byte public key hash (computed using Bitcoin HASH160
1099
+ /// over the compressed ECDSA public key) of the active wallet.
1100
+ /// Returns bytes20(0) if there is no active wallet at the moment.
1101
+ function activeWalletPubKeyHash() external view returns (bytes20) {
1102
+ return self.activeWalletPubKeyHash;
1103
+ }
1104
+
1105
+ /// @notice Gets the live wallets count.
1106
+ /// @return The current count of wallets being in the Live state.
1107
+ function liveWalletsCount() external view returns (uint32) {
1108
+ return self.liveWalletsCount;
1109
+ }
1110
+
1111
+ /// @notice Returns the fraud challenge identified by the given key built
1112
+ /// as keccak256(walletPublicKey|sighash).
1113
+ function fraudChallenges(uint256 challengeKey)
1114
+ external
1115
+ view
1116
+ returns (Fraud.FraudChallenge memory)
1117
+ {
1118
+ return self.fraudChallenges[challengeKey];
1119
+ }
1120
+
1121
+ /// @notice Indicates if the vault with the given address is trusted or not.
1122
+ /// Depositors can route their revealed deposits only to trusted
1123
+ /// vaults and have trusted vaults notified about new deposits as
1124
+ /// soon as these deposits get swept. Vaults not trusted by the
1125
+ /// Bridge can still be used by Bank balance owners on their own
1126
+ /// responsibility - anyone can approve their Bank balance to any
1127
+ /// address.
1128
+ function isVaultTrusted(address vault) external view returns (bool) {
1129
+ return self.isVaultTrusted[vault];
1130
+ }
1131
+
1132
+ /// @notice Returns the current values of Bridge deposit parameters.
1133
+ /// @return depositDustThreshold The minimal amount that can be requested
1134
+ /// to deposit. Value of this parameter must take into account the
1135
+ /// value of `depositTreasuryFeeDivisor` and `depositTxMaxFee`
1136
+ /// parameters in order to make requests that can incur the
1137
+ /// treasury and transaction fee and still satisfy the depositor.
1138
+ /// @return depositTreasuryFeeDivisor Divisor used to compute the treasury
1139
+ /// fee taken from each deposit and transferred to the treasury upon
1140
+ /// sweep proof submission. That fee is computed as follows:
1141
+ /// `treasuryFee = depositedAmount / depositTreasuryFeeDivisor`
1142
+ /// For example, if the treasury fee needs to be 2% of each deposit,
1143
+ /// the `depositTreasuryFeeDivisor` should be set to `50`
1144
+ /// because `1/50 = 0.02 = 2%`.
1145
+ /// @return depositTxMaxFee Maximum amount of BTC transaction fee that can
1146
+ /// be incurred by each swept deposit being part of the given sweep
1147
+ /// transaction. If the maximum BTC transaction fee is exceeded,
1148
+ /// such transaction is considered a fraud.
1149
+ function depositParameters()
1150
+ external
1151
+ view
1152
+ returns (
1153
+ uint64 depositDustThreshold,
1154
+ uint64 depositTreasuryFeeDivisor,
1155
+ uint64 depositTxMaxFee
1156
+ )
1157
+ {
1158
+ depositDustThreshold = self.depositDustThreshold;
1159
+ depositTreasuryFeeDivisor = self.depositTreasuryFeeDivisor;
1160
+ depositTxMaxFee = self.depositTxMaxFee;
1161
+ }
1162
+
1163
+ /// @notice Returns the current values of Bridge redemption parameters.
1164
+ /// @return redemptionDustThreshold The minimal amount that can be requested
1165
+ /// for redemption. Value of this parameter must take into account
1166
+ /// the value of `redemptionTreasuryFeeDivisor` and `redemptionTxMaxFee`
1167
+ /// parameters in order to make requests that can incur the
1168
+ /// treasury and transaction fee and still satisfy the redeemer.
1169
+ /// @return redemptionTreasuryFeeDivisor Divisor used to compute the treasury
1170
+ /// fee taken from each redemption request and transferred to the
1171
+ /// treasury upon successful request finalization. That fee is
1172
+ /// computed as follows:
1173
+ /// `treasuryFee = requestedAmount / redemptionTreasuryFeeDivisor`
1174
+ /// For example, if the treasury fee needs to be 2% of each
1175
+ /// redemption request, the `redemptionTreasuryFeeDivisor` should
1176
+ /// be set to `50` because `1/50 = 0.02 = 2%`.
1177
+ /// @return redemptionTxMaxFee Maximum amount of BTC transaction fee that
1178
+ /// can be incurred by each redemption request being part of the
1179
+ /// given redemption transaction. If the maximum BTC transaction
1180
+ /// fee is exceeded, such transaction is considered a fraud.
1181
+ /// This is a per-redemption output max fee for the redemption
1182
+ /// transaction.
1183
+ /// @return redemptionTimeout Time after which the redemption request can be
1184
+ /// reported as timed out. It is counted from the moment when the
1185
+ /// redemption request was created via `requestRedemption` call.
1186
+ /// Reported timed out requests are cancelled and locked TBTC is
1187
+ /// returned to the redeemer in full amount.
1188
+ function redemptionParameters()
1189
+ external
1190
+ view
1191
+ returns (
1192
+ uint64 redemptionDustThreshold,
1193
+ uint64 redemptionTreasuryFeeDivisor,
1194
+ uint64 redemptionTxMaxFee,
1195
+ uint256 redemptionTimeout
1196
+ )
1197
+ {
1198
+ redemptionDustThreshold = self.redemptionDustThreshold;
1199
+ redemptionTreasuryFeeDivisor = self.redemptionTreasuryFeeDivisor;
1200
+ redemptionTxMaxFee = self.redemptionTxMaxFee;
1201
+ redemptionTimeout = self.redemptionTimeout;
1202
+ }
1203
+
1204
+ /// @notice Returns the current values of Bridge moving funds between
1205
+ /// wallets parameters.
1206
+ /// @return movingFundsTxMaxTotalFee Maximum amount of the total BTC
1207
+ /// transaction fee that is acceptable in a single moving funds
1208
+ /// transaction. This is a _total_ max fee for the entire moving
1209
+ /// funds transaction.
1210
+ /// @return movingFundsTimeout Time after which the moving funds process
1211
+ /// can be reported as timed out. It is counted from the moment
1212
+ /// when the wallet was requested to move their funds and switched
1213
+ /// to the MovingFunds state. Value in seconds.
1214
+ /// @return movingFundsDustThreshold The minimal satoshi amount that makes
1215
+ // sense to be transferred during the moving funds process. Moving
1216
+ // funds wallets having their BTC balance below that value can
1217
+ // begin closing immediately as transferring such a low value may
1218
+ // not be possible due to BTC network fees.
1219
+ function movingFundsParameters()
1220
+ external
1221
+ view
1222
+ returns (
1223
+ uint64 movingFundsTxMaxTotalFee,
1224
+ uint32 movingFundsTimeout,
1225
+ uint64 movingFundsDustThreshold
1226
+ )
1227
+ {
1228
+ movingFundsTxMaxTotalFee = self.movingFundsTxMaxTotalFee;
1229
+ movingFundsTimeout = self.movingFundsTimeout;
1230
+ movingFundsDustThreshold = self.movingFundsDustThreshold;
1231
+ }
1232
+
1233
+ /// @return walletCreationPeriod Determines how frequently a new wallet
1234
+ /// creation can be requested. Value in seconds.
1235
+ /// @return walletMinBtcBalance The minimum BTC threshold in satoshi that is
1236
+ /// used to decide about wallet creation or closing.
1237
+ /// @return walletMaxBtcBalance The maximum BTC threshold in satoshi that is
1238
+ /// used to decide about wallet creation.
1239
+ /// @return walletMaxAge The maximum age of a wallet in seconds, after which
1240
+ /// the wallet moving funds process can be requested.
1241
+ /// @return walletMaxBtcTransfer The maximum BTC amount in satoshi than
1242
+ /// can be transferred to a single target wallet during the moving
1243
+ /// funds process.
1244
+ /// @return walletClosingPeriod Determines the length of the wallet closing
1245
+ /// period, i.e. the period when the wallet remains in the Closing
1246
+ /// state and can be subject of deposit fraud challenges. Value
1247
+ /// in seconds.
1248
+ function walletParameters()
1249
+ external
1250
+ view
1251
+ returns (
1252
+ uint32 walletCreationPeriod,
1253
+ uint64 walletMinBtcBalance,
1254
+ uint64 walletMaxBtcBalance,
1255
+ uint32 walletMaxAge,
1256
+ uint64 walletMaxBtcTransfer,
1257
+ uint32 walletClosingPeriod
1258
+ )
1259
+ {
1260
+ walletCreationPeriod = self.walletCreationPeriod;
1261
+ walletMinBtcBalance = self.walletMinBtcBalance;
1262
+ walletMaxBtcBalance = self.walletMaxBtcBalance;
1263
+ walletMaxAge = self.walletMaxAge;
1264
+ walletMaxBtcTransfer = self.walletMaxBtcTransfer;
1265
+ walletClosingPeriod = self.walletClosingPeriod;
1266
+ }
1267
+
1268
+ /// @notice Returns the current values of Bridge fraud parameters.
1269
+ /// @return fraudSlashingAmount The amount slashed from each wallet member
1270
+ /// for committing a fraud.
1271
+ /// @return fraudNotifierRewardMultiplier The percentage of the notifier
1272
+ /// reward from the staking contract the notifier of a fraud
1273
+ /// receives. The value is in the range [0, 100].
1274
+ /// @return fraudChallengeDefeatTimeout The amount of time the wallet has to
1275
+ /// defeat a fraud challenge.
1276
+ /// @return fraudChallengeDepositAmount The amount of ETH in wei the party
1277
+ /// challenging the wallet for fraud needs to deposit.
1278
+ function fraudParameters()
1279
+ external
1280
+ view
1281
+ returns (
1282
+ uint256 fraudSlashingAmount,
1283
+ uint256 fraudNotifierRewardMultiplier,
1284
+ uint256 fraudChallengeDefeatTimeout,
1285
+ uint256 fraudChallengeDepositAmount
1286
+ )
1287
+ {
1288
+ fraudSlashingAmount = self.fraudSlashingAmount;
1289
+ fraudNotifierRewardMultiplier = self.fraudNotifierRewardMultiplier;
1290
+ fraudChallengeDefeatTimeout = self.fraudChallengeDefeatTimeout;
1291
+ fraudChallengeDepositAmount = self.fraudChallengeDepositAmount;
1292
+ }
1293
+
1294
+ /// @notice Returns the addresses of contracts Bridge is interacting with.
1295
+ /// @return bank Address of the Bank the Bridge belongs to.
1296
+ /// @return relay Address of the Bitcoin relay providing the current Bitcoin
1297
+ /// network difficulty.
1298
+ /// @return ecdsaWalletRegistry Address of the ECDSA Wallet Registry.
1299
+ function contractReferences()
1300
+ external
1301
+ view
1302
+ returns (
1303
+ Bank bank,
1304
+ IRelay relay,
1305
+ EcdsaWalletRegistry ecdsaWalletRegistry
1306
+ )
1307
+ {
1308
+ bank = self.bank;
1309
+ relay = self.relay;
1310
+ ecdsaWalletRegistry = self.ecdsaWalletRegistry;
1311
+ }
1312
+
1313
+ /// @notice Address where the deposit treasury fees will be sent to.
1314
+ /// Treasury takes part in the operators rewarding process.
1315
+ function treasury() external view returns (address) {
1316
+ return self.treasury;
1317
+ }
1318
+
1319
+ /// @notice The number of confirmations on the Bitcoin chain required to
1320
+ /// successfully evaluate an SPV proof.
1321
+ function txProofDifficultyFactor() external view returns (uint256) {
1322
+ return self.txProofDifficultyFactor;
1323
+ }
176
1324
  }