@keep-network/tbtc-v2 0.1.1-dev.54 → 0.1.1-dev.57
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.
- package/artifacts/Bank.json +3 -3
- package/artifacts/Bridge.json +581 -234
- package/artifacts/Deposit.json +9 -9
- package/artifacts/DepositSweep.json +76 -0
- package/artifacts/EcdsaDkgValidator.json +1 -1
- package/artifacts/EcdsaInactivity.json +1 -1
- package/artifacts/Fraud.json +9 -9
- package/artifacts/KeepRegistry.json +1 -1
- package/artifacts/KeepStake.json +2 -2
- package/artifacts/KeepToken.json +2 -2
- package/artifacts/KeepTokenStaking.json +1 -1
- package/artifacts/MovingFunds.json +41 -11
- package/artifacts/NuCypherStakingEscrow.json +1 -1
- package/artifacts/NuCypherToken.json +2 -2
- package/artifacts/RandomBeaconStub.json +1 -1
- package/artifacts/Redemption.json +9 -9
- package/artifacts/ReimbursementPool.json +2 -2
- package/artifacts/Relay.json +9 -9
- package/artifacts/SortitionPool.json +2 -2
- package/artifacts/T.json +2 -2
- package/artifacts/TBTC.json +3 -3
- package/artifacts/TBTCToken.json +3 -3
- package/artifacts/TokenStaking.json +1 -1
- package/artifacts/TokenholderGovernor.json +9 -9
- package/artifacts/TokenholderTimelock.json +8 -8
- package/artifacts/VendingMachine.json +10 -10
- package/artifacts/VendingMachineKeep.json +1 -1
- package/artifacts/VendingMachineNuCypher.json +1 -1
- package/artifacts/WalletRegistry.json +2 -2
- package/artifacts/WalletRegistryGovernance.json +2 -2
- package/artifacts/Wallets.json +9 -9
- package/artifacts/solcInputs/{799c7b289d9b6d9cfc600d2fc23c7b64.json → d1140ac40baa1ba6f0d558afe0fa6d54.json} +10 -10
- package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
- package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
- package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +1 -1
- package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +2 -2
- package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
- package/build/contracts/bridge/Bridge.sol/Bridge.json +296 -128
- package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +1 -1
- package/build/contracts/bridge/BridgeState.sol/BridgeState.json +17 -11
- package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +1 -1
- package/build/contracts/bridge/Deposit.sol/Deposit.json +2 -2
- package/build/contracts/bridge/DepositSweep.sol/DepositSweep.dbg.json +4 -0
- package/build/contracts/bridge/DepositSweep.sol/DepositSweep.json +30 -0
- package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +1 -1
- package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +1 -1
- package/build/contracts/bridge/Fraud.sol/Fraud.json +2 -2
- package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +1 -1
- package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +1 -1
- package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +21 -2
- package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +1 -1
- package/build/contracts/bridge/Redemption.sol/OutboundTx.json +2 -2
- package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +1 -1
- package/build/contracts/bridge/Redemption.sol/Redemption.json +2 -2
- package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
- package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +1 -1
- package/build/contracts/bridge/Wallets.sol/Wallets.json +2 -2
- package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
- package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
- package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
- package/contracts/bridge/BitcoinTx.sol +69 -0
- package/contracts/bridge/Bridge.sol +132 -49
- package/contracts/bridge/BridgeState.sol +77 -46
- package/contracts/bridge/{Sweep.sol → DepositSweep.sol} +30 -18
- package/contracts/bridge/MovingFunds.sol +480 -76
- package/contracts/bridge/Wallets.sol +2 -0
- package/deploy/05_deploy_bridge.ts +5 -2
- package/export.json +348 -81
- package/package.json +1 -1
- package/artifacts/Sweep.json +0 -76
- package/build/contracts/bridge/Sweep.sol/Sweep.dbg.json +0 -4
- package/build/contracts/bridge/Sweep.sol/Sweep.json +0 -30
|
@@ -22,7 +22,7 @@ import {IWalletOwner as EcdsaWalletOwner} from "@keep-network/ecdsa/contracts/ap
|
|
|
22
22
|
import "./IRelay.sol";
|
|
23
23
|
import "./BridgeState.sol";
|
|
24
24
|
import "./Deposit.sol";
|
|
25
|
-
import "./
|
|
25
|
+
import "./DepositSweep.sol";
|
|
26
26
|
import "./Redemption.sol";
|
|
27
27
|
import "./BitcoinTx.sol";
|
|
28
28
|
import "./EcdsaLib.sol";
|
|
@@ -60,7 +60,7 @@ import "../bank/Bank.sol";
|
|
|
60
60
|
contract Bridge is Governable, EcdsaWalletOwner {
|
|
61
61
|
using BridgeState for BridgeState.Storage;
|
|
62
62
|
using Deposit for BridgeState.Storage;
|
|
63
|
-
using
|
|
63
|
+
using DepositSweep for BridgeState.Storage;
|
|
64
64
|
using Redemption for BridgeState.Storage;
|
|
65
65
|
using MovingFunds for BridgeState.Storage;
|
|
66
66
|
using Wallets for BridgeState.Storage;
|
|
@@ -121,6 +121,8 @@ contract Bridge is Governable, EcdsaWalletOwner {
|
|
|
121
121
|
|
|
122
122
|
event MovingFundsBelowDustReported(bytes20 walletPubKeyHash);
|
|
123
123
|
|
|
124
|
+
event MovedFundsSwept(bytes20 walletPubKeyHash, bytes32 sweepTxHash);
|
|
125
|
+
|
|
124
126
|
event NewWalletRequested();
|
|
125
127
|
|
|
126
128
|
event NewWalletRegistered(
|
|
@@ -177,10 +179,11 @@ contract Bridge is Governable, EcdsaWalletOwner {
|
|
|
177
179
|
|
|
178
180
|
event MovingFundsParametersUpdated(
|
|
179
181
|
uint64 movingFundsTxMaxTotalFee,
|
|
182
|
+
uint64 movingFundsDustThreshold,
|
|
180
183
|
uint32 movingFundsTimeout,
|
|
181
184
|
uint96 movingFundsTimeoutSlashingAmount,
|
|
182
185
|
uint256 movingFundsTimeoutNotifierRewardMultiplier,
|
|
183
|
-
uint64
|
|
186
|
+
uint64 movedFundsSweepTxMaxTotalFee
|
|
184
187
|
);
|
|
185
188
|
|
|
186
189
|
event WalletParametersUpdated(
|
|
@@ -194,10 +197,10 @@ contract Bridge is Governable, EcdsaWalletOwner {
|
|
|
194
197
|
);
|
|
195
198
|
|
|
196
199
|
event FraudParametersUpdated(
|
|
197
|
-
|
|
198
|
-
uint256 fraudNotifierRewardMultiplier,
|
|
200
|
+
uint256 fraudChallengeDepositAmount,
|
|
199
201
|
uint256 fraudChallengeDefeatTimeout,
|
|
200
|
-
|
|
202
|
+
uint96 fraudSlashingAmount,
|
|
203
|
+
uint256 fraudNotifierRewardMultiplier
|
|
201
204
|
);
|
|
202
205
|
|
|
203
206
|
constructor(
|
|
@@ -235,14 +238,15 @@ contract Bridge is Governable, EcdsaWalletOwner {
|
|
|
235
238
|
self.redemptionTimeoutSlashingAmount = 10000 * 1e18; // 10000 T
|
|
236
239
|
self.redemptionTimeoutNotifierRewardMultiplier = 100; // 100%
|
|
237
240
|
self.movingFundsTxMaxTotalFee = 10000; // 10000 satoshi
|
|
241
|
+
self.movingFundsDustThreshold = 20000; // 20000 satoshi
|
|
238
242
|
self.movingFundsTimeout = 7 days;
|
|
239
243
|
self.movingFundsTimeoutSlashingAmount = 10000 * 1e18; // 10000 T
|
|
240
244
|
self.movingFundsTimeoutNotifierRewardMultiplier = 100; //100%
|
|
241
|
-
self.
|
|
245
|
+
self.movedFundsSweepTxMaxTotalFee = 10000; // 10000 satoshi
|
|
246
|
+
self.fraudChallengeDepositAmount = 2 ether;
|
|
247
|
+
self.fraudChallengeDefeatTimeout = 7 days;
|
|
242
248
|
self.fraudSlashingAmount = 10000 * 1e18; // 10000 T
|
|
243
249
|
self.fraudNotifierRewardMultiplier = 100; // 100%
|
|
244
|
-
self.fraudChallengeDefeatTimeout = 7 days;
|
|
245
|
-
self.fraudChallengeDepositAmount = 2 ether;
|
|
246
250
|
self.walletCreationPeriod = 1 weeks;
|
|
247
251
|
self.walletCreationMinBtcBalance = 1e8; // 1 BTC
|
|
248
252
|
self.walletCreationMaxBtcBalance = 100e8; // 100 BTC
|
|
@@ -331,12 +335,12 @@ contract Bridge is Governable, EcdsaWalletOwner {
|
|
|
331
335
|
/// - `mainUtxo` components must point to the recent main UTXO
|
|
332
336
|
/// of the given wallet, as currently known on the Ethereum chain.
|
|
333
337
|
/// If there is no main UTXO, this parameter is ignored.
|
|
334
|
-
function
|
|
338
|
+
function submitDepositSweepProof(
|
|
335
339
|
BitcoinTx.Info calldata sweepTx,
|
|
336
340
|
BitcoinTx.Proof calldata sweepProof,
|
|
337
341
|
BitcoinTx.UTXO calldata mainUtxo
|
|
338
342
|
) external {
|
|
339
|
-
self.
|
|
343
|
+
self.submitDepositSweepProof(sweepTx, sweepProof, mainUtxo);
|
|
340
344
|
}
|
|
341
345
|
|
|
342
346
|
/// @notice Requests redemption of the given amount from the specified
|
|
@@ -503,6 +507,7 @@ contract Bridge is Governable, EcdsaWalletOwner {
|
|
|
503
507
|
/// @dev Requirements:
|
|
504
508
|
/// - The source wallet must be in the MovingFunds state
|
|
505
509
|
/// - The source wallet must not have pending redemption requests
|
|
510
|
+
/// - The source wallet must not have pending moved funds sweep requests
|
|
506
511
|
/// - The source wallet must not have submitted its commitment already
|
|
507
512
|
/// - The expression `keccak256(abi.encode(walletMembersIDs))` must
|
|
508
513
|
/// be exactly the same as the hash stored under `membersIdsHash`
|
|
@@ -641,6 +646,53 @@ contract Bridge is Governable, EcdsaWalletOwner {
|
|
|
641
646
|
self.notifyMovingFundsBelowDust(walletPubKeyHash, mainUtxo);
|
|
642
647
|
}
|
|
643
648
|
|
|
649
|
+
/// @notice Used by the wallet to prove the BTC moved funds sweep
|
|
650
|
+
/// transaction and to make the necessary state changes. Moved
|
|
651
|
+
/// funds sweep is only accepted if it satisfies SPV proof.
|
|
652
|
+
///
|
|
653
|
+
/// The function validates the sweep transaction structure by
|
|
654
|
+
/// checking if it actually spends the moved funds UTXO and the
|
|
655
|
+
/// sweeping wallet's main UTXO (optionally), and if it locks the
|
|
656
|
+
/// value on the sweeping wallet's 20-byte public key hash using a
|
|
657
|
+
/// reasonable transaction fee. If all preconditions are
|
|
658
|
+
/// met, this function updates the sweeping wallet main UTXO, thus
|
|
659
|
+
/// their BTC balance.
|
|
660
|
+
///
|
|
661
|
+
/// It is possible to prove the given sweep transaction only
|
|
662
|
+
/// one time.
|
|
663
|
+
/// @param sweepTx Bitcoin sweep funds transaction data
|
|
664
|
+
/// @param sweepProof Bitcoin sweep funds proof data
|
|
665
|
+
/// @param mainUtxo Data of the sweeping wallet's main UTXO, as currently
|
|
666
|
+
/// known on the Ethereum chain
|
|
667
|
+
/// @dev Requirements:
|
|
668
|
+
/// - `sweepTx` components must match the expected structure. See
|
|
669
|
+
/// `BitcoinTx.Info` docs for reference. Their values must exactly
|
|
670
|
+
/// correspond to appropriate Bitcoin transaction fields to produce
|
|
671
|
+
/// a provable transaction hash.
|
|
672
|
+
/// - The `sweepTx` should represent a Bitcoin transaction with
|
|
673
|
+
/// the first input pointing to a moved funds sweep request targeted
|
|
674
|
+
/// to the wallet, and optionally, the second input pointing to the
|
|
675
|
+
/// wallet's main UTXO, if the sweeping wallet has a main UTXO set.
|
|
676
|
+
/// There should be only one output locking funds on the sweeping
|
|
677
|
+
/// wallet 20-byte public key hash.
|
|
678
|
+
/// - `sweepProof` components must match the expected structure.
|
|
679
|
+
/// See `BitcoinTx.Proof` docs for reference. The `bitcoinHeaders`
|
|
680
|
+
/// field must contain a valid number of block headers, not less
|
|
681
|
+
/// than the `txProofDifficultyFactor` contract constant.
|
|
682
|
+
/// - `mainUtxo` components must point to the recent main UTXO
|
|
683
|
+
/// of the sweeping wallet, as currently known on the Ethereum chain.
|
|
684
|
+
/// If there is no main UTXO, this parameter is ignored.
|
|
685
|
+
/// - The sweeping wallet must be in the Live or MovingFunds state.
|
|
686
|
+
/// - The total Bitcoin transaction fee must be lesser or equal
|
|
687
|
+
/// to `movedFundsSweepTxMaxTotalFee` governable parameter.
|
|
688
|
+
function submitMovedFundsSweepProof(
|
|
689
|
+
BitcoinTx.Info calldata sweepTx,
|
|
690
|
+
BitcoinTx.Proof calldata sweepProof,
|
|
691
|
+
BitcoinTx.UTXO calldata mainUtxo
|
|
692
|
+
) external {
|
|
693
|
+
self.submitMovedFundsSweepProof(sweepTx, sweepProof, mainUtxo);
|
|
694
|
+
}
|
|
695
|
+
|
|
644
696
|
/// @notice Requests creation of a new wallet. This function just
|
|
645
697
|
/// forms a request and the creation process is performed
|
|
646
698
|
/// asynchronously. Once a wallet is created, the ECDSA Wallet
|
|
@@ -979,6 +1031,12 @@ contract Bridge is Governable, EcdsaWalletOwner {
|
|
|
979
1031
|
/// BTC transaction fee that is acceptable in a single moving funds
|
|
980
1032
|
/// transaction. This is a _total_ max fee for the entire moving
|
|
981
1033
|
/// funds transaction.
|
|
1034
|
+
/// @param movingFundsDustThreshold New value of the moving funds dust
|
|
1035
|
+
/// threshold. It is the minimal satoshi amount that makes sense to
|
|
1036
|
+
// be transferred during the moving funds process. Moving funds
|
|
1037
|
+
// wallets having their BTC balance below that value can begin
|
|
1038
|
+
// closing immediately as transferring such a low value may not be
|
|
1039
|
+
// possible due to BTC network fees.
|
|
982
1040
|
/// @param movingFundsTimeout New value of the moving funds timeout in
|
|
983
1041
|
/// seconds. It is the time after which the moving funds process can
|
|
984
1042
|
/// be reported as timed out. It is counted from the moment when the
|
|
@@ -992,31 +1050,33 @@ contract Bridge is Governable, EcdsaWalletOwner {
|
|
|
992
1050
|
/// it determines the percentage of the notifier reward from the
|
|
993
1051
|
/// staking contact the notifier of a moving funds timeout receives.
|
|
994
1052
|
/// The value must be in the range [0, 100]
|
|
995
|
-
/// @param
|
|
996
|
-
///
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
// possible due to BTC network fees.
|
|
1053
|
+
/// @param movedFundsSweepTxMaxTotalFee New value of the moved funds sweep
|
|
1054
|
+
/// transaction max total fee in satoshis. It is the maximum amount
|
|
1055
|
+
/// of the total BTC transaction fee that is acceptable in a single
|
|
1056
|
+
/// moved funds sweep transaction. This is a _total_ max fee for the
|
|
1057
|
+
/// entire moved funds sweep transaction.
|
|
1001
1058
|
/// @dev Requirements:
|
|
1002
1059
|
/// - Moving funds transaction max total fee must be greater than zero
|
|
1060
|
+
/// - Moving funds dust threshold must be greater than zero
|
|
1003
1061
|
/// - Moving funds timeout must be greater than zero
|
|
1004
1062
|
/// - Moving funds timeout notifier reward multiplier must be in the
|
|
1005
1063
|
/// range [0, 100]
|
|
1006
|
-
/// -
|
|
1064
|
+
/// - Moved funds sweep transaction max total fee must be greater than zero
|
|
1007
1065
|
function updateMovingFundsParameters(
|
|
1008
1066
|
uint64 movingFundsTxMaxTotalFee,
|
|
1067
|
+
uint64 movingFundsDustThreshold,
|
|
1009
1068
|
uint32 movingFundsTimeout,
|
|
1010
1069
|
uint96 movingFundsTimeoutSlashingAmount,
|
|
1011
1070
|
uint256 movingFundsTimeoutNotifierRewardMultiplier,
|
|
1012
|
-
uint64
|
|
1071
|
+
uint64 movedFundsSweepTxMaxTotalFee
|
|
1013
1072
|
) external onlyGovernance {
|
|
1014
1073
|
self.updateMovingFundsParameters(
|
|
1015
1074
|
movingFundsTxMaxTotalFee,
|
|
1075
|
+
movingFundsDustThreshold,
|
|
1016
1076
|
movingFundsTimeout,
|
|
1017
1077
|
movingFundsTimeoutSlashingAmount,
|
|
1018
1078
|
movingFundsTimeoutNotifierRewardMultiplier,
|
|
1019
|
-
|
|
1079
|
+
movedFundsSweepTxMaxTotalFee
|
|
1020
1080
|
);
|
|
1021
1081
|
}
|
|
1022
1082
|
|
|
@@ -1067,6 +1127,12 @@ contract Bridge is Governable, EcdsaWalletOwner {
|
|
|
1067
1127
|
}
|
|
1068
1128
|
|
|
1069
1129
|
/// @notice Updates parameters related to frauds.
|
|
1130
|
+
/// @param fraudChallengeDepositAmount New value of the fraud challenge
|
|
1131
|
+
/// deposit amount in wei, it is the amount of ETH the party
|
|
1132
|
+
/// challenging the wallet for fraud needs to deposit
|
|
1133
|
+
/// @param fraudChallengeDefeatTimeout New value of the challenge defeat
|
|
1134
|
+
/// timeout in seconds, it is the amount of time the wallet has to
|
|
1135
|
+
/// defeat a fraud challenge. The value must be greater than zero
|
|
1070
1136
|
/// @param fraudSlashingAmount New value of the fraud slashing amount in T,
|
|
1071
1137
|
/// it is the amount slashed from each wallet member for committing
|
|
1072
1138
|
/// a fraud
|
|
@@ -1074,26 +1140,20 @@ contract Bridge is Governable, EcdsaWalletOwner {
|
|
|
1074
1140
|
/// reward multiplier as percentage, it determines the percentage of
|
|
1075
1141
|
/// the notifier reward from the staking contact the notifier of
|
|
1076
1142
|
/// a fraud receives. The value must be in the range [0, 100]
|
|
1077
|
-
/// @param fraudChallengeDefeatTimeout New value of the challenge defeat
|
|
1078
|
-
/// timeout in seconds, it is the amount of time the wallet has to
|
|
1079
|
-
/// defeat a fraud challenge. The value must be greater than zero
|
|
1080
|
-
/// @param fraudChallengeDepositAmount New value of the fraud challenge
|
|
1081
|
-
/// deposit amount in wei, it is the amount of ETH the party
|
|
1082
|
-
/// challenging the wallet for fraud needs to deposit
|
|
1083
1143
|
/// @dev Requirements:
|
|
1084
|
-
/// - Fraud notifier reward multiplier must be in the range [0, 100]
|
|
1085
1144
|
/// - Fraud challenge defeat timeout must be greater than 0
|
|
1145
|
+
/// - Fraud notifier reward multiplier must be in the range [0, 100]
|
|
1086
1146
|
function updateFraudParameters(
|
|
1087
|
-
|
|
1088
|
-
uint256 fraudNotifierRewardMultiplier,
|
|
1147
|
+
uint256 fraudChallengeDepositAmount,
|
|
1089
1148
|
uint256 fraudChallengeDefeatTimeout,
|
|
1090
|
-
|
|
1149
|
+
uint96 fraudSlashingAmount,
|
|
1150
|
+
uint256 fraudNotifierRewardMultiplier
|
|
1091
1151
|
) external onlyGovernance {
|
|
1092
1152
|
self.updateFraudParameters(
|
|
1093
|
-
|
|
1094
|
-
fraudNotifierRewardMultiplier,
|
|
1153
|
+
fraudChallengeDepositAmount,
|
|
1095
1154
|
fraudChallengeDefeatTimeout,
|
|
1096
|
-
|
|
1155
|
+
fraudSlashingAmount,
|
|
1156
|
+
fraudNotifierRewardMultiplier
|
|
1097
1157
|
);
|
|
1098
1158
|
}
|
|
1099
1159
|
|
|
@@ -1200,6 +1260,23 @@ contract Bridge is Governable, EcdsaWalletOwner {
|
|
|
1200
1260
|
return self.fraudChallenges[challengeKey];
|
|
1201
1261
|
}
|
|
1202
1262
|
|
|
1263
|
+
/// @notice Collection of all moved funds sweep requests indexed by
|
|
1264
|
+
/// `keccak256(movingFundsTxHash | movingFundsOutputIndex)`.
|
|
1265
|
+
/// The `movingFundsTxHash` is `bytes32` (ordered as in Bitcoin
|
|
1266
|
+
/// internally) and `movingFundsOutputIndex` an `uint32`. Each entry
|
|
1267
|
+
/// is actually an UTXO representing the moved funds and is supposed
|
|
1268
|
+
/// to be swept with the current main UTXO of the recipient wallet.
|
|
1269
|
+
/// @param requestKey Request key built as
|
|
1270
|
+
/// `keccak256(movingFundsTxHash | movingFundsOutputIndex)`
|
|
1271
|
+
/// @return Details of the moved funds sweep request.
|
|
1272
|
+
function movedFundsSweepRequests(uint256 requestKey)
|
|
1273
|
+
external
|
|
1274
|
+
view
|
|
1275
|
+
returns (MovingFunds.MovedFundsSweepRequest memory)
|
|
1276
|
+
{
|
|
1277
|
+
return self.movedFundsSweepRequests[requestKey];
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1203
1280
|
/// @notice Indicates if the vault with the given address is trusted or not.
|
|
1204
1281
|
/// Depositors can route their revealed deposits only to trusted
|
|
1205
1282
|
/// vaults and have trusted vaults notified about new deposits as
|
|
@@ -1299,6 +1376,11 @@ contract Bridge is Governable, EcdsaWalletOwner {
|
|
|
1299
1376
|
/// transaction fee that is acceptable in a single moving funds
|
|
1300
1377
|
/// transaction. This is a _total_ max fee for the entire moving
|
|
1301
1378
|
/// funds transaction.
|
|
1379
|
+
/// @return movingFundsDustThreshold The minimal satoshi amount that makes
|
|
1380
|
+
/// sense to be transferred during the moving funds process. Moving
|
|
1381
|
+
/// funds wallets having their BTC balance below that value can
|
|
1382
|
+
/// begin closing immediately as transferring such a low value may
|
|
1383
|
+
/// not be possible due to BTC network fees.
|
|
1302
1384
|
/// @return movingFundsTimeout Time after which the moving funds process
|
|
1303
1385
|
/// can be reported as timed out. It is counted from the moment
|
|
1304
1386
|
/// when the wallet was requested to move their funds and switched
|
|
@@ -1308,29 +1390,30 @@ contract Bridge is Governable, EcdsaWalletOwner {
|
|
|
1308
1390
|
/// @return movingFundsTimeoutNotifierRewardMultiplier The percentage of the
|
|
1309
1391
|
/// notifier reward from the staking contract the notifier of a
|
|
1310
1392
|
/// moving funds timeout receives. The value is in the range [0, 100].
|
|
1311
|
-
/// @return
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
// not be possible due to BTC network fees.
|
|
1393
|
+
/// @return movedFundsSweepTxMaxTotalFee Maximum amount of the total BTC
|
|
1394
|
+
/// transaction fee that is acceptable in a single moved funds
|
|
1395
|
+
/// sweep transaction. This is a _total_ max fee for the entire
|
|
1396
|
+
/// moved funds sweep transaction.
|
|
1316
1397
|
function movingFundsParameters()
|
|
1317
1398
|
external
|
|
1318
1399
|
view
|
|
1319
1400
|
returns (
|
|
1320
1401
|
uint64 movingFundsTxMaxTotalFee,
|
|
1402
|
+
uint64 movingFundsDustThreshold,
|
|
1321
1403
|
uint32 movingFundsTimeout,
|
|
1322
1404
|
uint96 movingFundsTimeoutSlashingAmount,
|
|
1323
1405
|
uint256 movingFundsTimeoutNotifierRewardMultiplier,
|
|
1324
|
-
uint64
|
|
1406
|
+
uint64 movedFundsSweepTxMaxTotalFee
|
|
1325
1407
|
)
|
|
1326
1408
|
{
|
|
1327
1409
|
movingFundsTxMaxTotalFee = self.movingFundsTxMaxTotalFee;
|
|
1410
|
+
movingFundsDustThreshold = self.movingFundsDustThreshold;
|
|
1328
1411
|
movingFundsTimeout = self.movingFundsTimeout;
|
|
1329
1412
|
movingFundsTimeoutSlashingAmount = self
|
|
1330
1413
|
.movingFundsTimeoutSlashingAmount;
|
|
1331
1414
|
movingFundsTimeoutNotifierRewardMultiplier = self
|
|
1332
1415
|
.movingFundsTimeoutNotifierRewardMultiplier;
|
|
1333
|
-
|
|
1416
|
+
movedFundsSweepTxMaxTotalFee = self.movedFundsSweepTxMaxTotalFee;
|
|
1334
1417
|
}
|
|
1335
1418
|
|
|
1336
1419
|
/// @return walletCreationPeriod Determines how frequently a new wallet
|
|
@@ -1373,29 +1456,29 @@ contract Bridge is Governable, EcdsaWalletOwner {
|
|
|
1373
1456
|
}
|
|
1374
1457
|
|
|
1375
1458
|
/// @notice Returns the current values of Bridge fraud parameters.
|
|
1459
|
+
/// @return fraudChallengeDepositAmount The amount of ETH in wei the party
|
|
1460
|
+
/// challenging the wallet for fraud needs to deposit.
|
|
1461
|
+
/// @return fraudChallengeDefeatTimeout The amount of time the wallet has to
|
|
1462
|
+
/// defeat a fraud challenge.
|
|
1376
1463
|
/// @return fraudSlashingAmount The amount slashed from each wallet member
|
|
1377
1464
|
/// for committing a fraud.
|
|
1378
1465
|
/// @return fraudNotifierRewardMultiplier The percentage of the notifier
|
|
1379
1466
|
/// reward from the staking contract the notifier of a fraud
|
|
1380
1467
|
/// receives. The value is in the range [0, 100].
|
|
1381
|
-
/// @return fraudChallengeDefeatTimeout The amount of time the wallet has to
|
|
1382
|
-
/// defeat a fraud challenge.
|
|
1383
|
-
/// @return fraudChallengeDepositAmount The amount of ETH in wei the party
|
|
1384
|
-
/// challenging the wallet for fraud needs to deposit.
|
|
1385
1468
|
function fraudParameters()
|
|
1386
1469
|
external
|
|
1387
1470
|
view
|
|
1388
1471
|
returns (
|
|
1389
|
-
|
|
1390
|
-
uint256 fraudNotifierRewardMultiplier,
|
|
1472
|
+
uint256 fraudChallengeDepositAmount,
|
|
1391
1473
|
uint256 fraudChallengeDefeatTimeout,
|
|
1392
|
-
|
|
1474
|
+
uint96 fraudSlashingAmount,
|
|
1475
|
+
uint256 fraudNotifierRewardMultiplier
|
|
1393
1476
|
)
|
|
1394
1477
|
{
|
|
1478
|
+
fraudChallengeDepositAmount = self.fraudChallengeDepositAmount;
|
|
1479
|
+
fraudChallengeDefeatTimeout = self.fraudChallengeDefeatTimeout;
|
|
1395
1480
|
fraudSlashingAmount = self.fraudSlashingAmount;
|
|
1396
1481
|
fraudNotifierRewardMultiplier = self.fraudNotifierRewardMultiplier;
|
|
1397
|
-
fraudChallengeDefeatTimeout = self.fraudChallengeDefeatTimeout;
|
|
1398
|
-
fraudChallengeDepositAmount = self.fraudChallengeDepositAmount;
|
|
1399
1482
|
}
|
|
1400
1483
|
|
|
1401
1484
|
/// @notice Returns the addresses of contracts Bridge is interacting with.
|
|
@@ -22,6 +22,7 @@ import "./Deposit.sol";
|
|
|
22
22
|
import "./Redemption.sol";
|
|
23
23
|
import "./Fraud.sol";
|
|
24
24
|
import "./Wallets.sol";
|
|
25
|
+
import "./MovingFunds.sol";
|
|
25
26
|
|
|
26
27
|
import "../bank/Bank.sol";
|
|
27
28
|
|
|
@@ -83,6 +84,12 @@ library BridgeState {
|
|
|
83
84
|
// if per single redemption. `movingFundsTxMaxTotalFee` is a total
|
|
84
85
|
// fee for the entire transaction.
|
|
85
86
|
uint64 movingFundsTxMaxTotalFee;
|
|
87
|
+
// The minimal satoshi amount that makes sense to be transferred during
|
|
88
|
+
// the moving funds process. Moving funds wallets having their BTC
|
|
89
|
+
// balance below that value can begin closing immediately as
|
|
90
|
+
// transferring such a low value may not be possible due to
|
|
91
|
+
// BTC network fees.
|
|
92
|
+
uint64 movingFundsDustThreshold;
|
|
86
93
|
// Time after which the moving funds process can be reported as
|
|
87
94
|
// timed out. It is counted from the moment when the wallet
|
|
88
95
|
// was requested to move their funds and switched to the MovingFunds
|
|
@@ -95,12 +102,21 @@ library BridgeState {
|
|
|
95
102
|
// the notifier of a moving funds timeout receives. The value is in the
|
|
96
103
|
// range [0, 100].
|
|
97
104
|
uint256 movingFundsTimeoutNotifierRewardMultiplier;
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
//
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
|
|
105
|
+
// Maximum amount of the total BTC transaction fee that is acceptable in
|
|
106
|
+
// a single moved funds sweep transaction.
|
|
107
|
+
//
|
|
108
|
+
// This is a TOTAL max fee for the moved funds sweep transaction. Note
|
|
109
|
+
// that `depositTxMaxFee` is per single deposit and `redemptionTxMaxFee`
|
|
110
|
+
// if per single redemption. `movedFundsSweepTxMaxTotalFee` is a total
|
|
111
|
+
// fee for the entire transaction.
|
|
112
|
+
uint64 movedFundsSweepTxMaxTotalFee;
|
|
113
|
+
// Collection of all moved funds sweep requests indexed by
|
|
114
|
+
// `keccak256(movingFundsTxHash | movingFundsOutputIndex)`.
|
|
115
|
+
// The `movingFundsTxHash` is `bytes32` (ordered as in Bitcoin
|
|
116
|
+
// internally) and `movingFundsOutputIndex` an `uint32`. Each entry
|
|
117
|
+
// is actually an UTXO representing the moved funds and is supposed
|
|
118
|
+
// to be swept with the current main UTXO of the recipient wallet.
|
|
119
|
+
mapping(uint256 => MovingFunds.MovedFundsSweepRequest) movedFundsSweepRequests;
|
|
104
120
|
// The minimal amount that can be requested for redemption.
|
|
105
121
|
// Value of this parameter must take into account the value of
|
|
106
122
|
// `redemptionTreasuryFeeDivisor` and `redemptionTxMaxFee`
|
|
@@ -165,16 +181,16 @@ library BridgeState {
|
|
|
165
181
|
// mapping basing on a timed out request stored previously in
|
|
166
182
|
// `pendingRedemptions` mapping.
|
|
167
183
|
mapping(uint256 => Redemption.RedemptionRequest) timedOutRedemptions;
|
|
184
|
+
// The amount of ETH in wei the party challenging the wallet for fraud
|
|
185
|
+
// needs to deposit.
|
|
186
|
+
uint256 fraudChallengeDepositAmount;
|
|
187
|
+
// The amount of time the wallet has to defeat a fraud challenge.
|
|
188
|
+
uint256 fraudChallengeDefeatTimeout;
|
|
168
189
|
// The amount of stake slashed from each member of a wallet for a fraud.
|
|
169
190
|
uint96 fraudSlashingAmount;
|
|
170
191
|
// The percentage of the notifier reward from the staking contract
|
|
171
192
|
// the notifier of a fraud receives. The value is in the range [0, 100].
|
|
172
193
|
uint256 fraudNotifierRewardMultiplier;
|
|
173
|
-
// The amount of time the wallet has to defeat a fraud challenge.
|
|
174
|
-
uint256 fraudChallengeDefeatTimeout;
|
|
175
|
-
// The amount of ETH in wei the party challenging the wallet for fraud
|
|
176
|
-
// needs to deposit.
|
|
177
|
-
uint256 fraudChallengeDepositAmount;
|
|
178
194
|
// Collection of all submitted fraud challenges indexed by challenge
|
|
179
195
|
// key built as `keccak256(walletPublicKey|sighash)`.
|
|
180
196
|
mapping(uint256 => Fraud.FraudChallenge) fraudChallenges;
|
|
@@ -243,10 +259,11 @@ library BridgeState {
|
|
|
243
259
|
|
|
244
260
|
event MovingFundsParametersUpdated(
|
|
245
261
|
uint64 movingFundsTxMaxTotalFee,
|
|
262
|
+
uint64 movingFundsDustThreshold,
|
|
246
263
|
uint32 movingFundsTimeout,
|
|
247
264
|
uint96 movingFundsTimeoutSlashingAmount,
|
|
248
265
|
uint256 movingFundsTimeoutNotifierRewardMultiplier,
|
|
249
|
-
uint64
|
|
266
|
+
uint64 movedFundsSweepTxMaxTotalFee
|
|
250
267
|
);
|
|
251
268
|
|
|
252
269
|
event WalletParametersUpdated(
|
|
@@ -260,10 +277,10 @@ library BridgeState {
|
|
|
260
277
|
);
|
|
261
278
|
|
|
262
279
|
event FraudParametersUpdated(
|
|
263
|
-
|
|
264
|
-
uint256 fraudNotifierRewardMultiplier,
|
|
280
|
+
uint256 fraudChallengeDepositAmount,
|
|
265
281
|
uint256 fraudChallengeDefeatTimeout,
|
|
266
|
-
|
|
282
|
+
uint96 fraudSlashingAmount,
|
|
283
|
+
uint256 fraudNotifierRewardMultiplier
|
|
267
284
|
);
|
|
268
285
|
|
|
269
286
|
/// @notice Updates parameters of deposits.
|
|
@@ -425,6 +442,12 @@ library BridgeState {
|
|
|
425
442
|
/// BTC transaction fee that is acceptable in a single moving funds
|
|
426
443
|
/// transaction. This is a _total_ max fee for the entire moving
|
|
427
444
|
/// funds transaction.
|
|
445
|
+
/// @param _movingFundsDustThreshold New value of the moving funds dust
|
|
446
|
+
/// threshold. It is the minimal satoshi amount that makes sense to
|
|
447
|
+
// be transferred during the moving funds process. Moving funds
|
|
448
|
+
// wallets having their BTC balance below that value can begin
|
|
449
|
+
// closing immediately as transferring such a low value may not be
|
|
450
|
+
// possible due to BTC network fees.
|
|
428
451
|
/// @param _movingFundsTimeout New value of the moving funds timeout in
|
|
429
452
|
/// seconds. It is the time after which the moving funds process can
|
|
430
453
|
/// be reported as timed out. It is counted from the moment when the
|
|
@@ -438,31 +461,37 @@ library BridgeState {
|
|
|
438
461
|
/// it determines the percentage of the notifier reward from the
|
|
439
462
|
/// staking contact the notifier of a moving funds timeout receives.
|
|
440
463
|
/// The value must be in the range [0, 100]
|
|
441
|
-
/// @param
|
|
442
|
-
///
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
// possible due to BTC network fees.
|
|
464
|
+
/// @param _movedFundsSweepTxMaxTotalFee New value of the moved funds sweep
|
|
465
|
+
/// transaction max total fee in satoshis. It is the maximum amount
|
|
466
|
+
/// of the total BTC transaction fee that is acceptable in a single
|
|
467
|
+
/// moved funds sweep transaction. This is a _total_ max fee for the
|
|
468
|
+
/// entire moved funds sweep transaction.
|
|
447
469
|
/// @dev Requirements:
|
|
448
470
|
/// - Moving funds transaction max total fee must be greater than zero
|
|
471
|
+
/// - Moving funds dust threshold must be greater than zero
|
|
449
472
|
/// - Moving funds timeout must be greater than zero
|
|
450
473
|
/// - Moving funds timeout notifier reward multiplier must be in the
|
|
451
474
|
/// range [0, 100]
|
|
452
|
-
/// -
|
|
475
|
+
/// - Moved funds sweep transaction max total fee must be greater than zero
|
|
453
476
|
function updateMovingFundsParameters(
|
|
454
477
|
Storage storage self,
|
|
455
478
|
uint64 _movingFundsTxMaxTotalFee,
|
|
479
|
+
uint64 _movingFundsDustThreshold,
|
|
456
480
|
uint32 _movingFundsTimeout,
|
|
457
481
|
uint96 _movingFundsTimeoutSlashingAmount,
|
|
458
482
|
uint256 _movingFundsTimeoutNotifierRewardMultiplier,
|
|
459
|
-
uint64
|
|
483
|
+
uint64 _movedFundsSweepTxMaxTotalFee
|
|
460
484
|
) internal {
|
|
461
485
|
require(
|
|
462
486
|
_movingFundsTxMaxTotalFee > 0,
|
|
463
487
|
"Moving funds transaction max total fee must be greater than zero"
|
|
464
488
|
);
|
|
465
489
|
|
|
490
|
+
require(
|
|
491
|
+
_movingFundsDustThreshold > 0,
|
|
492
|
+
"Moving funds dust threshold must be greater than zero"
|
|
493
|
+
);
|
|
494
|
+
|
|
466
495
|
require(
|
|
467
496
|
_movingFundsTimeout > 0,
|
|
468
497
|
"Moving funds timeout must be greater than zero"
|
|
@@ -474,24 +503,26 @@ library BridgeState {
|
|
|
474
503
|
);
|
|
475
504
|
|
|
476
505
|
require(
|
|
477
|
-
|
|
478
|
-
"
|
|
506
|
+
_movedFundsSweepTxMaxTotalFee > 0,
|
|
507
|
+
"Moved funds sweep transaction max total fee must be greater than zero"
|
|
479
508
|
);
|
|
480
509
|
|
|
481
510
|
self.movingFundsTxMaxTotalFee = _movingFundsTxMaxTotalFee;
|
|
511
|
+
self.movingFundsDustThreshold = _movingFundsDustThreshold;
|
|
482
512
|
self.movingFundsTimeout = _movingFundsTimeout;
|
|
483
513
|
self
|
|
484
514
|
.movingFundsTimeoutSlashingAmount = _movingFundsTimeoutSlashingAmount;
|
|
485
515
|
self
|
|
486
516
|
.movingFundsTimeoutNotifierRewardMultiplier = _movingFundsTimeoutNotifierRewardMultiplier;
|
|
487
|
-
self.
|
|
517
|
+
self.movedFundsSweepTxMaxTotalFee = _movedFundsSweepTxMaxTotalFee;
|
|
488
518
|
|
|
489
519
|
emit MovingFundsParametersUpdated(
|
|
490
520
|
_movingFundsTxMaxTotalFee,
|
|
521
|
+
_movingFundsDustThreshold,
|
|
491
522
|
_movingFundsTimeout,
|
|
492
523
|
_movingFundsTimeoutSlashingAmount,
|
|
493
524
|
_movingFundsTimeoutNotifierRewardMultiplier,
|
|
494
|
-
|
|
525
|
+
_movedFundsSweepTxMaxTotalFee
|
|
495
526
|
);
|
|
496
527
|
}
|
|
497
528
|
|
|
@@ -568,6 +599,12 @@ library BridgeState {
|
|
|
568
599
|
}
|
|
569
600
|
|
|
570
601
|
/// @notice Updates parameters related to frauds.
|
|
602
|
+
/// @param _fraudChallengeDepositAmount New value of the fraud challenge
|
|
603
|
+
/// deposit amount in wei, it is the amount of ETH the party
|
|
604
|
+
/// challenging the wallet for fraud needs to deposit
|
|
605
|
+
/// @param _fraudChallengeDefeatTimeout New value of the challenge defeat
|
|
606
|
+
/// timeout in seconds, it is the amount of time the wallet has to
|
|
607
|
+
/// defeat a fraud challenge. The value must be greater than zero
|
|
571
608
|
/// @param _fraudSlashingAmount New value of the fraud slashing amount in T,
|
|
572
609
|
/// it is the amount slashed from each wallet member for committing
|
|
573
610
|
/// a fraud
|
|
@@ -575,42 +612,36 @@ library BridgeState {
|
|
|
575
612
|
/// reward multiplier as percentage, it determines the percentage of
|
|
576
613
|
/// the notifier reward from the staking contact the notifier of
|
|
577
614
|
/// a fraud receives. The value must be in the range [0, 100]
|
|
578
|
-
/// @param _fraudChallengeDefeatTimeout New value of the challenge defeat
|
|
579
|
-
/// timeout in seconds, it is the amount of time the wallet has to
|
|
580
|
-
/// defeat a fraud challenge. The value must be greater than zero
|
|
581
|
-
/// @param _fraudChallengeDepositAmount New value of the fraud challenge
|
|
582
|
-
/// deposit amount in wei, it is the amount of ETH the party
|
|
583
|
-
/// challenging the wallet for fraud needs to deposit
|
|
584
615
|
/// @dev Requirements:
|
|
585
|
-
/// - Fraud notifier reward multiplier must be in the range [0, 100]
|
|
586
616
|
/// - Fraud challenge defeat timeout must be greater than 0
|
|
617
|
+
/// - Fraud notifier reward multiplier must be in the range [0, 100]
|
|
587
618
|
function updateFraudParameters(
|
|
588
619
|
Storage storage self,
|
|
589
|
-
|
|
590
|
-
uint256 _fraudNotifierRewardMultiplier,
|
|
620
|
+
uint256 _fraudChallengeDepositAmount,
|
|
591
621
|
uint256 _fraudChallengeDefeatTimeout,
|
|
592
|
-
|
|
622
|
+
uint96 _fraudSlashingAmount,
|
|
623
|
+
uint256 _fraudNotifierRewardMultiplier
|
|
593
624
|
) internal {
|
|
594
625
|
require(
|
|
595
|
-
|
|
596
|
-
"Fraud
|
|
626
|
+
_fraudChallengeDefeatTimeout > 0,
|
|
627
|
+
"Fraud challenge defeat timeout must be greater than zero"
|
|
597
628
|
);
|
|
598
629
|
|
|
599
630
|
require(
|
|
600
|
-
|
|
601
|
-
"Fraud
|
|
631
|
+
_fraudNotifierRewardMultiplier <= 100,
|
|
632
|
+
"Fraud notifier reward multiplier must be in the range [0, 100]"
|
|
602
633
|
);
|
|
603
634
|
|
|
635
|
+
self.fraudChallengeDepositAmount = _fraudChallengeDepositAmount;
|
|
636
|
+
self.fraudChallengeDefeatTimeout = _fraudChallengeDefeatTimeout;
|
|
604
637
|
self.fraudSlashingAmount = _fraudSlashingAmount;
|
|
605
638
|
self.fraudNotifierRewardMultiplier = _fraudNotifierRewardMultiplier;
|
|
606
|
-
self.fraudChallengeDefeatTimeout = _fraudChallengeDefeatTimeout;
|
|
607
|
-
self.fraudChallengeDepositAmount = _fraudChallengeDepositAmount;
|
|
608
639
|
|
|
609
640
|
emit FraudParametersUpdated(
|
|
610
|
-
|
|
611
|
-
_fraudNotifierRewardMultiplier,
|
|
641
|
+
_fraudChallengeDepositAmount,
|
|
612
642
|
_fraudChallengeDefeatTimeout,
|
|
613
|
-
|
|
643
|
+
_fraudSlashingAmount,
|
|
644
|
+
_fraudNotifierRewardMultiplier
|
|
614
645
|
);
|
|
615
646
|
}
|
|
616
647
|
}
|