@keep-network/tbtc-v2 0.1.1-dev.39 → 0.1.1-dev.41

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 (38) hide show
  1. package/artifacts/TBTC.json +3 -3
  2. package/artifacts/TBTCToken.json +3 -3
  3. package/artifacts/VendingMachine.json +10 -10
  4. package/artifacts/solcInputs/{518efc6faeb6612766a5b3fef24e13ad.json → e9b173393b9fd7287a0bfaa6d4eb4b71.json} +6 -6
  5. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
  6. package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
  7. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +1 -1
  8. package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
  9. package/build/contracts/bridge/Bridge.sol/Bridge.json +99 -107
  10. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +1 -1
  11. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +2 -2
  12. package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +1 -1
  13. package/build/contracts/bridge/Deposit.sol/Deposit.json +2 -2
  14. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +1 -1
  15. package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +4 -0
  16. package/build/contracts/bridge/Fraud.sol/Fraud.json +138 -0
  17. package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +1 -1
  18. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +1 -1
  19. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +2 -2
  20. package/build/contracts/bridge/Redeem.sol/OutboundTx.dbg.json +1 -1
  21. package/build/contracts/bridge/Redeem.sol/OutboundTx.json +2 -2
  22. package/build/contracts/bridge/Redeem.sol/Redeem.dbg.json +1 -1
  23. package/build/contracts/bridge/Redeem.sol/Redeem.json +2 -2
  24. package/build/contracts/bridge/Sweep.sol/Sweep.dbg.json +1 -1
  25. package/build/contracts/bridge/Sweep.sol/Sweep.json +2 -2
  26. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
  27. package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +1 -1
  28. package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
  29. package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
  30. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
  31. package/contracts/bridge/Bridge.sol +56 -95
  32. package/contracts/bridge/BridgeState.sol +116 -111
  33. package/contracts/bridge/Deposit.sol +4 -4
  34. package/contracts/bridge/{Frauds.sol → Fraud.sol} +58 -131
  35. package/contracts/bridge/Sweep.sol +1 -1
  36. package/package.json +1 -1
  37. package/build/contracts/bridge/Frauds.sol/Frauds.dbg.json +0 -4
  38. package/build/contracts/bridge/Frauds.sol/Frauds.json +0 -138
@@ -30,7 +30,7 @@ import "./Redeem.sol";
30
30
  import "./BitcoinTx.sol";
31
31
  import "./EcdsaLib.sol";
32
32
  import "./Wallets.sol";
33
- import "./Frauds.sol";
33
+ import "./Fraud.sol";
34
34
  import "./MovingFunds.sol";
35
35
 
36
36
  import "../bank/Bank.sol";
