@keep-network/tbtc-v2 0.1.1-dev.96 → 0.1.1-dev.99

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 (73) hide show
  1. package/artifacts/Bank.json +8 -8
  2. package/artifacts/Bridge.json +67 -67
  3. package/artifacts/Deposit.json +9 -9
  4. package/artifacts/DepositSweep.json +9 -9
  5. package/artifacts/EcdsaDkgValidator.json +1 -1
  6. package/artifacts/EcdsaInactivity.json +1 -1
  7. package/artifacts/EcdsaSortitionPool.json +2 -2
  8. package/artifacts/Fraud.json +9 -9
  9. package/artifacts/KeepRegistry.json +1 -1
  10. package/artifacts/KeepStake.json +2 -2
  11. package/artifacts/KeepToken.json +2 -2
  12. package/artifacts/KeepTokenStaking.json +1 -1
  13. package/artifacts/MovingFunds.json +9 -9
  14. package/artifacts/NuCypherStakingEscrow.json +1 -1
  15. package/artifacts/NuCypherToken.json +2 -2
  16. package/artifacts/RandomBeaconStub.json +1 -1
  17. package/artifacts/Redemption.json +10 -10
  18. package/artifacts/ReimbursementPool.json +2 -2
  19. package/artifacts/Relay.json +9 -9
  20. package/artifacts/T.json +2 -2
  21. package/artifacts/TBTC.json +10 -10
  22. package/artifacts/TBTCToken.json +10 -10
  23. package/artifacts/TBTCVault.json +15 -15
  24. package/artifacts/TokenStaking.json +1 -1
  25. package/artifacts/TokenholderGovernor.json +9 -9
  26. package/artifacts/TokenholderTimelock.json +8 -8
  27. package/artifacts/VendingMachine.json +11 -11
  28. package/artifacts/VendingMachineKeep.json +1 -1
  29. package/artifacts/VendingMachineNuCypher.json +1 -1
  30. package/artifacts/WalletRegistry.json +5 -5
  31. package/artifacts/WalletRegistryGovernance.json +2 -2
  32. package/artifacts/Wallets.json +11 -11
  33. package/artifacts/solcInputs/{3cf46a7694ce157f71d9dbf4db692b09.json → 5334fac3c976c2a5cd9bc3d6190e35c4.json} +9 -9
  34. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
  35. package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
  36. package/build/contracts/bank/IReceiveBalanceApproval.sol/IReceiveBalanceApproval.dbg.json +1 -1
  37. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +1 -1
  38. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +2 -2
  39. package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
  40. package/build/contracts/bridge/Bridge.sol/Bridge.json +123 -123
  41. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +1 -1
  42. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +16 -16
  43. package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +1 -1
  44. package/build/contracts/bridge/Deposit.sol/Deposit.json +2 -2
  45. package/build/contracts/bridge/DepositSweep.sol/DepositSweep.dbg.json +1 -1
  46. package/build/contracts/bridge/DepositSweep.sol/DepositSweep.json +2 -2
  47. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +1 -1
  48. package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +1 -1
  49. package/build/contracts/bridge/Fraud.sol/Fraud.json +2 -2
  50. package/build/contracts/bridge/Heartbeat.sol/Heartbeat.dbg.json +1 -1
  51. package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +1 -1
  52. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +1 -1
  53. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +2 -2
  54. package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +1 -1
  55. package/build/contracts/bridge/Redemption.sol/OutboundTx.json +2 -2
  56. package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +1 -1
  57. package/build/contracts/bridge/Redemption.sol/Redemption.json +2 -2
  58. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
  59. package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +1 -1
  60. package/build/contracts/bridge/Wallets.sol/Wallets.json +2 -2
  61. package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
  62. package/build/contracts/vault/DonationVault.sol/DonationVault.dbg.json +1 -1
  63. package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
  64. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
  65. package/contracts/bridge/BitcoinTx.sol +74 -39
  66. package/contracts/bridge/Bridge.sol +31 -31
  67. package/contracts/bridge/BridgeState.sol +100 -84
  68. package/contracts/bridge/Fraud.sol +7 -32
  69. package/contracts/bridge/MovingFunds.sol +18 -51
  70. package/contracts/bridge/Redemption.sol +95 -76
  71. package/contracts/bridge/Wallets.sol +309 -143
  72. package/export.json +54 -54
  73. package/package.json +2 -2
@@ -190,9 +190,9 @@ contract Bridge is
190
190
  uint64 redemptionDustThreshold,
191
191
  uint64 redemptionTreasuryFeeDivisor,
192
192
  uint64 redemptionTxMaxFee,
193
- uint256 redemptionTimeout,
193
+ uint32 redemptionTimeout,
194
194
  uint96 redemptionTimeoutSlashingAmount,
195
- uint256 redemptionTimeoutNotifierRewardMultiplier
195
+ uint32 redemptionTimeoutNotifierRewardMultiplier
196
196
  );
197
197
 
