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

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 (69) hide show
  1. package/artifacts/Bank.json +3 -3
  2. package/artifacts/Bridge.json +11 -11
  3. package/artifacts/Deposit.json +7 -7
  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 +9 -9
  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/{4a775d74796a3fcb9cf30efbb6a767dd.json → 3cf46a7694ce157f71d9dbf4db692b09.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 +2 -2
  41. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +1 -1
  42. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +2 -2
  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/DepositSweep.sol +3 -0
  66. package/contracts/bridge/MovingFunds.sol +27 -6
  67. package/contracts/bridge/Redemption.sol +56 -38
  68. package/contracts/bridge/Wallets.sol +5 -5
  69. package/package.json +2 -2
@@ -42,34 +42,11 @@ library OutboundTx {
42
42
  /// before it is passed here.
43
43
  /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
44
44
  /// the Ethereum chain.
45
- /// @param walletPubKeyHash 20-byte public key hash (computed using Bitcoin
46
- // HASH160 over the compressed ECDSA public key) of the wallet which
47
- /// performed the outbound transaction.
48
45
  function processWalletOutboundTxInput(
49
46
  BridgeState.Storage storage self,
50
47
  bytes memory walletOutboundTxInputVector,
51
- BitcoinTx.UTXO calldata mainUtxo,
52
- bytes20 walletPubKeyHash
48
+ BitcoinTx.UTXO calldata mainUtxo
53
49
  ) internal {
54
- // Assert that main UTXO for passed wallet exists in storage.
55
- bytes32 mainUtxoHash = self
56
- .registeredWallets[walletPubKeyHash]
57
- .mainUtxoHash;
58
- require(mainUtxoHash != bytes32(0), "No main UTXO for given wallet");
59
-
60
- // Assert that passed main UTXO parameter is the same as in storage and
61
- // can be used for further processing.
62
- require(
63
- keccak256(
64
- abi.encodePacked(
65
- mainUtxo.txHash,
66
- mainUtxo.txOutputIndex,
67
- mainUtxo.txOutputValue
68
- )
69
- ) == mainUtxoHash,
70
- "Invalid main UTXO data"
71
- );
72
-
73
50
  // Assert that the single outbound transaction input actually
74
51
  // refers to the wallet's main UTXO.
75
52
  (
@@ -583,6 +560,9 @@ library Redemption {
583
560
  BitcoinTx.UTXO calldata mainUtxo,
584
561
  bytes20 walletPubKeyHash
585
562
  ) external {
563
+ // Wallet state validation is performed in the `resolveRedeemingWallet`
564
+ // function.
565
+
586
566
  // The actual transaction proof is performed here. After that point, we
587
567
  // can assume the transaction happened on Bitcoin chain and has
588
568
  // a sufficient number of confirmations as determined by
@@ -592,24 +572,18 @@ library Redemption {
592
572
  redemptionProof
593
573
  );
594
574
 
575
+ Wallets.Wallet storage wallet = resolveRedeemingWallet(
576
+ self,
577
+ walletPubKeyHash,
578
+ mainUtxo
579
+ );
580
+
595
581
  // Process the redemption transaction input. Specifically, check if it
596
582
  // refers to the expected wallet's main UTXO.
597
583
  OutboundTx.processWalletOutboundTxInput(
598
584
  self,
599
585
  redemptionTx.inputVector,
600
- mainUtxo,
601
- walletPubKeyHash
602
- );
603
-
604
- Wallets.Wallet storage wallet = self.registeredWallets[
605
- walletPubKeyHash
606
- ];
607
-
608
- Wallets.WalletState walletState = wallet.state;
609
- require(
610
- walletState == Wallets.WalletState.Live ||
611
- walletState == Wallets.WalletState.MovingFunds,
612
- "Wallet must be in Live or MovingFunds state"
586
+ mainUtxo
613
587
  );
614
588
 
615
589
  // Process redemption transaction outputs to extract some info required
@@ -645,6 +619,50 @@ library Redemption {
645
619
  self.bank.transferBalance(self.treasury, outputsInfo.totalTreasuryFee);
646
620
  }
647
621
 
622
+ /// @notice Resolves redeeming wallet based on the provided wallet public
623
+ /// key hash. Validates the wallet state and current main UTXO, as
624
+ /// currently known on the Ethereum chain.
625
+ /// @param walletPubKeyHash public key hash of the wallet proving the sweep
626
+ /// Bitcoin transaction.
627
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
628
+ /// the Ethereum chain.
629
+ /// @return wallet Data of the sweeping wallet.
630
+ /// @dev Requirements:
631
+ /// - Sweeping wallet must be either in Live or MovingFunds state,
632
+ /// - Main UTXO of the redeeming wallet must exists in the storage,
633
+ /// - The passed `mainUTXO` parameter must be equal to the stored one.
634
+ function resolveRedeemingWallet(
635
+ BridgeState.Storage storage self,
636
+ bytes20 walletPubKeyHash,
637
+ BitcoinTx.UTXO calldata mainUtxo
638
+ ) internal view returns (Wallets.Wallet storage wallet) {
639
+ wallet = self.registeredWallets[walletPubKeyHash];
640
+
641
+ // Assert that main UTXO for passed wallet exists in storage.
642
+ bytes32 mainUtxoHash = wallet.mainUtxoHash;
643
+ require(mainUtxoHash != bytes32(0), "No main UTXO for given wallet");
644
+
645
+ // Assert that passed main UTXO parameter is the same as in storage and
646
+ // can be used for further processing.
647
+ require(
648
+ keccak256(
649
+ abi.encodePacked(
650
+ mainUtxo.txHash,
651
+ mainUtxo.txOutputIndex,
652
+ mainUtxo.txOutputValue
653
+ )
654
+ ) == mainUtxoHash,
655
+ "Invalid main UTXO data"
656
+ );
657
+
658
+ Wallets.WalletState walletState = wallet.state;
659
+ require(
660
+ walletState == Wallets.WalletState.Live ||
661
+ walletState == Wallets.WalletState.MovingFunds,
662
+ "Wallet must be in Live or MovingFunds state"
663
+ );
664
+ }
665
+
648
666
  /// @notice Processes the Bitcoin redemption transaction output vector.
649
667
  /// It extracts each output and tries to identify it as a pending
650
668
  /// redemption request, reported timed out request, or change.
@@ -982,7 +1000,7 @@ library Redemption {
982
1000
  wallet.state == Wallets.WalletState.Live ||
983
1001
  wallet.state == Wallets.WalletState.MovingFunds ||
984
1002
  wallet.state == Wallets.WalletState.Terminated,
985
- "The wallet must be in Live, MovingFunds or Terminated state"
1003
+ "Wallet must be in Live, MovingFunds or Terminated state"
986
1004
  );
987
1005
 
988
1006
  // It is worth noting that there is no need to check if
@@ -287,7 +287,7 @@ library Wallets {
287
287
 
288
288
  require(
289
289
  self.registeredWallets[walletPubKeyHash].state == WalletState.Live,
290
- "ECDSA wallet must be in Live state"
290
+ "Wallet must be in Live state"
291
291
  );
292
292
 
293
293
  moveFunds(self, walletPubKeyHash);
@@ -312,7 +312,7 @@ library Wallets {
312
312
  require(
313
313
  walletState == WalletState.Live ||
314
314
  walletState == WalletState.MovingFunds,
315
- "ECDSA wallet must be in Live or MovingFunds state"
315
+ "Wallet must be in Live or MovingFunds state"
316
316
  );
317
317
 
318
318
  if (walletState == WalletState.Live) {
@@ -348,7 +348,7 @@ library Wallets {
348
348
  Wallet storage wallet = self.registeredWallets[walletPubKeyHash];
349
349
  require(
350
350
  wallet.state == WalletState.Live,
351
- "ECDSA wallet must be in Live state"
351
+ "Wallet must be in Live state"
352
352
  );
353
353
 
354
354
  /* solhint-disable-next-line not-rely-on-time */
@@ -435,7 +435,7 @@ library Wallets {
435
435
 
436
436
  require(
437
437
  wallet.state == WalletState.Closing,
438
- "ECDSA wallet must be in Closing state"
438
+ "Wallet must be in Closing state"
439
439
  );
440
440
 
441
441
  require(
@@ -527,7 +527,7 @@ library Wallets {
527
527
  // not reported yet.
528
528
  require(
529
529
  wallet.state == WalletState.MovingFunds,
530
- "ECDSA wallet must be in MovingFunds state"
530
+ "Wallet must be in MovingFunds state"
531
531
  );
532
532
 
533
533
  bytes32 targetWalletsCommitmentHash = wallet
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keep-network/tbtc-v2",
3
- "version": "0.1.1-dev.93+main.559b6e2597a9d2395df901adec25179331f1a16a",
3
+ "version": "0.1.1-dev.96+main.5131d26731c4fd456a3943a2d889d7356624a67d",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "artifacts/",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "@defi-wonderland/smock": "^2.0.7",
41
- "@keep-network/hardhat-helpers": "^0.6.0-pre.5",
41
+ "@keep-network/hardhat-helpers": "^0.6.0-pre.7",
42
42
  "@keep-network/hardhat-local-networks-config": "^0.1.0-pre.4",
43
43
  "@nomiclabs/hardhat-ethers": "^2.0.6",
44
44
  "@nomiclabs/hardhat-etherscan": "^2.1.4",