@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.
Files changed (72) hide show
  1. package/artifacts/Bank.json +3 -3
  2. package/artifacts/Bridge.json +581 -234
  3. package/artifacts/Deposit.json +9 -9
  4. package/artifacts/DepositSweep.json +76 -0
  5. package/artifacts/EcdsaDkgValidator.json +1 -1
  6. package/artifacts/EcdsaInactivity.json +1 -1
  7. package/artifacts/Fraud.json +9 -9
  8. package/artifacts/KeepRegistry.json +1 -1
  9. package/artifacts/KeepStake.json +2 -2
  10. package/artifacts/KeepToken.json +2 -2
  11. package/artifacts/KeepTokenStaking.json +1 -1
  12. package/artifacts/MovingFunds.json +41 -11
  13. package/artifacts/NuCypherStakingEscrow.json +1 -1
  14. package/artifacts/NuCypherToken.json +2 -2
  15. package/artifacts/RandomBeaconStub.json +1 -1
  16. package/artifacts/Redemption.json +9 -9
  17. package/artifacts/ReimbursementPool.json +2 -2
  18. package/artifacts/Relay.json +9 -9
  19. package/artifacts/SortitionPool.json +2 -2
  20. package/artifacts/T.json +2 -2
  21. package/artifacts/TBTC.json +3 -3
  22. package/artifacts/TBTCToken.json +3 -3
  23. package/artifacts/TokenStaking.json +1 -1
  24. package/artifacts/TokenholderGovernor.json +9 -9
  25. package/artifacts/TokenholderTimelock.json +8 -8
  26. package/artifacts/VendingMachine.json +10 -10
  27. package/artifacts/VendingMachineKeep.json +1 -1
  28. package/artifacts/VendingMachineNuCypher.json +1 -1
  29. package/artifacts/WalletRegistry.json +2 -2
  30. package/artifacts/WalletRegistryGovernance.json +2 -2
  31. package/artifacts/Wallets.json +9 -9
  32. package/artifacts/solcInputs/{799c7b289d9b6d9cfc600d2fc23c7b64.json → d1140ac40baa1ba6f0d558afe0fa6d54.json} +10 -10
  33. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
  34. package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
  35. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +1 -1
  36. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +2 -2
  37. package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
  38. package/build/contracts/bridge/Bridge.sol/Bridge.json +296 -128
  39. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +1 -1
  40. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +17 -11
  41. package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +1 -1
  42. package/build/contracts/bridge/Deposit.sol/Deposit.json +2 -2
  43. package/build/contracts/bridge/DepositSweep.sol/DepositSweep.dbg.json +4 -0
  44. package/build/contracts/bridge/DepositSweep.sol/DepositSweep.json +30 -0
  45. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +1 -1
  46. package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +1 -1
  47. package/build/contracts/bridge/Fraud.sol/Fraud.json +2 -2
  48. package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +1 -1
  49. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +1 -1
  50. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +21 -2
  51. package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +1 -1
  52. package/build/contracts/bridge/Redemption.sol/OutboundTx.json +2 -2
  53. package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +1 -1
  54. package/build/contracts/bridge/Redemption.sol/Redemption.json +2 -2
  55. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
  56. package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +1 -1
  57. package/build/contracts/bridge/Wallets.sol/Wallets.json +2 -2
  58. package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
  59. package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
  60. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
  61. package/contracts/bridge/BitcoinTx.sol +69 -0
  62. package/contracts/bridge/Bridge.sol +132 -49
  63. package/contracts/bridge/BridgeState.sol +77 -46
  64. package/contracts/bridge/{Sweep.sol → DepositSweep.sol} +30 -18
  65. package/contracts/bridge/MovingFunds.sol +480 -76
  66. package/contracts/bridge/Wallets.sol +2 -0
  67. package/deploy/05_deploy_bridge.ts +5 -2
  68. package/export.json +348 -81
  69. package/package.json +1 -1
  70. package/artifacts/Sweep.json +0 -76
  71. package/build/contracts/bridge/Sweep.sol/Sweep.dbg.json +0 -4
  72. package/build/contracts/bridge/Sweep.sol/Sweep.json +0 -30