@@ -65,7 +65,7 @@ contract Bridge is Ownable, EcdsaWalletOwner {
65
65
  using Sweep for BridgeState.Storage;
66
66
  using Redeem for BridgeState.Storage;
67
67
  using MovingFunds for BridgeState.Storage;
68
- using Frauds for Frauds.Data;
68
+ using Fraud for BridgeState.Storage;
69
69
  using Wallets for Wallets.Data;
70
70
 
71
71
  using BTCUtils for bytes;
@@ -74,10 +74,6 @@ contract Bridge is Ownable, EcdsaWalletOwner {
74
74
 
75
75
  BridgeState.Storage internal self;
76
76
 
77
- /// @notice Contains parameters related to frauds and the collection of all
78
- /// submitted fraud challenges.
79
- Frauds.Data internal frauds;
80
-
81
77
  /// @notice State related with wallets.
82
78
  Wallets.Data internal wallets;
83
79
 
@@ -208,12 +204,10 @@ contract Bridge is Ownable, EcdsaWalletOwner {
208
204
  self.redemptionTxMaxFee = 10000; // 10000 satoshi
209
205
  self.redemptionTimeout = 172800; // 48 hours
210
206
  self.movingFundsTxMaxTotalFee = 10000; // 10000 satoshi
211
-
212
- // TODO: Revisit initial values.
213
- frauds.setSlashingAmount(10000 * 1e18); // 10000 T
214
- frauds.setNotifierRewardMultiplier(100); // 100%
215
- frauds.setChallengeDefeatTimeout(7 days);
216
- frauds.setChallengeDepositAmount(2 ether);
207
+ self.fraudSlashingAmount = 10000 * 1e18; // 10000 T
208
+ self.fraudNotifierRewardMultiplier = 100; // 100%
209
+ self.fraudChallengeDefeatTimeout = 7 days;
210
+ self.fraudChallengeDepositAmount = 2 ether;
217
211
 
218
212
  // TODO: Revisit initial values.
219
213
  wallets.init(_ecdsaWalletRegistry);
@@ -417,7 +411,7 @@ contract Bridge is Ownable, EcdsaWalletOwner {
417
411
  /// deposit script unlocks to receive their BTC back.
418
412
  function revealDeposit(
419
413
  BitcoinTx.Info calldata fundingTx,
420
- Deposit.RevealInfo calldata reveal
414
+ Deposit.DepositRevealInfo calldata reveal
421
415
  ) external {
422
416
  self.revealDeposit(wallets, fundingTx, reveal);
423
417
  }
@@ -503,28 +497,7 @@ contract Bridge is Ownable, EcdsaWalletOwner {
503
497
  bytes32 sighash,
504
498
  BitcoinTx.RSVSignature calldata signature
505
499
  ) external payable {
506
- bytes memory compressedWalletPublicKey = EcdsaLib.compressPublicKey(
507
- walletPublicKey.slice32(0),
508
- walletPublicKey.slice32(32)
509
- );
510
- bytes20 walletPubKeyHash = compressedWalletPublicKey.hash160View();
511
-
512
- Wallets.Wallet storage wallet = wallets.registeredWallets[
513
- walletPubKeyHash
514
- ];
515
-
516
- require(
517
- wallet.state == Wallets.WalletState.Live ||
518
- wallet.state == Wallets.WalletState.MovingFunds,
519
- "Wallet is neither in Live nor MovingFunds state"
520
- );
521
-
522
- frauds.submitChallenge(
523
- walletPublicKey,
524
- walletPubKeyHash,
525
- sighash,
526
- signature
527
- );
500
+ self.submitFraudChallenge(wallets, walletPublicKey, sighash, signature);
528
501
  }
529
502
 
530
503
  /// @notice Allows to defeat a pending fraud challenge against a wallet if
@@ -560,19 +533,7 @@ contract Bridge is Ownable, EcdsaWalletOwner {
560
533
  bytes calldata preimage,
561
534
  bool witness
562
535
  ) external {
563
- uint256 utxoKey = frauds.unwrapChallenge(
564
- walletPublicKey,
565
- preimage,
566
- witness
567
- );
568
-
569
- // Check that the UTXO key identifies a correctly spent UTXO.
570
- require(
571
- self.deposits[utxoKey].sweptAt > 0 || self.spentMainUTXOs[utxoKey],
572
- "Spent UTXO not found among correctly spent UTXOs"
573
- );
574
-
575
- frauds.defeatChallenge(walletPublicKey, preimage, self.treasury);
536
+ self.defeatFraudChallenge(walletPublicKey, preimage, witness);
576
537
  }
577
538
 
578
539
  /// @notice Notifies about defeat timeout for the given fraud challenge.
@@ -602,35 +563,7 @@ contract Bridge is Ownable, EcdsaWalletOwner {
602
563
  bytes calldata walletPublicKey,
603
564
  bytes32 sighash
604
565
  ) external {
605
- frauds.notifyChallengeDefeatTimeout(walletPublicKey, sighash);
606
- }
607
-
608
- /// @notice Returns parameters used by the `Frauds` library.
609
- /// @return slashingAmount Value of the slashing amount
610
- /// @return notifierRewardMultiplier Value of the notifier reward multiplier
611
- /// @return challengeDefeatTimeout Value of the challenge defeat timeout
612
- /// @return challengeDepositAmount Value of the challenge deposit amount
613
- function getFraudParameters()
614
- external
615
- view
616
- returns (
617
- uint256 slashingAmount,
618
- uint256 notifierRewardMultiplier,
619
- uint256 challengeDefeatTimeout,
620
- uint256 challengeDepositAmount
621
- )
622
- {
623
- slashingAmount = frauds.slashingAmount;
624
- notifierRewardMultiplier = frauds.notifierRewardMultiplier;
625
- challengeDefeatTimeout = frauds.challengeDefeatTimeout;
626
- challengeDepositAmount = frauds.challengeDepositAmount;
627
-
628
- return (
629
- slashingAmount,
630
- notifierRewardMultiplier,
631
- challengeDefeatTimeout,
632
- challengeDepositAmount
633
- );
566
+ self.notifyFraudChallengeDefeatTimeout(walletPublicKey, sighash);
634
567
  }
635
568
 
636
569
  /// @notice Returns the fraud challenge identified by the given key built
@@ -638,9 +571,9 @@ contract Bridge is Ownable, EcdsaWalletOwner {
638
571
  function fraudChallenges(uint256 challengeKey)
639
572
  external
640
573
  view
641
- returns (Frauds.FraudChallenge memory)
574
+ returns (Fraud.FraudChallenge memory)
642
575
  {
643
- return frauds.challenges[challengeKey];
576
+ return self.fraudChallenges[challengeKey];
644
577
  }
645
578
 
646
579
  /// @notice Requests redemption of the given amount from the specified
@@ -850,6 +783,22 @@ contract Bridge is Ownable, EcdsaWalletOwner {
850
783
  relay = self.relay;
851
784
  }
852
785
 
786
+ /// @notice Address where the deposit treasury fees will be sent to.
787
+ /// Treasury takes part in the operators rewarding process.
788
+ function treasury() external view returns (address treasury) {
789
+ treasury = self.treasury;
790
+ }
791
+
792
+ /// @notice The number of confirmations on the Bitcoin chain required to
793
+ /// successfully evaluate an SPV proof.
794
+ function txProofDifficultyFactor()
795
+ external
796
+ view
797
+ returns (uint256 txProofDifficultyFactor)
798
+ {
799
+ txProofDifficultyFactor = self.txProofDifficultyFactor;
800
+ }
801
+
853
802
  /// @notice Returns the current values of Bridge deposit parameters.
854
803
  /// @return depositDustThreshold The minimal amount that can be requested
855
804
  /// to deposit. Value of this parameter must take into account the
@@ -867,26 +816,18 @@ contract Bridge is Ownable, EcdsaWalletOwner {
867
816
  /// be incurred by each swept deposit being part of the given sweep
868
817
  /// transaction. If the maximum BTC transaction fee is exceeded,
869
818
  /// such transaction is considered a fraud.
870
- /// @return treasury Address where the deposit treasury fees will be
871
- /// sent to. Treasury takes part in the operators rewarding process.
872
- /// @return txProofDifficultyFactor The number of confirmations on the
873
- /// Bitcoin chain required to successfully evaluate an SPV proof.
874
819
  function depositParameters()
875
820
  external
876
821
  view
877
822
  returns (
878
823
  uint64 depositDustThreshold,
879
824
  uint64 depositTreasuryFeeDivisor,
880
- uint64 depositTxMaxFee,
881
- address treasury,
882
- uint256 txProofDifficultyFactor
825
+ uint64 depositTxMaxFee
883
826
  )
884
827
  {
885
828
  depositDustThreshold = self.depositDustThreshold;
886
829
  depositTreasuryFeeDivisor = self.depositTreasuryFeeDivisor;
887
830
  depositTxMaxFee = self.depositTxMaxFee;
888
- treasury = self.treasury;
889
- txProofDifficultyFactor = self.txProofDifficultyFactor;
890
831
  }
891
832
 
892
833
  /// @notice Returns the current values of Bridge redemption parameters.
@@ -912,10 +853,6 @@ contract Bridge is Ownable, EcdsaWalletOwner {
912
853
  /// redemption request was created via `requestRedemption` call.
913
854
  /// Reported timed out requests are cancelled and locked TBTC is
914
855
  /// returned to the redeemer in full amount.
915
- /// @return treasury Address where the redemption treasury fees will be
916
- /// sent to. Treasury takes part in the operators rewarding process.
917
- /// @return txProofDifficultyFactor The number of confirmations on the
918
- /// Bitcoin chain required to successfully evaluate an SPV proof.
919
856
  function redemptionParameters()
920
857
  external
921
858
  view
@@ -932,8 +869,6 @@ contract Bridge is Ownable, EcdsaWalletOwner {
932
869
  redemptionTreasuryFeeDivisor = self.redemptionTreasuryFeeDivisor;
933
870
  redemptionTxMaxFee = self.redemptionTxMaxFee;
934
871
  redemptionTimeout = self.redemptionTimeout;
935
- treasury = self.treasury;
936
- txProofDifficultyFactor = self.txProofDifficultyFactor;
937
872
  }
938
873
 
939
874
  /// @notice Returns the current values of Bridge moving funds between
@@ -951,6 +886,32 @@ contract Bridge is Ownable, EcdsaWalletOwner {
951
886
  movingFundsTxMaxTotalFee = self.movingFundsTxMaxTotalFee;
952
887
  }
953
888
 
889
+ /// @notice Returns the current values of Bridge fraud parameters.
890
+ /// @return fraudSlashingAmount The amount slashed from each wallet member
891
+ /// for committing a fraud.
892
+ /// @return fraudNotifierRewardMultiplier The percentage of the notifier
893
+ /// reward from the staking contract the notifier of a fraud
894
+ /// receives. The value is in the range [0, 100].
895
+ /// @return fraudChallengeDefeatTimeout The amount of time the wallet has to
896
+ /// defeat a fraud challenge.
897
+ /// @return fraudChallengeDepositAmount The amount of ETH in wei the party
898
+ /// challenging the wallet for fraud needs to deposit.
899
+ function fraudParameters()
900
+ external
901
+ view
902
+ returns (
903
+ uint256 fraudSlashingAmount,
904
+ uint256 fraudNotifierRewardMultiplier,
905
+ uint256 fraudChallengeDefeatTimeout,
906
+ uint256 fraudChallengeDepositAmount
907
+ )
908
+ {
909
+ fraudSlashingAmount = self.fraudSlashingAmount;
910
+ fraudNotifierRewardMultiplier = self.fraudNotifierRewardMultiplier;
911
+ fraudChallengeDefeatTimeout = self.fraudChallengeDefeatTimeout;
912
+ fraudChallengeDepositAmount = self.fraudChallengeDepositAmount;
913
+ }
914
+
954
915
  /// @notice Indicates if the vault with the given address is trusted or not.
955
916
  /// Depositors can route their revealed deposits only to trusted
956
917
  /// vaults and have trusted vaults notified about new deposits as
@@ -971,7 +932,7 @@ contract Bridge is Ownable, EcdsaWalletOwner {
971
932
  function deposits(uint256 depositKey)
972
933
  external
973
934
  view
974
- returns (Deposit.Request memory)
935
+ returns (Deposit.DepositRequest memory)
975
936
  {
976
937
  return self.deposits[depositKey];
977
938
  }
@@ -18,137 +18,142 @@ pragma solidity ^0.8.9;
18
18
  import "./IRelay.sol";
19
19
  import "./Deposit.sol";
20
20
  import "./Redeem.sol";
21
+ import "./Fraud.sol";
21
22
 
22
23
  import "../bank/Bank.sol";
23
24
 
24
25
  library BridgeState {
26
+ // TODO: Make parameters governable
25
27
  struct Storage {
26
- /// @notice The number of confirmations on the Bitcoin chain required to
27
- /// successfully evaluate an SPV proof.
28
+ // The number of confirmations on the Bitcoin chain required to
29
+ // successfully evaluate an SPV proof.
28
30
  uint256 txProofDifficultyFactor;
29
- /// TODO: Revisit whether it should be governable or not.
30
- /// @notice Address of the Bank this Bridge belongs to.
31
+ // Address of the Bank this Bridge belongs to.
31
32
  Bank bank;
32
- /// TODO: Make it governable.
33
- /// @notice Bitcoin relay providing the current Bitcoin network
34
- /// difficulty.
33
+ // Bitcoin relay providing the current Bitcoin network difficulty.
35
34
  IRelay relay;
36
- /// TODO: Revisit whether it should be governable or not.
37
- /// @notice Address where the deposit and redemption treasury fees will
38
- /// be sent to. Treasury takes part in the operators rewarding
39
- /// process.
35
+ // Address where the deposit and redemption treasury fees will be sent
36
+ // to. Treasury takes part in the operators rewarding process.
40
37
  address treasury;
41
- /// TODO: Make it governable.
42
- /// @notice The minimal amount that can be requested to deposit.
43
- /// Value of this parameter must take into account the value of
44
- /// `depositTreasuryFeeDivisor` and `depositTxMaxFee`
45
- /// parameters in order to make requests that can incur the
46
- /// treasury and transaction fee and still satisfy the depositor.
38
+ // The minimal amount that can be requested to deposit.
39
+ // Value of this parameter must take into account the value of
40
+ // `depositTreasuryFeeDivisor` and `depositTxMaxFee` parameters in order
41
+ // to make requests that can incur the treasury and transaction fee and
42
+ // still satisfy the depositor.
47
43
  uint64 depositDustThreshold;
48
- /// TODO: Make it governable.
49
- /// @notice Divisor used to compute the treasury fee taken from each
50
- /// deposit and transferred to the treasury upon sweep proof
51
- /// submission. That fee is computed as follows:
52
- /// `treasuryFee = depositedAmount / depositTreasuryFeeDivisor`
53
- /// For example, if the treasury fee needs to be 2% of each deposit,
54
- /// the `depositTreasuryFeeDivisor` should be set to `50`
55
- /// because `1/50 = 0.02 = 2%`.
44
+ // Divisor used to compute the treasury fee taken from each deposit and
45
+ // transferred to the treasury upon sweep proof submission. That fee is
46
+ // computed as follows:
47
+ // `treasuryFee = depositedAmount / depositTreasuryFeeDivisor`
48
+ // For example, if the treasury fee needs to be 2% of each deposit,
49
+ // the `depositTreasuryFeeDivisor` should be set to `50` because
50
+ // `1/50 = 0.02 = 2%`.
56
51
  uint64 depositTreasuryFeeDivisor;
57
- /// TODO: Make it governable.
58
- /// @notice Maximum amount of BTC transaction fee that can be incurred by
59
- /// each swept deposit being part of the given sweep
60
- /// transaction. If the maximum BTC transaction fee is exceeded,
61
- /// such transaction is considered a fraud.
62
- /// @dev This is a per-deposit input max fee for the sweep transaction.
52
+ // Maximum amount of BTC transaction fee that can be incurred by each
53
+ // swept deposit being part of the given sweep transaction. If the
54
+ // maximum BTC transaction fee is exceeded, such transaction is
55
+ // considered a fraud.
56
+ //
57
+ // This is a per-deposit input max fee for the sweep transaction.
63
58
  uint64 depositTxMaxFee;
64
- /// @notice 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
69
- /// validating them before attempting to execute a sweep.
70
- mapping(uint256 => Deposit.Request) deposits;
71
- /// @notice Indicates if the vault with the given address is trusted or not.
72
- /// Depositors can route their revealed deposits only to trusted
73
- /// vaults and have trusted vaults notified about new deposits as
74
- /// soon as these deposits get swept. Vaults not trusted by the
75
- /// Bridge can still be used by Bank balance owners on their own
76
- /// responsibility - anyone can approve their Bank balance to any
77
- /// address.
59
+ // Collection of all revealed deposits indexed by
60
+ // `keccak256(fundingTxHash | fundingOutputIndex)`.
61
+ // The `fundingTxHash` is `bytes32` (ordered as in Bitcoin internally)
62
+ // and `fundingOutputIndex` an `uint32`. This mapping may contain valid
63
+ // and invalid deposits and the wallet is responsible for validating
64
+ // them before attempting to execute a sweep.
65
+ mapping(uint256 => Deposit.DepositRequest) deposits;
66
+ // Indicates if the vault with the given address is trusted or not.
67
+ // Depositors can route their revealed deposits only to trusted vaults
68
+ // and have trusted vaults notified about new deposits as soon as these
69
+ // deposits get swept. Vaults not trusted by the Bridge can still be
70
+ // used by Bank balance owners on their own responsibility - anyone can
71
+ // approve their Bank balance to any address.
78
72
  mapping(address => bool) isVaultTrusted;
79
- /// TODO: Make it governable.
80
- /// @notice Maximum amount of the total BTC transaction fee that is
81
- /// acceptable in a single moving funds transaction.
82
- /// @dev This is a TOTAL max fee for the moving funds transaction. Note
83
- /// that `depositTxMaxFee` is per single deposit and `redemptionTxMaxFee`
84
- /// if per single redemption. `movingFundsTxMaxTotalFee` is a total
85
- /// fee for the entire transaction.
73
+ // Maximum amount of the total BTC transaction fee that is acceptable in
74
+ // a single moving funds transaction.
75
+ //
76
+ // This is a TOTAL max fee for the moving funds transaction. Note
77
+ // that `depositTxMaxFee` is per single deposit and `redemptionTxMaxFee`
78
+ // if per single redemption. `movingFundsTxMaxTotalFee` is a total
79
+ // fee for the entire transaction.
86
80
  uint64 movingFundsTxMaxTotalFee;
87
- /// TODO: Make it governable.
88
- /// @notice The minimal amount that can be requested for redemption.
89
- /// Value of this parameter must take into account the value of
90
- /// `redemptionTreasuryFeeDivisor` and `redemptionTxMaxFee`
91
- /// parameters in order to make requests that can incur the
92
- /// treasury and transaction fee and still satisfy the redeemer.
81
+ // The minimal amount that can be requested for redemption.
82
+ // Value of this parameter must take into account the value of
83
+ // `redemptionTreasuryFeeDivisor` and `redemptionTxMaxFee`
84
+ // parameters in order to make requests that can incur the
85
+ // treasury and transaction fee and still satisfy the redeemer.
93
86
  uint64 redemptionDustThreshold;
94
- /// TODO: Make it governable.
95
- /// @notice Divisor used to compute the treasury fee taken from each
96
- /// redemption request and transferred to the treasury upon
97
- /// successful request finalization. That fee is computed as follows:
98
- /// `treasuryFee = requestedAmount / redemptionTreasuryFeeDivisor`
99
- /// For example, if the treasury fee needs to be 2% of each
100
- /// redemption request, the `redemptionTreasuryFeeDivisor` should
101
- /// be set to `50` because `1/50 = 0.02 = 2%`.
87
+ // Divisor used to compute the treasury fee taken from each
88
+ // redemption request and transferred to the treasury upon
89
+ // successful request finalization. That fee is computed as follows:
90
+ // `treasuryFee = requestedAmount / redemptionTreasuryFeeDivisor`
91
+ // For example, if the treasury fee needs to be 2% of each
92
+ // redemption request, the `redemptionTreasuryFeeDivisor` should
93
+ // be set to `50` because `1/50 = 0.02 = 2%`.
102
94
  uint64 redemptionTreasuryFeeDivisor;
103
- /// TODO: Make it governable.
104
- /// @notice Maximum amount of BTC transaction fee that can be incurred by
105
- /// each redemption request being part of the given redemption
106
- /// transaction. If the maximum BTC transaction fee is exceeded, such
107
- /// transaction is considered a fraud.
108
- /// @dev This is a per-redemption output max fee for the redemption transaction.
95
+ // Maximum amount of BTC transaction fee that can be incurred by
96
+ // each redemption request being part of the given redemption
97
+ // transaction. If the maximum BTC transaction fee is exceeded, such
98
+ // transaction is considered a fraud.
99
+ //
100
+ // This is a per-redemption output max fee for the redemption
101
+ // transaction.
109
102
  uint64 redemptionTxMaxFee;
110
- /// TODO: Make it governable.
111
- /// @notice Time after which the redemption request can be reported as
112
- /// timed out. It is counted from the moment when the redemption
113
- /// request was created via `requestRedemption` call. Reported
114
- /// timed out requests are cancelled and locked TBTC is returned
115
- /// to the redeemer in full amount.
103
+ // Time after which the redemption request can be reported as
104
+ // timed out. It is counted from the moment when the redemption
105
+ // request was created via `requestRedemption` call. Reported
106
+ // timed out requests are cancelled and locked TBTC is returned
107
+ // to the redeemer in full amount.
116
108
  uint256 redemptionTimeout;
117
- /// @notice Collection of all pending redemption requests indexed by
118
- /// redemption key built as
119
- /// keccak256(walletPubKeyHash | redeemerOutputScript). The
120
- /// walletPubKeyHash is the 20-byte wallet's public key hash
121
- /// (computed using Bitcoin HASH160 over the compressed ECDSA
122
- /// public key) and redeemerOutputScript is a Bitcoin script
123
- /// (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
124
- /// redeemed BTC as requested by the redeemer. Requests are added
125
- /// to this mapping by the `requestRedemption` method (duplicates
126
- /// not allowed) and are removed by one of the following methods:
127
- /// - `submitRedemptionProof` in case the request was handled
128
- /// successfully
129
- /// - `notifyRedemptionTimeout` in case the request was reported
130
- /// to be timed out
109
+ // Collection of all pending redemption requests indexed by
110
+ // redemption key built as
111
+ // `keccak256(walletPubKeyHash | redeemerOutputScript)`.
112
+ // The `walletPubKeyHash` is the 20-byte wallet's public key hash
113
+ // (computed using Bitcoin HASH160 over the compressed ECDSA
114
+ // public key) and `redeemerOutputScript` is a Bitcoin script
115
+ // (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
116
+ // redeemed BTC as requested by the redeemer. Requests are added
117
+ // to this mapping by the `requestRedemption` method (duplicates
118
+ // not allowed) and are removed by one of the following methods:
119
+ // - `submitRedemptionProof` in case the request was handled
120
+ // successfully
121
+ // - `notifyRedemptionTimeout` in case the request was reported
122
+ // to be timed out
131
123
  mapping(uint256 => Redeem.RedemptionRequest) pendingRedemptions;
132
- /// @notice Collection of all timed out redemptions requests indexed by
133
- /// redemption key built as
134
- /// keccak256(walletPubKeyHash | redeemerOutputScript). The
135
- /// walletPubKeyHash is the 20-byte wallet's public key hash
136
- /// (computed using Bitcoin HASH160 over the compressed ECDSA
137
- /// public key) and redeemerOutputScript is the Bitcoin script
138
- /// (P2PKH, P2WPKH, P2SH or P2WSH) that is involved in the timed
139
- /// out request. Timed out requests are stored in this mapping to
140
- /// avoid slashing the wallets multiple times for the same timeout.
141
- /// Only one method can add to this mapping:
142
- /// - `notifyRedemptionTimeout` which puts the redemption key
143
- /// to this mapping basing on a timed out request stored
144
- /// previously in `pendingRedemptions` mapping.
124
+ // Collection of all timed out redemptions requests indexed by
125
+ // redemption key built as
126
+ // `keccak256(walletPubKeyHash | redeemerOutputScript)`. The
127
+ // `walletPubKeyHash` is the 20-byte wallet's public key hash
128
+ // (computed using Bitcoin HASH160 over the compressed ECDSA
129
+ // public key) and `redeemerOutputScript` is the Bitcoin script
130
+ // (P2PKH, P2WPKH, P2SH or P2WSH) that is involved in the timed
131
+ // out request. Timed out requests are stored in this mapping to
132
+ // avoid slashing the wallets multiple times for the same timeout.
133
+ // Only one method can add to this mapping:
134
+ // - `notifyRedemptionTimeout` which puts the redemption key to this
135
+ // mapping basing on a timed out request stored previously in
136
+ // `pendingRedemptions` mapping.
145
137
  mapping(uint256 => Redeem.RedemptionRequest) timedOutRedemptions;
146
- /// @notice Collection of main UTXOs that are honestly spent indexed by
147
- /// keccak256(fundingTxHash | fundingOutputIndex). The fundingTxHash
148
- /// is bytes32 (ordered as in Bitcoin internally) and
149
- /// fundingOutputIndex an uint32. A main UTXO is considered honestly
150
- /// spent if it was used as an input of a transaction that have been
151
- /// proven in the Bridge.
138
+ // The amount of stake slashed from each member of a wallet for a fraud.
139
+ uint256 fraudSlashingAmount;
140
+ // The percentage of the notifier reward from the staking contract
141
+ // the notifier of a fraud receives. The value is in the range [0, 100].
142
+ uint256 fraudNotifierRewardMultiplier;
143
+ // The amount of time the wallet has to defeat a fraud challenge.
144
+ uint256 fraudChallengeDefeatTimeout;
145
+ // The amount of ETH in wei the party challenging the wallet for fraud
146
+ // needs to deposit.
147
+ uint256 fraudChallengeDepositAmount;
148
+ // Collection of all submitted fraud challenges indexed by challenge
149
+ // key built as `keccak256(walletPublicKey|sighash)`.
150
+ mapping(uint256 => Fraud.FraudChallenge) fraudChallenges;
151
+ // Collection of main UTXOs that are honestly spent indexed by
152
+ // `keccak256(fundingTxHash | fundingOutputIndex)`. The `fundingTxHash`
153
+ // is `bytes32` (ordered as in Bitcoin internally) and
154
+ // `fundingOutputIndex` an `uint32`. A main UTXO is considered honestly
155
+ // spent if it was used as an input of a transaction that have been
156
+ // proven in the Bridge.
152
157
  mapping(uint256 => bool) spentMainUTXOs;
153
158
  }
154
159
 
@@ -30,7 +30,7 @@ library Deposit {
30
30
 
31
31
  /// @notice Represents data which must be revealed by the depositor during
32
32
  /// deposit reveal.
33
- struct RevealInfo {
33
+ struct DepositRevealInfo {
34
34
  // Index of the funding output belonging to the funding transaction.
35
35
  uint32 fundingOutputIndex;
36
36
  // Ethereum depositor address.
@@ -57,7 +57,7 @@ library Deposit {
57
57
  }
58
58
 
59
59
  /// @notice Represents tBTC deposit request data.
60
- struct Request {
60
+ struct DepositRequest {
61
61
  // Ethereum depositor address.
62
62
  address depositor;
63
63
  // Deposit amount in satoshi.
@@ -125,7 +125,7 @@ library Deposit {
125
125
  BridgeState.Storage storage self,
126
126
  Wallets.Data storage wallets,
127
127
  BitcoinTx.Info calldata fundingTx,
128
- RevealInfo calldata reveal
128
+ DepositRevealInfo calldata reveal
129
129
  ) external {
130
130
  require(
131
131
  wallets.registeredWallets[reveal.walletPubKeyHash].state ==
@@ -207,7 +207,7 @@ library Deposit {
207
207
  )
208
208
  .hash256View();
209
209
 
210
- Request storage deposit = self.deposits[
210
+ DepositRequest storage deposit = self.deposits[
211
211
  uint256(
212
212
  keccak256(
213
213
  abi.encodePacked(fundingTxHash, reveal.fundingOutputIndex)