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

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