@keep-network/tbtc-v2 0.1.1-dev.98 → 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 (70) hide show
  1. package/artifacts/Bank.json +3 -3
  2. package/artifacts/Bridge.json +28 -28
  3. package/artifacts/Deposit.json +9 -9
  4. package/artifacts/DepositSweep.json +7 -7
  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 +3 -3
  22. package/artifacts/TBTCToken.json +3 -3
  23. package/artifacts/TBTCVault.json +12 -12
  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 +10 -10
  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 +9 -9
  33. package/artifacts/solcInputs/{becdd5668a2170e95004d124119e4fcb.json → 5334fac3c976c2a5cd9bc3d6190e35c4.json} +4 -4
  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 +74 -74
  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 +2 -0
  66. package/contracts/bridge/Bridge.sol +22 -22
  67. package/contracts/bridge/BridgeState.sol +30 -22
  68. package/contracts/bridge/Redemption.sol +12 -10
  69. package/export.json +15 -15
  70. package/package.json +1 -1
@@ -40,6 +40,10 @@ library BridgeState {
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
@@ -62,9 +66,9 @@ library BridgeState {
62
66
  // This is a per-deposit input max fee for the sweep transaction.
63
67
  uint64 depositTxMaxFee;
64
68
  // Move movingFundsTxMaxTotalFee to the next storage slot for a more
65
- // efficient variable layout
69
+ // efficient variable layout in the storage.
66
70
  // slither-disable-next-line unused-state
67
- bytes8 __depositAlignmentGap;
71
+ bytes32 __depositAlignmentGap;
68
72
  // Maximum amount of the total BTC transaction fee that is acceptable in
69
73
  // a single moving funds transaction.
70
74
  //
@@ -100,7 +104,11 @@ library BridgeState {
100
104
  // The percentage of the notifier reward from the staking contract
101
105
  // the notifier of a moving funds timeout receives. The value is in the
102
106
  // range [0, 100].
103
- 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;
104
112
  // Maximum amount of the total BTC transaction fee that is acceptable in
105
113
  // a single moved funds sweep transaction.
106
114
  //
@@ -119,7 +127,7 @@ library BridgeState {
119
127
  // The percentage of the notifier reward from the staking contract
120
128
  // the notifier of a moved funds sweep timeout receives. The value is
121
129
  // in the range [0, 100].
122
- uint64 movedFundsSweepTimeoutNotifierRewardMultiplier;
130
+ uint32 movedFundsSweepTimeoutNotifierRewardMultiplier;
123
131
  // The minimal amount that can be requested for redemption.
124
132
  // Value of this parameter must take into account the value of
125
133
  // `redemptionTreasuryFeeDivisor` and `redemptionTxMaxFee`
@@ -146,22 +154,22 @@ library BridgeState {
146
154
  // transaction.
147
155
  uint64 redemptionTxMaxFee;
148
156
  // Move redemptionTimeout to the next storage slot for a more efficient
149
- // variable layout
157
+ // variable layout in the storage.
150
158
  // slither-disable-next-line unused-state
151
- bytes8 __redemptionAlignmentGap;
159
+ bytes32 __redemptionAlignmentGap;
152
160
  // Time after which the redemption request can be reported as
153
161
  // timed out. It is counted from the moment when the redemption
154
162
  // request was created via `requestRedemption` call. Reported
155
163
  // timed out requests are cancelled and locked TBTC is returned
156
164
  // to the redeemer in full amount.
157
- uint64 redemptionTimeout;
165
+ uint32 redemptionTimeout;
158
166
  // The amount of stake slashed from each member of a wallet for a
159
167
  // redemption timeout.
160
168
  uint96 redemptionTimeoutSlashingAmount;
161
169
  // The percentage of the notifier reward from the staking contract
162
170
  // the notifier of a redemption timeout receives. The value is in the
163
171
  // range [0, 100].
164
- uint64 redemptionTimeoutNotifierRewardMultiplier;
172
+ uint32 redemptionTimeoutNotifierRewardMultiplier;
165
173
  // The amount of ETH in wei the party challenging the wallet for fraud
166
174
  // needs to deposit.
167
175
  uint96 fraudChallengeDepositAmount;
@@ -230,7 +238,7 @@ library BridgeState {
230
238
  mapping(uint256 => MovingFunds.MovedFundsSweepRequest) movedFundsSweepRequests;
231
239
  // Collection of all pending redemption requests indexed by
232
240
  // redemption key built as
233
- // `keccak256(walletPubKeyHash | redeemerOutputScript)`.
241
+ // `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
234
242
  // The `walletPubKeyHash` is the 20-byte wallet's public key hash
235
243
  // (computed using Bitcoin HASH160 over the compressed ECDSA
236
244
  // public key) and `redeemerOutputScript` is a Bitcoin script
@@ -245,8 +253,8 @@ library BridgeState {
245
253
  mapping(uint256 => Redemption.RedemptionRequest) pendingRedemptions;
246
254
  // Collection of all timed out redemptions requests indexed by
247
255
  // redemption key built as
248
- // `keccak256(walletPubKeyHash | redeemerOutputScript)`. The
249
- // `walletPubKeyHash` is the 20-byte wallet's public key hash
256
+ // `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
257
+ // The `walletPubKeyHash` is the 20-byte wallet's public key hash
250
258
  // (computed using Bitcoin HASH160 over the compressed ECDSA
251
259
  // public key) and `redeemerOutputScript` is the Bitcoin script
252
260
  // (P2PKH, P2WPKH, P2SH or P2WSH) that is involved in the timed
@@ -291,9 +299,9 @@ library BridgeState {
291
299
  uint64 redemptionDustThreshold,
292
300
  uint64 redemptionTreasuryFeeDivisor,
293
301
  uint64 redemptionTxMaxFee,
294
- uint256 redemptionTimeout,
302
+ uint32 redemptionTimeout,
295
303
  uint96 redemptionTimeoutSlashingAmount,
296
- uint256 redemptionTimeoutNotifierRewardMultiplier
304
+ uint32 redemptionTimeoutNotifierRewardMultiplier
297
305
  );
298
306
 
299
307
  event MovingFundsParametersUpdated(
@@ -302,11 +310,11 @@ library BridgeState {
302
310
  uint32 movingFundsTimeoutResetDelay,
303
311
  uint32 movingFundsTimeout,
304
312
  uint96 movingFundsTimeoutSlashingAmount,
305
- uint256 movingFundsTimeoutNotifierRewardMultiplier,
313
+ uint32 movingFundsTimeoutNotifierRewardMultiplier,
306
314
  uint64 movedFundsSweepTxMaxTotalFee,
307
315
  uint32 movedFundsSweepTimeout,
308
316
  uint96 movedFundsSweepTimeoutSlashingAmount,
309
- uint256 movedFundsSweepTimeoutNotifierRewardMultiplier
317
+ uint32 movedFundsSweepTimeoutNotifierRewardMultiplier
310
318
  );
311
319
 
312
320
  event WalletParametersUpdated(
@@ -320,10 +328,10 @@ library BridgeState {
320
328
  );
321
329
 
322
330
  event FraudParametersUpdated(
323
- uint256 fraudChallengeDepositAmount,
324
- uint256 fraudChallengeDefeatTimeout,
331
+ uint96 fraudChallengeDepositAmount,
332
+ uint32 fraudChallengeDefeatTimeout,
325
333
  uint96 fraudSlashingAmount,
326
- uint256 fraudNotifierRewardMultiplier
334
+ uint32 fraudNotifierRewardMultiplier
327
335
  );
328
336
 
329
337
  /// @notice Updates parameters of deposits.
@@ -433,9 +441,9 @@ library BridgeState {
433
441
  uint64 _redemptionDustThreshold,
434
442
  uint64 _redemptionTreasuryFeeDivisor,
435
443
  uint64 _redemptionTxMaxFee,
436
- uint64 _redemptionTimeout,
444
+ uint32 _redemptionTimeout,
437
445
  uint96 _redemptionTimeoutSlashingAmount,
438
- uint64 _redemptionTimeoutNotifierRewardMultiplier
446
+ uint32 _redemptionTimeoutNotifierRewardMultiplier
439
447
  ) internal {
440
448
  require(
441
449
  _redemptionDustThreshold > self.movingFundsDustThreshold,
@@ -550,11 +558,11 @@ library BridgeState {
550
558
  uint32 _movingFundsTimeoutResetDelay,
551
559
  uint32 _movingFundsTimeout,
552
560
  uint96 _movingFundsTimeoutSlashingAmount,
553
- uint256 _movingFundsTimeoutNotifierRewardMultiplier,
561
+ uint32 _movingFundsTimeoutNotifierRewardMultiplier,
554
562
  uint64 _movedFundsSweepTxMaxTotalFee,
555
563
  uint32 _movedFundsSweepTimeout,
556
564
  uint96 _movedFundsSweepTimeoutSlashingAmount,
557
- uint64 _movedFundsSweepTimeoutNotifierRewardMultiplier
565
+ uint32 _movedFundsSweepTimeoutNotifierRewardMultiplier
558
566
  ) internal {
559
567
  require(
560
568
  _movingFundsTxMaxTotalFee > 0,
@@ -777,10 +777,6 @@ library Redemption {
777
777
 
778
778
  // Outputs processing loop.
779
779
  for (uint256 i = 0; i < processInfo.outputsCount; i++) {
780
- // TODO: Check if we can optimize gas costs by adding
781
- // `extractValueAt` and `extractHashAt` in `bitcoin-spv-sol`
782
- // in order to avoid allocating bytes in memory.
783
- // https://github.com/keep-network/tbtc-v2/issues/257
784
780
  uint256 outputLength = redemptionTxOutputVector
785
781
  .determineOutputLengthAt(processInfo.outputStartingIndex);
786
782
 
@@ -789,17 +785,20 @@ library Redemption {
789
785
  processInfo.outputStartingIndex
790
786
  );
791
787
 
792
- uint256 scriptLength = outputLength - 8;
793
-
794
788
  // The output consists of an 8-byte value and a variable length
795
789
  // script. To hash that script we slice the output starting from
796
790
  // 9th byte until the end.
797
-
791
+ uint256 scriptLength = outputLength - 8;
798
792
  uint256 outputScriptStart = processInfo.outputStartingIndex + 8;
799
793
 
800
794
  bytes32 outputScriptHash;
801
795
  /* solhint-disable-next-line no-inline-assembly */
802
796
  assembly {
797
+ // The first argument to assembly keccak256 is the pointer.
798
+ // We point to `redemptionTxOutputVector` but at the position
799
+ // indicated by `outputScriptStart`. To load that position, we
800
+ // need to call `add(outputScriptStart, 32)` because
801
+ // `outputScriptStart` has 32 bytes.
803
802
  outputScriptHash := keccak256(
804
803
  add(redemptionTxOutputVector, add(outputScriptStart, 32)),
805
804
  scriptLength
@@ -867,6 +866,9 @@ library Redemption {
867
866
  /// outputs to evaluate the total treasury fee for the entire
868
867
  /// redemption transaction. This value is 0 for a timed-out
869
868
  /// redemption request.
869
+ /// @dev Requirements:
870
+ /// - This function should be called only if the given output
871
+ /// represents redemption. It must not be the change output.
870
872
  function processNonChangeRedemptionTxOutput(
871
873
  BridgeState.Storage storage self,
872
874
  uint256 redemptionKey,
@@ -933,7 +935,7 @@ library Redemption {
933
935
  /// @notice Notifies that there is a pending redemption request associated
934
936
  /// with the given wallet, that has timed out. The redemption
935
937
  /// request is identified by the key built as
936
- /// `keccak256(walletPubKeyHash | redeemerOutputScript)`.
938
+ /// `keccak256(keccak256(redeemerOutputScript) | walletPubKeyHash)`.
937
939
  /// The results of calling this function:
938
940
  /// - the pending redemptions value for the wallet will be decreased
939
941
  /// by the requested amount (minus treasury fee),
@@ -1018,7 +1020,7 @@ library Redemption {
1018
1020
  /// @notice Calculate redemption key without allocations.
1019
1021
  /// @param walletPubKeyHash the pubkey hash of the wallet.
1020
1022
  /// @param script the output script of the redemption.
1021
- /// @return The key = keccak256(keccak256(script), walletPubKeyHash).
1023
+ /// @return The key = keccak256(keccak256(script) | walletPubKeyHash).
1022
1024
  function getRedemptionKey(bytes20 walletPubKeyHash, bytes memory script)
1023
1025
  internal
1024
1026
  pure
@@ -1038,7 +1040,7 @@ library Redemption {
1038
1040
  /// @notice Finish calculating redemption key without allocations.
1039
1041
  /// @param walletPubKeyHash the pubkey hash of the wallet.
1040
1042
  /// @param scriptHash the output script hash of the redemption.
1041
- /// @return The key = keccak256(scriptHash, walletPubKeyHash).
1043
+ /// @return The key = keccak256(scriptHash | walletPubKeyHash).
1042
1044
  function _getRedemptionKey(bytes20 walletPubKeyHash, bytes32 scriptHash)
1043
1045
  internal
1044
1046
  pure
package/export.json CHANGED
@@ -14371,12 +14371,12 @@
14371
14371
  "name": "FraudParametersUpdated",
14372
14372
  "inputs": [
14373
14373
  {
14374
- "type": "uint256",
14374
+ "type": "uint96",
14375
14375
  "name": "fraudChallengeDepositAmount",
14376
14376
  "indexed": false
14377
14377
  },
14378
14378
  {
14379
- "type": "uint256",
14379
+ "type": "uint32",
14380
14380
  "name": "fraudChallengeDefeatTimeout",
14381
14381
  "indexed": false
14382
14382
  },
@@ -14386,7 +14386,7 @@
14386
14386
  "indexed": false
14387
14387
  },
14388
14388
  {
14389
- "type": "uint256",
14389
+ "type": "uint32",
14390
14390
  "name": "fraudNotifierRewardMultiplier",
14391
14391
  "indexed": false
14392
14392
  }
@@ -14542,7 +14542,7 @@
14542
14542
  "indexed": false
14543
14543
  },
14544
14544
  {
14545
- "type": "uint256",
14545
+ "type": "uint32",
14546
14546
  "name": "movingFundsTimeoutNotifierRewardMultiplier",
14547
14547
  "indexed": false
14548
14548
  },
@@ -14562,7 +14562,7 @@
14562
14562
  "indexed": false
14563
14563
  },
14564
14564
  {
14565
- "type": "uint256",
14565
+ "type": "uint32",
14566
14566
  "name": "movedFundsSweepTimeoutNotifierRewardMultiplier",
14567
14567
  "indexed": false
14568
14568
  }
@@ -14636,7 +14636,7 @@
14636
14636
  "indexed": false
14637
14637
  },
14638
14638
  {
14639
- "type": "uint256",
14639
+ "type": "uint32",
14640
14640
  "name": "redemptionTimeout",
14641
14641
  "indexed": false
14642
14642
  },
@@ -14646,7 +14646,7 @@
14646
14646
  "indexed": false
14647
14647
  },
14648
14648
  {
14649
- "type": "uint256",
14649
+ "type": "uint32",
14650
14650
  "name": "redemptionTimeoutNotifierRewardMultiplier",
14651
14651
  "indexed": false
14652
14652
  }
@@ -15246,7 +15246,7 @@
15246
15246
  "name": "movingFundsTimeoutSlashingAmount"
15247
15247
  },
15248
15248
  {
15249
- "type": "uint256",
15249
+ "type": "uint32",
15250
15250
  "name": "movingFundsTimeoutNotifierRewardMultiplier"
15251
15251
  },
15252
15252
  {
@@ -15262,7 +15262,7 @@
15262
15262
  "name": "movedFundsSweepTimeoutSlashingAmount"
15263
15263
  },
15264
15264
  {
15265
- "type": "uint256",
15265
+ "type": "uint32",
15266
15266
  "name": "movedFundsSweepTimeoutNotifierRewardMultiplier"
15267
15267
  }
15268
15268
  ]
@@ -15514,7 +15514,7 @@
15514
15514
  "name": "redemptionTxMaxFee"
15515
15515
  },
15516
15516
  {
15517
- "type": "uint64",
15517
+ "type": "uint32",
15518
15518
  "name": "redemptionTimeout"
15519
15519
  },
15520
15520
  {
@@ -15522,7 +15522,7 @@
15522
15522
  "name": "redemptionTimeoutSlashingAmount"
15523
15523
  },
15524
15524
  {
15525
- "type": "uint64",
15525
+ "type": "uint32",
15526
15526
  "name": "redemptionTimeoutNotifierRewardMultiplier"
15527
15527
  }
15528
15528
  ]
@@ -16236,7 +16236,7 @@
16236
16236
  "name": "movingFundsTimeoutSlashingAmount"
16237
16237
  },
16238
16238
  {
16239
- "type": "uint256",
16239
+ "type": "uint32",
16240
16240
  "name": "movingFundsTimeoutNotifierRewardMultiplier"
16241
16241
  },
16242
16242
  {
@@ -16252,7 +16252,7 @@
16252
16252
  "name": "movedFundsSweepTimeoutSlashingAmount"
16253
16253
  },
16254
16254
  {
16255
- "type": "uint64",
16255
+ "type": "uint32",
16256
16256
  "name": "movedFundsSweepTimeoutNotifierRewardMultiplier"
16257
16257
  }
16258
16258
  ],
@@ -16278,7 +16278,7 @@
16278
16278
  "name": "redemptionTxMaxFee"
16279
16279
  },
16280
16280
  {
16281
- "type": "uint64",
16281
+ "type": "uint32",
16282
16282
  "name": "redemptionTimeout"
16283
16283
  },
16284
16284
  {
@@ -16286,7 +16286,7 @@
16286
16286
  "name": "redemptionTimeoutSlashingAmount"
16287
16287
  },
16288
16288
  {
16289
- "type": "uint64",
16289
+ "type": "uint32",
16290
16290
  "name": "redemptionTimeoutNotifierRewardMultiplier"
16291
16291
  }
16292
16292
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keep-network/tbtc-v2",
3
- "version": "0.1.1-dev.98+main.f6402ddc3a00709426dc87405c889b433f8aef6b",
3
+ "version": "0.1.1-dev.99+main.c478e89661909b419e54eb84d05ecfb7689112d8",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "artifacts/",