198
198
  event MovingFundsParametersUpdated(
@@ -201,11 +201,11 @@ contract Bridge is
201
201
  uint32 movingFundsTimeoutResetDelay,
202
202
  uint32 movingFundsTimeout,
203
203
  uint96 movingFundsTimeoutSlashingAmount,
204
- uint256 movingFundsTimeoutNotifierRewardMultiplier,
204
+ uint32 movingFundsTimeoutNotifierRewardMultiplier,
205
205
  uint64 movedFundsSweepTxMaxTotalFee,
206
206
  uint32 movedFundsSweepTimeout,
207
207
  uint96 movedFundsSweepTimeoutSlashingAmount,
208
- uint256 movedFundsSweepTimeoutNotifierRewardMultiplier
208
+ uint32 movedFundsSweepTimeoutNotifierRewardMultiplier
209
209
  );
210
210
 
211
211
  event WalletParametersUpdated(
@@ -219,10 +219,10 @@ contract Bridge is
219
219
  );
220
220
 
221
221
  event FraudParametersUpdated(
222
- uint256 fraudChallengeDepositAmount,
223
- uint256 fraudChallengeDefeatTimeout,
222
+ uint96 fraudChallengeDepositAmount,
223
+ uint32 fraudChallengeDefeatTimeout,
224
224
  uint96 fraudSlashingAmount,
225
- uint256 fraudNotifierRewardMultiplier
225
+ uint32 fraudNotifierRewardMultiplier
226
226
  );
227
227
 
228
228
  /// @dev Initializes upgradable contract on deployment.
@@ -239,7 +239,7 @@ contract Bridge is
239
239
  address _relay,
240
240
  address _treasury,
241
241
  address _ecdsaWalletRegistry,
