@keep-network/tbtc-v2 0.1.1-dev.43 → 0.1.1-dev.44
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 +742 -0
- package/artifacts/Bridge.json +2914 -0
- package/artifacts/Deposit.json +117 -0
- package/artifacts/EcdsaDkgValidator.json +532 -0
- package/artifacts/EcdsaInactivity.json +156 -0
- package/artifacts/Fraud.json +153 -0
- package/artifacts/KeepRegistry.json +99 -0
- package/artifacts/KeepStake.json +286 -0
- package/artifacts/KeepToken.json +711 -0
- package/artifacts/KeepTokenStaking.json +483 -0
- package/artifacts/MovingFunds.json +137 -0
- package/artifacts/NuCypherStakingEscrow.json +256 -0
- package/artifacts/NuCypherToken.json +711 -0
- package/artifacts/RandomBeaconStub.json +141 -0
- package/artifacts/Redemption.json +161 -0
- package/artifacts/ReimbursementPool.json +509 -0
- package/artifacts/Relay.json +123 -0
- package/artifacts/SortitionPool.json +944 -0
- package/artifacts/Sweep.json +76 -0
- package/artifacts/T.json +1148 -0
- package/artifacts/TBTC.json +21 -21
- package/artifacts/TBTCToken.json +21 -21
- package/artifacts/TokenStaking.json +2288 -0
- package/artifacts/TokenholderGovernor.json +1795 -0
- package/artifacts/TokenholderTimelock.json +1058 -0
- package/artifacts/VendingMachine.json +24 -24
- package/artifacts/VendingMachineKeep.json +400 -0
- package/artifacts/VendingMachineNuCypher.json +400 -0
- package/artifacts/WalletRegistry.json +2709 -0
- package/artifacts/WalletRegistryGovernance.json +2364 -0
- package/artifacts/Wallets.json +186 -0
- package/artifacts/solcInputs/{f2c15d3cf1bd9566483f595c5ed30ccc.json → bbe44823ec28554a9429cce5cafee035.json} +19 -19
- 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 +409 -31
- package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +1 -1
- package/build/contracts/bridge/BridgeState.sol/BridgeState.json +114 -2
- 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/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 +5 -5
- 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 +40 -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/Sweep.sol/Sweep.dbg.json +1 -1
- package/build/contracts/bridge/Sweep.sol/Sweep.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 +21 -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/Bridge.sol +276 -18
- package/contracts/bridge/BridgeState.sol +238 -5
- package/contracts/bridge/Deposit.sol +2 -2
- package/contracts/bridge/Fraud.sol +47 -17
- package/contracts/bridge/MovingFunds.sol +181 -1
- package/contracts/bridge/Redemption.sol +7 -12
- package/contracts/bridge/Sweep.sol +0 -3
- package/contracts/bridge/Wallets.sol +53 -35
- package/deploy/00_resolve_relay.ts +28 -0
- package/deploy/04_deploy_bank.ts +25 -0
- package/deploy/05_deploy_bridge.ts +60 -0
- package/deploy/06_bank_update_bridge.ts +19 -0
- package/deploy/07_transfer_ownership.ts +17 -0
- package/export.json +14797 -459
- package/package.json +2 -2
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
pragma solidity ^0.8.9;
|
|
17
17
|
|
|
18
|
+
import {IWalletRegistry as EcdsaWalletRegistry} from "@keep-network/ecdsa/contracts/api/IWalletRegistry.sol";
|
|
19
|
+
|
|
18
20
|
import "./IRelay.sol";
|
|
19
21
|
import "./Deposit.sol";
|
|
20
22
|
import "./Redemption.sol";
|
|
@@ -81,6 +83,11 @@ library BridgeState {
|
|
|
81
83
|
// if per single redemption. `movingFundsTxMaxTotalFee` is a total
|
|
82
84
|
// fee for the entire transaction.
|
|
83
85
|
uint64 movingFundsTxMaxTotalFee;
|
|
86
|
+
// Time after which the moving funds process can be reported as
|
|
87
|
+
// timed out. It is counted from the moment when the wallet
|
|
88
|
+
// was requested to move their funds and switched to the MovingFunds
|
|
89
|
+
// state. Value in seconds.
|
|
90
|
+
uint32 movingFundsTimeout;
|
|
84
91
|
// The minimal amount that can be requested for redemption.
|
|
85
92
|
// Value of this parameter must take into account the value of
|
|
86
93
|
// `redemptionTreasuryFeeDivisor` and `redemptionTxMaxFee`
|
|
@@ -174,40 +181,213 @@ library BridgeState {
|
|
|
174
181
|
// active wallet. Can be unset to the zero value under certain
|
|
175
182
|
// circumstances.
|
|
176
183
|
bytes20 activeWalletPubKeyHash;
|
|
184
|
+
// The current number of wallets in the Live state.
|
|
185
|
+
uint32 liveWalletsCount;
|
|
186
|
+
// The maximum BTC amount in satoshi than can be transferred to a single
|
|
187
|
+
// target wallet during the moving funds process.
|
|
188
|
+
uint64 walletMaxBtcTransfer;
|
|
177
189
|
// Maps the 20-byte wallet public key hash (computed using Bitcoin
|
|
178
190
|
// HASH160 over the compressed ECDSA public key) to the basic wallet
|
|
179
191
|
// information like state and pending redemptions value.
|
|
180
192
|
mapping(bytes20 => Wallets.Wallet) registeredWallets;
|
|
181
193
|
}
|
|
182
194
|
|
|
195
|
+
event DepositParametersUpdated(
|
|
196
|
+
uint64 depositDustThreshold,
|
|
197
|
+
uint64 depositTreasuryFeeDivisor,
|
|
198
|
+
uint64 depositTxMaxFee
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
event RedemptionParametersUpdated(
|
|
202
|
+
uint64 redemptionDustThreshold,
|
|
203
|
+
uint64 redemptionTreasuryFeeDivisor,
|
|
204
|
+
uint64 redemptionTxMaxFee,
|
|
205
|
+
uint256 redemptionTimeout
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
event MovingFundsParametersUpdated(
|
|
209
|
+
uint64 movingFundsTxMaxTotalFee,
|
|
210
|
+
uint32 movingFundsTimeout
|
|
211
|
+
);
|
|
212
|
+
|
|
183
213
|
event WalletParametersUpdated(
|
|
184
214
|
uint32 walletCreationPeriod,
|
|
185
215
|
uint64 walletMinBtcBalance,
|
|
186
216
|
uint64 walletMaxBtcBalance,
|
|
187
|
-
uint32 walletMaxAge
|
|
217
|
+
uint32 walletMaxAge,
|
|
218
|
+
uint64 walletMaxBtcTransfer
|
|
188
219
|
);
|
|
189
220
|
|
|
221
|
+
event FraudParametersUpdated(
|
|
222
|
+
uint256 fraudSlashingAmount,
|
|
223
|
+
uint256 fraudNotifierRewardMultiplier,
|
|
224
|
+
uint256 fraudChallengeDefeatTimeout,
|
|
225
|
+
uint256 fraudChallengeDepositAmount
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
/// @notice Updates parameters of deposits.
|
|
229
|
+
/// @param _depositDustThreshold New value of the deposit dust threshold in
|
|
230
|
+
/// satoshis. It is the minimal amount that can be requested to
|
|
231
|
+
//// deposit. Value of this parameter must take into account the value
|
|
232
|
+
/// of `depositTreasuryFeeDivisor` and `depositTxMaxFee` parameters
|
|
233
|
+
/// in order to make requests that can incur the treasury and
|
|
234
|
+
/// transaction fee and still satisfy the depositor
|
|
235
|
+
/// @param _depositTreasuryFeeDivisor New value of the treasury fee divisor.
|
|
236
|
+
/// It is the divisor used to compute the treasury fee taken from
|
|
237
|
+
/// each deposit and transferred to the treasury upon sweep proof
|
|
238
|
+
/// submission. That fee is computed as follows:
|
|
239
|
+
/// `treasuryFee = depositedAmount / depositTreasuryFeeDivisor`
|
|
240
|
+
/// For example, if the treasury fee needs to be 2% of each deposit,
|
|
241
|
+
/// the `depositTreasuryFeeDivisor` should be set to `50`
|
|
242
|
+
/// because `1/50 = 0.02 = 2%`
|
|
243
|
+
/// @param _depositTxMaxFee New value of the deposit tx max fee in satoshis.
|
|
244
|
+
/// It is the maximum amount of BTC transaction fee that can
|
|
245
|
+
/// be incurred by each swept deposit being part of the given sweep
|
|
246
|
+
/// transaction. If the maximum BTC transaction fee is exceeded,
|
|
247
|
+
/// such transaction is considered a fraud
|
|
248
|
+
/// @dev Requirements:
|
|
249
|
+
/// - Deposit treasury fee divisor must be greater than zero
|
|
250
|
+
function updateDepositParameters(
|
|
251
|
+
Storage storage self,
|
|
252
|
+
uint64 _depositDustThreshold,
|
|
253
|
+
uint64 _depositTreasuryFeeDivisor,
|
|
254
|
+
uint64 _depositTxMaxFee
|
|
255
|
+
) internal {
|
|
256
|
+
require(
|
|
257
|
+
_depositTreasuryFeeDivisor > 0,
|
|
258
|
+
"Deposit treasury fee divisor must be greater than zero"
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
self.depositDustThreshold = _depositDustThreshold;
|
|
262
|
+
self.depositTreasuryFeeDivisor = _depositTreasuryFeeDivisor;
|
|
263
|
+
self.depositTxMaxFee = _depositTxMaxFee;
|
|
264
|
+
|
|
265
|
+
emit DepositParametersUpdated(
|
|
266
|
+
_depositDustThreshold,
|
|
267
|
+
_depositTreasuryFeeDivisor,
|
|
268
|
+
_depositTxMaxFee
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/// @notice Updates parameters of redemptions.
|
|
273
|
+
/// @param _redemptionDustThreshold New value of the redemption dust
|
|
274
|
+
/// threshold in satoshis. It is the minimal amount that can be
|
|
275
|
+
/// requested for redemption. Value of this parameter must take into
|
|
276
|
+
/// account the value of `redemptionTreasuryFeeDivisor` and
|
|
277
|
+
/// `redemptionTxMaxFee` parameters in order to make requests that
|
|
278
|
+
/// can incur the treasury and transaction fee and still satisfy the
|
|
279
|
+
/// redeemer.
|
|
280
|
+
/// @param _redemptionTreasuryFeeDivisor New value of the redemption
|
|
281
|
+
/// treasury fee divisor. It is the divisor used to compute the
|
|
282
|
+
/// treasury fee taken from each redemption request and transferred
|
|
283
|
+
/// to the treasury upon successful request finalization. That fee is
|
|
284
|
+
/// computed as follows:
|
|
285
|
+
/// `treasuryFee = requestedAmount / redemptionTreasuryFeeDivisor`
|
|
286
|
+
/// For example, if the treasury fee needs to be 2% of each
|
|
287
|
+
/// redemption request, the `redemptionTreasuryFeeDivisor` should
|
|
288
|
+
/// be set to `50` because `1/50 = 0.02 = 2%`.
|
|
289
|
+
/// @param _redemptionTxMaxFee New value of the redemption transaction max
|
|
290
|
+
/// fee in satoshis. It is the maximum amount of BTC transaction fee
|
|
291
|
+
/// that can be incurred by each redemption request being part of the
|
|
292
|
+
/// given redemption transaction. If the maximum BTC transaction fee
|
|
293
|
+
/// is exceeded, such transaction is considered a fraud.
|
|
294
|
+
/// @param _redemptionTimeout New value of the redemption timeout in seconds.
|
|
295
|
+
/// It is the time after which the redemption request can be reported
|
|
296
|
+
/// as timed out. It is counted from the moment when the redemption
|
|
297
|
+
/// request was created via `requestRedemption` call. Reported timed
|
|
298
|
+
/// out requests are cancelled and locked TBTC is returned to the
|
|
299
|
+
/// redeemer in full amount.
|
|
300
|
+
/// @dev Requirements:
|
|
301
|
+
/// - Redemption treasury fee divisor must be greater than zero
|
|
302
|
+
/// - Redemption timeout must be greater than zero
|
|
303
|
+
function updateRedemptionParameters(
|
|
304
|
+
Storage storage self,
|
|
305
|
+
uint64 _redemptionDustThreshold,
|
|
306
|
+
uint64 _redemptionTreasuryFeeDivisor,
|
|
307
|
+
uint64 _redemptionTxMaxFee,
|
|
308
|
+
uint256 _redemptionTimeout
|
|
309
|
+
) internal {
|
|
310
|
+
require(
|
|
311
|
+
_redemptionTreasuryFeeDivisor > 0,
|
|
312
|
+
"Redemption treasury fee divisor must be greater than zero"
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
require(
|
|
316
|
+
_redemptionTimeout > 0,
|
|
317
|
+
"Redemption timeout must be greater than zero"
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
self.redemptionDustThreshold = _redemptionDustThreshold;
|
|
321
|
+
self.redemptionTreasuryFeeDivisor = _redemptionTreasuryFeeDivisor;
|
|
322
|
+
self.redemptionTxMaxFee = _redemptionTxMaxFee;
|
|
323
|
+
self.redemptionTimeout = _redemptionTimeout;
|
|
324
|
+
|
|
325
|
+
emit RedemptionParametersUpdated(
|
|
326
|
+
_redemptionDustThreshold,
|
|
327
|
+
_redemptionTreasuryFeeDivisor,
|
|
328
|
+
_redemptionTxMaxFee,
|
|
329
|
+
_redemptionTimeout
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/// @notice Updates parameters of moving funds.
|
|
334
|
+
/// @param _movingFundsTxMaxTotalFee New value of the moving funds transaction
|
|
335
|
+
/// max total fee in satoshis. It is the maximum amount of the total
|
|
336
|
+
/// BTC transaction fee that is acceptable in a single moving funds
|
|
337
|
+
/// transaction. This is a _total_ max fee for the entire moving
|
|
338
|
+
/// funds transaction.
|
|
339
|
+
/// @param _movingFundsTimeout New value of the moving funds timeout in
|
|
340
|
+
/// seconds. It is the time after which the moving funds process can
|
|
341
|
+
/// be reported as timed out. It is counted from the moment when the
|
|
342
|
+
/// wallet was requested to move their funds and switched to the
|
|
343
|
+
/// MovingFunds state.
|
|
344
|
+
/// @dev Requirements:
|
|
345
|
+
/// - Moving funds timeout must be greater than zero
|
|
346
|
+
function updateMovingFundsParameters(
|
|
347
|
+
Storage storage self,
|
|
348
|
+
uint64 _movingFundsTxMaxTotalFee,
|
|
349
|
+
uint32 _movingFundsTimeout
|
|
350
|
+
) internal {
|
|
351
|
+
require(
|
|
352
|
+
_movingFundsTimeout > 0,
|
|
353
|
+
"Moving funds timeout must be greater than zero"
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
self.movingFundsTxMaxTotalFee = _movingFundsTxMaxTotalFee;
|
|
357
|
+
self.movingFundsTimeout = _movingFundsTimeout;
|
|
358
|
+
|
|
359
|
+
emit MovingFundsParametersUpdated(
|
|
360
|
+
_movingFundsTxMaxTotalFee,
|
|
361
|
+
_movingFundsTimeout
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
|
|
190
365
|
/// @notice Updates parameters of wallets.
|
|
191
366
|
/// @param _walletCreationPeriod New value of the wallet creation period in
|
|
192
367
|
/// seconds, determines how frequently a new wallet creation can be
|
|
193
368
|
/// requested
|
|
194
369
|
/// @param _walletMinBtcBalance New value of the wallet minimum BTC balance
|
|
195
|
-
/// in
|
|
370
|
+
/// in satoshi, used to decide about wallet creation or closing
|
|
196
371
|
/// @param _walletMaxBtcBalance New value of the wallet maximum BTC balance
|
|
197
|
-
/// in
|
|
372
|
+
/// in satoshi, used to decide about wallet creation
|
|
198
373
|
/// @param _walletMaxAge New value of the wallet maximum age in seconds,
|
|
199
374
|
/// indicates the maximum age of a wallet in seconds, after which
|
|
200
375
|
/// the wallet moving funds process can be requested
|
|
376
|
+
/// @param _walletMaxBtcTransfer New value of the wallet maximum BTC transfer
|
|
377
|
+
/// in satoshi, determines the maximum amount that can be transferred
|
|
378
|
+
// to a single target wallet during the moving funds process
|
|
201
379
|
/// @dev Requirements:
|
|
202
380
|
/// - Wallet minimum BTC balance must be greater than zero
|
|
203
381
|
/// - Wallet maximum BTC balance must be greater than the wallet
|
|
204
382
|
/// minimum BTC balance
|
|
383
|
+
/// - Wallet maximum BTC transfer must be greater than zero
|
|
205
384
|
function updateWalletParameters(
|
|
206
385
|
Storage storage self,
|
|
207
386
|
uint32 _walletCreationPeriod,
|
|
208
387
|
uint64 _walletMinBtcBalance,
|
|
209
388
|
uint64 _walletMaxBtcBalance,
|
|
210
|
-
uint32 _walletMaxAge
|
|
389
|
+
uint32 _walletMaxAge,
|
|
390
|
+
uint64 _walletMaxBtcTransfer
|
|
211
391
|
) internal {
|
|
212
392
|
require(
|
|
213
393
|
_walletMinBtcBalance > 0,
|
|
@@ -217,17 +397,70 @@ library BridgeState {
|
|
|
217
397
|
_walletMaxBtcBalance > _walletMinBtcBalance,
|
|
218
398
|
"Wallet maximum BTC balance must be greater than the minimum"
|
|
219
399
|
);
|
|
400
|
+
require(
|
|
401
|
+
_walletMaxBtcTransfer > 0,
|
|
402
|
+
"Wallet maximum BTC transfer must be greater than zero"
|
|
403
|
+
);
|
|
220
404
|
|
|
221
405
|
self.walletCreationPeriod = _walletCreationPeriod;
|
|
222
406
|
self.walletMinBtcBalance = _walletMinBtcBalance;
|
|
223
407
|
self.walletMaxBtcBalance = _walletMaxBtcBalance;
|
|
224
408
|
self.walletMaxAge = _walletMaxAge;
|
|
409
|
+
self.walletMaxBtcTransfer = _walletMaxBtcTransfer;
|
|
225
410
|
|
|
226
411
|
emit WalletParametersUpdated(
|
|
227
412
|
_walletCreationPeriod,
|
|
228
413
|
_walletMinBtcBalance,
|
|
229
414
|
_walletMaxBtcBalance,
|
|
230
|
-
_walletMaxAge
|
|
415
|
+
_walletMaxAge,
|
|
416
|
+
_walletMaxBtcTransfer
|
|
417
|
+
);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/// @notice Updates parameters related to frauds.
|
|
421
|
+
/// @param _fraudSlashingAmount New value of the fraud slashing amount in T,
|
|
422
|
+
/// it is the amount slashed from each wallet member for committing
|
|
423
|
+
/// a fraud
|
|
424
|
+
/// @param _fraudNotifierRewardMultiplier New value of the fraud notifier
|
|
425
|
+
/// reward multiplier as percentage, it determines the percentage of
|
|
426
|
+
/// the notifier reward from the staking contact the notifier of
|
|
427
|
+
/// a fraud receives. The value must be in the range [0, 100]
|
|
428
|
+
/// @param _fraudChallengeDefeatTimeout New value of the challenge defeat
|
|
429
|
+
/// timeout in seconds, it is the amount of time the wallet has to
|
|
430
|
+
/// defeat a fraud challenge. The value must be greater than zero
|
|
431
|
+
/// @param _fraudChallengeDepositAmount New value of the fraud challenge
|
|
432
|
+
/// deposit amount in wei, it is the amount of ETH the party
|
|
433
|
+
/// challenging the wallet for fraud needs to deposit
|
|
434
|
+
/// @dev Requirements:
|
|
435
|
+
/// - Fraud notifier reward multiplier must be in the range [0, 100]
|
|
436
|
+
/// - Fraud challenge defeat timeout must be greater than 0
|
|
437
|
+
function updateFraudParameters(
|
|
438
|
+
Storage storage self,
|
|
439
|
+
uint256 _fraudSlashingAmount,
|
|
440
|
+
uint256 _fraudNotifierRewardMultiplier,
|
|
441
|
+
uint256 _fraudChallengeDefeatTimeout,
|
|
442
|
+
uint256 _fraudChallengeDepositAmount
|
|
443
|
+
) internal {
|
|
444
|
+
require(
|
|
445
|
+
_fraudNotifierRewardMultiplier <= 100,
|
|
446
|
+
"Fraud notifier reward multiplier must be in the range [0, 100]"
|
|
447
|
+
);
|
|
448
|
+
|
|
449
|
+
require(
|
|
450
|
+
_fraudChallengeDefeatTimeout > 0,
|
|
451
|
+
"Fraud challenge defeat timeout must be greater than zero"
|
|
452
|
+
);
|
|
453
|
+
|
|
454
|
+
self.fraudSlashingAmount = _fraudSlashingAmount;
|
|
455
|
+
self.fraudNotifierRewardMultiplier = _fraudNotifierRewardMultiplier;
|
|
456
|
+
self.fraudChallengeDefeatTimeout = _fraudChallengeDefeatTimeout;
|
|
457
|
+
self.fraudChallengeDepositAmount = _fraudChallengeDepositAmount;
|
|
458
|
+
|
|
459
|
+
emit FraudParametersUpdated(
|
|
460
|
+
_fraudSlashingAmount,
|
|
461
|
+
_fraudNotifierRewardMultiplier,
|
|
462
|
+
_fraudChallengeDefeatTimeout,
|
|
463
|
+
_fraudChallengeDepositAmount
|
|
231
464
|
);
|
|
232
465
|
}
|
|
233
466
|
}
|
|
@@ -149,7 +149,7 @@ library Deposit {
|
|
|
149
149
|
require(
|
|
150
150
|
self.registeredWallets[reveal.walletPubKeyHash].state ==
|
|
151
151
|
Wallets.WalletState.Live,
|
|
152
|
-
"Wallet
|
|
152
|
+
"Wallet must be in Live state"
|
|
153
153
|
);
|
|
154
154
|
|
|
155
155
|
require(
|
|
@@ -250,7 +250,7 @@ library Deposit {
|
|
|
250
250
|
deposit.treasuryFee = self.depositTreasuryFeeDivisor > 0
|
|
251
251
|
? fundingOutputAmount / self.depositTreasuryFeeDivisor
|
|
252
252
|
: 0;
|
|
253
|
-
|
|
253
|
+
// slither-disable-next-line reentrancy-events
|
|
254
254
|
emit DepositRevealed(
|
|
255
255
|
fundingTxHash,
|
|
256
256
|
reveal.fundingOutputIndex,
|
|
@@ -42,6 +42,8 @@ import "./Wallets.sol";
|
|
|
42
42
|
/// Therefore the transaction spending the UTXO must be proven in the
|
|
43
43
|
/// Bridge before a challenge defeat is called.
|
|
44
44
|
library Fraud {
|
|
45
|
+
using Wallets for BridgeState.Storage;
|
|
46
|
+
|
|
45
47
|
using BytesLib for bytes;
|
|
46
48
|
using BTCUtils for bytes;
|
|
47
49
|
using BTCUtils for uint32;
|
|
@@ -59,17 +61,17 @@ library Fraud {
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
event FraudChallengeSubmitted(
|
|
62
|
-
bytes20
|
|
64
|
+
bytes20 walletPubKeyHash,
|
|
63
65
|
bytes32 sighash,
|
|
64
66
|
uint8 v,
|
|
65
67
|
bytes32 r,
|
|
66
68
|
bytes32 s
|
|
67
69
|
);
|
|
68
70
|
|
|
69
|
-
event FraudChallengeDefeated(bytes20
|
|
71
|
+
event FraudChallengeDefeated(bytes20 walletPubKeyHash, bytes32 sighash);
|
|
70
72
|
|
|
71
73
|
event FraudChallengeDefeatTimedOut(
|
|
72
|
-
bytes20
|
|
74
|
+
bytes20 walletPubKeyHash,
|
|
73
75
|
bytes32 sighash
|
|
74
76
|
);
|
|
75
77
|
|
|
@@ -98,8 +100,8 @@ library Fraud {
|
|
|
98
100
|
/// for reference
|
|
99
101
|
/// @param signature Bitcoin signature in the R/S/V format
|
|
100
102
|
/// @dev Requirements:
|
|
101
|
-
/// - Wallet behind `walletPublicKey` must be in
|
|
102
|
-
/// state
|
|
103
|
+
/// - Wallet behind `walletPublicKey` must be in Live or MovingFunds
|
|
104
|
+
/// or Closing state
|
|
103
105
|
/// - The challenger must send appropriate amount of ETH used as
|
|
104
106
|
/// fraud challenge deposit
|
|
105
107
|
/// - The signature (represented by r, s and v) must be generated by
|
|
@@ -139,8 +141,9 @@ library Fraud {
|
|
|
139
141
|
|
|
140
142
|
require(
|
|
141
143
|
wallet.state == Wallets.WalletState.Live ||
|
|
142
|
-
wallet.state == Wallets.WalletState.MovingFunds
|
|
143
|
-
|
|
144
|
+
wallet.state == Wallets.WalletState.MovingFunds ||
|
|
145
|
+
wallet.state == Wallets.WalletState.Closing,
|
|
146
|
+
"Wallet must be in Live or MovingFunds or Closing state"
|
|
144
147
|
);
|
|
145
148
|
|
|
146
149
|
uint256 challengeKey = uint256(
|
|
@@ -155,7 +158,7 @@ library Fraud {
|
|
|
155
158
|
/* solhint-disable-next-line not-rely-on-time */
|
|
156
159
|
challenge.reportedAt = uint32(block.timestamp);
|
|
157
160
|
challenge.resolved = false;
|
|
158
|
-
|
|
161
|
+
// slither-disable-next-line reentrancy-events
|
|
159
162
|
emit FraudChallengeSubmitted(
|
|
160
163
|
walletPubKeyHash,
|
|
161
164
|
sighash,
|
|
@@ -232,7 +235,7 @@ library Fraud {
|
|
|
232
235
|
|
|
233
236
|
// Send the ether deposited by the challenger to the treasury
|
|
234
237
|
/* solhint-disable avoid-low-level-calls */
|
|
235
|
-
// slither-disable-next-line low-level-calls
|
|
238
|
+
// slither-disable-next-line low-level-calls,unchecked-lowlevel,arbitrary-send
|
|
236
239
|
self.treasury.call{gas: 100000, value: challenge.depositAmount}("");
|
|
237
240
|
/* solhint-enable avoid-low-level-calls */
|
|
238
241
|
|
|
@@ -241,7 +244,7 @@ library Fraud {
|
|
|
241
244
|
walletPublicKey.slice32(32)
|
|
242
245
|
);
|
|
243
246
|
bytes20 walletPubKeyHash = compressedWalletPublicKey.hash160View();
|
|
244
|
-
|
|
247
|
+
// slither-disable-next-line reentrancy-events
|
|
245
248
|
emit FraudChallengeDefeated(walletPubKeyHash, sighash);
|
|
246
249
|
}
|
|
247
250
|
|
|
@@ -264,9 +267,11 @@ library Fraud {
|
|
|
264
267
|
/// the transaction input the signature is produced for. See BIP-143
|
|
265
268
|
/// for reference
|
|
266
269
|
/// @dev Requirements:
|
|
267
|
-
/// -
|
|
270
|
+
/// - The wallet must be in the Live or MovingFunds or Closing or
|
|
271
|
+
/// Terminated state
|
|
272
|
+
/// - The `walletPublicKey` and `sighash` must identify an open fraud
|
|
268
273
|
/// challenge
|
|
269
|
-
/// -
|
|
274
|
+
/// - The amount of time indicated by `challengeDefeatTimeout` must pass
|
|
270
275
|
/// after the challenge was reported
|
|
271
276
|
function notifyFraudChallengeDefeatTimeout(
|
|
272
277
|
BridgeState.Storage storage self,
|
|
@@ -278,11 +283,14 @@ library Fraud {
|
|
|
278
283
|
);
|
|
279
284
|
|
|
280
285
|
FraudChallenge storage challenge = self.fraudChallenges[challengeKey];
|
|
286
|
+
|
|
281
287
|
require(challenge.reportedAt > 0, "Fraud challenge does not exist");
|
|
288
|
+
|
|
282
289
|
require(
|
|
283
290
|
!challenge.resolved,
|
|
284
291
|
"Fraud challenge has already been resolved"
|
|
285
292
|
);
|
|
293
|
+
|
|
286
294
|
require(
|
|
287
295
|
/* solhint-disable-next-line not-rely-on-time */
|
|
288
296
|
block.timestamp >=
|
|
@@ -290,14 +298,10 @@ library Fraud {
|
|
|
290
298
|
"Fraud challenge defeat period did not time out yet"
|
|
291
299
|
);
|
|
292
300
|
|
|
293
|
-
// TODO: Call notifyFraud from Wallets library
|
|
294
|
-
// TODO: Reward the challenger
|
|
295
|
-
|
|
296
301
|
challenge.resolved = true;
|
|
297
|
-
|
|
298
302
|
// Return the ether deposited by the challenger
|
|
299
303
|
/* solhint-disable avoid-low-level-calls */
|
|
300
|
-
// slither-disable-next-line low-level-calls
|
|
304
|
+
// slither-disable-next-line low-level-calls,unchecked-lowlevel
|
|
301
305
|
challenge.challenger.call{gas: 100000, value: challenge.depositAmount}(
|
|
302
306
|
""
|
|
303
307
|
);
|
|
@@ -308,7 +312,33 @@ library Fraud {
|
|
|
308
312
|
walletPublicKey.slice32(32)
|
|
309
313
|
);
|
|
310
314
|
bytes20 walletPubKeyHash = compressedWalletPublicKey.hash160View();
|
|
315
|
+
Wallets.WalletState walletState = self
|
|
316
|
+
.registeredWallets[walletPubKeyHash]
|
|
317
|
+
.state;
|
|
318
|
+
|
|
319
|
+
if (
|
|
320
|
+
walletState == Wallets.WalletState.Live ||
|
|
321
|
+
walletState == Wallets.WalletState.MovingFunds ||
|
|
322
|
+
walletState == Wallets.WalletState.Closing
|
|
323
|
+
) {
|
|
324
|
+
self.terminateWallet(walletPubKeyHash);
|
|
325
|
+
|
|
326
|
+
// TODO: Perform slashing of the wallet operators, reward the
|
|
327
|
+
// challenger, and add unit tests for that.
|
|
328
|
+
} else if (walletState == Wallets.WalletState.Terminated) {
|
|
329
|
+
// This is a special case when the wallet was already terminated
|
|
330
|
+
// due to a previous deliberate protocol violation. In that
|
|
331
|
+
// case, this function should be still callable for other fraud
|
|
332
|
+
// challenges timeouts in order to let the challenger unlock its
|
|
333
|
+
// ETH deposit back. However, the wallet termination logic is
|
|
334
|
+
// not called and the challenger is not rewarded.
|
|
335
|
+
} else {
|
|
336
|
+
revert(
|
|
337
|
+
"Wallet must be in Live or MovingFunds or Closing or Terminated state"
|
|
338
|
+
);
|
|
339
|
+
}
|
|
311
340
|
|
|
341
|
+
// slither-disable-next-line reentrancy-events
|
|
312
342
|
emit FraudChallengeDefeatTimedOut(walletPubKeyHash, sighash);
|
|
313
343
|
}
|
|
314
344
|
|