@@ -33,7 +33,7 @@ import "../bank/Bank.sol";
33
33
  /// This has two main effects: it consolidates the UTXO set and it disables
34
34
  /// the refund. Balances of depositors in the Bank are increased when the
35
35
  /// SPV sweep proof is submitted to the Bridge.
36
- library Sweep {
36
+ library DepositSweep {
37
37
  using BridgeState for BridgeState.Storage;
38
38
  using BitcoinTx for BridgeState.Storage;
39
39
 
@@ -41,7 +41,7 @@ library Sweep {
41
41
 
42
42
  /// @notice Represents an outcome of the sweep Bitcoin transaction
43
43
  /// inputs processing.
44
- struct SweepTxInputsInfo {
44
+ struct DepositSweepTxInputsInfo {
45
45
  // Sum of all inputs values i.e. all deposits and main UTXO value,
46
46
  // if present.
47
47
  uint256 inputsTotalValue;
@@ -103,7 +103,7 @@ library Sweep {
103
103
  /// - `mainUtxo` components must point to the recent main UTXO
104
104
  /// of the given wallet, as currently known on the Ethereum chain.
105
105
  /// If there is no main UTXO, this parameter is ignored.
106
- function submitSweepProof(
106
+ function submitDepositSweepProof(
107
107
  BridgeState.Storage storage self,
108
108
  BitcoinTx.Info calldata sweepTx,
109
109
  BitcoinTx.Proof calldata sweepProof,
@@ -120,20 +120,21 @@ library Sweep {
120
120
  (
121
121
  bytes20 walletPubKeyHash,
122
122
  uint64 sweepTxOutputValue
123
- ) = processSweepTxOutput(sweepTx.outputVector);
123
+ ) = processDepositSweepTxOutput(sweepTx.outputVector);
124
124
 
125
125
  (
126
126
  Wallets.Wallet storage wallet,
127
127
  BitcoinTx.UTXO memory resolvedMainUtxo
128
- ) = resolveSweepingWallet(self, walletPubKeyHash, mainUtxo);
128
+ ) = resolveDepositSweepingWallet(self, walletPubKeyHash, mainUtxo);
129
129
 
130
130
  // Process sweep transaction inputs and extract all information needed
131
131
  // to perform deposit bookkeeping.
132
- SweepTxInputsInfo memory inputsInfo = processSweepTxInputs(
133
- self,
134
- sweepTx.inputVector,
135
- resolvedMainUtxo
136
- );
132
+ DepositSweepTxInputsInfo
133
+ memory inputsInfo = processDepositSweepTxInputs(
134
+ self,
135
+ sweepTx.inputVector,
136
+ resolvedMainUtxo
137
+ );
137
138
 
138
139
  // Helper variable that will hold the sum of treasury fees paid by
139
140
  // all deposits.
@@ -145,7 +146,7 @@ library Sweep {
145
146
  (
146
147
  uint256 depositTxFee,
147
148
  uint256 depositTxFeeRemainder
148
- ) = sweepTxFeeDistribution(
149
+ ) = depositSweepTxFeeDistribution(
149
150
  inputsInfo.inputsTotalValue,
150
151
  sweepTxOutputValue,
151
152
  inputsInfo.depositedAmounts.length
@@ -206,11 +207,16 @@ library Sweep {
206
207
  /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
207
208
  /// the Ethereum chain. If no main UTXO exists for the given wallet,
208
209
  /// this parameter is ignored
210
+ /// @return wallet Data of the sweeping wallet.
211
+ /// @return resolvedMainUtxo The actual main UTXO of the sweeping wallet
212
+ /// resolved by cross-checking the `mainUtxo` parameter with
213
+ /// the chain state. If the validation went well, this is the
214
+ /// plain-text main UTXO corresponding to the `wallet.mainUtxoHash`.
209
215
  /// @dev Requirements:
210
216
  /// - Sweeping wallet must be either in Live or MovingFunds state.
211
217
  /// - If the main UTXO of the sweeping wallet exists in the storage,
212
218
  /// the passed `mainUTXO` parameter must be equal to the stored one.
213
- function resolveSweepingWallet(
219
+ function resolveDepositSweepingWallet(
214
220
  BridgeState.Storage storage self,
215
221
  bytes20 walletPubKeyHash,
216
222
  BitcoinTx.UTXO calldata mainUtxo
@@ -261,7 +267,7 @@ library Sweep {
261
267
  /// it is passed here
262
268
  /// @return walletPubKeyHash 20-byte wallet public key hash.
263
269
  /// @return value 8-byte sweep transaction output value.
264
- function processSweepTxOutput(bytes memory sweepTxOutputVector)
270
+ function processDepositSweepTxOutput(bytes memory sweepTxOutputVector)
265
271
  internal
266
272
  pure
267
273
  returns (bytes20 walletPubKeyHash, uint64 value)
@@ -282,6 +288,8 @@ library Sweep {
282
288
 
283
289
  bytes memory output = sweepTxOutputVector.extractOutputAtIndex(0);
284
290
  value = output.extractValue();
291
+ // TODO: Extract `walletPubKeyHash` using `self.extractPubKeyHash`
292
+ // in order to get stronger validation.
285
293
  bytes memory walletPubKeyHashBytes = output.extractHash();
286
294
  // The sweep transaction output should always be P2PKH or P2WPKH.
287
295
  // In both cases, the wallet public key hash should be 20 bytes length.
@@ -311,11 +319,11 @@ library Sweep {
311
319
  /// exists for the given the wallet, this parameter's fields should
312
320
  /// be zeroed to bypass the main UTXO validation
313
321
  /// @return info Outcomes of the processing.
314
- function processSweepTxInputs(
322
+ function processDepositSweepTxInputs(
315
323
  BridgeState.Storage storage self,
316
324
  bytes memory sweepTxInputVector,
317
325
  BitcoinTx.UTXO memory mainUtxo
318
- ) internal returns (SweepTxInputsInfo memory info) {
326
+ ) internal returns (DepositSweepTxInputsInfo memory info) {
319
327
  // If the passed `mainUtxo` parameter's values are zeroed, the main UTXO
320
328
  // for the given wallet doesn't exist and it is not expected to be
321
329
  // included in the sweep transaction input vector.
@@ -365,7 +373,10 @@ library Sweep {
365
373
  bytes32 outpointTxHash,
366
374
  uint32 outpointIndex,
367
375
  uint256 inputLength
368
- ) = parseTxInputAt(sweepTxInputVector, inputStartingIndex);
376
+ ) = parseDepositSweepTxInputAt(
377
+ sweepTxInputVector,
378
+ inputStartingIndex
379
+ );
369
380
 
370
381
  Deposit.DepositRequest storage deposit = self.deposits[
371
382
  uint256(
@@ -402,6 +413,7 @@ library Sweep {
402
413
  } else if (
403
414
  mainUtxoExpected != mainUtxoFound &&
404
415
  mainUtxo.txHash == outpointTxHash
416
+ // TODO: We probably need to check `mainUtxo.txOutputIndex == outpointIndex` as well.
405
417
  ) {
406
418
  // If we entered here, that means the input was identified as
407
419
  // the expected main UTXO.
@@ -455,7 +467,7 @@ library Sweep {
455
467
  /// @dev This function assumes vector's structure is valid so it must be
456
468
  /// validated using e.g. `BTCUtils.validateVin` function before it
457
469
  /// is passed here.
458
- function parseTxInputAt(
470
+ function parseDepositSweepTxInputAt(
459
471
  bytes memory inputVector,
460
472
  uint256 inputStartingIndex
461
473
  )
@@ -490,7 +502,7 @@ library Sweep {
490
502
  /// transaction fee than cannot be distributed over all deposits.
491
503
  /// @dev It is up to the caller to decide how the remainder should be
492
504
  /// counted in. This function only computes its value.
493
- function sweepTxFeeDistribution(
505
+ function depositSweepTxFeeDistribution(
494
506
  uint256 sweepTxInputsTotalValue,
495
507
  uint256 sweepTxOutputValue,
496
508
  uint256 depositsCount