@keep-network/tbtc-v2 0.1.1-dev.42 → 0.1.1-dev.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/artifacts/TBTC.json +3 -3
  2. package/artifacts/TBTCToken.json +3 -3
  3. package/artifacts/VendingMachine.json +10 -10
  4. package/artifacts/solcInputs/{002940e9cc8128f6629e90620c66cba5.json → f2c15d3cf1bd9566483f595c5ed30ccc.json} +10 -10
  5. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
  6. package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
  7. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +1 -1
  8. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +2 -2
  9. package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
  10. package/build/contracts/bridge/Bridge.sol/Bridge.json +123 -185
  11. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +1 -1
  12. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +2 -2
  13. package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +1 -1
  14. package/build/contracts/bridge/Deposit.sol/Deposit.json +2 -2
  15. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +1 -1
  16. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.json +2 -2
  17. package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +1 -1
  18. package/build/contracts/bridge/Fraud.sol/Fraud.json +2 -54
  19. package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +1 -1
  20. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +1 -1
  21. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +2 -2
  22. package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +4 -0
  23. package/build/contracts/bridge/{Redeem.sol → Redemption.sol}/OutboundTx.json +3 -3
  24. package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +4 -0
  25. package/build/contracts/bridge/Redemption.sol/Redemption.json +92 -0
  26. package/build/contracts/bridge/Sweep.sol/Sweep.dbg.json +1 -1
  27. package/build/contracts/bridge/Sweep.sol/Sweep.json +2 -2
  28. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
  29. package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +1 -1
  30. package/build/contracts/bridge/Wallets.sol/Wallets.json +2 -2
  31. package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
  32. package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
  33. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
  34. package/contracts/bridge/BitcoinTx.sol +19 -26
  35. package/contracts/bridge/Bridge.sol +466 -486
  36. package/contracts/bridge/BridgeState.sol +5 -23
  37. package/contracts/bridge/Deposit.sol +22 -0
  38. package/contracts/bridge/EcdsaLib.sol +15 -0
  39. package/contracts/bridge/Fraud.sol +17 -14
  40. package/contracts/bridge/MovingFunds.sol +13 -5
  41. package/contracts/bridge/{Redeem.sol → Redemption.sol} +13 -6
  42. package/contracts/bridge/Sweep.sol +13 -5
  43. package/package.json +1 -1
  44. package/build/contracts/bridge/Redeem.sol/OutboundTx.dbg.json +0 -4
  45. package/build/contracts/bridge/Redeem.sol/Redeem.dbg.json +0 -4
  46. package/build/contracts/bridge/Redeem.sol/Redeem.json +0 -92
@@ -17,16 +17,13 @@ pragma solidity ^0.8.9;
17
17
 
18
18
  import "@openzeppelin/contracts/access/Ownable.sol";
19
19
 
20
- import {BTCUtils} from "@keep-network/bitcoin-spv-sol/contracts/BTCUtils.sol";
21
- import {BytesLib} from "@keep-network/bitcoin-spv-sol/contracts/BytesLib.sol";
22
-
23
20
  import {IWalletOwner as EcdsaWalletOwner} from "@keep-network/ecdsa/contracts/api/IWalletOwner.sol";
24
21
 
25
22
  import "./IRelay.sol";
26
23
  import "./BridgeState.sol";
27
24
  import "./Deposit.sol";
28
25
  import "./Sweep.sol";
29
- import "./Redeem.sol";
26
+ import "./Redemption.sol";
30
27
  import "./BitcoinTx.sol";
31
28
  import "./EcdsaLib.sol";
32
29
  import "./Wallets.sol";
@@ -53,72 +50,20 @@ import "../bank/Bank.sol";
53
50
  /// the sweep operation is confirmed on the Bitcoin network, the ECDSA
54
51
  /// wallet informs the Bridge about the sweep increasing appropriate
55
52
  /// balances in the Bank.