242
- uint256 _txProofDifficultyFactor
242
+ uint96 _txProofDifficultyFactor
243
243
  ) external initializer {
244
244
  require(_bank != address(0), "Bank address cannot be zero");
245
245
  self.bank = Bank(_bank);
@@ -580,7 +580,7 @@ contract Bridge is
580
580
  /// @notice Notifies that there is a pending redemption request associated
581
581
  /// with the given wallet, that has timed out. The redemption
582
582
  /// request is identified by the key built as
583
- /// `keccak256(walletPubKeyHash | redeemerOutputScript)`.
583
+ /// `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
584
584
  /// The results of calling this function:
585
585
  /// - The pending redemptions value for the wallet will be decreased
586
586
  /// by the requested amount (minus treasury fee),
@@ -944,11 +944,11 @@ contract Bridge is
944
944
  /// can be empty as it is ignored since the wallet balance is
945
945
  /// assumed to be zero,
946
946
  /// - Wallet must be in Live state.
947
- function notifyCloseableWallet(
947
+ function notifyWalletCloseable(
948
948
  bytes20 walletPubKeyHash,
949
949
  BitcoinTx.UTXO calldata walletMainUtxo
950
950
  ) external {
951
- self.notifyCloseableWallet(walletPubKeyHash, walletMainUtxo);
951
+ self.notifyWalletCloseable(walletPubKeyHash, walletMainUtxo);
952
952
  }
953
953
 
954
954
  /// @notice Notifies about the end of the closing period for the given wallet.
@@ -1228,9 +1228,9 @@ contract Bridge is
1228
1228
  uint64 redemptionDustThreshold,
1229
1229
  uint64 redemptionTreasuryFeeDivisor,
1230
1230
  uint64 redemptionTxMaxFee,
1231
- uint256 redemptionTimeout,
1231
+ uint32 redemptionTimeout,
1232
1232
  uint96 redemptionTimeoutSlashingAmount,
1233
- uint256 redemptionTimeoutNotifierRewardMultiplier
1233
+ uint32 redemptionTimeoutNotifierRewardMultiplier
1234
1234
  ) external onlyGovernance {
1235
1235
  self.updateRedemptionParameters(
1236
1236
  redemptionDustThreshold,
@@ -1311,11 +1311,11 @@ contract Bridge is
1311
1311
  uint32 movingFundsTimeoutResetDelay,
1312
1312
  uint32 movingFundsTimeout,
1313
1313
  uint96 movingFundsTimeoutSlashingAmount,
1314
- uint256 movingFundsTimeoutNotifierRewardMultiplier,
1314
+ uint32 movingFundsTimeoutNotifierRewardMultiplier,
1315
1315
  uint64 movedFundsSweepTxMaxTotalFee,
1316
1316
  uint32 movedFundsSweepTimeout,
1317
1317
  uint96 movedFundsSweepTimeoutSlashingAmount,
1318
- uint256 movedFundsSweepTimeoutNotifierRewardMultiplier
1318
+ uint32 movedFundsSweepTimeoutNotifierRewardMultiplier
1319
1319
  ) external onlyGovernance {
1320
1320
  self.updateMovingFundsParameters(
1321
1321
  movingFundsTxMaxTotalFee,
@@ -1395,10 +1395,10 @@ contract Bridge is
1395
1395
  /// - Fraud challenge defeat timeout must be greater than 0,
1396
1396
  /// - Fraud notifier reward multiplier must be in the range [0, 100].
1397
1397
  function updateFraudParameters(
1398
- uint256 fraudChallengeDepositAmount,
1399
- uint256 fraudChallengeDefeatTimeout,
1398
+ uint96 fraudChallengeDepositAmount,
1399
+ uint32 fraudChallengeDefeatTimeout,
1400
1400
  uint96 fraudSlashingAmount,
1401
- uint256 fraudNotifierRewardMultiplier
1401
+ uint32 fraudNotifierRewardMultiplier
1402
1402
  ) external onlyGovernance {
1403
1403
  self.updateFraudParameters(
1404
1404
  fraudChallengeDepositAmount,
@@ -1424,10 +1424,10 @@ contract Bridge is
1424
1424
 
1425
1425
  /// @notice Collection of all pending redemption requests indexed by
1426
1426
  /// redemption key built as
1427
- /// keccak256(walletPubKeyHash | redeemerOutputScript). The
1428
- /// walletPubKeyHash is the 20-byte wallet's public key hash
1427
+ /// `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
1428
+ /// The walletPubKeyHash is the 20-byte wallet's public key hash
1429
1429
  /// (computed using Bitcoin HASH160 over the compressed ECDSA
1430
- /// public key) and redeemerOutputScript is a Bitcoin script
1430
+ /// public key) and `redeemerOutputScript` is a Bitcoin script
1431
1431
  /// (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
1432
1432
  /// redeemed BTC as requested by the redeemer. Requests are added
1433
1433
  /// to this mapping by the `requestRedemption` method (duplicates
@@ -1446,10 +1446,10 @@ contract Bridge is
1446
1446
 
1447
1447
  /// @notice Collection of all timed out redemptions requests indexed by
1448
1448
  /// redemption key built as
1449
- /// keccak256(walletPubKeyHash | redeemerOutputScript). The
1450
- /// walletPubKeyHash is the 20-byte wallet's public key hash
1449
+ /// `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
1450
+ /// The walletPubKeyHash is the 20-byte wallet's public key hash
1451
1451
  /// (computed using Bitcoin HASH160 over the compressed ECDSA
1452
- /// public key) and redeemerOutputScript is the Bitcoin script
1452
+ /// public key) and `redeemerOutputScript` is the Bitcoin script
1453
1453
  /// (P2PKH, P2WPKH, P2SH or P2WSH) that is involved in the timed
1454
1454
  /// out request. Timed out requests are stored in this mapping to
1455
1455
  /// avoid slashing the wallets multiple times for the same timeout.
@@ -1607,9 +1607,9 @@ contract Bridge is
1607
1607
  uint64 redemptionDustThreshold,
1608
1608
  uint64 redemptionTreasuryFeeDivisor,
1609
1609
  uint64 redemptionTxMaxFee,
1610
- uint256 redemptionTimeout,
1610
+ uint32 redemptionTimeout,
1611
1611
  uint96 redemptionTimeoutSlashingAmount,
1612
- uint256 redemptionTimeoutNotifierRewardMultiplier
1612
+ uint32 redemptionTimeoutNotifierRewardMultiplier
1613
1613
  )
1614
1614
  {
1615
1615
  redemptionDustThreshold = self.redemptionDustThreshold;
@@ -1672,11 +1672,11 @@ contract Bridge is
1672
1672
  uint32 movingFundsTimeoutResetDelay,
1673
1673
  uint32 movingFundsTimeout,
1674
1674
  uint96 movingFundsTimeoutSlashingAmount,
1675
- uint256 movingFundsTimeoutNotifierRewardMultiplier,
1675
+ uint32 movingFundsTimeoutNotifierRewardMultiplier,
1676
1676
  uint64 movedFundsSweepTxMaxTotalFee,
1677
1677
  uint32 movedFundsSweepTimeout,
1678
1678
  uint96 movedFundsSweepTimeoutSlashingAmount,
1679
- uint256 movedFundsSweepTimeoutNotifierRewardMultiplier
1679
+ uint32 movedFundsSweepTimeoutNotifierRewardMultiplier
1680
1680
  )
1681
1681
  {
1682
1682
  movingFundsTxMaxTotalFee = self.movingFundsTxMaxTotalFee;
@@ -1748,10 +1748,10 @@ contract Bridge is
1748
1748
  external
1749
1749
  view
1750
1750
  returns (
1751
- uint256 fraudChallengeDepositAmount,
1752
- uint256 fraudChallengeDefeatTimeout,
1751
+ uint96 fraudChallengeDepositAmount,
1752
+ uint32 fraudChallengeDefeatTimeout,
1753
1753
  uint96 fraudSlashingAmount,
1754
- uint256 fraudNotifierRewardMultiplier
1754
+ uint32 fraudNotifierRewardMultiplier
1755
1755
  )
1756
1756
  {
1757
1757
  fraudChallengeDepositAmount = self.fraudChallengeDepositAmount;
@@ -32,14 +32,18 @@ library BridgeState {
32
32
  Bank bank;
33
33
  // Bitcoin relay providing the current Bitcoin network difficulty.
34
34
  IRelay relay;
35
- // ECDSA Wallet Registry contract handle.
36
- EcdsaWalletRegistry ecdsaWalletRegistry;
37
35
  // The number of confirmations on the Bitcoin chain required to
38
36
  // successfully evaluate an SPV proof.
39
- uint256 txProofDifficultyFactor;
37
+ uint96 txProofDifficultyFactor;
38
+ // ECDSA Wallet Registry contract handle.
39
+ EcdsaWalletRegistry ecdsaWalletRegistry;
40
40
  // Address where the deposit and redemption treasury fees will be sent
41
41
  // to. Treasury takes part in the operators rewarding process.
42
42
  address treasury;
43
+ // Move depositDustThreshold to the next storage slot for a more
44
+ // efficient variable layout in the storage.
45
+ // slither-disable-next-line unused-state
46
+ bytes32 __treasuryAlignmentGap;
43
47
  // The minimal amount that can be requested to deposit.
44
48
  // Value of this parameter must take into account the value of
45
49
  // `depositTreasuryFeeDivisor` and `depositTxMaxFee` parameters in order
@@ -61,20 +65,10 @@ library BridgeState {
61
65
  //
62
66
  // This is a per-deposit input max fee for the sweep transaction.
63
67
  uint64 depositTxMaxFee;
64
- // Collection of all revealed deposits indexed by
65
- // `keccak256(fundingTxHash | fundingOutputIndex)`.
66
- // The `fundingTxHash` is `bytes32` (ordered as in Bitcoin internally)
67
- // and `fundingOutputIndex` an `uint32`. This mapping may contain valid
68
- // and invalid deposits and the wallet is responsible for validating
69
- // them before attempting to execute a sweep.
70
- mapping(uint256 => Deposit.DepositRequest) deposits;
71
- // Indicates if the vault with the given address is trusted or not.
72
- // Depositors can route their revealed deposits only to trusted vaults
73
- // and have trusted vaults notified about new deposits as soon as these
74
- // deposits get swept. Vaults not trusted by the Bridge can still be
75
- // used by Bank balance owners on their own responsibility - anyone can
76
- // approve their Bank balance to any address.
77
- mapping(address => bool) isVaultTrusted;
68
+ // Move movingFundsTxMaxTotalFee to the next storage slot for a more
69
+ // efficient variable layout in the storage.
70
+ // slither-disable-next-line unused-state
71
+ bytes32 __depositAlignmentGap;
78
72
  // Maximum amount of the total BTC transaction fee that is acceptable in
79
73
  // a single moving funds transaction.
80
74
  //
@@ -110,7 +104,11 @@ library BridgeState {
110
104
  // The percentage of the notifier reward from the staking contract
111
105
  // the notifier of a moving funds timeout receives. The value is in the
112
106
  // range [0, 100].
113
- uint256 movingFundsTimeoutNotifierRewardMultiplier;
107
+ uint32 movingFundsTimeoutNotifierRewardMultiplier;
108
+ // Move movedFundsSweepTxMaxTotalFee to the next storage slot for a more
109
+ // efficient variable layout in the storage.
110
+ // slither-disable-next-line unused-state
111
+ bytes32 __movingFundsAlignmentGap;
114
112
  // Maximum amount of the total BTC transaction fee that is acceptable in
115
113
  // a single moved funds sweep transaction.
116
114
  //
@@ -129,14 +127,7 @@ library BridgeState {
129
127
  // The percentage of the notifier reward from the staking contract
130
128
  // the notifier of a moved funds sweep timeout receives. The value is
131
129
  // in the range [0, 100].
132
- uint256 movedFundsSweepTimeoutNotifierRewardMultiplier;
133
- // Collection of all moved funds sweep requests indexed by
134
- // `keccak256(movingFundsTxHash | movingFundsOutputIndex)`.
135
- // The `movingFundsTxHash` is `bytes32` (ordered as in Bitcoin
136
- // internally) and `movingFundsOutputIndex` an `uint32`. Each entry
137
- // is actually an UTXO representing the moved funds and is supposed
138
- // to be swept with the current main UTXO of the recipient wallet.
139
- mapping(uint256 => MovingFunds.MovedFundsSweepRequest) movedFundsSweepRequests;
130
+ uint32 movedFundsSweepTimeoutNotifierRewardMultiplier;
140
131
  // The minimal amount that can be requested for redemption.
141
132
  // Value of this parameter must take into account the value of
142
133
  // `redemptionTreasuryFeeDivisor` and `redemptionTxMaxFee`
@@ -162,68 +153,33 @@ library BridgeState {
162
153
  // This is a per-redemption output max fee for the redemption
163
154
  // transaction.
164
155
  uint64 redemptionTxMaxFee;
156
+ // Move redemptionTimeout to the next storage slot for a more efficient
157
+ // variable layout in the storage.
158
+ // slither-disable-next-line unused-state
159
+ bytes32 __redemptionAlignmentGap;
165
160
  // Time after which the redemption request can be reported as
166
161
  // timed out. It is counted from the moment when the redemption
167
162
  // request was created via `requestRedemption` call. Reported
168
163
  // timed out requests are cancelled and locked TBTC is returned
169
164
  // to the redeemer in full amount.
170
- uint256 redemptionTimeout;
165
+ uint32 redemptionTimeout;
171
166
  // The amount of stake slashed from each member of a wallet for a
172
167
  // redemption timeout.
173
168
  uint96 redemptionTimeoutSlashingAmount;
174
169
  // The percentage of the notifier reward from the staking contract
175
170
  // the notifier of a redemption timeout receives. The value is in the
176
171
  // range [0, 100].
177
- uint256 redemptionTimeoutNotifierRewardMultiplier;
178
- // Collection of all pending redemption requests indexed by
179
- // redemption key built as
180
- // `keccak256(walletPubKeyHash | redeemerOutputScript)`.
181
- // The `walletPubKeyHash` is the 20-byte wallet's public key hash
182
- // (computed using Bitcoin HASH160 over the compressed ECDSA
183
- // public key) and `redeemerOutputScript` is a Bitcoin script
184
- // (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
185
- // redeemed BTC as requested by the redeemer. Requests are added
186
- // to this mapping by the `requestRedemption` method (duplicates
187
- // not allowed) and are removed by one of the following methods:
188
- // - `submitRedemptionProof` in case the request was handled
189
- // successfully,
190
- // - `notifyRedemptionTimeout` in case the request was reported
191
- // to be timed out.
192
- mapping(uint256 => Redemption.RedemptionRequest) pendingRedemptions;
193
- // Collection of all timed out redemptions requests indexed by
194
- // redemption key built as
195
- // `keccak256(walletPubKeyHash | redeemerOutputScript)`. The
196
- // `walletPubKeyHash` is the 20-byte wallet's public key hash
197
- // (computed using Bitcoin HASH160 over the compressed ECDSA
198
- // public key) and `redeemerOutputScript` is the Bitcoin script
199
- // (P2PKH, P2WPKH, P2SH or P2WSH) that is involved in the timed
200
- // out request. Timed out requests are stored in this mapping to
201
- // avoid slashing the wallets multiple times for the same timeout.
202
- // Only one method can add to this mapping:
203
- // - `notifyRedemptionTimeout` which puts the redemption key to this
204
- // mapping basing on a timed out request stored previously in
205
- // `pendingRedemptions` mapping.
206
- mapping(uint256 => Redemption.RedemptionRequest) timedOutRedemptions;
172
+ uint32 redemptionTimeoutNotifierRewardMultiplier;
207
173
  // The amount of ETH in wei the party challenging the wallet for fraud
208
174
  // needs to deposit.
209
- uint256 fraudChallengeDepositAmount;
175
+ uint96 fraudChallengeDepositAmount;
210
176
  // The amount of time the wallet has to defeat a fraud challenge.
211
- uint256 fraudChallengeDefeatTimeout;
177
+ uint32 fraudChallengeDefeatTimeout;
212
178
  // The amount of stake slashed from each member of a wallet for a fraud.
213
179
  uint96 fraudSlashingAmount;
214
180
  // The percentage of the notifier reward from the staking contract
215
181
  // the notifier of a fraud receives. The value is in the range [0, 100].
216
- uint256 fraudNotifierRewardMultiplier;
217
- // Collection of all submitted fraud challenges indexed by challenge
218
- // key built as `keccak256(walletPublicKey|sighash)`.
219
- mapping(uint256 => Fraud.FraudChallenge) fraudChallenges;
220
- // Collection of main UTXOs that are honestly spent indexed by
221
- // `keccak256(fundingTxHash | fundingOutputIndex)`. The `fundingTxHash`
222
- // is `bytes32` (ordered as in Bitcoin internally) and
223
- // `fundingOutputIndex` an `uint32`. A main UTXO is considered honestly
224
- // spent if it was used as an input of a transaction that have been
225
- // proven in the Bridge.
226
- mapping(uint256 => bool) spentMainUTXOs;
182
+ uint32 fraudNotifierRewardMultiplier;
227
183
  // Determines how frequently a new wallet creation can be requested.
228
184
  // Value in seconds.
229
185
  uint32 walletCreationPeriod;
@@ -259,6 +215,66 @@ library BridgeState {
259
215
  // of deposit fraud challenges. This value is in seconds and should be
260
216
  // greater than the deposit refund time plus some time margin.
261
217
  uint32 walletClosingPeriod;
218
+ // Collection of all revealed deposits indexed by
219
+ // `keccak256(fundingTxHash | fundingOutputIndex)`.
220
+ // The `fundingTxHash` is `bytes32` (ordered as in Bitcoin internally)
221
+ // and `fundingOutputIndex` an `uint32`. This mapping may contain valid
222
+ // and invalid deposits and the wallet is responsible for validating
223
+ // them before attempting to execute a sweep.
224
+ mapping(uint256 => Deposit.DepositRequest) deposits;
225
+ // Indicates if the vault with the given address is trusted or not.
226
+ // Depositors can route their revealed deposits only to trusted vaults
227
+ // and have trusted vaults notified about new deposits as soon as these
228
+ // deposits get swept. Vaults not trusted by the Bridge can still be
229
+ // used by Bank balance owners on their own responsibility - anyone can
230
+ // approve their Bank balance to any address.
231
+ mapping(address => bool) isVaultTrusted;
232
+ // Collection of all moved funds sweep requests indexed by
233
+ // `keccak256(movingFundsTxHash | movingFundsOutputIndex)`.
234
+ // The `movingFundsTxHash` is `bytes32` (ordered as in Bitcoin
235
+ // internally) and `movingFundsOutputIndex` an `uint32`. Each entry
236
+ // is actually an UTXO representing the moved funds and is supposed
237
+ // to be swept with the current main UTXO of the recipient wallet.
238
+ mapping(uint256 => MovingFunds.MovedFundsSweepRequest) movedFundsSweepRequests;
239
+ // Collection of all pending redemption requests indexed by
240
+ // redemption key built as
241
+ // `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
242
+ // The `walletPubKeyHash` is the 20-byte wallet's public key hash
243
+ // (computed using Bitcoin HASH160 over the compressed ECDSA
244
+ // public key) and `redeemerOutputScript` is a Bitcoin script
245
+ // (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
246
+ // redeemed BTC as requested by the redeemer. Requests are added
247
+ // to this mapping by the `requestRedemption` method (duplicates
248
+ // not allowed) and are removed by one of the following methods:
249
+ // - `submitRedemptionProof` in case the request was handled
250
+ // successfully,
251
+ // - `notifyRedemptionTimeout` in case the request was reported
252
+ // to be timed out.
253
+ mapping(uint256 => Redemption.RedemptionRequest) pendingRedemptions;
254
+ // Collection of all timed out redemptions requests indexed by
255
+ // redemption key built as
256
+ // `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
257
+ // The `walletPubKeyHash` is the 20-byte wallet's public key hash
258
+ // (computed using Bitcoin HASH160 over the compressed ECDSA
259
+ // public key) and `redeemerOutputScript` is the Bitcoin script
260
+ // (P2PKH, P2WPKH, P2SH or P2WSH) that is involved in the timed
261
+ // out request. Timed out requests are stored in this mapping to
262
+ // avoid slashing the wallets multiple times for the same timeout.
263
+ // Only one method can add to this mapping:
264
+ // - `notifyRedemptionTimeout` which puts the redemption key to this
265
+ // mapping basing on a timed out request stored previously in
266
+ // `pendingRedemptions` mapping.
267
+ mapping(uint256 => Redemption.RedemptionRequest) timedOutRedemptions;
268
+ // Collection of all submitted fraud challenges indexed by challenge
269
+ // key built as `keccak256(walletPublicKey|sighash)`.
270
+ mapping(uint256 => Fraud.FraudChallenge) fraudChallenges;
271
+ // Collection of main UTXOs that are honestly spent indexed by
272
+ // `keccak256(fundingTxHash | fundingOutputIndex)`. The `fundingTxHash`
273
+ // is `bytes32` (ordered as in Bitcoin internally) and
274
+ // `fundingOutputIndex` an `uint32`. A main UTXO is considered honestly
275
+ // spent if it was used as an input of a transaction that have been
276
+ // proven in the Bridge.
277
+ mapping(uint256 => bool) spentMainUTXOs;
262
278
  // Maps the 20-byte wallet public key hash (computed using Bitcoin
263
279
  // HASH160 over the compressed ECDSA public key) to the basic wallet
264
280
  // information like state and pending redemptions value.
@@ -283,9 +299,9 @@ library BridgeState {
283
299
  uint64 redemptionDustThreshold,
284
300
  uint64 redemptionTreasuryFeeDivisor,
285
301
  uint64 redemptionTxMaxFee,
286
- uint256 redemptionTimeout,
302
+ uint32 redemptionTimeout,
287
303
  uint96 redemptionTimeoutSlashingAmount,
288
- uint256 redemptionTimeoutNotifierRewardMultiplier
304
+ uint32 redemptionTimeoutNotifierRewardMultiplier
289
305
  );
290
306
 
291
307
  event MovingFundsParametersUpdated(
@@ -294,11 +310,11 @@ library BridgeState {
294
310
  uint32 movingFundsTimeoutResetDelay,
295
311
  uint32 movingFundsTimeout,
296
312
  uint96 movingFundsTimeoutSlashingAmount,
297
- uint256 movingFundsTimeoutNotifierRewardMultiplier,
313
+ uint32 movingFundsTimeoutNotifierRewardMultiplier,
298
314
  uint64 movedFundsSweepTxMaxTotalFee,
299
315
  uint32 movedFundsSweepTimeout,
300
316
  uint96 movedFundsSweepTimeoutSlashingAmount,
301
- uint256 movedFundsSweepTimeoutNotifierRewardMultiplier
317
+ uint32 movedFundsSweepTimeoutNotifierRewardMultiplier
302
318
  );
303
319
 
304
320
  event WalletParametersUpdated(
@@ -312,10 +328,10 @@ library BridgeState {
312
328
  );
313
329
 
314
330
  event FraudParametersUpdated(
315
- uint256 fraudChallengeDepositAmount,
316
- uint256 fraudChallengeDefeatTimeout,
331
+ uint96 fraudChallengeDepositAmount,
332
+ uint32 fraudChallengeDefeatTimeout,
317
333
  uint96 fraudSlashingAmount,
318
- uint256 fraudNotifierRewardMultiplier
334
+ uint32 fraudNotifierRewardMultiplier
319
335
  );
320
336
 
321
337
  /// @notice Updates parameters of deposits.
@@ -425,9 +441,9 @@ library BridgeState {
425
441
  uint64 _redemptionDustThreshold,
426
442
  uint64 _redemptionTreasuryFeeDivisor,
427
443
  uint64 _redemptionTxMaxFee,
428
- uint256 _redemptionTimeout,
444
+ uint32 _redemptionTimeout,
429
445
  uint96 _redemptionTimeoutSlashingAmount,
430
- uint256 _redemptionTimeoutNotifierRewardMultiplier
446
+ uint32 _redemptionTimeoutNotifierRewardMultiplier
431
447
  ) internal {
432
448
  require(
433
449
  _redemptionDustThreshold > self.movingFundsDustThreshold,
@@ -542,11 +558,11 @@ library BridgeState {
542
558
  uint32 _movingFundsTimeoutResetDelay,
543
559
  uint32 _movingFundsTimeout,
544
560
  uint96 _movingFundsTimeoutSlashingAmount,
545
- uint256 _movingFundsTimeoutNotifierRewardMultiplier,
561
+ uint32 _movingFundsTimeoutNotifierRewardMultiplier,
546
562
  uint64 _movedFundsSweepTxMaxTotalFee,
547
563
  uint32 _movedFundsSweepTimeout,
548
564
  uint96 _movedFundsSweepTimeoutSlashingAmount,
549
- uint256 _movedFundsSweepTimeoutNotifierRewardMultiplier
565
+ uint32 _movedFundsSweepTimeoutNotifierRewardMultiplier
550
566
  ) internal {
551
567
  require(
552
568
  _movingFundsTxMaxTotalFee > 0,
@@ -709,10 +725,10 @@ library BridgeState {
709
725
  /// - Fraud notifier reward multiplier must be in the range [0, 100].
710
726
  function updateFraudParameters(
711
727
  Storage storage self,
712
- uint256 _fraudChallengeDepositAmount,
713
- uint256 _fraudChallengeDefeatTimeout,
728
+ uint96 _fraudChallengeDepositAmount,
729
+ uint32 _fraudChallengeDefeatTimeout,
714
730
  uint96 _fraudSlashingAmount,
715
- uint256 _fraudNotifierRewardMultiplier
731
+ uint32 _fraudNotifierRewardMultiplier
716
732
  ) internal {
717
733
  require(
718
734
  _fraudChallengeDefeatTimeout > 0,
@@ -384,6 +384,8 @@ library Fraud {
384
384
  uint32[] calldata walletMembersIDs,
385
385
  bytes memory preimageSha256
386
386
  ) external {
387
+ // Wallet state is validated in `notifyWalletFraudChallengeDefeatTimeout`.
388
+
387
389
  bytes32 sighash = sha256(preimageSha256);
388
390
 
389
391
  uint256 challengeKey = uint256(
@@ -421,38 +423,11 @@ library Fraud {
421
423
  );
422
424
  bytes20 walletPubKeyHash = compressedWalletPublicKey.hash160View();
423
425
 
424
- Wallets.Wallet storage wallet = self.registeredWallets[
425
- walletPubKeyHash
426
- ];
427
-
428
- Wallets.WalletState walletState = wallet.state;
429
-
430
- if (
431
- walletState == Wallets.WalletState.Live ||
432
- walletState == Wallets.WalletState.MovingFunds ||
433
- walletState == Wallets.WalletState.Closing
434
- ) {
435
- self.ecdsaWalletRegistry.seize(
436
- self.fraudSlashingAmount,
437
- self.fraudNotifierRewardMultiplier,
438
- challenge.challenger,
439
- wallet.ecdsaWalletID,
440
- walletMembersIDs
441
- );
442
-
443
- self.terminateWallet(walletPubKeyHash);
444
- } else if (walletState == Wallets.WalletState.Terminated) {
445
- // This is a special case when the wallet was already terminated
446
- // due to a previous deliberate protocol violation. In that
447
- // case, this function should be still callable for other fraud
448
- // challenges timeouts in order to let the challenger unlock its
449
- // ETH deposit back. However, the wallet termination logic is
450
- // not called and the challenger is not rewarded.
451
- } else {
452
- revert(
453
- "Wallet must be in Live or MovingFunds or Closing or Terminated state"
454
- );
455
- }
426
+ self.notifyWalletFraudChallengeDefeatTimeout(
427
+ walletPubKeyHash,
428
+ walletMembersIDs,
429
+ challenge.challenger
430
+ );
456
431
 
457
432
  // slither-disable-next-line reentrancy-events
458
433
  emit FraudChallengeDefeatTimedOut(walletPubKeyHash, sighash);
@@ -359,6 +359,8 @@ library MovingFunds {
359
359
  BitcoinTx.UTXO calldata mainUtxo,
360
360
  bytes20 walletPubKeyHash
361
361
  ) external {
362
+ // Wallet state is validated in `notifyWalletFundsMoved`.
363
+
362
364
  // The actual transaction proof is performed here. After that point, we
363
365
  // can assume the transaction happened on Bitcoin chain and has
364
366
  // a sufficient number of confirmations as determined by
@@ -566,31 +568,19 @@ library MovingFunds {
566
568
  bytes20 walletPubKeyHash,
567
569
  uint32[] calldata walletMembersIDs
568
570
  ) external {
569
- Wallets.Wallet storage wallet = self.registeredWallets[
570
- walletPubKeyHash
571
- ];
571
+ // Wallet state is validated in `notifyWalletMovingFundsTimeout`.
572
572
 
573
- require(
574
- wallet.state == Wallets.WalletState.MovingFunds,
575
- "Wallet must be in MovingFunds state"
576
- );
573
+ uint32 movingFundsRequestedAt = self
574
+ .registeredWallets[walletPubKeyHash]
575
+ .movingFundsRequestedAt;
577
576
 
578
577
  require(
579
578
  /* solhint-disable-next-line not-rely-on-time */
580
- block.timestamp >
581
- wallet.movingFundsRequestedAt + self.movingFundsTimeout,
579
+ block.timestamp > movingFundsRequestedAt + self.movingFundsTimeout,
582
580
  "Moving funds has not timed out yet"
583
581
  );
584
582
 
585
- self.ecdsaWalletRegistry.seize(
586
- self.movingFundsTimeoutSlashingAmount,
587
- self.movingFundsTimeoutNotifierRewardMultiplier,
588
- msg.sender,
589
- wallet.ecdsaWalletID,
590
- walletMembersIDs
591
- );
592
-
593
- self.terminateWallet(walletPubKeyHash);
583
+ self.notifyWalletMovingFundsTimeout(walletPubKeyHash, walletMembersIDs);
594
584
 
595
585
  // slither-disable-next-line reentrancy-events
596
586
  emit MovingFundsTimedOut(walletPubKeyHash);
@@ -614,14 +604,7 @@ library MovingFunds {
614
604
  bytes20 walletPubKeyHash,
615
605
  BitcoinTx.UTXO calldata mainUtxo
616
606
  ) external {
617
- Wallets.Wallet storage wallet = self.registeredWallets[
618
- walletPubKeyHash
619
- ];
620
-
621
- require(
622
- wallet.state == Wallets.WalletState.MovingFunds,
623
- "Wallet must be in MovingFunds state"
624
- );
607
+ // Wallet state is validated in `notifyWalletMovingFundsBelowDust`.
625
608
 
626
609
  uint64 walletBtcBalance = self.getWalletBtcBalance(
627
610
  walletPubKeyHash,
@@ -633,7 +616,7 @@ library MovingFunds {
633
616
  "Wallet BTC balance must be below the moving funds dust threshold"
634
617
  );
635
618
 
636
- self.beginWalletClosing(walletPubKeyHash);
619
+ self.notifyWalletMovingFundsBelowDust(walletPubKeyHash);
637
620
 
638
621
  // slither-disable-next-line reentrancy-events
639
622
  emit MovingFundsBelowDustReported(walletPubKeyHash);
@@ -1045,6 +1028,8 @@ library MovingFunds {
1045
1028
  uint32 movingFundsTxOutputIndex,
1046
1029
  uint32[] calldata walletMembersIDs
1047
1030
  ) external {
1031
+ // Wallet state is validated in `notifyWalletMovedFundsSweepTimeout`.
1032
+
1048
1033
  MovedFundsSweepRequest storage sweepRequest = self
1049
1034
  .movedFundsSweepRequests[
1050
1035
  uint256(
@@ -1070,36 +1055,18 @@ library MovingFunds {
1070
1055
  );
1071
1056
 
1072
1057
  bytes20 walletPubKeyHash = sweepRequest.walletPubKeyHash;
1073
- Wallets.Wallet storage wallet = self.registeredWallets[
1074
- walletPubKeyHash
1075
- ];
1076
- Wallets.WalletState walletState = wallet.state;
1077
1058
 
1078
- require(
1079
- walletState == Wallets.WalletState.Live ||
1080
- walletState == Wallets.WalletState.MovingFunds ||
1081
- walletState == Wallets.WalletState.Terminated,
1082
- "Wallet must be in Live or MovingFunds or Terminated state"
1059
+ self.notifyWalletMovedFundsSweepTimeout(
1060
+ walletPubKeyHash,
1061
+ walletMembersIDs
1083
1062
  );
1084
1063
 
1064
+ Wallets.Wallet storage wallet = self.registeredWallets[
1065
+ walletPubKeyHash
1066
+ ];
1085
1067
  sweepRequest.state = MovedFundsSweepRequestState.TimedOut;
1086
1068
  wallet.pendingMovedFundsSweepRequestsCount--;
1087
1069
 
1088
- if (
1089
- walletState == Wallets.WalletState.Live ||
1090
- walletState == Wallets.WalletState.MovingFunds
1091
- ) {
1092
- self.ecdsaWalletRegistry.seize(
1093
- self.movedFundsSweepTimeoutSlashingAmount,
1094
- self.movedFundsSweepTimeoutNotifierRewardMultiplier,
1095
- msg.sender,
1096
- wallet.ecdsaWalletID,
1097
- walletMembersIDs
1098
- );
1099
-
1100
- self.terminateWallet(walletPubKeyHash);
1101
- }
1102
-
1103
1070
  // slither-disable-next-line reentrancy-events
1104
1071
  emit MovedFundsSweepTimedOut(
1105
1072
  walletPubKeyHash,