@keep-network/tbtc-v2 0.1.1-dev.53 → 0.1.1-dev.56

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 (72) hide show
  1. package/artifacts/Bank.json +3 -3
  2. package/artifacts/Bridge.json +626 -254
  3. package/artifacts/Deposit.json +7 -7
  4. package/artifacts/DepositSweep.json +76 -0
  5. package/artifacts/EcdsaDkgValidator.json +1 -1
  6. package/artifacts/EcdsaInactivity.json +1 -1
  7. package/artifacts/Fraud.json +8 -8
  8. package/artifacts/KeepRegistry.json +1 -1
  9. package/artifacts/KeepStake.json +2 -2
  10. package/artifacts/KeepToken.json +2 -2
  11. package/artifacts/KeepTokenStaking.json +1 -1
  12. package/artifacts/MovingFunds.json +44 -13
  13. package/artifacts/NuCypherStakingEscrow.json +1 -1
  14. package/artifacts/NuCypherToken.json +2 -2
  15. package/artifacts/RandomBeaconStub.json +1 -1
  16. package/artifacts/Redemption.json +11 -11
  17. package/artifacts/ReimbursementPool.json +2 -2
  18. package/artifacts/Relay.json +9 -9
  19. package/artifacts/SortitionPool.json +2 -2
  20. package/artifacts/T.json +2 -2
  21. package/artifacts/TBTC.json +3 -3
  22. package/artifacts/TBTCToken.json +3 -3
  23. package/artifacts/TokenStaking.json +1 -1
  24. package/artifacts/TokenholderGovernor.json +9 -9
  25. package/artifacts/TokenholderTimelock.json +8 -8
  26. package/artifacts/VendingMachine.json +10 -10
  27. package/artifacts/VendingMachineKeep.json +1 -1
  28. package/artifacts/VendingMachineNuCypher.json +1 -1
  29. package/artifacts/WalletRegistry.json +2 -2
  30. package/artifacts/WalletRegistryGovernance.json +2 -2
  31. package/artifacts/Wallets.json +7 -7
  32. package/artifacts/solcInputs/{fa22a04615b4037761340d27e55c86ee.json → 5dd2a7c685770548b7ea9ce25e179326.json} +11 -11
  33. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
  34. package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
  35. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +1 -1
  36. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +2 -2
  37. package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
  38. package/build/contracts/bridge/Bridge.sol/Bridge.json +328 -128
  39. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +1 -1
  40. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +29 -11
  41. package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +1 -1
  42. package/build/contracts/bridge/Deposit.sol/Deposit.json +2 -2
  43. package/build/contracts/bridge/DepositSweep.sol/DepositSweep.dbg.json +4 -0
  44. package/build/contracts/bridge/{Sweep.sol/Sweep.json → DepositSweep.sol/DepositSweep.json} +4 -4
  45. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +1 -1
  46. package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +1 -1
  47. package/build/contracts/bridge/Fraud.sol/Fraud.json +2 -2
  48. package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +1 -1
  49. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +1 -1
  50. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +21 -2
  51. package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +1 -1
  52. package/build/contracts/bridge/Redemption.sol/OutboundTx.json +2 -2
  53. package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +1 -1
  54. package/build/contracts/bridge/Redemption.sol/Redemption.json +2 -2
  55. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
  56. package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +1 -1
  57. package/build/contracts/bridge/Wallets.sol/Wallets.json +2 -2
  58. package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
  59. package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
  60. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
  61. package/contracts/bridge/BitcoinTx.sol +69 -0
  62. package/contracts/bridge/Bridge.sol +176 -55
  63. package/contracts/bridge/BridgeState.sol +107 -44
  64. package/contracts/bridge/{Sweep.sol → DepositSweep.sol} +30 -18
  65. package/contracts/bridge/Fraud.sol +1 -1
  66. package/contracts/bridge/MovingFunds.sol +485 -79
  67. package/contracts/bridge/Redemption.sol +4 -4
  68. package/deploy/05_deploy_bridge.ts +5 -2
  69. package/export.json +375 -94
  70. package/package.json +1 -1
  71. package/artifacts/Sweep.json +0 -76
  72. package/build/contracts/bridge/Sweep.sol/Sweep.dbg.json +0 -4