56
- /// @dev Bridge is an upgradeable component of the Bank.
57
- ///
58
- // TODO: All wallets-related operations that are currently done directly
59
- // by the Bridge can be probably delegated to the Wallets library.
60
- // Examples of such operations are main UTXO or pending redemptions
61
- // value updates.
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.
62
56
  contract Bridge is Ownable, EcdsaWalletOwner {
63
57
  using BridgeState for BridgeState.Storage;
64
58
  using Deposit for BridgeState.Storage;
65
59
  using Sweep for BridgeState.Storage;
66
- using Redeem for BridgeState.Storage;
60
+ using Redemption for BridgeState.Storage;
67
61
  using MovingFunds for BridgeState.Storage;
68
- using Fraud for BridgeState.Storage;
69
62
  using Wallets for BridgeState.Storage;
70
-
71
- using BTCUtils for bytes;
72
- using BTCUtils for uint256;
73
- using BytesLib for bytes;
63
+ using Fraud for BridgeState.Storage;
74
64
 
75
65
  BridgeState.Storage internal self;
76
66
 
77
- event WalletParametersUpdated(
78
- uint32 walletCreationPeriod,
79
- uint64 walletMinBtcBalance,
80
- uint64 walletMaxBtcBalance,
81
- uint32 walletMaxAge
82
- );
83
-
84
- event NewWalletRequested();
85
-
86
- event NewWalletRegistered(
87
- bytes32 indexed ecdsaWalletID,
88
- bytes20 indexed walletPubKeyHash
89
- );
90
-
91
- event WalletMovingFunds(
92
- bytes32 indexed ecdsaWalletID,
93
- bytes20 indexed walletPubKeyHash
94
- );
95
-
96
- event WalletClosed(
97
- bytes32 indexed ecdsaWalletID,
98
- bytes20 indexed walletPubKeyHash
99
- );
100
-
101
- event WalletTerminated(
102
- bytes32 indexed ecdsaWalletID,
103
- bytes20 indexed walletPubKeyHash
104
- );
105
-
106
- event VaultStatusUpdated(address indexed vault, bool isTrusted);
107
-
108
- event FraudSlashingAmountUpdated(uint256 newFraudSlashingAmount);
109
-
110
- event FraudNotifierRewardMultiplierUpdated(
111
- uint256 newFraudNotifierRewardMultiplier
112
- );
113
-
114
- event FraudChallengeDefeatTimeoutUpdated(
115
- uint256 newFraudChallengeDefeatTimeout
116
- );
117
-
118
- event FraudChallengeDepositAmountUpdated(
119
- uint256 newFraudChallengeDepositAmount
120
- );
121
-
122
67
  event DepositRevealed(
123
68
  bytes32 fundingTxHash,
124
69
  uint32 fundingOutputIndex,
@@ -152,6 +97,33 @@ contract Bridge is Ownable, EcdsaWalletOwner {
152
97
  bytes redeemerOutputScript
153
98
  );
154
99
 
100
+ event WalletMovingFunds(
101
+ bytes32 indexed ecdsaWalletID,
102
+ bytes20 indexed walletPubKeyHash
103
+ );
104
+
105
+ event MovingFundsCompleted(
106
+ bytes20 walletPubKeyHash,
107
+ bytes32 movingFundsTxHash
108
+ );
109
+
110
+ event NewWalletRequested();
111
+
112
+ event NewWalletRegistered(
113
+ bytes32 indexed ecdsaWalletID,
114
+ bytes20 indexed walletPubKeyHash
115
+ );
116
+
117
+ event WalletClosed(
118
+ bytes32 indexed ecdsaWalletID,
119
+ bytes20 indexed walletPubKeyHash
120
+ );
121
+
122
+ event WalletTerminated(
123
+ bytes32 indexed ecdsaWalletID,
124
+ bytes20 indexed walletPubKeyHash
125
+ );
126
+
155
127
  event FraudChallengeSubmitted(
156
128
  bytes20 walletPublicKeyHash,
157
129
  bytes32 sighash,
@@ -167,9 +139,13 @@ contract Bridge is Ownable, EcdsaWalletOwner {
167
139
  bytes32 sighash
168
140
  );
169
141
 
170
- event MovingFundsCompleted(
171
- bytes20 walletPubKeyHash,
172
- bytes32 movingFundsTxHash
142
+ event VaultStatusUpdated(address indexed vault, bool isTrusted);
143
+
144
+ event WalletParametersUpdated(
145
+ uint32 walletCreationPeriod,
146
+ uint64 walletMinBtcBalance,
147
+ uint64 walletMaxBtcBalance,
148
+ uint32 walletMaxAge
173
149
  );
174
150
 
175
151
  constructor(
@@ -215,123 +191,6 @@ contract Bridge is Ownable, EcdsaWalletOwner {
215
191
  self.walletMaxAge = 26 weeks; // ~6 months
216
192
  }
217
193
 
218
- /// @notice Allows the Governance to mark the given vault address as trusted
219
- /// or no longer trusted. Vaults are not trusted by default.
220
- /// Trusted vault must meet the following criteria:
221
- /// - `IVault.receiveBalanceIncrease` must have a known, low gas
222
- /// cost.
223
- /// - `IVault.receiveBalanceIncrease` must never revert.
224
- /// @dev Without restricting reveal only to trusted vaults, malicious
225
- /// vaults not meeting the criteria would be able to nuke sweep proof
226
- /// transactions executed by ECDSA wallet with deposits routed to
227
- /// them.
228
- /// @param vault The address of the vault
229
- /// @param isTrusted flag indicating whether the vault is trusted or not
230
- /// @dev Can only be called by the Governance.
231
- function setVaultStatus(address vault, bool isTrusted) external onlyOwner {
232
- self.isVaultTrusted[vault] = isTrusted;
233
- emit VaultStatusUpdated(vault, isTrusted);
234
- }
235
-
236
- /// @notice Requests creation of a new wallet. This function just
237
- /// forms a request and the creation process is performed
238
- /// asynchronously. Once a wallet is created, the ECDSA Wallet
239
- /// Registry will notify this contract by calling the
240
- /// `__ecdsaWalletCreatedCallback` function.
241
- /// @param activeWalletMainUtxo Data of the active wallet's main UTXO, as
242
- /// currently known on the Ethereum chain.
243
- /// @dev Requirements:
244
- /// - `activeWalletMainUtxo` components must point to the recent main
245
- /// UTXO of the given active wallet, as currently known on the
246
- /// Ethereum chain. If there is no active wallet at the moment, or
247
- /// the active wallet has no main UTXO, this parameter can be
248
- /// empty as it is ignored.
249
- /// - Wallet creation must not be in progress
250
- /// - If the active wallet is set, one of the following
251
- /// conditions must be true:
252
- /// - The active wallet BTC balance is above the minimum threshold
253
- /// and the active wallet is old enough, i.e. the creation period
254
- /// was elapsed since its creation time
255
- /// - The active wallet BTC balance is above the maximum threshold
256
- function requestNewWallet(BitcoinTx.UTXO calldata activeWalletMainUtxo)
257
- external
258
- {
259
- self.requestNewWallet(activeWalletMainUtxo);
260
- }
261
-
262
- /// @notice A callback function that is called by the ECDSA Wallet Registry
263
- /// once a new ECDSA wallet is created.
264
- /// @param ecdsaWalletID Wallet's unique identifier.
265
- /// @param publicKeyX Wallet's public key's X coordinate.
266
- /// @param publicKeyY Wallet's public key's Y coordinate.
267
- /// @dev Requirements:
268
- /// - The only caller authorized to call this function is `registry`
269
- /// - Given wallet data must not belong to an already registered wallet
270
- function __ecdsaWalletCreatedCallback(
271
- bytes32 ecdsaWalletID,
272
- bytes32 publicKeyX,
273
- bytes32 publicKeyY
274
- ) external override {
275
- self.registerNewWallet(ecdsaWalletID, publicKeyX, publicKeyY);
276
- }
277
-
278
- /// @notice A callback function that is called by the ECDSA Wallet Registry
279
- /// once a wallet heartbeat failure is detected.
280
- /// @param publicKeyX Wallet's public key's X coordinate
281
- /// @param publicKeyY Wallet's public key's Y coordinate
282
- /// @dev Requirements:
283
- /// - The only caller authorized to call this function is `registry`
284
- /// - Wallet must be in Live state
285
- function __ecdsaWalletHeartbeatFailedCallback(
286
- bytes32,
287
- bytes32 publicKeyX,
288
- bytes32 publicKeyY
289
- ) external override {
290
- self.notifyWalletHeartbeatFailed(publicKeyX, publicKeyY);
291
- }
292
-
293
- /// @notice Notifies that the wallet is either old enough or has too few
294
- /// satoshis left and qualifies to be closed.
295
- /// @param walletPubKeyHash 20-byte public key hash of the wallet
296
- /// @param walletMainUtxo Data of the wallet's main UTXO, as currently
297
- /// known on the Ethereum chain.
298
- /// @dev Requirements:
299
- /// - Wallet must not be set as the current active wallet
300
- /// - Wallet must exceed the wallet maximum age OR the wallet BTC
301
- /// balance must be lesser than the minimum threshold. If the latter
302
- /// case is true, the `walletMainUtxo` components must point to the
303
- /// recent main UTXO of the given wallet, as currently known on the
304
- /// Ethereum chain. If the wallet has no main UTXO, this parameter
305
- /// can be empty as it is ignored since the wallet balance is
306
- /// assumed to be zero.
307
- /// - Wallet must be in Live state
308
- function notifyCloseableWallet(
309
- bytes20 walletPubKeyHash,
310
- BitcoinTx.UTXO calldata walletMainUtxo
311
- ) external {
312
- self.notifyCloseableWallet(walletPubKeyHash, walletMainUtxo);
313
- }
314
-
315
- /// @notice Gets details about a registered wallet.
316
- /// @param walletPubKeyHash The 20-byte wallet public key hash (computed
317
- /// using Bitcoin HASH160 over the compressed ECDSA public key)
318
- /// @return Wallet details.
319
- function getWallet(bytes20 walletPubKeyHash)
320
- external
321
- view
322
- returns (Wallets.Wallet memory)
323
- {
324
- return self.registeredWallets[walletPubKeyHash];
325
- }
326
-
327
- /// @notice Gets the public key hash of the active wallet.
328
- /// @return The 20-byte public key hash (computed using Bitcoin HASH160
329
- /// over the compressed ECDSA public key) of the active wallet.
330
- /// Returns bytes20(0) if there is no active wallet at the moment.
331
- function getActiveWalletPubKeyHash() external view returns (bytes20) {
332
- return self.activeWalletPubKeyHash;
333
- }
334
-
335
194
  /// @notice Used by the depositor to reveal information about their P2(W)SH
336
195
  /// Bitcoin deposit to the Bridge on Ethereum chain. The off-chain
337
196
  /// wallet listens for revealed deposit events and may decide to
@@ -417,139 +276,23 @@ contract Bridge is Ownable, EcdsaWalletOwner {
417
276
  self.submitSweepProof(sweepTx, sweepProof, mainUtxo);
418
277
  }
419
278
 
420
- /// @notice Submits a fraud challenge indicating that a UTXO being under
421
- /// wallet control was unlocked by the wallet but was not used
422
- /// according to the protocol rules. That means the wallet signed
423
- /// a transaction input pointing to that UTXO and there is a unique
424
- /// sighash and signature pair associated with that input. This
425
- /// function uses those parameters to create a fraud accusation that
426
- /// proves a given transaction input unlocking the given UTXO was
427
- /// actually signed by the wallet. This function cannot determine
428
- /// whether the transaction was actually broadcast and the input was
429
- /// consumed in a fraudulent way so it just opens a challenge period
430
- /// during which the wallet can defeat the challenge by submitting
431
- /// proof of a transaction that consumes the given input according
432
- /// to protocol rules. To prevent spurious allegations, the caller
433
- /// must deposit ETH that is returned back upon justified fraud
434
- /// challenge or confiscated otherwise.
435
- ///@param walletPublicKey The public key of the wallet in the uncompressed
436
- /// and unprefixed format (64 bytes)
437
- /// @param sighash The hash that was used to produce the ECDSA signature
438
- /// that is the subject of the fraud claim. This hash is constructed
439
- /// by applying double SHA-256 over a serialized subset of the
440
- /// transaction. The exact subset used as hash preimage depends on
441
- /// the transaction input the signature is produced for. See BIP-143
442
- /// for reference
443
- /// @param signature Bitcoin signature in the R/S/V format
444
- /// @dev Requirements:
445
- /// - Wallet behind `walletPubKey` must be in `Live` or `MovingFunds`
446
- /// state
447
- /// - The challenger must send appropriate amount of ETH used as
448
- /// fraud challenge deposit
449
- /// - The signature (represented by r, s and v) must be generated by
450
- /// the wallet behind `walletPubKey` during signing of `sighash`
451
- /// - Wallet can be challenged for the given signature only once
452
- function submitFraudChallenge(
453
- bytes calldata walletPublicKey,
454
- bytes32 sighash,
455
- BitcoinTx.RSVSignature calldata signature
456
- ) external payable {
457
- self.submitFraudChallenge(walletPublicKey, sighash, signature);
458
- }
459
-
460
- /// @notice Allows to defeat a pending fraud challenge against a wallet if
461
- /// the transaction that spends the UTXO follows the protocol rules.
462
- /// In order to defeat the challenge the same `walletPublicKey` and
463
- /// signature (represented by `r`, `s` and `v`) must be provided as
464
- /// were used to calculate the sighash during input signing.
465
- /// The fraud challenge defeat attempt will only succeed if the
466
- /// inputs in the preimage are considered honestly spent by the
467
- /// wallet. Therefore the transaction spending the UTXO must be
468
- /// proven in the Bridge before a challenge defeat is called.
469
- /// If successfully defeated, the fraud challenge is marked as
470
- /// resolved and the amount of ether deposited by the challenger is
471
- /// sent to the treasury.
472
- /// @param walletPublicKey The public key of the wallet in the uncompressed
473
- /// and unprefixed format (64 bytes)
474
- /// @param preimage The preimage which produces sighash used to generate the
475
- /// ECDSA signature that is the subject of the fraud claim. It is a
476
- /// serialized subset of the transaction. The exact subset used as
477
- /// the preimage depends on the transaction input the signature is
478
- /// produced for. See BIP-143 for reference
479
- /// @param witness Flag indicating whether the preimage was produced for a
480
- /// witness input. True for witness, false for non-witness input
481
- /// @dev Requirements:
482
- /// - `walletPublicKey` and `sighash` calculated as `hash256(preimage)`
483
- /// must identify an open fraud challenge
484
- /// - the preimage must be a valid preimage of a transaction generated
485
- /// according to the protocol rules and already proved in the Bridge
486
- /// - before a defeat attempt is made the transaction that spends the
487
- /// given UTXO must be proven in the Bridge
488
- function defeatFraudChallenge(
489
- bytes calldata walletPublicKey,
490
- bytes calldata preimage,
491
- bool witness
492
- ) external {
493
- self.defeatFraudChallenge(walletPublicKey, preimage, witness);
494
- }
495
-
496
- /// @notice Notifies about defeat timeout for the given fraud challenge.
497
- /// Can be called only if there was a fraud challenge identified by
498
- /// the provided `walletPublicKey` and `sighash` and it was not
499
- /// defeated on time. The amount of time that needs to pass after
500
- /// a fraud challenge is reported is indicated by the
501
- /// `challengeDefeatTimeout`. After a successful fraud challenge
502
- /// defeat timeout notification the fraud challenge is marked as
503
- /// resolved, the stake of each operator is slashed, the ether
504
- /// deposited is returned to the challenger and the challenger is
505
- /// rewarded.
506
- /// @param walletPublicKey The public key of the wallet in the uncompressed
507
- /// and unprefixed format (64 bytes)
508
- /// @param sighash The hash that was used to produce the ECDSA signature
509
- /// that is the subject of the fraud claim. This hash is constructed
510
- /// by applying double SHA-256 over a serialized subset of the
511
- /// transaction. The exact subset used as hash preimage depends on
512
- /// the transaction input the signature is produced for. See BIP-143
513
- /// for reference
514
- /// @dev Requirements:
515
- /// - `walletPublicKey`and `sighash` must identify an open fraud
516
- /// challenge
517
- /// - the amount of time indicated by `challengeDefeatTimeout` must
518
- /// pass after the challenge was reported
519
- function notifyFraudChallengeDefeatTimeout(
520
- bytes calldata walletPublicKey,
521
- bytes32 sighash
522
- ) external {
523
- self.notifyFraudChallengeDefeatTimeout(walletPublicKey, sighash);
524
- }
525
-
526
- /// @notice Returns the fraud challenge identified by the given key built
527
- /// as keccak256(walletPublicKey|sighash).
528
- function fraudChallenges(uint256 challengeKey)
529
- external
530
- view
531
- returns (Fraud.FraudChallenge memory)
532
- {
533
- return self.fraudChallenges[challengeKey];
534
- }
535
-
536
- /// @notice Requests redemption of the given amount from the specified
537
- /// wallet to the redeemer Bitcoin output script.
538
- /// @param walletPubKeyHash The 20-byte wallet public key hash (computed
539
- /// using Bitcoin HASH160 over the compressed ECDSA public key)
540
- /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
541
- /// the Ethereum chain
542
- /// @param redeemerOutputScript The redeemer's length-prefixed output
543
- /// script (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
544
- /// redeemed BTC
545
- /// @param amount Requested amount in satoshi. This is also the TBTC amount
546
- /// that is taken from redeemer's balance in the Bank upon request.
547
- /// Once the request is handled, the actual amount of BTC locked
548
- /// on the redeemer output script will be always lower than this value
549
- /// since the treasury and Bitcoin transaction fees must be incurred.
550
- /// The minimal amount satisfying the request can be computed as:
551
- /// `amount - (amount / redemptionTreasuryFeeDivisor) - redemptionTxMaxFee`.
552
- /// Fees values are taken at the moment of request creation.
279
+ /// @notice Requests redemption of the given amount from the specified
280
+ /// wallet to the redeemer Bitcoin output script.
281
+ /// @param walletPubKeyHash The 20-byte wallet public key hash (computed
282
+ /// using Bitcoin HASH160 over the compressed ECDSA public key)
283
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
284
+ /// the Ethereum chain
285
+ /// @param redeemerOutputScript The redeemer's length-prefixed output
286
+ /// script (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
287
+ /// redeemed BTC
288
+ /// @param amount Requested amount in satoshi. This is also the TBTC amount
289
+ /// that is taken from redeemer's balance in the Bank upon request.
290
+ /// Once the request is handled, the actual amount of BTC locked
291
+ /// on the redeemer output script will be always lower than this value
292
+ /// since the treasury and Bitcoin transaction fees must be incurred.
293
+ /// The minimal amount satisfying the request can be computed as:
294
+ /// `amount - (amount / redemptionTreasuryFeeDivisor) - redemptionTxMaxFee`.
295
+ /// Fees values are taken at the moment of request creation.
553
296
  /// @dev Requirements:
554
297
  /// - Wallet behind `walletPubKeyHash` must be live
555
298
  /// - `mainUtxo` components must point to the recent main UTXO
@@ -724,176 +467,221 @@ contract Bridge is Ownable, EcdsaWalletOwner {
724
467
  );
725
468
  }
726
469
 
727
- /// @notice Returns the addresses of contracts Bridge is interacting with.
728
- /// @return bank Address of the Bank the Bridge belongs to.
729
- /// @return relay Address of the Bitcoin relay providing the current Bitcoin
730
- /// network difficulty.
731
- function getContracts() external view returns (Bank bank, IRelay relay) {
732
- bank = self.bank;
733
- relay = self.relay;
734
- }
735
-
736
- /// @notice Address where the deposit treasury fees will be sent to.
737
- /// Treasury takes part in the operators rewarding process.
738
- function treasury() external view returns (address treasury) {
739
- treasury = self.treasury;
740
- }
741
-
742
- /// @notice The number of confirmations on the Bitcoin chain required to
743
- /// successfully evaluate an SPV proof.
744
- function txProofDifficultyFactor()
470
+ /// @notice Requests creation of a new wallet. This function just
471
+ /// forms a request and the creation process is performed
472
+ /// asynchronously. Once a wallet is created, the ECDSA Wallet
473
+ /// Registry will notify this contract by calling the
474
+ /// `__ecdsaWalletCreatedCallback` function.
475
+ /// @param activeWalletMainUtxo Data of the active wallet's main UTXO, as
476
+ /// currently known on the Ethereum chain.
477
+ /// @dev Requirements:
478
+ /// - `activeWalletMainUtxo` components must point to the recent main
479
+ /// UTXO of the given active wallet, as currently known on the
480
+ /// Ethereum chain. If there is no active wallet at the moment, or
481
+ /// the active wallet has no main UTXO, this parameter can be
482
+ /// empty as it is ignored.
483
+ /// - Wallet creation must not be in progress
484
+ /// - If the active wallet is set, one of the following
485
+ /// conditions must be true:
486
+ /// - The active wallet BTC balance is above the minimum threshold
487
+ /// and the active wallet is old enough, i.e. the creation period
488
+ /// was elapsed since its creation time
489
+ /// - The active wallet BTC balance is above the maximum threshold
490
+ function requestNewWallet(BitcoinTx.UTXO calldata activeWalletMainUtxo)
745
491
  external
746
- view
747
- returns (uint256 txProofDifficultyFactor)
748
492
  {
749
- txProofDifficultyFactor = self.txProofDifficultyFactor;
493
+ self.requestNewWallet(activeWalletMainUtxo);
750
494
  }
751
495
 
752
- /// @notice Returns the current values of Bridge deposit parameters.
753
- /// @return depositDustThreshold The minimal amount that can be requested
754
- /// to deposit. Value of this parameter must take into account the
755
- /// value of `depositTreasuryFeeDivisor` and `depositTxMaxFee`
756
- /// parameters in order to make requests that can incur the
757
- /// treasury and transaction fee and still satisfy the depositor.
758
- /// @return depositTreasuryFeeDivisor Divisor used to compute the treasury
759
- /// fee taken from each deposit and transferred to the treasury upon
760
- /// sweep proof submission. That fee is computed as follows:
761
- /// `treasuryFee = depositedAmount / depositTreasuryFeeDivisor`
762
- /// For example, if the treasury fee needs to be 2% of each deposit,
763
- /// the `depositTreasuryFeeDivisor` should be set to `50`
764
- /// because `1/50 = 0.02 = 2%`.
765
- /// @return depositTxMaxFee Maximum amount of BTC transaction fee that can
766
- /// be incurred by each swept deposit being part of the given sweep
767
- /// transaction. If the maximum BTC transaction fee is exceeded,
768
- /// such transaction is considered a fraud.
769
- function depositParameters()
770
- external
771
- view
772
- returns (
773
- uint64 depositDustThreshold,
774
- uint64 depositTreasuryFeeDivisor,
775
- uint64 depositTxMaxFee
776
- )
777
- {
778
- depositDustThreshold = self.depositDustThreshold;
779
- depositTreasuryFeeDivisor = self.depositTreasuryFeeDivisor;
780
- depositTxMaxFee = self.depositTxMaxFee;
496
+ /// @notice A callback function that is called by the ECDSA Wallet Registry
497
+ /// once a new ECDSA wallet is created.
498
+ /// @param ecdsaWalletID Wallet's unique identifier.
499
+ /// @param publicKeyX Wallet's public key's X coordinate.
500
+ /// @param publicKeyY Wallet's public key's Y coordinate.
501
+ /// @dev Requirements:
502
+ /// - The only caller authorized to call this function is `registry`
503
+ /// - Given wallet data must not belong to an already registered wallet
504
+ function __ecdsaWalletCreatedCallback(
505
+ bytes32 ecdsaWalletID,
506
+ bytes32 publicKeyX,
507
+ bytes32 publicKeyY
508
+ ) external override {
509
+ self.registerNewWallet(ecdsaWalletID, publicKeyX, publicKeyY);
781
510
  }
782
511
 
783
- /// @notice Returns the current values of Bridge redemption parameters.
784
- /// @return redemptionDustThreshold The minimal amount that can be requested
785
- /// for redemption. Value of this parameter must take into account
786
- /// the value of `redemptionTreasuryFeeDivisor` and `redemptionTxMaxFee`
787
- /// parameters in order to make requests that can incur the
788
- /// treasury and transaction fee and still satisfy the redeemer.
789
- /// @return redemptionTreasuryFeeDivisor Divisor used to compute the treasury
790
- /// fee taken from each redemption request and transferred to the
791
- /// treasury upon successful request finalization. That fee is
792
- /// computed as follows:
793
- /// `treasuryFee = requestedAmount / redemptionTreasuryFeeDivisor`
794
- /// For example, if the treasury fee needs to be 2% of each
795
- /// redemption request, the `redemptionTreasuryFeeDivisor` should
796
- /// be set to `50` because `1/50 = 0.02 = 2%`.
797
- /// @return redemptionTxMaxFee Maximum amount of BTC transaction fee that
798
- /// can be incurred by each redemption request being part of the
799
- /// given redemption transaction. If the maximum BTC transaction
800
- /// fee is exceeded, such transaction is considered a fraud.
801
- /// @return redemptionTimeout Time after which the redemption request can be
802
- /// reported as timed out. It is counted from the moment when the
803
- /// redemption request was created via `requestRedemption` call.
804
- /// Reported timed out requests are cancelled and locked TBTC is
805
- /// returned to the redeemer in full amount.
806
- function redemptionParameters()
807
- external
808
- view
809
- returns (
810
- uint64 redemptionDustThreshold,
811
- uint64 redemptionTreasuryFeeDivisor,
812
- uint64 redemptionTxMaxFee,
813
- uint256 redemptionTimeout,
814
- address treasury,
815
- uint256 txProofDifficultyFactor
816
- )
817
- {
818
- redemptionDustThreshold = self.redemptionDustThreshold;
819
- redemptionTreasuryFeeDivisor = self.redemptionTreasuryFeeDivisor;
820
- redemptionTxMaxFee = self.redemptionTxMaxFee;
821
- redemptionTimeout = self.redemptionTimeout;
512
+ /// @notice A callback function that is called by the ECDSA Wallet Registry
513
+ /// once a wallet heartbeat failure is detected.
514
+ /// @param publicKeyX Wallet's public key's X coordinate
515
+ /// @param publicKeyY Wallet's public key's Y coordinate
516
+ /// @dev Requirements:
517
+ /// - The only caller authorized to call this function is `registry`
518
+ /// - Wallet must be in Live state
519
+ function __ecdsaWalletHeartbeatFailedCallback(
520
+ bytes32,
521
+ bytes32 publicKeyX,
522
+ bytes32 publicKeyY
523
+ ) external override {
524
+ self.notifyWalletHeartbeatFailed(publicKeyX, publicKeyY);
822
525
  }
823
526
 
824
- /// @notice Returns the current values of Bridge moving funds between
825
- /// wallets parameters.
826
- /// @return movingFundsTxMaxTotalFee Maximum amount of the total BTC
827
- /// transaction fee that is acceptable in a single moving funds
828
- /// transaction. This is a _total_ max fee for the entire moving
829
- /// funds transaction.
830
- function movingFundsParameters()
831
- external
832
- view
833
- returns (uint64 movingFundsTxMaxTotalFee)
834
- {
835
- // TODO: we will have more parameters here, for example moving funds timeout
836
- movingFundsTxMaxTotalFee = self.movingFundsTxMaxTotalFee;
527
+ /// @notice Notifies that the wallet is either old enough or has too few
528
+ /// satoshis left and qualifies to be closed.
529
+ /// @param walletPubKeyHash 20-byte public key hash of the wallet
530
+ /// @param walletMainUtxo Data of the wallet's main UTXO, as currently
531
+ /// known on the Ethereum chain.
532
+ /// @dev Requirements:
533
+ /// - Wallet must not be set as the current active wallet
534
+ /// - Wallet must exceed the wallet maximum age OR the wallet BTC
535
+ /// balance must be lesser than the minimum threshold. If the latter
536
+ /// case is true, the `walletMainUtxo` components must point to the
537
+ /// recent main UTXO of the given wallet, as currently known on the
538
+ /// Ethereum chain. If the wallet has no main UTXO, this parameter
539
+ /// can be empty as it is ignored since the wallet balance is
540
+ /// assumed to be zero.
541
+ /// - Wallet must be in Live state
542
+ function notifyCloseableWallet(
543
+ bytes20 walletPubKeyHash,
544
+ BitcoinTx.UTXO calldata walletMainUtxo
545
+ ) external {
546
+ self.notifyCloseableWallet(walletPubKeyHash, walletMainUtxo);
837
547
  }
838
548
 
839
- /// @notice Returns the current values of Bridge fraud parameters.
840
- /// @return fraudSlashingAmount The amount slashed from each wallet member
841
- /// for committing a fraud.
842
- /// @return fraudNotifierRewardMultiplier The percentage of the notifier
843
- /// reward from the staking contract the notifier of a fraud
844
- /// receives. The value is in the range [0, 100].
845
- /// @return fraudChallengeDefeatTimeout The amount of time the wallet has to
846
- /// defeat a fraud challenge.
847
- /// @return fraudChallengeDepositAmount The amount of ETH in wei the party
848
- /// challenging the wallet for fraud needs to deposit.
849
- function fraudParameters()
850
- external
851
- view
852
- returns (
853
- uint256 fraudSlashingAmount,
854
- uint256 fraudNotifierRewardMultiplier,
855
- uint256 fraudChallengeDefeatTimeout,
856
- uint256 fraudChallengeDepositAmount
857
- )
858
- {
859
- fraudSlashingAmount = self.fraudSlashingAmount;
860
- fraudNotifierRewardMultiplier = self.fraudNotifierRewardMultiplier;
861
- fraudChallengeDefeatTimeout = self.fraudChallengeDefeatTimeout;
862
- fraudChallengeDepositAmount = self.fraudChallengeDepositAmount;
549
+ /// @notice Submits a fraud challenge indicating that a UTXO being under
550
+ /// wallet control was unlocked by the wallet but was not used
551
+ /// according to the protocol rules. That means the wallet signed
552
+ /// a transaction input pointing to that UTXO and there is a unique
553
+ /// sighash and signature pair associated with that input. This
554
+ /// function uses those parameters to create a fraud accusation that
555
+ /// proves a given transaction input unlocking the given UTXO was
556
+ /// actually signed by the wallet. This function cannot determine
557
+ /// whether the transaction was actually broadcast and the input was
558
+ /// consumed in a fraudulent way so it just opens a challenge period
559
+ /// during which the wallet can defeat the challenge by submitting
560
+ /// proof of a transaction that consumes the given input according
561
+ /// to protocol rules. To prevent spurious allegations, the caller
562
+ /// must deposit ETH that is returned back upon justified fraud
563
+ /// challenge or confiscated otherwise.
564
+ ///@param walletPublicKey The public key of the wallet in the uncompressed
565
+ /// and unprefixed format (64 bytes)
566
+ /// @param sighash The hash that was used to produce the ECDSA signature
567
+ /// that is the subject of the fraud claim. This hash is constructed
568
+ /// by applying double SHA-256 over a serialized subset of the
569
+ /// transaction. The exact subset used as hash preimage depends on
570
+ /// the transaction input the signature is produced for. See BIP-143
571
+ /// for reference
572
+ /// @param signature Bitcoin signature in the R/S/V format
573
+ /// @dev Requirements:
574
+ /// - Wallet behind `walletPubKey` must be in `Live` or `MovingFunds`
575
+ /// state
576
+ /// - The challenger must send appropriate amount of ETH used as
577
+ /// fraud challenge deposit
578
+ /// - The signature (represented by r, s and v) must be generated by
579
+ /// the wallet behind `walletPubKey` during signing of `sighash`
580
+ /// - Wallet can be challenged for the given signature only once
581
+ function submitFraudChallenge(
582
+ bytes calldata walletPublicKey,
583
+ bytes32 sighash,
584
+ BitcoinTx.RSVSignature calldata signature
585
+ ) external payable {
586
+ self.submitFraudChallenge(walletPublicKey, sighash, signature);
863
587
  }
864
588
 
865
- /// @return walletCreationPeriod Determines how frequently a new wallet
866
- /// creation can be requested. Value in seconds.
867
- /// @return walletMinBtcBalance The minimum BTC threshold in satoshi that is
868
- /// used to decide about wallet creation or closing.
869
- /// @return walletMaxBtcBalance The maximum BTC threshold in satoshi that is
870
- /// used to decide about wallet creation.
871
- /// @return walletMaxAge The maximum age of a wallet in seconds, after which
872
- /// the wallet moving funds process can be requested.
873
- function walletParameters()
874
- external
875
- view
876
- returns (
877
- uint32 walletCreationPeriod,
878
- uint64 walletMinBtcBalance,
879
- uint64 walletMaxBtcBalance,
880
- uint32 walletMaxAge
881
- )
882
- {
883
- walletCreationPeriod = self.walletCreationPeriod;
884
- walletMinBtcBalance = self.walletMinBtcBalance;
885
- walletMaxBtcBalance = self.walletMaxBtcBalance;
886
- walletMaxAge = self.walletMaxAge;
589
+ /// @notice Allows to defeat a pending fraud challenge against a wallet if
590
+ /// the transaction that spends the UTXO follows the protocol rules.
591
+ /// In order to defeat the challenge the same `walletPublicKey` and
592
+ /// signature (represented by `r`, `s` and `v`) must be provided as
593
+ /// were used to calculate the sighash during input signing.
594
+ /// The fraud challenge defeat attempt will only succeed if the
595
+ /// inputs in the preimage are considered honestly spent by the
596
+ /// wallet. Therefore the transaction spending the UTXO must be
597
+ /// proven in the Bridge before a challenge defeat is called.
598
+ /// If successfully defeated, the fraud challenge is marked as
599
+ /// resolved and the amount of ether deposited by the challenger is
600
+ /// sent to the treasury.
601
+ /// @param walletPublicKey The public key of the wallet in the uncompressed
602
+ /// and unprefixed format (64 bytes)
603
+ /// @param preimage The preimage which produces sighash used to generate the
604
+ /// ECDSA signature that is the subject of the fraud claim. It is a
605
+ /// serialized subset of the transaction. The exact subset used as
606
+ /// the preimage depends on the transaction input the signature is
607
+ /// produced for. See BIP-143 for reference
608
+ /// @param witness Flag indicating whether the preimage was produced for a
609
+ /// witness input. True for witness, false for non-witness input
610
+ /// @dev Requirements:
611
+ /// - `walletPublicKey` and `sighash` calculated as `hash256(preimage)`
612
+ /// must identify an open fraud challenge
613
+ /// - the preimage must be a valid preimage of a transaction generated
614
+ /// according to the protocol rules and already proved in the Bridge
615
+ /// - before a defeat attempt is made the transaction that spends the
616
+ /// given UTXO must be proven in the Bridge
617
+ function defeatFraudChallenge(
618
+ bytes calldata walletPublicKey,
619
+ bytes calldata preimage,
620
+ bool witness
621
+ ) external {
622
+ self.defeatFraudChallenge(walletPublicKey, preimage, witness);
623
+ }
624
+
625
+ /// @notice Notifies about defeat timeout for the given fraud challenge.
626
+ /// Can be called only if there was a fraud challenge identified by
627
+ /// the provided `walletPublicKey` and `sighash` and it was not
628
+ /// defeated on time. The amount of time that needs to pass after
629
+ /// a fraud challenge is reported is indicated by the
630
+ /// `challengeDefeatTimeout`. After a successful fraud challenge
631
+ /// defeat timeout notification the fraud challenge is marked as
632
+ /// resolved, the stake of each operator is slashed, the ether
633
+ /// deposited is returned to the challenger and the challenger is
634
+ /// rewarded.
635
+ /// @param walletPublicKey The public key of the wallet in the uncompressed
636
+ /// and unprefixed format (64 bytes)
637
+ /// @param sighash The hash that was used to produce the ECDSA signature
638
+ /// that is the subject of the fraud claim. This hash is constructed
639
+ /// by applying double SHA-256 over a serialized subset of the
640
+ /// transaction. The exact subset used as hash preimage depends on
641
+ /// the transaction input the signature is produced for. See BIP-143
642
+ /// for reference
643
+ /// @dev Requirements:
644
+ /// - `walletPublicKey`and `sighash` must identify an open fraud
645
+ /// challenge
646
+ /// - the amount of time indicated by `challengeDefeatTimeout` must
647
+ /// pass after the challenge was reported
648
+ function notifyFraudChallengeDefeatTimeout(
649
+ bytes calldata walletPublicKey,
650
+ bytes32 sighash
651
+ ) external {
652
+ self.notifyFraudChallengeDefeatTimeout(walletPublicKey, sighash);
653
+ }
654
+
655
+ /// @notice Allows the Governance to mark the given vault address as trusted
656
+ /// or no longer trusted. Vaults are not trusted by default.
657
+ /// Trusted vault must meet the following criteria:
658
+ /// - `IVault.receiveBalanceIncrease` must have a known, low gas
659
+ /// cost.
660
+ /// - `IVault.receiveBalanceIncrease` must never revert.
661
+ /// @dev Without restricting reveal only to trusted vaults, malicious
662
+ /// vaults not meeting the criteria would be able to nuke sweep proof
663
+ /// transactions executed by ECDSA wallet with deposits routed to
664
+ /// them.
665
+ /// @param vault The address of the vault
666
+ /// @param isTrusted flag indicating whether the vault is trusted or not
667
+ /// @dev Can only be called by the Governance.
668
+ function setVaultStatus(address vault, bool isTrusted) external onlyOwner {
669
+ self.isVaultTrusted[vault] = isTrusted;
670
+ emit VaultStatusUpdated(vault, isTrusted);
887
671
  }
888
672
 
673
+ // TODO: updateDepositParameters
674
+ // TODO: updateRedemptionParameters
675
+ // TODO: updateMovingFundsParameters
676
+
889
677
  /// @notice Updates parameters of wallets.
890
678
  /// @param walletCreationPeriod New value of the wallet creation period in
891
679
  /// seconds, determines how frequently a new wallet creation can be
892
680
  /// requested
893
681
  /// @param walletMinBtcBalance New value of the wallet minimum BTC balance
894
- /// in sathoshis, used to decide about wallet creation or closing
682
+ /// in satoshis, used to decide about wallet creation or closing
895
683
  /// @param walletMaxBtcBalance New value of the wallet maximum BTC balance
896
- /// in sathoshis, used to decide about wallet creation
684
+ /// in satoshis, used to decide about wallet creation
897
685
  /// @param walletMaxAge New value of the wallet maximum age in seconds,
898
686
  /// indicates the maximum age of a wallet in seconds, after which
899
687
  /// the wallet moving funds process can be requested
@@ -915,16 +703,7 @@ contract Bridge is Ownable, EcdsaWalletOwner {
915
703
  );
916
704
  }
917
705
 
918
- /// @notice Indicates if the vault with the given address is trusted or not.
919
- /// Depositors can route their revealed deposits only to trusted
920
- /// vaults and have trusted vaults notified about new deposits as
921
- /// soon as these deposits get swept. Vaults not trusted by the
922
- /// Bridge can still be used by Bank balance owners on their own
923
- /// responsibility - anyone can approve their Bank balance to any
924
- /// address.
925
- function isVaultTrusted(address vault) external view returns (bool) {
926
- return self.isVaultTrusted[vault];
927
- }
706
+ // TODO: updateFraudParameters
928
707
 
929
708
  /// @notice Collection of all revealed deposits indexed by
930
709
  /// keccak256(fundingTxHash | fundingOutputIndex).
@@ -940,16 +719,6 @@ contract Bridge is Ownable, EcdsaWalletOwner {
940
719
  return self.deposits[depositKey];
941
720
  }
942
721
 
943
- /// @notice Collection of main UTXOs that are honestly spent indexed by
944
- /// keccak256(fundingTxHash | fundingOutputIndex). The fundingTxHash
945
- /// is bytes32 (ordered as in Bitcoin internally) and
946
- /// fundingOutputIndex an uint32. A main UTXO is considered honestly
947
- /// spent if it was used as an input of a transaction that have been
948
- /// proven in the Bridge.
949
- function spentMainUTXOs(uint256 utxoKey) external view returns (bool) {
950
- return self.spentMainUTXOs[utxoKey];
951
- }
952
-
953
722
  /// @notice Collection of all pending redemption requests indexed by
954
723
  /// redemption key built as
955
724
  /// keccak256(walletPubKeyHash | redeemerOutputScript). The
@@ -967,7 +736,7 @@ contract Bridge is Ownable, EcdsaWalletOwner {
967
736
  function pendingRedemptions(uint256 redemptionKey)
968
737
  external
969
738
  view
970
- returns (Redeem.RedemptionRequest memory)
739
+ returns (Redemption.RedemptionRequest memory)
971
740
  {
972
741
  return self.pendingRedemptions[redemptionKey];
973
742
  }
@@ -988,8 +757,219 @@ contract Bridge is Ownable, EcdsaWalletOwner {
988
757
  function timedOutRedemptions(uint256 redemptionKey)
989
758
  external
990
759
  view
991
- returns (Redeem.RedemptionRequest memory)
760
+ returns (Redemption.RedemptionRequest memory)
992
761
  {
993
762
  return self.timedOutRedemptions[redemptionKey];
994
763
  }
764
+
765
+ /// @notice Collection of main UTXOs that are honestly spent indexed by
766
+ /// keccak256(fundingTxHash | fundingOutputIndex). The fundingTxHash
767
+ /// is bytes32 (ordered as in Bitcoin internally) and
768
+ /// fundingOutputIndex an uint32. A main UTXO is considered honestly
769
+ /// spent if it was used as an input of a transaction that have been
770
+ /// proven in the Bridge.
771
+ function spentMainUTXOs(uint256 utxoKey) external view returns (bool) {
772
+ return self.spentMainUTXOs[utxoKey];
773
+ }
774
+
775
+ /// @notice Gets details about a registered wallet.
776
+ /// @param walletPubKeyHash The 20-byte wallet public key hash (computed
777
+ /// using Bitcoin HASH160 over the compressed ECDSA public key)
778
+ /// @return Wallet details.
779
+ function wallets(bytes20 walletPubKeyHash)
780
+ external
781
+ view
782
+ returns (Wallets.Wallet memory)
783
+ {
784
+ return self.registeredWallets[walletPubKeyHash];
785
+ }
786
+
787
+ /// @notice Gets the public key hash of the active wallet.
788
+ /// @return The 20-byte public key hash (computed using Bitcoin HASH160
789
+ /// over the compressed ECDSA public key) of the active wallet.
790
+ /// Returns bytes20(0) if there is no active wallet at the moment.
791
+ function activeWalletPubKeyHash() external view returns (bytes20) {
792
+ return self.activeWalletPubKeyHash;
793
+ }
794
+
795
+ /// @notice Returns the fraud challenge identified by the given key built
796
+ /// as keccak256(walletPublicKey|sighash).
797
+ function fraudChallenges(uint256 challengeKey)
798
+ external
799
+ view
800
+ returns (Fraud.FraudChallenge memory)
801
+ {
802
+ return self.fraudChallenges[challengeKey];
803
+ }
804
+
805
+ /// @notice Indicates if the vault with the given address is trusted or not.
806
+ /// Depositors can route their revealed deposits only to trusted
807
+ /// vaults and have trusted vaults notified about new deposits as
808
+ /// soon as these deposits get swept. Vaults not trusted by the
809
+ /// Bridge can still be used by Bank balance owners on their own
810
+ /// responsibility - anyone can approve their Bank balance to any
811
+ /// address.
812
+ function isVaultTrusted(address vault) external view returns (bool) {
813
+ return self.isVaultTrusted[vault];
814
+ }
815
+
816
+ /// @notice Returns the current values of Bridge deposit parameters.
817
+ /// @return depositDustThreshold The minimal amount that can be requested
818
+ /// to deposit. Value of this parameter must take into account the
819
+ /// value of `depositTreasuryFeeDivisor` and `depositTxMaxFee`
820
+ /// parameters in order to make requests that can incur the
821
+ /// treasury and transaction fee and still satisfy the depositor.
822
+ /// @return depositTreasuryFeeDivisor Divisor used to compute the treasury
823
+ /// fee taken from each deposit and transferred to the treasury upon
824
+ /// sweep proof submission. That fee is computed as follows:
825
+ /// `treasuryFee = depositedAmount / depositTreasuryFeeDivisor`
826
+ /// For example, if the treasury fee needs to be 2% of each deposit,
827
+ /// the `depositTreasuryFeeDivisor` should be set to `50`
828
+ /// because `1/50 = 0.02 = 2%`.
829
+ /// @return depositTxMaxFee Maximum amount of BTC transaction fee that can
830
+ /// be incurred by each swept deposit being part of the given sweep
831
+ /// transaction. If the maximum BTC transaction fee is exceeded,
832
+ /// such transaction is considered a fraud.
833
+ function depositParameters()
834
+ external
835
+ view
836
+ returns (
837
+ uint64 depositDustThreshold,
838
+ uint64 depositTreasuryFeeDivisor,
839
+ uint64 depositTxMaxFee
840
+ )
841
+ {
842
+ depositDustThreshold = self.depositDustThreshold;
843
+ depositTreasuryFeeDivisor = self.depositTreasuryFeeDivisor;
844
+ depositTxMaxFee = self.depositTxMaxFee;
845
+ }
846
+
847
+ /// @notice Returns the current values of Bridge redemption parameters.
848
+ /// @return redemptionDustThreshold The minimal amount that can be requested
849
+ /// for redemption. Value of this parameter must take into account
850
+ /// the value of `redemptionTreasuryFeeDivisor` and `redemptionTxMaxFee`
851
+ /// parameters in order to make requests that can incur the
852
+ /// treasury and transaction fee and still satisfy the redeemer.
853
+ /// @return redemptionTreasuryFeeDivisor Divisor used to compute the treasury
854
+ /// fee taken from each redemption request and transferred to the
855
+ /// treasury upon successful request finalization. That fee is
856
+ /// computed as follows:
857
+ /// `treasuryFee = requestedAmount / redemptionTreasuryFeeDivisor`
858
+ /// For example, if the treasury fee needs to be 2% of each
859
+ /// redemption request, the `redemptionTreasuryFeeDivisor` should
860
+ /// be set to `50` because `1/50 = 0.02 = 2%`.
861
+ /// @return redemptionTxMaxFee Maximum amount of BTC transaction fee that
862
+ /// can be incurred by each redemption request being part of the
863
+ /// given redemption transaction. If the maximum BTC transaction
864
+ /// fee is exceeded, such transaction is considered a fraud.
865
+ /// @return redemptionTimeout Time after which the redemption request can be
866
+ /// reported as timed out. It is counted from the moment when the
867
+ /// redemption request was created via `requestRedemption` call.
868
+ /// Reported timed out requests are cancelled and locked TBTC is
869
+ /// returned to the redeemer in full amount.
870
+ function redemptionParameters()
871
+ external
872
+ view
873
+ returns (
874
+ uint64 redemptionDustThreshold,
875
+ uint64 redemptionTreasuryFeeDivisor,
876
+ uint64 redemptionTxMaxFee,
877
+ uint256 redemptionTimeout
878
+ )
879
+ {
880
+ redemptionDustThreshold = self.redemptionDustThreshold;
881
+ redemptionTreasuryFeeDivisor = self.redemptionTreasuryFeeDivisor;
882
+ redemptionTxMaxFee = self.redemptionTxMaxFee;
883
+ redemptionTimeout = self.redemptionTimeout;
884
+ }
885
+
886
+ /// @notice Returns the current values of Bridge moving funds between
887
+ /// wallets parameters.
888
+ /// @return movingFundsTxMaxTotalFee Maximum amount of the total BTC
889
+ /// transaction fee that is acceptable in a single moving funds
890
+ /// transaction. This is a _total_ max fee for the entire moving
891
+ /// funds transaction.
892
+ function movingFundsParameters()
893
+ external
894
+ view
895
+ returns (uint64 movingFundsTxMaxTotalFee)
896
+ {
897
+ // TODO: we will have more parameters here, for example moving funds timeout
898
+ movingFundsTxMaxTotalFee = self.movingFundsTxMaxTotalFee;
899
+ }
900
+
901
+ /// @return walletCreationPeriod Determines how frequently a new wallet
902
+ /// creation can be requested. Value in seconds.
903
+ /// @return walletMinBtcBalance The minimum BTC threshold in satoshi that is
904
+ /// used to decide about wallet creation or closing.
905
+ /// @return walletMaxBtcBalance The maximum BTC threshold in satoshi that is
906
+ /// used to decide about wallet creation.
907
+ /// @return walletMaxAge The maximum age of a wallet in seconds, after which
908
+ /// the wallet moving funds process can be requested.
909
+ function walletParameters()
910
+ external
911
+ view
912
+ returns (
913
+ uint32 walletCreationPeriod,
914
+ uint64 walletMinBtcBalance,
915
+ uint64 walletMaxBtcBalance,
916
+ uint32 walletMaxAge
917
+ )
918
+ {
919
+ walletCreationPeriod = self.walletCreationPeriod;
920
+ walletMinBtcBalance = self.walletMinBtcBalance;
921
+ walletMaxBtcBalance = self.walletMaxBtcBalance;
922
+ walletMaxAge = self.walletMaxAge;
923
+ }
924
+
925
+ /// @notice Returns the current values of Bridge fraud parameters.
926
+ /// @return fraudSlashingAmount The amount slashed from each wallet member
927
+ /// for committing a fraud.
928
+ /// @return fraudNotifierRewardMultiplier The percentage of the notifier
929
+ /// reward from the staking contract the notifier of a fraud
930
+ /// receives. The value is in the range [0, 100].
931
+ /// @return fraudChallengeDefeatTimeout The amount of time the wallet has to
932
+ /// defeat a fraud challenge.
933
+ /// @return fraudChallengeDepositAmount The amount of ETH in wei the party
934
+ /// challenging the wallet for fraud needs to deposit.
935
+ function fraudParameters()
936
+ external
937
+ view
938
+ returns (
939
+ uint256 fraudSlashingAmount,
940
+ uint256 fraudNotifierRewardMultiplier,
941
+ uint256 fraudChallengeDefeatTimeout,
942
+ uint256 fraudChallengeDepositAmount
943
+ )
944
+ {
945
+ fraudSlashingAmount = self.fraudSlashingAmount;
946
+ fraudNotifierRewardMultiplier = self.fraudNotifierRewardMultiplier;
947
+ fraudChallengeDefeatTimeout = self.fraudChallengeDefeatTimeout;
948
+ fraudChallengeDepositAmount = self.fraudChallengeDepositAmount;
949
+ }
950
+
951
+ /// @notice Returns the addresses of contracts Bridge is interacting with.
952
+ /// @return bank Address of the Bank the Bridge belongs to.
953
+ /// @return relay Address of the Bitcoin relay providing the current Bitcoin
954
+ /// network difficulty.
955
+ function contractReferences()
956
+ external
957
+ view
958
+ returns (Bank bank, IRelay relay)
959
+ {
960
+ bank = self.bank;
961
+ relay = self.relay;
962
+ }
963
+
964
+ /// @notice Address where the deposit treasury fees will be sent to.
965
+ /// Treasury takes part in the operators rewarding process.
966
+ function treasury() external view returns (address) {
967
+ return self.treasury;
968
+ }
969
+
970
+ /// @notice The number of confirmations on the Bitcoin chain required to
971
+ /// successfully evaluate an SPV proof.
972
+ function txProofDifficultyFactor() external view returns (uint256) {
973
+ return self.txProofDifficultyFactor;
974
+ }
995
975
  }