@keep-network/tbtc-v2 0.1.1-dev.51 → 0.1.1-dev.54

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 (68) hide show
  1. package/artifacts/Bank.json +6 -6
  2. package/artifacts/Bridge.json +282 -156
  3. package/artifacts/Deposit.json +7 -7
  4. package/artifacts/EcdsaDkgValidator.json +1 -1
  5. package/artifacts/EcdsaInactivity.json +1 -1
  6. package/artifacts/Fraud.json +10 -10
  7. package/artifacts/KeepRegistry.json +1 -1
  8. package/artifacts/KeepStake.json +2 -2
  9. package/artifacts/KeepToken.json +2 -2
  10. package/artifacts/KeepTokenStaking.json +1 -1
  11. package/artifacts/MovingFunds.json +13 -12
  12. package/artifacts/NuCypherStakingEscrow.json +1 -1
  13. package/artifacts/NuCypherToken.json +2 -2
  14. package/artifacts/RandomBeaconStub.json +1 -1
  15. package/artifacts/Redemption.json +14 -13
  16. package/artifacts/ReimbursementPool.json +2 -2
  17. package/artifacts/Relay.json +11 -11
  18. package/artifacts/SortitionPool.json +2 -2
  19. package/artifacts/Sweep.json +9 -9
  20. package/artifacts/T.json +2 -2
  21. package/artifacts/TBTC.json +6 -6
  22. package/artifacts/TBTCToken.json +6 -6
  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 +13 -13
  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 +9 -9
  32. package/artifacts/solcInputs/{c0a2aa3c07bd118332a0dc765c7f6da0.json → 799c7b289d9b6d9cfc600d2fc23c7b64.json} +7 -7
  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 +130 -40
  39. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +1 -1
  40. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +34 -4
  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/EcdsaLib.sol/EcdsaLib.dbg.json +1 -1
  44. package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +1 -1
  45. package/build/contracts/bridge/Fraud.sol/Fraud.json +2 -2
  46. package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +1 -1
  47. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +1 -1
  48. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +2 -2
  49. package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +1 -1
  50. package/build/contracts/bridge/Redemption.sol/OutboundTx.json +2 -2
  51. package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +1 -1
  52. package/build/contracts/bridge/Redemption.sol/Redemption.json +2 -2
  53. package/build/contracts/bridge/Sweep.sol/Sweep.dbg.json +1 -1
  54. package/build/contracts/bridge/Sweep.sol/Sweep.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/Bridge.sol +133 -40
  62. package/contracts/bridge/BridgeState.sol +101 -23
  63. package/contracts/bridge/Fraud.sol +1 -1
  64. package/contracts/bridge/MovingFunds.sol +16 -3
  65. package/contracts/bridge/Redemption.sol +34 -12
  66. package/contracts/bridge/Wallets.sol +9 -12
  67. package/export.json +96 -19
  68. package/package.json +1 -1