@@ -22,6 +22,7 @@ import "./Deposit.sol";
22
22
  import "./Redemption.sol";
23
23
  import "./Fraud.sol";
24
24
  import "./Wallets.sol";
25
+ import "./MovingFunds.sol";
25
26
 
26
27
  import "../bank/Bank.sol";
27
28
 
@@ -83,17 +84,39 @@ library BridgeState {
83
84
  // if per single redemption. `movingFundsTxMaxTotalFee` is a total
84
85
  // fee for the entire transaction.
85
86
  uint64 movingFundsTxMaxTotalFee;
86
- // Time after which the moving funds process can be reported as
87
- // timed out. It is counted from the moment when the wallet
88
- // was requested to move their funds and switched to the MovingFunds
89
- // state. Value in seconds.
90
- uint32 movingFundsTimeout;
91
87
  // The minimal satoshi amount that makes sense to be transferred during
92
88
  // the moving funds process. Moving funds wallets having their BTC
93
89
  // balance below that value can begin closing immediately as
94
90
  // transferring such a low value may not be possible due to
95
91
  // BTC network fees.
96
92
  uint64 movingFundsDustThreshold;
93
+ // Time after which the moving funds process can be reported as
94
+ // timed out. It is counted from the moment when the wallet
95
+ // was requested to move their funds and switched to the MovingFunds
96
+ // state. Value in seconds.
97
+ uint32 movingFundsTimeout;
98
+ // The amount of stake slashed from each member of a wallet for a moving
99
+ // funds timeout.
100
+ uint96 movingFundsTimeoutSlashingAmount;
101
+ // The percentage of the notifier reward from the staking contract
102
+ // the notifier of a moving funds timeout receives. The value is in the
103
+ // range [0, 100].
104
+ uint256 movingFundsTimeoutNotifierRewardMultiplier;
105
+ // Maximum amount of the total BTC transaction fee that is acceptable in
106
+ // a single moved funds sweep transaction.
107
+ //
108
+ // This is a TOTAL max fee for the moved funds sweep transaction. Note
109
+ // that `depositTxMaxFee` is per single deposit and `redemptionTxMaxFee`
110
+ // if per single redemption. `movedFundsSweepTxMaxTotalFee` is a total
111
+ // fee for the entire transaction.
112
+ uint64 movedFundsSweepTxMaxTotalFee;
113
+ // Collection of all moved funds sweep requests indexed by
114
+ // `keccak256(movingFundsTxHash | movingFundsOutputIndex)`.
115
+ // The `movingFundsTxHash` is `bytes32` (ordered as in Bitcoin
116
+ // internally) and `movingFundsOutputIndex` an `uint32`. Each entry
117
+ // is actually an UTXO representing the moved funds and is supposed
118
+ // to be swept with the current main UTXO of the recipient wallet.
119
+ mapping(uint256 => MovingFunds.MovedFundsSweepRequest) movedFundsSweepRequests;
97
120
  // The minimal amount that can be requested for redemption.
98
121
  // Value of this parameter must take into account the value of
99
122
  // `redemptionTreasuryFeeDivisor` and `redemptionTxMaxFee`
@@ -158,16 +181,16 @@ library BridgeState {
158
181
  // mapping basing on a timed out request stored previously in
159
182
  // `pendingRedemptions` mapping.
160
183
  mapping(uint256 => Redemption.RedemptionRequest) timedOutRedemptions;
184
+ // The amount of ETH in wei the party challenging the wallet for fraud
185
+ // needs to deposit.
186
+ uint256 fraudChallengeDepositAmount;
187
+ // The amount of time the wallet has to defeat a fraud challenge.
188
+ uint256 fraudChallengeDefeatTimeout;
161
189
  // The amount of stake slashed from each member of a wallet for a fraud.
162
190
  uint96 fraudSlashingAmount;
163
191
  // The percentage of the notifier reward from the staking contract
164
192
  // the notifier of a fraud receives. The value is in the range [0, 100].
165
193
  uint256 fraudNotifierRewardMultiplier;
166
- // The amount of time the wallet has to defeat a fraud challenge.
167
- uint256 fraudChallengeDefeatTimeout;
168
- // The amount of ETH in wei the party challenging the wallet for fraud
169
- // needs to deposit.
170
- uint256 fraudChallengeDepositAmount;
171
194
  // Collection of all submitted fraud challenges indexed by challenge
172
195
  // key built as `keccak256(walletPublicKey|sighash)`.
173
196
  mapping(uint256 => Fraud.FraudChallenge) fraudChallenges;
@@ -236,8 +259,11 @@ library BridgeState {
236
259
 
237
260
  event MovingFundsParametersUpdated(
238
261
  uint64 movingFundsTxMaxTotalFee,
262
+ uint64 movingFundsDustThreshold,
239
263
  uint32 movingFundsTimeout,
240
- uint64 movingFundsDustThreshold
264
+ uint96 movingFundsTimeoutSlashingAmount,
265
+ uint256 movingFundsTimeoutNotifierRewardMultiplier,
266
+ uint64 movedFundsSweepTxMaxTotalFee
241
267
  );
242
268
 
243
269
  event WalletParametersUpdated(
@@ -251,10 +277,10 @@ library BridgeState {
251
277
  );
252
278
 
253
279
  event FraudParametersUpdated(
254
- uint96 fraudSlashingAmount,
255
- uint256 fraudNotifierRewardMultiplier,
280
+ uint256 fraudChallengeDepositAmount,
256
281
  uint256 fraudChallengeDefeatTimeout,
257
- uint256 fraudChallengeDepositAmount
282
+ uint96 fraudSlashingAmount,
283
+ uint256 fraudNotifierRewardMultiplier
258
284
  );
259
285
 
260
286
  /// @notice Updates parameters of deposits.
@@ -416,50 +442,87 @@ library BridgeState {
416
442
  /// BTC transaction fee that is acceptable in a single moving funds
417
443
  /// transaction. This is a _total_ max fee for the entire moving
418
444
  /// funds transaction.
419
- /// @param _movingFundsTimeout New value of the moving funds timeout in
420
- /// seconds. It is the time after which the moving funds process can
421
- /// be reported as timed out. It is counted from the moment when the
422
- /// wallet was requested to move their funds and switched to the
423
- /// MovingFunds state.
424
445
  /// @param _movingFundsDustThreshold New value of the moving funds dust
425
446
  /// threshold. It is the minimal satoshi amount that makes sense to
426
447
  // be transferred during the moving funds process. Moving funds
427
448
  // wallets having their BTC balance below that value can begin
428
449
  // closing immediately as transferring such a low value may not be
429
450
  // possible due to BTC network fees.
451
+ /// @param _movingFundsTimeout New value of the moving funds timeout in
452
+ /// seconds. It is the time after which the moving funds process can
453
+ /// be reported as timed out. It is counted from the moment when the
454
+ /// wallet was requested to move their funds and switched to the
455
+ /// MovingFunds state.
456
+ /// @param _movingFundsTimeoutSlashingAmount New value of the moving funds
457
+ /// timeout slashing amount in T, it is the amount slashed from each
458
+ /// wallet member for moving funds timeout
459
+ /// @param _movingFundsTimeoutNotifierRewardMultiplier New value of the
460
+ /// moving funds timeout notifier reward multiplier as percentage,
461
+ /// it determines the percentage of the notifier reward from the
462
+ /// staking contact the notifier of a moving funds timeout receives.
463
+ /// The value must be in the range [0, 100]
464
+ /// @param _movedFundsSweepTxMaxTotalFee New value of the moved funds sweep
465
+ /// transaction max total fee in satoshis. It is the maximum amount
466
+ /// of the total BTC transaction fee that is acceptable in a single
467
+ /// moved funds sweep transaction. This is a _total_ max fee for the
468
+ /// entire moved funds sweep transaction.
430
469
  /// @dev Requirements:
431
470
  /// - Moving funds transaction max total fee must be greater than zero
432
- /// - Moving funds timeout must be greater than zero
433
471
  /// - Moving funds dust threshold must be greater than zero
472
+ /// - Moving funds timeout must be greater than zero
473
+ /// - Moving funds timeout notifier reward multiplier must be in the
474
+ /// range [0, 100]
475
+ /// - Moved funds sweep transaction max total fee must be greater than zero
434
476
  function updateMovingFundsParameters(
435
477
  Storage storage self,
436
478
  uint64 _movingFundsTxMaxTotalFee,
479
+ uint64 _movingFundsDustThreshold,
437
480
  uint32 _movingFundsTimeout,
438
- uint64 _movingFundsDustThreshold
481
+ uint96 _movingFundsTimeoutSlashingAmount,
482
+ uint256 _movingFundsTimeoutNotifierRewardMultiplier,
483
+ uint64 _movedFundsSweepTxMaxTotalFee
439
484
  ) internal {
440
485
  require(
441
486
  _movingFundsTxMaxTotalFee > 0,
442
487
  "Moving funds transaction max total fee must be greater than zero"
443
488
  );
444
489
 
490
+ require(
491
+ _movingFundsDustThreshold > 0,
492
+ "Moving funds dust threshold must be greater than zero"
493
+ );
494
+
445
495
  require(
446
496
  _movingFundsTimeout > 0,
447
497
  "Moving funds timeout must be greater than zero"
448
498
  );
449
499
 
450
500
  require(
451
- _movingFundsDustThreshold > 0,
452
- "Moving funds dust threshold must be greater than zero"
501
+ _movingFundsTimeoutNotifierRewardMultiplier <= 100,
502
+ "Moving funds timeout notifier reward multiplier must be in the range [0, 100]"
503
+ );
504
+
505
+ require(
506
+ _movedFundsSweepTxMaxTotalFee > 0,
507
+ "Moved funds sweep transaction max total fee must be greater than zero"
453
508
  );
454
509
 
455
510
  self.movingFundsTxMaxTotalFee = _movingFundsTxMaxTotalFee;
456
- self.movingFundsTimeout = _movingFundsTimeout;
457
511
  self.movingFundsDustThreshold = _movingFundsDustThreshold;
512
+ self.movingFundsTimeout = _movingFundsTimeout;
513
+ self
514
+ .movingFundsTimeoutSlashingAmount = _movingFundsTimeoutSlashingAmount;
515
+ self
516
+ .movingFundsTimeoutNotifierRewardMultiplier = _movingFundsTimeoutNotifierRewardMultiplier;
517
+ self.movedFundsSweepTxMaxTotalFee = _movedFundsSweepTxMaxTotalFee;
458
518
 
459
519
  emit MovingFundsParametersUpdated(
460
520
  _movingFundsTxMaxTotalFee,
521
+ _movingFundsDustThreshold,
461
522
  _movingFundsTimeout,
462
- _movingFundsDustThreshold
523
+ _movingFundsTimeoutSlashingAmount,
524
+ _movingFundsTimeoutNotifierRewardMultiplier,
525
+ _movedFundsSweepTxMaxTotalFee
463
526
  );
464
527
  }
465
528
 
@@ -536,6 +599,12 @@ library BridgeState {
536
599
  }
537
600
 
538
601
  /// @notice Updates parameters related to frauds.
602
+ /// @param _fraudChallengeDepositAmount New value of the fraud challenge
603
+ /// deposit amount in wei, it is the amount of ETH the party
604
+ /// challenging the wallet for fraud needs to deposit
605
+ /// @param _fraudChallengeDefeatTimeout New value of the challenge defeat
606
+ /// timeout in seconds, it is the amount of time the wallet has to
607
+ /// defeat a fraud challenge. The value must be greater than zero
539
608
  /// @param _fraudSlashingAmount New value of the fraud slashing amount in T,
540
609
  /// it is the amount slashed from each wallet member for committing
541
610
  /// a fraud
@@ -543,42 +612,36 @@ library BridgeState {
543
612
  /// reward multiplier as percentage, it determines the percentage of
544
613
  /// the notifier reward from the staking contact the notifier of
545
614
  /// a fraud receives. The value must be in the range [0, 100]
546
- /// @param _fraudChallengeDefeatTimeout New value of the challenge defeat
547
- /// timeout in seconds, it is the amount of time the wallet has to
548
- /// defeat a fraud challenge. The value must be greater than zero
549
- /// @param _fraudChallengeDepositAmount New value of the fraud challenge
550
- /// deposit amount in wei, it is the amount of ETH the party
551
- /// challenging the wallet for fraud needs to deposit
552
615
  /// @dev Requirements:
553
- /// - Fraud notifier reward multiplier must be in the range [0, 100]
554
616
  /// - Fraud challenge defeat timeout must be greater than 0
617
+ /// - Fraud notifier reward multiplier must be in the range [0, 100]
555
618
  function updateFraudParameters(
556
619
  Storage storage self,
557
- uint96 _fraudSlashingAmount,
558
- uint256 _fraudNotifierRewardMultiplier,
620
+ uint256 _fraudChallengeDepositAmount,
559
621
  uint256 _fraudChallengeDefeatTimeout,
560
- uint256 _fraudChallengeDepositAmount
622
+ uint96 _fraudSlashingAmount,
623
+ uint256 _fraudNotifierRewardMultiplier
561
624
  ) internal {
562
625
  require(
563
- _fraudNotifierRewardMultiplier <= 100,
564
- "Fraud notifier reward multiplier must be in the range [0, 100]"
626
+ _fraudChallengeDefeatTimeout > 0,
627
+ "Fraud challenge defeat timeout must be greater than zero"
565
628
  );
566
629
 
567
630
  require(
568
- _fraudChallengeDefeatTimeout > 0,
569
- "Fraud challenge defeat timeout must be greater than zero"
631
+ _fraudNotifierRewardMultiplier <= 100,
632
+ "Fraud notifier reward multiplier must be in the range [0, 100]"
570
633
  );
571
634
 
635
+ self.fraudChallengeDepositAmount = _fraudChallengeDepositAmount;
636
+ self.fraudChallengeDefeatTimeout = _fraudChallengeDefeatTimeout;
572
637
  self.fraudSlashingAmount = _fraudSlashingAmount;
573
638
  self.fraudNotifierRewardMultiplier = _fraudNotifierRewardMultiplier;
574
- self.fraudChallengeDefeatTimeout = _fraudChallengeDefeatTimeout;
575
- self.fraudChallengeDepositAmount = _fraudChallengeDepositAmount;
576
639
 
577
640
  emit FraudParametersUpdated(
578
- _fraudSlashingAmount,
579
- _fraudNotifierRewardMultiplier,
641
+ _fraudChallengeDepositAmount,
580
642
  _fraudChallengeDefeatTimeout,
581
- _fraudChallengeDepositAmount
643
+ _fraudSlashingAmount,
644
+ _fraudNotifierRewardMultiplier
582
645
  );
583
646
  }
584
647
  }
@@ -33,7 +33,7 @@ import "../bank/Bank.sol";
33
33
  /// This has two main effects: it consolidates the UTXO set and it disables
34
34
  /// the refund. Balances of depositors in the Bank are increased when the
35
35
  /// SPV sweep proof is submitted to the Bridge.
36
- library Sweep {
36
+ library DepositSweep {
37
37
  using BridgeState for BridgeState.Storage;
38
38
  using BitcoinTx for BridgeState.Storage;
39
39
 
@@ -41,7 +41,7 @@ library Sweep {
41
41
 
42
42
  /// @notice Represents an outcome of the sweep Bitcoin transaction
43
43
  /// inputs processing.
44
- struct SweepTxInputsInfo {
44
+ struct DepositSweepTxInputsInfo {
45
45
  // Sum of all inputs values i.e. all deposits and main UTXO value,
46
46
  // if present.
47
47
  uint256 inputsTotalValue;
@@ -103,7 +103,7 @@ library Sweep {
103
103
  /// - `mainUtxo` components must point to the recent main UTXO
104
104
  /// of the given wallet, as currently known on the Ethereum chain.
105
105
  /// If there is no main UTXO, this parameter is ignored.
106
- function submitSweepProof(
106
+ function submitDepositSweepProof(
107
107
  BridgeState.Storage storage self,
108
108
  BitcoinTx.Info calldata sweepTx,
109
109
  BitcoinTx.Proof calldata sweepProof,
@@ -120,20 +120,21 @@ library Sweep {
120
120
  (
121
121
  bytes20 walletPubKeyHash,
122
122
  uint64 sweepTxOutputValue
123
- ) = processSweepTxOutput(sweepTx.outputVector);
123
+ ) = processDepositSweepTxOutput(sweepTx.outputVector);
124
124
 
125
125
  (
126
126
  Wallets.Wallet storage wallet,
127
127
  BitcoinTx.UTXO memory resolvedMainUtxo
128
- ) = resolveSweepingWallet(self, walletPubKeyHash, mainUtxo);
128
+ ) = resolveDepositSweepingWallet(self, walletPubKeyHash, mainUtxo);
129
129
 
130
130
  // Process sweep transaction inputs and extract all information needed
131
131
  // to perform deposit bookkeeping.
132
- SweepTxInputsInfo memory inputsInfo = processSweepTxInputs(
133
- self,
134
- sweepTx.inputVector,
135
- resolvedMainUtxo
136
- );
132
+ DepositSweepTxInputsInfo
133
+ memory inputsInfo = processDepositSweepTxInputs(
134
+ self,
135
+ sweepTx.inputVector,
136
+ resolvedMainUtxo
137
+ );
137
138
 
138
139
  // Helper variable that will hold the sum of treasury fees paid by
139
140
  // all deposits.
@@ -145,7 +146,7 @@ library Sweep {
145
146
  (
146
147
  uint256 depositTxFee,
147
148
  uint256 depositTxFeeRemainder
148
- ) = sweepTxFeeDistribution(
149
+ ) = depositSweepTxFeeDistribution(
149
150
  inputsInfo.inputsTotalValue,
150
151
  sweepTxOutputValue,
151
152
  inputsInfo.depositedAmounts.length
@@ -206,11 +207,16 @@ library Sweep {
206
207
  /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
207
208
  /// the Ethereum chain. If no main UTXO exists for the given wallet,
208
209
  /// this parameter is ignored
210
+ /// @return wallet Data of the sweeping wallet.
211
+ /// @return resolvedMainUtxo The actual main UTXO of the sweeping wallet
212
+ /// resolved by cross-checking the `mainUtxo` parameter with
213
+ /// the chain state. If the validation went well, this is the
214
+ /// plain-text main UTXO corresponding to the `wallet.mainUtxoHash`.
209
215
  /// @dev Requirements:
210
216
  /// - Sweeping wallet must be either in Live or MovingFunds state.
211
217
  /// - If the main UTXO of the sweeping wallet exists in the storage,
212
218
  /// the passed `mainUTXO` parameter must be equal to the stored one.
213
- function resolveSweepingWallet(
219
+ function resolveDepositSweepingWallet(
214
220
  BridgeState.Storage storage self,
215
221
  bytes20 walletPubKeyHash,
216
222
  BitcoinTx.UTXO calldata mainUtxo
@@ -261,7 +267,7 @@ library Sweep {
261
267
  /// it is passed here
262
268
  /// @return walletPubKeyHash 20-byte wallet public key hash.
263
269
  /// @return value 8-byte sweep transaction output value.
264
- function processSweepTxOutput(bytes memory sweepTxOutputVector)
270
+ function processDepositSweepTxOutput(bytes memory sweepTxOutputVector)
265
271
  internal
266
272
  pure
267
273
  returns (bytes20 walletPubKeyHash, uint64 value)
@@ -282,6 +288,8 @@ library Sweep {
282
288
 
283
289
  bytes memory output = sweepTxOutputVector.extractOutputAtIndex(0);
284
290
  value = output.extractValue();
291
+ // TODO: Extract `walletPubKeyHash` using `self.extractPubKeyHash`
292
+ // in order to get stronger validation.
285
293
  bytes memory walletPubKeyHashBytes = output.extractHash();
286
294
  // The sweep transaction output should always be P2PKH or P2WPKH.
287
295
  // In both cases, the wallet public key hash should be 20 bytes length.
@@ -311,11 +319,11 @@ library Sweep {
311
319
  /// exists for the given the wallet, this parameter's fields should
312
320
  /// be zeroed to bypass the main UTXO validation
313
321
  /// @return info Outcomes of the processing.
314
- function processSweepTxInputs(
322
+ function processDepositSweepTxInputs(
315
323
  BridgeState.Storage storage self,
316
324
  bytes memory sweepTxInputVector,
317
325
  BitcoinTx.UTXO memory mainUtxo
318
- ) internal returns (SweepTxInputsInfo memory info) {
326
+ ) internal returns (DepositSweepTxInputsInfo memory info) {
319
327
  // If the passed `mainUtxo` parameter's values are zeroed, the main UTXO
320
328
  // for the given wallet doesn't exist and it is not expected to be
321
329
  // included in the sweep transaction input vector.
@@ -365,7 +373,10 @@ library Sweep {
365
373
  bytes32 outpointTxHash,
366
374
  uint32 outpointIndex,
367
375
  uint256 inputLength
368
- ) = parseTxInputAt(sweepTxInputVector, inputStartingIndex);
376
+ ) = parseDepositSweepTxInputAt(
377
+ sweepTxInputVector,
378
+ inputStartingIndex
379
+ );
369
380
 
370
381
  Deposit.DepositRequest storage deposit = self.deposits[
371
382
  uint256(
@@ -402,6 +413,7 @@ library Sweep {
402
413
  } else if (
403
414
  mainUtxoExpected != mainUtxoFound &&
404
415
  mainUtxo.txHash == outpointTxHash
416
+ // TODO: We probably need to check `mainUtxo.txOutputIndex == outpointIndex` as well.
405
417
  ) {
406
418
  // If we entered here, that means the input was identified as
407
419
  // the expected main UTXO.
@@ -455,7 +467,7 @@ library Sweep {
455
467
  /// @dev This function assumes vector's structure is valid so it must be
456
468
  /// validated using e.g. `BTCUtils.validateVin` function before it
457
469
  /// is passed here.
458
- function parseTxInputAt(
470
+ function parseDepositSweepTxInputAt(
459
471
  bytes memory inputVector,
460
472
  uint256 inputStartingIndex
461
473
  )
@@ -490,7 +502,7 @@ library Sweep {
490
502
  /// transaction fee than cannot be distributed over all deposits.
491
503
  /// @dev It is up to the caller to decide how the remainder should be
492
504
  /// counted in. This function only computes its value.
493
- function sweepTxFeeDistribution(
505
+ function depositSweepTxFeeDistribution(
494
506
  uint256 sweepTxInputsTotalValue,
495
507
  uint256 sweepTxOutputValue,
496
508
  uint256 depositsCount
@@ -277,7 +277,7 @@ library Fraud {
277
277
  /// for the given `walletID`. Those IDs are not directly stored
278
278
  /// in the contract for gas efficiency purposes but they can be
279
279
  /// read from appropriate `DkgResultSubmitted` and `DkgResultApproved`
280
- /// events.
280
+ /// events of the `WalletRegistry` contract
281
281
  /// - The amount of time indicated by `challengeDefeatTimeout` must pass
282
282
  /// after the challenge was reported
283
283
  function notifyFraudChallengeDefeatTimeout(