@@ -434,12 +434,20 @@ library MovingFunds {
434
434
  /// @notice Notifies about a timed out moving funds process. Terminates
435
435
  /// the wallet and slashes signing group members as a result.
436
436
  /// @param walletPubKeyHash 20-byte public key hash of the wallet
437
+ /// @param walletMembersIDs Identifiers of the wallet signing group members
437
438
  /// @dev Requirements:
438
439
  /// - The wallet must be in the MovingFunds state
439
440
  /// - The moving funds timeout must be actually exceeded
441
+ /// - The expression `keccak256(abi.encode(walletMembersIDs))` must
442
+ /// be exactly the same as the hash stored under `membersIdsHash`
443
+ /// for the given `walletID`. Those IDs are not directly stored
444
+ /// in the contract for gas efficiency purposes but they can be
445
+ /// read from appropriate `DkgResultSubmitted` and `DkgResultApproved`
446
+ /// events of the `WalletRegistry` contract
440
447
  function notifyMovingFundsTimeout(
441
448
  BridgeState.Storage storage self,
442
- bytes20 walletPubKeyHash
449
+ bytes20 walletPubKeyHash,
450
+ uint32[] calldata walletMembersIDs
443
451
  ) external {
444
452
  Wallets.Wallet storage wallet = self.registeredWallets[
445
453
  walletPubKeyHash
@@ -459,8 +467,13 @@ library MovingFunds {
459
467
 
460
468
  self.terminateWallet(walletPubKeyHash);
461
469
 
462
- // TODO: Perform slashing of wallet operators, reward the notifier
463
- // using seized amount, and add unit tests for that.
470
+ self.ecdsaWalletRegistry.seize(
471
+ self.movingFundsTimeoutSlashingAmount,
472
+ self.movingFundsTimeoutNotifierRewardMultiplier,
473
+ msg.sender,
474
+ wallet.ecdsaWalletID,
475
+ walletMembersIDs
476
+ );
464
477
 
465
478
  // slither-disable-next-line reentrancy-events
466
479
  emit MovingFundsTimedOut(walletPubKeyHash);
@@ -765,29 +765,41 @@ library Redemption {
765
765
  /// with the given wallet, that has timed out. The redemption
766
766
  /// request is identified by the key built as
767
767
  /// `keccak256(walletPubKeyHash | redeemerOutputScript)`.
768
- /// The results of calling this function: the pending redemptions
769
- /// value for the wallet will be decreased by the requested amount
770
- /// (minus treasury fee), the tokens taken from the redeemer on
771
- /// redemption request will be returned to the redeemer, the request
772
- /// will be moved from pending redemptions to timed-out redemptions.
773
- /// If the state of the wallet is `Live` or `MovingFunds`, the
774
- /// wallet operators will be slashed.
775
- /// Additionally, if the state of wallet is `Live`, the wallet will
776
- /// be closed or marked as `MovingFunds` (depending on the presence
777
- /// or absence of the wallet's main UTXO) and the wallet will no
778
- /// longer be marked as the active wallet (if it was marked as such).
768
+ /// The results of calling this function:
769
+ /// - the pending redemptions value for the wallet will be decreased
770
+ /// by the requested amount (minus treasury fee),
771
+ /// - the tokens taken from the redeemer on redemption request will
772
+ /// be returned to the redeemer,
773
+ /// - the request will be moved from pending redemptions to
774
+ /// timed-out redemptions,
775
+ /// - if the state of the wallet is `Live` or `MovingFunds`, the
776
+ /// wallet operators will be slashed and the notifier will be
777
+ /// rewarded,
778
+ /// - if the state of wallet is `Live`, the wallet will be closed or
779
+ /// marked as `MovingFunds` (depending on the presence or absence
780
+ /// of the wallet's main UTXO) and the wallet will no longer be
781
+ /// marked as the active wallet (if it was marked as such).
779
782
  /// @param walletPubKeyHash 20-byte public key hash of the wallet
783
+ /// @param walletMembersIDs Identifiers of the wallet signing group members
780
784
  /// @param redeemerOutputScript The redeemer's length-prefixed output
781
785
  /// script (P2PKH, P2WPKH, P2SH or P2WSH)
782
786
  /// @dev Requirements:
787
+ /// - The wallet must be in the Live or MovingFunds or Terminated state
783
788
  /// - The redemption request identified by `walletPubKeyHash` and
784
789
  /// `redeemerOutputScript` must exist
790
+ /// - The expression `keccak256(abi.encode(walletMembersIDs))` must
791
+ /// be exactly the same as the hash stored under `membersIdsHash`
792
+ /// for the given `walletID`. Those IDs are not directly stored
793
+ /// in the contract for gas efficiency purposes but they can be
794
+ /// read from appropriate `DkgResultSubmitted` and `DkgResultApproved`
795
+ /// events of the `WalletRegistry` contract
785
796
  /// - The amount of time defined by `redemptionTimeout` must have
786
797
  /// passed since the redemption was requested (the request must be
787
- /// timed-out).
798
+ /// timed-out)
788
799
  function notifyRedemptionTimeout(
789
800
  BridgeState.Storage storage self,
790
801
  bytes20 walletPubKeyHash,
802
+ uint32[] calldata walletMembersIDs,
791
803
  bytes calldata redeemerOutputScript
792
804
  ) external {
793
805
  uint256 redemptionKey = uint256(
@@ -836,7 +848,17 @@ library Redemption {
836
848
  ) {
837
849
  // Propagate timeout consequences to the wallet
838
850
  self.notifyWalletTimedOutRedemption(walletPubKeyHash);
851
+
852
+ // Slash the wallet operators and reward the notifier
853
+ self.ecdsaWalletRegistry.seize(
854
+ self.redemptionTimeoutSlashingAmount,
855
+ self.redemptionTimeoutNotifierRewardMultiplier,
856
+ msg.sender,
857
+ wallet.ecdsaWalletID,
858
+ walletMembersIDs
859
+ );
839
860
  }
861
+
840
862
  // slither-disable-next-line reentrancy-events
841
863
  emit RedemptionTimedOut(walletPubKeyHash, redeemerOutputScript);
842
864
 
@@ -163,8 +163,9 @@ library Wallets {
163
163
 
164
164
  require(
165
165
  (activeWalletOldEnough &&
166
- activeWalletBtcBalance >= self.walletMinBtcBalance) ||
167
- activeWalletBtcBalance >= self.walletMaxBtcBalance,
166
+ activeWalletBtcBalance >=
167
+ self.walletCreationMinBtcBalance) ||
168
+ activeWalletBtcBalance >= self.walletCreationMaxBtcBalance,
168
169
  "Wallet creation conditions are not met"
169
170
  );
170
171
  }
@@ -287,12 +288,11 @@ library Wallets {
287
288
  moveFunds(self, walletPubKeyHash);
288
289
  }
289
290
 
290
- /// @notice Handles a notification about a wallet redemption timeout
291
- /// and requests slashing of the wallet operators. Triggers the
292
- /// wallet moving funds process only if the wallet is still in the
293
- /// Live state. That means multiple action timeouts can be reported
294
- /// for the same wallet but only the first report requests the
295
- /// wallet to move their funds.
291
+ /// @notice Handles a notification about a wallet redemption timeout.
292
+ /// Triggers the wallet moving funds process only if the wallet is
293
+ /// still in the Live state. That means multiple action timeouts can
294
+ /// be reported for the same wallet but only the first report
295
+ /// requests the wallet to move their funds.
296
296
  /// @param walletPubKeyHash 20-byte public key hash of the wallet
297
297
  /// @dev Requirements:
298
298
  /// - The wallet must be in the `Live` or `MovingFunds` state
@@ -313,9 +313,6 @@ library Wallets {
313
313
  if (walletState == WalletState.Live) {
314
314
  moveFunds(self, walletPubKeyHash);
315
315
  }
316
-
317
- // TODO: Perform slashing of wallet operators and transfer some of the
318
- // slashed tokens to the caller of this function.
319
316
  }
320
317
 
321
318
  /// @notice Notifies that the wallet is either old enough or has too few
@@ -356,7 +353,7 @@ library Wallets {
356
353
  require(
357
354
  walletOldEnough ||
358
355
  getWalletBtcBalance(self, walletPubKeyHash, walletMainUtxo) <
359
- self.walletMinBtcBalance,
356
+ self.walletClosureMinBtcBalance,
360
357
  "Wallet needs to be old enough or have too few satoshis"
361
358
  );
362
359
 
package/export.json CHANGED
@@ -14326,6 +14326,18 @@
14326
14326
  "name": "movingFundsTimeout",
14327
14327
  "type": "uint32"
14328
14328
  },
14329
+ {
14330
+ "indexed": false,
14331
+ "internalType": "uint96",
14332
+ "name": "movingFundsTimeoutSlashingAmount",
14333
+ "type": "uint96"
14334
+ },
14335
+ {
14336
+ "indexed": false,
14337
+ "internalType": "uint256",
14338
+ "name": "movingFundsTimeoutNotifierRewardMultiplier",
14339
+ "type": "uint256"
14340
+ },
14329
14341
  {
14330
14342
  "indexed": false,
14331
14343
  "internalType": "uint64",
@@ -14400,6 +14412,18 @@
14400
14412
  "internalType": "uint256",
14401
14413
  "name": "redemptionTimeout",
14402
14414
  "type": "uint256"
14415
+ },
14416
+ {
14417
+ "indexed": false,
14418
+ "internalType": "uint96",
14419
+ "name": "redemptionTimeoutSlashingAmount",
14420
+ "type": "uint96"
14421
+ },
14422
+ {
14423
+ "indexed": false,
14424
+ "internalType": "uint256",
14425
+ "name": "redemptionTimeoutNotifierRewardMultiplier",
14426
+ "type": "uint256"
14403
14427
  }
14404
14428
  ],
14405
14429
  "name": "RedemptionParametersUpdated",
@@ -14574,13 +14598,19 @@
14574
14598
  {
14575
14599
  "indexed": false,
14576
14600
  "internalType": "uint64",
14577
- "name": "walletMinBtcBalance",
14601
+ "name": "walletCreationMinBtcBalance",
14602
+ "type": "uint64"
14603
+ },
14604
+ {
14605
+ "indexed": false,
14606
+ "internalType": "uint64",
14607
+ "name": "walletCreationMaxBtcBalance",
14578
14608
  "type": "uint64"
14579
14609
  },
14580
14610
  {
14581
14611
  "indexed": false,
14582
14612
  "internalType": "uint64",
14583
- "name": "walletMaxBtcBalance",
14613
+ "name": "walletClosureMinBtcBalance",
14584
14614
  "type": "uint64"
14585
14615
  },
14586
14616
  {
@@ -14931,6 +14961,16 @@
14931
14961
  "name": "movingFundsTimeout",
14932
14962
  "type": "uint32"
14933
14963
  },
14964
+ {
14965
+ "internalType": "uint96",
14966
+ "name": "movingFundsTimeoutSlashingAmount",
14967
+ "type": "uint96"
14968
+ },
14969
+ {
14970
+ "internalType": "uint256",
14971
+ "name": "movingFundsTimeoutNotifierRewardMultiplier",
14972
+ "type": "uint256"
14973
+ },
14934
14974
  {
14935
14975
  "internalType": "uint64",
14936
14976
  "name": "movingFundsDustThreshold",
@@ -15039,6 +15079,11 @@
15039
15079
  "internalType": "bytes20",
15040
15080
  "name": "walletPubKeyHash",
15041
15081
  "type": "bytes20"
15082
+ },
15083
+ {
15084
+ "internalType": "uint32[]",
15085
+ "name": "walletMembersIDs",
15086
+ "type": "uint32[]"
15042
15087
  }
15043
15088
  ],
15044
15089
  "name": "notifyMovingFundsTimeout",
@@ -15053,6 +15098,11 @@
15053
15098
  "name": "walletPubKeyHash",
15054
15099
  "type": "bytes20"
15055
15100
  },
15101
+ {
15102
+ "internalType": "uint32[]",
15103
+ "name": "walletMembersIDs",
15104
+ "type": "uint32[]"
15105
+ },
15056
15106
  {
15057
15107
  "internalType": "bytes",
15058
15108
  "name": "redeemerOutputScript",
@@ -15146,6 +15196,16 @@
15146
15196
  "internalType": "uint256",
15147
15197
  "name": "redemptionTimeout",
15148
15198
  "type": "uint256"
15199
+ },
15200
+ {
15201
+ "internalType": "uint96",
15202
+ "name": "redemptionTimeoutSlashingAmount",
15203
+ "type": "uint96"
15204
+ },
15205
+ {
15206
+ "internalType": "uint256",
15207
+ "name": "redemptionTimeoutNotifierRewardMultiplier",
15208
+ "type": "uint256"
15149
15209
  }
15150
15210
  ],
15151
15211
  "stateMutability": "view",
@@ -15995,19 +16055,6 @@
15995
16055
  "stateMutability": "view",
15996
16056
  "type": "function"
15997
16057
  },
15998
- {
15999
- "inputs": [
16000
- {
16001
- "internalType": "bytes20",
16002
- "name": "walletPubKeyHash",
16003
- "type": "bytes20"
16004
- }
16005
- ],
16006
- "name": "unsetWalletMainUtxo",
16007
- "outputs": [],
16008
- "stateMutability": "nonpayable",
16009
- "type": "function"
16010
- },
16011
16058
  {
16012
16059
  "inputs": [
16013
16060
  {
@@ -16071,6 +16118,16 @@
16071
16118
  "name": "movingFundsTimeout",
16072
16119
  "type": "uint32"
16073
16120
  },
16121
+ {
16122
+ "internalType": "uint96",
16123
+ "name": "movingFundsTimeoutSlashingAmount",
16124
+ "type": "uint96"
16125
+ },
16126
+ {
16127
+ "internalType": "uint256",
16128
+ "name": "movingFundsTimeoutNotifierRewardMultiplier",
16129
+ "type": "uint256"
16130
+ },
16074
16131
  {
16075
16132
  "internalType": "uint64",
16076
16133
  "name": "movingFundsDustThreshold",
@@ -16103,6 +16160,16 @@
16103
16160
  "internalType": "uint256",
16104
16161
  "name": "redemptionTimeout",
16105
16162
  "type": "uint256"
16163
+ },
16164
+ {
16165
+ "internalType": "uint96",
16166
+ "name": "redemptionTimeoutSlashingAmount",
16167
+ "type": "uint96"
16168
+ },
16169
+ {
16170
+ "internalType": "uint256",
16171
+ "name": "redemptionTimeoutNotifierRewardMultiplier",
16172
+ "type": "uint256"
16106
16173
  }
16107
16174
  ],
16108
16175
  "name": "updateRedemptionParameters",
@@ -16119,12 +16186,17 @@
16119
16186
  },
16120
16187
  {
16121
16188
  "internalType": "uint64",
16122
- "name": "walletMinBtcBalance",
16189
+ "name": "walletCreationMinBtcBalance",
16190
+ "type": "uint64"
16191
+ },
16192
+ {
16193
+ "internalType": "uint64",
16194
+ "name": "walletCreationMaxBtcBalance",
16123
16195
  "type": "uint64"
16124
16196
  },
16125
16197
  {
16126
16198
  "internalType": "uint64",
16127
- "name": "walletMaxBtcBalance",
16199
+ "name": "walletClosureMinBtcBalance",
16128
16200
  "type": "uint64"
16129
16201
  },
16130
16202
  {
@@ -16159,12 +16231,17 @@
16159
16231
  },
16160
16232
  {
16161
16233
  "internalType": "uint64",
16162
- "name": "walletMinBtcBalance",
16234
+ "name": "walletCreationMinBtcBalance",
16235
+ "type": "uint64"
16236
+ },
16237
+ {
16238
+ "internalType": "uint64",
16239
+ "name": "walletCreationMaxBtcBalance",
16163
16240
  "type": "uint64"
16164
16241
  },
16165
16242
  {
16166
16243
  "internalType": "uint64",
16167
- "name": "walletMaxBtcBalance",
16244
+ "name": "walletClosureMinBtcBalance",
16168
16245
  "type": "uint64"
16169
16246
  },
16170
16247
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keep-network/tbtc-v2",
3
- "version": "0.1.1-dev.51+main.2bbde1a93f2bb8ae73f42ac83ee999962a07cfb8",
3
+ "version": "0.1.1-dev.54+main.76eaffd21a4cdb7ff99e40f5d66c1c66eda4f730",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "artifacts/",