@keep-network/tbtc-v2 0.1.1-dev.7 → 0.1.1-dev.70

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 (110) hide show
  1. package/README.adoc +12 -0
  2. package/artifacts/Bank.json +752 -0
  3. package/artifacts/Bridge.json +2556 -0
  4. package/artifacts/DefaultProxyAdmin.json +259 -0
  5. package/artifacts/Deposit.json +117 -0
  6. package/artifacts/DepositSweep.json +77 -0
  7. package/artifacts/EcdsaDkgValidator.json +533 -0
  8. package/artifacts/EcdsaInactivity.json +156 -0
  9. package/artifacts/Fraud.json +164 -0
  10. package/artifacts/KeepRegistry.json +99 -0
  11. package/artifacts/KeepStake.json +286 -0
  12. package/artifacts/KeepToken.json +711 -0
  13. package/artifacts/KeepTokenStaking.json +483 -0
  14. package/artifacts/MovingFunds.json +249 -0
  15. package/artifacts/NuCypherStakingEscrow.json +256 -0
  16. package/artifacts/NuCypherToken.json +711 -0
  17. package/artifacts/RandomBeaconStub.json +141 -0
  18. package/artifacts/Redemption.json +162 -0
  19. package/artifacts/ReimbursementPool.json +509 -0
  20. package/artifacts/Relay.json +123 -0
  21. package/artifacts/SortitionPool.json +1005 -0
  22. package/artifacts/T.json +1148 -0
  23. package/artifacts/TBTC.json +27 -26
  24. package/artifacts/TBTCToken.json +27 -26
  25. package/artifacts/TokenStaking.json +2288 -0
  26. package/artifacts/TokenholderGovernor.json +1795 -0
  27. package/artifacts/TokenholderTimelock.json +1058 -0
  28. package/artifacts/VendingMachine.json +30 -29
  29. package/artifacts/VendingMachineKeep.json +400 -0
  30. package/artifacts/VendingMachineNuCypher.json +400 -0
  31. package/artifacts/WalletRegistry.json +2117 -0
  32. package/artifacts/WalletRegistry_Implementation.json +2824 -0
  33. package/artifacts/WalletRegistry_Proxy.json +259 -0
  34. package/artifacts/Wallets.json +186 -0
  35. package/artifacts/solcInputs/1635d55d57a0a2552952c0d22586ed23.json +56 -0
  36. package/artifacts/solcInputs/922f95457ca7980d018c851fb3308a7e.json +269 -0
  37. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
  38. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.json +2 -2
  39. package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
  40. package/build/contracts/bank/Bank.sol/Bank.json +20 -2
  41. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +1 -1
  42. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +2 -2
  43. package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
  44. package/build/contracts/bridge/Bridge.sol/Bridge.json +2546 -128
  45. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +4 -0
  46. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +220 -0
  47. package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +4 -0
  48. package/build/contracts/bridge/Deposit.sol/Deposit.json +72 -0
  49. package/build/contracts/bridge/DepositSweep.sol/DepositSweep.dbg.json +4 -0
  50. package/build/contracts/bridge/DepositSweep.sol/DepositSweep.json +30 -0
  51. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +4 -0
  52. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.json +10 -0
  53. package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +4 -0
  54. package/build/contracts/bridge/Fraud.sol/Fraud.json +86 -0
  55. package/build/contracts/bridge/Heartbeat.sol/Heartbeat.dbg.json +4 -0
  56. package/build/contracts/bridge/Heartbeat.sol/Heartbeat.json +10 -0
  57. package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +4 -0
  58. package/build/contracts/bridge/IRelay.sol/IRelay.json +37 -0
  59. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +4 -0
  60. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +138 -0
  61. package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +4 -0
  62. package/build/contracts/bridge/Redemption.sol/OutboundTx.json +10 -0
  63. package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +4 -0
  64. package/build/contracts/bridge/Redemption.sol/Redemption.json +92 -0
  65. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
  66. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.json +2 -2
  67. package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +4 -0
  68. package/build/contracts/bridge/Wallets.sol/Wallets.json +112 -0
  69. package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
  70. package/build/contracts/token/TBTC.sol/TBTC.json +2 -2
  71. package/build/contracts/vault/DonationVault.sol/DonationVault.dbg.json +4 -0
  72. package/build/contracts/vault/DonationVault.sol/DonationVault.json +103 -0
  73. package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
  74. package/build/contracts/vault/IVault.sol/IVault.json +19 -1
  75. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
  76. package/build/contracts/vault/TBTCVault.sol/TBTCVault.json +36 -18
  77. package/contracts/GovernanceUtils.sol +1 -1
  78. package/contracts/bank/Bank.sol +34 -18
  79. package/contracts/bridge/BitcoinTx.sol +231 -9
  80. package/contracts/bridge/Bridge.sol +1592 -211
  81. package/contracts/bridge/BridgeState.sol +714 -0
  82. package/contracts/bridge/Deposit.sol +271 -0
  83. package/contracts/bridge/DepositSweep.sol +571 -0
  84. package/contracts/bridge/EcdsaLib.sol +45 -0
  85. package/contracts/bridge/Fraud.sol +604 -0
  86. package/contracts/bridge/Heartbeat.sol +112 -0
  87. package/contracts/bridge/IRelay.sol +28 -0
  88. package/contracts/bridge/MovingFunds.sol +1080 -0
  89. package/contracts/bridge/Redemption.sol +874 -0
  90. package/contracts/bridge/VendingMachine.sol +1 -1
  91. package/contracts/bridge/Wallets.sol +553 -0
  92. package/contracts/hardhat-dependency-compiler/.hardhat-dependency-compiler +1 -0
  93. package/contracts/hardhat-dependency-compiler/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol +3 -0
  94. package/contracts/hardhat-dependency-compiler/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol +3 -0
  95. package/contracts/token/TBTC.sol +1 -1
  96. package/contracts/vault/DonationVault.sol +125 -0
  97. package/contracts/vault/IVault.sol +32 -10
  98. package/contracts/vault/TBTCVault.sol +20 -2
  99. package/deploy/00_resolve_relay.ts +28 -0
  100. package/deploy/00_resolve_wallet_registry.ts +83 -0
  101. package/deploy/04_deploy_bank.ts +27 -0
  102. package/deploy/05_deploy_bridge.ts +76 -0
  103. package/deploy/06_bank_update_bridge.ts +19 -0
  104. package/deploy/07_transfer_ownership.ts +15 -0
  105. package/deploy/08_transfer_governance.ts +20 -0
  106. package/deploy/09_transfer_proxy_admin_ownership.ts +23 -0
  107. package/deploy/10_deploy_proxy_admin_with_deputy.ts +33 -0
  108. package/export.json +16243 -475
  109. package/package.json +31 -24
  110. package/artifacts/solcInputs/25bea07ad744b8c97e466495ad2abf97.json +0 -128
@@ -0,0 +1,874 @@
1
+ // SPDX-License-Identifier: MIT
2
+
3
+ // ██████████████ ▐████▌ ██████████████
4
+ // ██████████████ ▐████▌ ██████████████
5
+ // ▐████▌ ▐████▌
6
+ // ▐████▌ ▐████▌
7
+ // ██████████████ ▐████▌ ██████████████
8
+ // ██████████████ ▐████▌ ██████████████
9
+ // ▐████▌ ▐████▌
10
+ // ▐████▌ ▐████▌
11
+ // ▐████▌ ▐████▌
12
+ // ▐████▌ ▐████▌
13
+ // ▐████▌ ▐████▌
14
+ // ▐████▌ ▐████▌
15
+
16
+ pragma solidity ^0.8.9;
17
+
18
+ import {BTCUtils} from "@keep-network/bitcoin-spv-sol/contracts/BTCUtils.sol";
19
+ import {BytesLib} from "@keep-network/bitcoin-spv-sol/contracts/BytesLib.sol";
20
+
21
+ import "./BitcoinTx.sol";
22
+ import "./BridgeState.sol";
23
+ import "./Wallets.sol";
24
+
25
+ import "../bank/Bank.sol";
26
+
27
+ /// @notice Aggregates functions common to the redemption transaction proof
28
+ /// validation and to the moving funds transaction proof validation.
29
+ library OutboundTx {
30
+ using BTCUtils for bytes;
31
+
32
+ /// @notice Checks whether an outbound Bitcoin transaction performed from
33
+ /// the given wallet has an input vector that contains a single
34
+ /// input referring to the wallet's main UTXO. Marks that main UTXO
35
+ /// as correctly spent if the validation succeeds. Reverts otherwise.
36
+ /// There are two outbound transactions from a wallet possible: a
37
+ /// redemption transaction or a moving funds to another wallet
38
+ /// transaction.
39
+ /// @param walletOutboundTxInputVector Bitcoin outbound transaction's input
40
+ /// vector. This function assumes vector's structure is valid so it
41
+ /// must be validated using e.g. `BTCUtils.validateVin` function
42
+ /// before it is passed here
43
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
44
+ /// the Ethereum chain.
45
+ /// @param walletPubKeyHash 20-byte public key hash (computed using Bitcoin
46
+ // HASH160 over the compressed ECDSA public key) of the wallet which
47
+ /// performed the outbound transaction.
48
+ function processWalletOutboundTxInput(
49
+ BridgeState.Storage storage self,
50
+ bytes memory walletOutboundTxInputVector,
51
+ BitcoinTx.UTXO calldata mainUtxo,
52
+ bytes20 walletPubKeyHash
53
+ ) internal {
54
+ // Assert that main UTXO for passed wallet exists in storage.
55
+ bytes32 mainUtxoHash = self
56
+ .registeredWallets[walletPubKeyHash]
57
+ .mainUtxoHash;
58
+ require(mainUtxoHash != bytes32(0), "No main UTXO for given wallet");
59
+
60
+ // Assert that passed main UTXO parameter is the same as in storage and
61
+ // can be used for further processing.
62
+ require(
63
+ keccak256(
64
+ abi.encodePacked(
65
+ mainUtxo.txHash,
66
+ mainUtxo.txOutputIndex,
67
+ mainUtxo.txOutputValue
68
+ )
69
+ ) == mainUtxoHash,
70
+ "Invalid main UTXO data"
71
+ );
72
+
73
+ // Assert that the single outbound transaction input actually
74
+ // refers to the wallet's main UTXO.
75
+ (
76
+ bytes32 outpointTxHash,
77
+ uint32 outpointIndex
78
+ ) = parseWalletOutboundTxInput(walletOutboundTxInputVector);
79
+ require(
80
+ mainUtxo.txHash == outpointTxHash &&
81
+ mainUtxo.txOutputIndex == outpointIndex,
82
+ "Outbound transaction input must point to the wallet's main UTXO"
83
+ );
84
+
85
+ // Main UTXO used as an input, mark it as spent.
86
+ self.spentMainUTXOs[
87
+ uint256(
88
+ keccak256(
89
+ abi.encodePacked(mainUtxo.txHash, mainUtxo.txOutputIndex)
90
+ )
91
+ )
92
+ ] = true;
93
+ }
94
+
95
+ /// @notice Parses the input vector of an outbound Bitcoin transaction
96
+ /// performed from the given wallet. It extracts the single input
97
+ /// then the transaction hash and output index from its outpoint.
98
+ /// There are two outbound transactions from a wallet possible: a
99
+ /// redemption transaction or a moving funds to another wallet
100
+ /// transaction.
101
+ /// @param walletOutboundTxInputVector Bitcoin outbound transaction input
102
+ /// vector. This function assumes vector's structure is valid so it
103
+ /// must be validated using e.g. `BTCUtils.validateVin` function
104
+ /// before it is passed here
105
+ /// @return outpointTxHash 32-byte hash of the Bitcoin transaction which is
106
+ /// pointed in the input's outpoint.
107
+ /// @return outpointIndex 4-byte index of the Bitcoin transaction output
108
+ /// which is pointed in the input's outpoint.
109
+ function parseWalletOutboundTxInput(
110
+ bytes memory walletOutboundTxInputVector
111
+ ) internal pure returns (bytes32 outpointTxHash, uint32 outpointIndex) {
112
+ // To determine the total number of Bitcoin transaction inputs,
113
+ // we need to parse the compactSize uint (VarInt) the input vector is
114
+ // prepended by. That compactSize uint encodes the number of vector
115
+ // elements using the format presented in:
116
+ // https://developer.bitcoin.org/reference/transactions.html#compactsize-unsigned-integers
117
+ // We don't need asserting the compactSize uint is parseable since it
118
+ // was already checked during `validateVin` validation.
119
+ // See `BitcoinTx.inputVector` docs for more details.
120
+ (, uint256 inputsCount) = walletOutboundTxInputVector.parseVarInt();
121
+ require(
122
+ inputsCount == 1,
123
+ "Outbound transaction must have a single input"
124
+ );
125
+
126
+ bytes memory input = walletOutboundTxInputVector.extractInputAtIndex(0);
127
+
128
+ outpointTxHash = input.extractInputTxIdLE();
129
+
130
+ outpointIndex = BTCUtils.reverseUint32(
131
+ uint32(input.extractTxIndexLE())
132
+ );
133
+
134
+ // There is only one input in the transaction. Input has an outpoint
135
+ // field that is a reference to the transaction being spent (see
136
+ // `BitcoinTx` docs). The outpoint contains the hash of the transaction
137
+ // to spend (`outpointTxHash`) and the index of the specific output
138
+ // from that transaction (`outpointIndex`).
139
+ return (outpointTxHash, outpointIndex);
140
+ }
141
+ }
142
+
143
+ /// @title Bridge redemption
144
+ /// @notice The library handles the logic for redeeming Bitcoin balances from
145
+ /// the Bridge.
146
+ /// @dev To initiate a redemption, a user with a Bank balance supplies
147
+ /// a Bitcoin address. Then, the system calculates the redemption fee, and
148
+ /// releases balance to the provided Bitcoin address. Just like in case of
149
+ /// sweeps of revealed deposits, redemption requests are processed in
150
+ /// batches and require SPV proof to be submitted to the Bridge.
151
+ library Redemption {
152
+ using BridgeState for BridgeState.Storage;
153
+ using Wallets for BridgeState.Storage;
154
+ using BitcoinTx for BridgeState.Storage;
155
+
156
+ using BTCUtils for bytes;
157
+ using BytesLib for bytes;
158
+
159
+ /// @notice Represents a redemption request.
160
+ struct RedemptionRequest {
161
+ // ETH address of the redeemer who created the request.
162
+ address redeemer;
163
+ // Requested TBTC amount in satoshi.
164
+ uint64 requestedAmount;
165
+ // Treasury TBTC fee in satoshi at the moment of request creation.
166
+ uint64 treasuryFee;
167
+ // Transaction maximum BTC fee in satoshi at the moment of request
168
+ // creation.
169
+ uint64 txMaxFee;
170
+ // UNIX timestamp the request was created at.
171
+ uint32 requestedAt;
172
+ // This struct doesn't contain `__gap` property as the structure is stored
173
+ // in a mapping, mappings store values in different slots and they are
174
+ // not contiguous with other values.
175
+ }
176
+
177
+ /// @notice Represents an outcome of the redemption Bitcoin transaction
178
+ /// outputs processing.
179
+ struct RedemptionTxOutputsInfo {
180
+ // Total TBTC value in satoshi that should be burned by the Bridge.
181
+ // It includes the total amount of all BTC redeemed in the transaction
182
+ // and the fee paid to BTC miners for the redemption transaction.
183
+ uint64 totalBurnableValue;
184
+ // Total TBTC value in satoshi that should be transferred to
185
+ // the treasury. It is a sum of all treasury fees paid by all
186
+ // redeemers included in the redemption transaction.
187
+ uint64 totalTreasuryFee;
188
+ // Index of the change output. The change output becomes
189
+ // the new main wallet's UTXO.
190
+ uint32 changeIndex;
191
+ // Value in satoshi of the change output.
192
+ uint64 changeValue;
193
+ // This struct doesn't contain `__gap` property as the structure is not
194
+ // stored, it is used as a function's memory argument.
195
+ }
196
+
197
+ /// @notice Represents temporary information needed during the processing of
198
+ /// the redemption Bitcoin transaction outputs. This structure is an
199
+ /// internal one and should not be exported outside of the redemption
200
+ /// transaction processing code.
201
+ /// @dev Allows to mitigate "stack too deep" errors on EVM.
202
+ struct RedemptionTxOutputsProcessingInfo {
203
+ // The first output starting index in the transaction.
204
+ uint256 outputStartingIndex;
205
+ // The number of outputs in the transaction.
206
+ uint256 outputsCount;
207
+ // P2PKH script for the wallet. Needed to determine the change output.
208
+ bytes32 walletP2PKHScriptKeccak;
209
+ // P2WPKH script for the wallet. Needed to determine the change output.
210
+ bytes32 walletP2WPKHScriptKeccak;
211
+ // This struct doesn't contain `__gap` property as the structure is not
212
+ // stored, it is used as a function's memory argument.
213
+ }
214
+
215
+ event RedemptionRequested(
216
+ bytes20 indexed walletPubKeyHash,
217
+ bytes redeemerOutputScript,
218
+ address indexed redeemer,
219
+ uint64 requestedAmount,
220
+ uint64 treasuryFee,
221
+ uint64 txMaxFee
222
+ );
223
+
224
+ event RedemptionsCompleted(
225
+ bytes20 indexed walletPubKeyHash,
226
+ bytes32 redemptionTxHash
227
+ );
228
+
229
+ event RedemptionTimedOut(
230
+ bytes20 indexed walletPubKeyHash,
231
+ bytes redeemerOutputScript
232
+ );
233
+
234
+ /// @notice Requests redemption of the given amount from the specified
235
+ /// wallet to the redeemer Bitcoin output script.
236
+ /// @param walletPubKeyHash The 20-byte wallet public key hash (computed
237
+ /// using Bitcoin HASH160 over the compressed ECDSA public key)
238
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
239
+ /// the Ethereum chain
240
+ /// @param redeemerOutputScript The redeemer's length-prefixed output
241
+ /// script (P2PKH, P2WPKH, P2SH or P2WSH) that will be used to lock
242
+ /// redeemed BTC
243
+ /// @param amount Requested amount in satoshi. This is also the TBTC amount
244
+ /// that is taken from redeemer's balance in the Bank upon request.
245
+ /// Once the request is handled, the actual amount of BTC locked
246
+ /// on the redeemer output script will be always lower than this value
247
+ /// since the treasury and Bitcoin transaction fees must be incurred.
248
+ /// The minimal amount satisfying the request can be computed as:
249
+ /// `amount - (amount / redemptionTreasuryFeeDivisor) - redemptionTxMaxFee`.
250
+ /// Fees values are taken at the moment of request creation.
251
+ /// @dev Requirements:
252
+ /// - Wallet behind `walletPubKeyHash` must be live
253
+ /// - `mainUtxo` components must point to the recent main UTXO
254
+ /// of the given wallet, as currently known on the Ethereum chain.
255
+ /// - `redeemerOutputScript` must be a proper Bitcoin script
256
+ /// - `redeemerOutputScript` cannot have wallet PKH as payload
257
+ /// - `amount` must be above or equal the `redemptionDustThreshold`
258
+ /// - Given `walletPubKeyHash` and `redeemerOutputScript` pair can be
259
+ /// used for only one pending request at the same time
260
+ /// - Wallet must have enough Bitcoin balance to proceed the request
261
+ /// - Redeemer must make an allowance in the Bank that the Bridge
262
+ /// contract can spend the given `amount`.
263
+ function requestRedemption(
264
+ BridgeState.Storage storage self,
265
+ bytes20 walletPubKeyHash,
266
+ BitcoinTx.UTXO calldata mainUtxo,
267
+ bytes calldata redeemerOutputScript,
268
+ uint64 amount
269
+ ) external {
270
+ Wallets.Wallet storage wallet = self.registeredWallets[
271
+ walletPubKeyHash
272
+ ];
273
+
274
+ require(
275
+ wallet.state == Wallets.WalletState.Live,
276
+ "Wallet must be in Live state"
277
+ );
278
+
279
+ bytes32 mainUtxoHash = wallet.mainUtxoHash;
280
+ require(
281
+ mainUtxoHash != bytes32(0),
282
+ "No main UTXO for the given wallet"
283
+ );
284
+ require(
285
+ keccak256(
286
+ abi.encodePacked(
287
+ mainUtxo.txHash,
288
+ mainUtxo.txOutputIndex,
289
+ mainUtxo.txOutputValue
290
+ )
291
+ ) == mainUtxoHash,
292
+ "Invalid main UTXO data"
293
+ );
294
+
295
+ // TODO: Confirm if `walletPubKeyHash` should be validated by checking
296
+ // if it is the oldest one who can handle the request. This will
297
+ // be suggested by the dApp but may not be respected by users who
298
+ // interact directly with the contract. Do we need to enforce it
299
+ // here? One option is not to enforce it, to save on gas, but if
300
+ // we see this rule is not respected, upgrade Bridge contract to
301
+ // require it.
302
+
303
+ // Validate if redeemer output script is a correct standard type
304
+ // (P2PKH, P2WPKH, P2SH or P2WSH). This is done by building a stub
305
+ // output with 0 as value and using `BTCUtils.extractHash` on it. Such
306
+ // a function extracts the payload properly only from standard outputs
307
+ // so if it succeeds, we have a guarantee the redeemer output script
308
+ // is proper. Worth to note `extractHash` ignores the value at all
309
+ // so this is why we can use 0 safely. This way of validation is the
310
+ // same as in tBTC v1.
311
+ bytes memory redeemerOutputScriptPayload = abi
312
+ .encodePacked(bytes8(0), redeemerOutputScript)
313
+ .extractHash();
314
+ require(
315
+ redeemerOutputScriptPayload.length > 0,
316
+ "Redeemer output script must be a standard type"
317
+ );
318
+ // Check if the redeemer output script payload does not point to the
319
+ // wallet public key hash.
320
+ require(
321
+ keccak256(abi.encodePacked(walletPubKeyHash)) !=
322
+ keccak256(redeemerOutputScriptPayload),
323
+ "Redeemer output script must not point to the wallet PKH"
324
+ );
325
+
326
+ require(
327
+ amount >= self.redemptionDustThreshold,
328
+ "Redemption amount too small"
329
+ );
330
+
331
+ // The redemption key is built on top of the wallet public key hash
332
+ // and redeemer output script pair. That means there can be only one
333
+ // request asking for redemption from the given wallet to the given
334
+ // BTC script at the same time.
335
+ uint256 redemptionKey = uint256(
336
+ keccak256(abi.encodePacked(walletPubKeyHash, redeemerOutputScript))
337
+ );
338
+
339
+ // Check if given redemption key is not used by a pending redemption.
340
+ // There is no need to check for existence in `timedOutRedemptions`
341
+ // since the wallet's state is changed to other than Live after
342
+ // first time out is reported so making new requests is not possible.
343
+ // slither-disable-next-line incorrect-equality
344
+ require(
345
+ self.pendingRedemptions[redemptionKey].requestedAt == 0,
346
+ "There is a pending redemption request from this wallet to the same address"
347
+ );
348
+
349
+ // No need to check whether `amount - treasuryFee - txMaxFee > 0`
350
+ // since the `redemptionDustThreshold` should force that condition
351
+ // to be always true.
352
+ uint64 treasuryFee = self.redemptionTreasuryFeeDivisor > 0
353
+ ? amount / self.redemptionTreasuryFeeDivisor
354
+ : 0;
355
+ uint64 txMaxFee = self.redemptionTxMaxFee;
356
+
357
+ // The main wallet UTXO's value doesn't include all pending redemptions.
358
+ // To determine if the requested redemption can be performed by the
359
+ // wallet we need to subtract the total value of all pending redemptions
360
+ // from that wallet's main UTXO value. Given that the treasury fee is
361
+ // not redeemed from the wallet, we are subtracting it.
362
+ wallet.pendingRedemptionsValue += amount - treasuryFee;
363
+ require(
364
+ mainUtxo.txOutputValue >= wallet.pendingRedemptionsValue,
365
+ "Insufficient wallet funds"
366
+ );
367
+
368
+ self.pendingRedemptions[redemptionKey] = RedemptionRequest(
369
+ msg.sender,
370
+ amount,
371
+ treasuryFee,
372
+ txMaxFee,
373
+ /* solhint-disable-next-line not-rely-on-time */
374
+ uint32(block.timestamp)
375
+ );
376
+
377
+ emit RedemptionRequested(
378
+ walletPubKeyHash,
379
+ redeemerOutputScript,
380
+ msg.sender,
381
+ amount,
382
+ treasuryFee,
383
+ txMaxFee
384
+ );
385
+
386
+ self.bank.transferBalanceFrom(msg.sender, address(this), amount);
387
+ }
388
+
389
+ /// @notice Used by the wallet to prove the BTC redemption transaction
390
+ /// and to make the necessary bookkeeping. Redemption is only
391
+ /// accepted if it satisfies SPV proof.
392
+ ///
393
+ /// The function is performing Bank balance updates by burning
394
+ /// the total redeemed Bitcoin amount from Bridge balance and
395
+ /// transferring the treasury fee sum to the treasury address.
396
+ ///
397
+ /// It is possible to prove the given redemption only one time.
398
+ /// @param redemptionTx Bitcoin redemption transaction data
399
+ /// @param redemptionProof Bitcoin redemption proof data
400
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
401
+ /// the Ethereum chain
402
+ /// @param walletPubKeyHash 20-byte public key hash (computed using Bitcoin
403
+ /// HASH160 over the compressed ECDSA public key) of the wallet which
404
+ /// performed the redemption transaction
405
+ /// @dev Requirements:
406
+ /// - `redemptionTx` components must match the expected structure. See
407
+ /// `BitcoinTx.Info` docs for reference. Their values must exactly
408
+ /// correspond to appropriate Bitcoin transaction fields to produce
409
+ /// a provable transaction hash.
410
+ /// - The `redemptionTx` should represent a Bitcoin transaction with
411
+ /// exactly 1 input that refers to the wallet's main UTXO. That
412
+ /// transaction should have 1..n outputs handling existing pending
413
+ /// redemption requests or pointing to reported timed out requests.
414
+ /// There can be also 1 optional output representing the
415
+ /// change and pointing back to the 20-byte wallet public key hash.
416
+ /// The change should be always present if the redeemed value sum
417
+ /// is lower than the total wallet's BTC balance.
418
+ /// - `redemptionProof` components must match the expected structure.
419
+ /// See `BitcoinTx.Proof` docs for reference. The `bitcoinHeaders`
420
+ /// field must contain a valid number of block headers, not less
421
+ /// than the `txProofDifficultyFactor` contract constant.
422
+ /// - `mainUtxo` components must point to the recent main UTXO
423
+ /// of the given wallet, as currently known on the Ethereum chain.
424
+ /// Additionally, the recent main UTXO on Ethereum must be set.
425
+ /// - `walletPubKeyHash` must be connected with the main UTXO used
426
+ /// as transaction single input.
427
+ /// Other remarks:
428
+ /// - Putting the change output as the first transaction output can
429
+ /// save some gas because the output processing loop begins each
430
+ /// iteration by checking whether the given output is the change
431
+ /// thus uses some gas for making the comparison. Once the change
432
+ /// is identified, that check is omitted in further iterations.
433
+ function submitRedemptionProof(
434
+ BridgeState.Storage storage self,
435
+ BitcoinTx.Info calldata redemptionTx,
436
+ BitcoinTx.Proof calldata redemptionProof,
437
+ BitcoinTx.UTXO calldata mainUtxo,
438
+ bytes20 walletPubKeyHash
439
+ ) external {
440
+ // The actual transaction proof is performed here. After that point, we
441
+ // can assume the transaction happened on Bitcoin chain and has
442
+ // a sufficient number of confirmations as determined by
443
+ // `txProofDifficultyFactor` constant.
444
+ bytes32 redemptionTxHash = self.validateProof(
445
+ redemptionTx,
446
+ redemptionProof
447
+ );
448
+
449
+ // Process the redemption transaction input. Specifically, check if it
450
+ // refers to the expected wallet's main UTXO.
451
+ OutboundTx.processWalletOutboundTxInput(
452
+ self,
453
+ redemptionTx.inputVector,
454
+ mainUtxo,
455
+ walletPubKeyHash
456
+ );
457
+
458
+ Wallets.Wallet storage wallet = self.registeredWallets[
459
+ walletPubKeyHash
460
+ ];
461
+
462
+ Wallets.WalletState walletState = wallet.state;
463
+ require(
464
+ walletState == Wallets.WalletState.Live ||
465
+ walletState == Wallets.WalletState.MovingFunds,
466
+ "Wallet must be in Live or MovingFunds state"
467
+ );
468
+
469
+ // Process redemption transaction outputs to extract some info required
470
+ // for further processing.
471
+ RedemptionTxOutputsInfo memory outputsInfo = processRedemptionTxOutputs(
472
+ self,
473
+ redemptionTx.outputVector,
474
+ walletPubKeyHash
475
+ );
476
+
477
+ if (outputsInfo.changeValue > 0) {
478
+ // If the change value is grater than zero, it means the change
479
+ // output exists and can be used as new wallet's main UTXO.
480
+ wallet.mainUtxoHash = keccak256(
481
+ abi.encodePacked(
482
+ redemptionTxHash,
483
+ outputsInfo.changeIndex,
484
+ outputsInfo.changeValue
485
+ )
486
+ );
487
+ } else {
488
+ // If the change value is zero, it means the change output doesn't
489
+ // exists and no funds left on the wallet. Delete the main UTXO
490
+ // for that wallet to represent that state in a proper way.
491
+ delete wallet.mainUtxoHash;
492
+ }
493
+
494
+ wallet.pendingRedemptionsValue -= outputsInfo.totalBurnableValue;
495
+
496
+ emit RedemptionsCompleted(walletPubKeyHash, redemptionTxHash);
497
+
498
+ self.bank.decreaseBalance(outputsInfo.totalBurnableValue);
499
+ self.bank.transferBalance(self.treasury, outputsInfo.totalTreasuryFee);
500
+ }
501
+
502
+ /// @notice Processes the Bitcoin redemption transaction output vector.
503
+ /// It extracts each output and tries to identify it as a pending
504
+ /// redemption request, reported timed out request, or change.
505
+ /// Reverts if one of the outputs cannot be recognized properly.
506
+ /// This function also marks each request as processed by removing
507
+ /// them from `pendingRedemptions` mapping.
508
+ /// @param redemptionTxOutputVector Bitcoin redemption transaction output
509
+ /// vector. This function assumes vector's structure is valid so it
510
+ /// must be validated using e.g. `BTCUtils.validateVout` function
511
+ /// before it is passed here
512
+ /// @param walletPubKeyHash 20-byte public key hash (computed using Bitcoin
513
+ // HASH160 over the compressed ECDSA public key) of the wallet which
514
+ /// performed the redemption transaction.
515
+ /// @return info Outcomes of the processing.
516
+ function processRedemptionTxOutputs(
517
+ BridgeState.Storage storage self,
518
+ bytes memory redemptionTxOutputVector,
519
+ bytes20 walletPubKeyHash
520
+ ) internal returns (RedemptionTxOutputsInfo memory info) {
521
+ // Determining the total number of redemption transaction outputs in
522
+ // the same way as for number of inputs. See `BitcoinTx.outputVector`
523
+ // docs for more details.
524
+ (
525
+ uint256 outputsCompactSizeUintLength,
526
+ uint256 outputsCount
527
+ ) = redemptionTxOutputVector.parseVarInt();
528
+
529
+ // To determine the first output starting index, we must jump over
530
+ // the compactSize uint which prepends the output vector. One byte
531
+ // must be added because `BtcUtils.parseVarInt` does not include
532
+ // compactSize uint tag in the returned length.
533
+ //
534
+ // For >= 0 && <= 252, `BTCUtils.determineVarIntDataLengthAt`
535
+ // returns `0`, so we jump over one byte of compactSize uint.
536
+ //
537
+ // For >= 253 && <= 0xffff there is `0xfd` tag,
538
+ // `BTCUtils.determineVarIntDataLengthAt` returns `2` (no
539
+ // tag byte included) so we need to jump over 1+2 bytes of
540
+ // compactSize uint.
541
+ //
542
+ // Please refer `BTCUtils` library and compactSize uint
543
+ // docs in `BitcoinTx` library for more details.
544
+ uint256 outputStartingIndex = 1 + outputsCompactSizeUintLength;
545
+
546
+ // Calculate the keccak256 for two possible wallet's P2PKH or P2WPKH
547
+ // scripts that can be used to lock the change. This is done upfront to
548
+ // save on gas. Both scripts have a strict format defined by Bitcoin.
549
+ //
550
+ // The P2PKH script has the byte format: <0x1976a914> <20-byte PKH> <0x88ac>.
551
+ // According to https://en.bitcoin.it/wiki/Script#Opcodes this translates to:
552
+ // - 0x19: Byte length of the entire script
553
+ // - 0x76: OP_DUP
554
+ // - 0xa9: OP_HASH160
555
+ // - 0x14: Byte length of the public key hash
556
+ // - 0x88: OP_EQUALVERIFY
557
+ // - 0xac: OP_CHECKSIG
558
+ // which matches the P2PKH structure as per:
559
+ // https://en.bitcoin.it/wiki/Transaction#Pay-to-PubkeyHash
560
+ bytes32 walletP2PKHScriptKeccak = keccak256(
561
+ abi.encodePacked(hex"1976a914", walletPubKeyHash, hex"88ac")
562
+ );
563
+ // The P2WPKH script has the byte format: <0x160014> <20-byte PKH>.
564
+ // According to https://en.bitcoin.it/wiki/Script#Opcodes this translates to:
565
+ // - 0x16: Byte length of the entire script
566
+ // - 0x00: OP_0
567
+ // - 0x14: Byte length of the public key hash
568
+ // which matches the P2WPKH structure as per:
569
+ // https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#P2WPKH
570
+ bytes32 walletP2WPKHScriptKeccak = keccak256(
571
+ abi.encodePacked(hex"160014", walletPubKeyHash)
572
+ );
573
+
574
+ return
575
+ processRedemptionTxOutputs(
576
+ self,
577
+ redemptionTxOutputVector,
578
+ walletPubKeyHash,
579
+ RedemptionTxOutputsProcessingInfo(
580
+ outputStartingIndex,
581
+ outputsCount,
582
+ walletP2PKHScriptKeccak,
583
+ walletP2WPKHScriptKeccak
584
+ )
585
+ );
586
+ }
587
+
588
+ /// @notice Processes all outputs from the redemption transaction. Tries to
589
+ /// identify output as a change output, pending redemption request
590
+ // or reported redemption. Reverts if one of the outputs cannot be
591
+ /// recognized properly. Marks each request as processed by removing
592
+ /// them from `pendingRedemptions` mapping.
593
+ /// @param redemptionTxOutputVector Bitcoin redemption transaction output
594
+ /// vector. This function assumes vector's structure is valid so it
595
+ /// must be validated using e.g. `BTCUtils.validateVout` function
596
+ /// before it is passed here
597
+ /// @param walletPubKeyHash 20-byte public key hash (computed using Bitcoin
598
+ // HASH160 over the compressed ECDSA public key) of the wallet which
599
+ /// performed the redemption transaction.
600
+ /// @param processInfo RedemptionTxOutputsProcessingInfo identifying output
601
+ /// starting index, the number of outputs and possible wallet change
602
+ /// P2PKH and P2WPKH scripts.
603
+ function processRedemptionTxOutputs(
604
+ BridgeState.Storage storage self,
605
+ bytes memory redemptionTxOutputVector,
606
+ bytes20 walletPubKeyHash,
607
+ RedemptionTxOutputsProcessingInfo memory processInfo
608
+ ) internal returns (RedemptionTxOutputsInfo memory resultInfo) {
609
+ // Helper flag indicating whether there was at least one redemption
610
+ // output present (redemption must be either pending or reported as
611
+ // timed out).
612
+ bool redemptionPresent = false;
613
+
614
+ // Outputs processing loop.
615
+ for (uint256 i = 0; i < processInfo.outputsCount; i++) {
616
+ // TODO: Check if we can optimize gas costs by adding
617
+ // `extractValueAt` and `extractHashAt` in `bitcoin-spv-sol`
618
+ // in order to avoid allocating bytes in memory.
619
+ uint256 outputLength = redemptionTxOutputVector
620
+ .determineOutputLengthAt(processInfo.outputStartingIndex);
621
+ bytes memory output = redemptionTxOutputVector.slice(
622
+ processInfo.outputStartingIndex,
623
+ outputLength
624
+ );
625
+
626
+ // Extract the value from given output.
627
+ uint64 outputValue = output.extractValue();
628
+ // The output consists of an 8-byte value and a variable length
629
+ // script. To extract that script we slice the output starting from
630
+ // 9th byte until the end.
631
+ bytes memory outputScript = output.slice(8, output.length - 8);
632
+
633
+ if (
634
+ resultInfo.changeValue == 0 &&
635
+ (keccak256(outputScript) ==
636
+ processInfo.walletP2PKHScriptKeccak ||
637
+ keccak256(outputScript) ==
638
+ processInfo.walletP2WPKHScriptKeccak) &&
639
+ outputValue > 0
640
+ ) {
641
+ // If we entered here, that means the change output with a
642
+ // proper non-zero value was found.
643
+ resultInfo.changeIndex = uint32(i);
644
+ resultInfo.changeValue = outputValue;
645
+ } else {
646
+ // If we entered here, that the means the given output is
647
+ // supposed to represent a redemption.
648
+ (
649
+ uint64 burnableValue,
650
+ uint64 treasuryFee
651
+ ) = processNonChangeRedemptionTxOutput(
652
+ self,
653
+ walletPubKeyHash,
654
+ outputScript,
655
+ outputValue
656
+ );
657
+ resultInfo.totalBurnableValue += burnableValue;
658
+ resultInfo.totalTreasuryFee += treasuryFee;
659
+ redemptionPresent = true;
660
+ }
661
+
662
+ // Make the `outputStartingIndex` pointing to the next output by
663
+ // increasing it by current output's length.
664
+ processInfo.outputStartingIndex += outputLength;
665
+ }
666
+
667
+ // Protect against the cases when there is only a single change output
668
+ // referring back to the wallet PKH and just burning main UTXO value
669
+ // for transaction fees.
670
+ require(
671
+ redemptionPresent,
672
+ "Redemption transaction must process at least one redemption"
673
+ );
674
+ }
675
+
676
+ /// @notice Processes a single redemption transaction output. Tries to
677
+ /// identify output as a pending redemption request or reported
678
+ /// redemption timeout. Output script passed to this function must
679
+ /// not be the change output. Such output needs to be identified
680
+ /// separately before calling this function.
681
+ /// Reverts if output is neither requested pending redemption nor
682
+ /// requested and reported timed-out redemption.
683
+ /// This function also marks each pending request as processed by
684
+ /// removing them from `pendingRedemptions` mapping.
685
+ /// @param walletPubKeyHash 20-byte public key hash (computed using Bitcoin
686
+ // HASH160 over the compressed ECDSA public key) of the wallet which
687
+ /// performed the redemption transaction.
688
+ /// @param outputScript Non-change output script to be processed
689
+ /// @param outputValue Value of the output being processed
690
+ /// @return burnableValue The value burnable as a result of processing this
691
+ /// single redemption output. This value needs to be summed up with
692
+ /// burnable values of all other outputs to evaluate total burnable
693
+ /// value for the entire redemption transaction. This value is 0
694
+ /// for a timed-out redemption request.
695
+ /// @return treasuryFee The treasury fee from this single redemption output.
696
+ /// This value needs to be summed up with treasury fees of all other
697
+ /// outputs to evaluate the total treasury fee for the entire
698
+ /// redemption transaction. This value is 0 for a timed-out
699
+ /// redemption request.
700
+ function processNonChangeRedemptionTxOutput(
701
+ BridgeState.Storage storage self,
702
+ bytes20 walletPubKeyHash,
703
+ bytes memory outputScript,
704
+ uint64 outputValue
705
+ ) internal returns (uint64 burnableValue, uint64 treasuryFee) {
706
+ // This function should be called only if the given output is
707
+ // supposed to represent a redemption. Build the redemption key
708
+ // to perform that check.
709
+ uint256 redemptionKey = uint256(
710
+ keccak256(abi.encodePacked(walletPubKeyHash, outputScript))
711
+ );
712
+
713
+ if (self.pendingRedemptions[redemptionKey].requestedAt != 0) {
714
+ // If we entered here, that means the output was identified
715
+ // as a pending redemption request.
716
+ RedemptionRequest storage request = self.pendingRedemptions[
717
+ redemptionKey
718
+ ];
719
+ // Compute the request's redeemable amount as the requested
720
+ // amount reduced by the treasury fee. The request's
721
+ // minimal amount is then the redeemable amount reduced by
722
+ // the maximum transaction fee.
723
+ uint64 redeemableAmount = request.requestedAmount -
724
+ request.treasuryFee;
725
+ // Output value must fit between the request's redeemable
726
+ // and minimal amounts to be deemed valid.
727
+ require(
728
+ redeemableAmount - request.txMaxFee <= outputValue &&
729
+ outputValue <= redeemableAmount,
730
+ "Output value is not within the acceptable range of the pending request"
731
+ );
732
+ // Add the redeemable amount to the total burnable value
733
+ // the Bridge will use to decrease its balance in the Bank.
734
+ burnableValue = redeemableAmount;
735
+ // Add the request's treasury fee to the total treasury fee
736
+ // value the Bridge will transfer to the treasury.
737
+ treasuryFee = request.treasuryFee;
738
+ // Request was properly handled so remove its redemption
739
+ // key from the mapping to make it reusable for further
740
+ // requests.
741
+ delete self.pendingRedemptions[redemptionKey];
742
+ } else {
743
+ // If we entered here, the output is not a redemption
744
+ // request but there is still a chance the given output is
745
+ // related to a reported timed out redemption request.
746
+ // If so, check if the output value matches the request
747
+ // amount to confirm this is an overdue request fulfillment
748
+ // then bypass this output and process the subsequent
749
+ // ones. That also means the wallet was already punished
750
+ // for the inactivity. Otherwise, just revert.
751
+ RedemptionRequest storage request = self.timedOutRedemptions[
752
+ redemptionKey
753
+ ];
754
+
755
+ require(
756
+ request.requestedAt != 0,
757
+ "Output is a non-requested redemption"
758
+ );
759
+
760
+ uint64 redeemableAmount = request.requestedAmount -
761
+ request.treasuryFee;
762
+
763
+ require(
764
+ redeemableAmount - request.txMaxFee <= outputValue &&
765
+ outputValue <= redeemableAmount,
766
+ "Output value is not within the acceptable range of the timed out request"
767
+ );
768
+ }
769
+ }
770
+
771
+ /// @notice Notifies that there is a pending redemption request associated
772
+ /// with the given wallet, that has timed out. The redemption
773
+ /// request is identified by the key built as
774
+ /// `keccak256(walletPubKeyHash | redeemerOutputScript)`.
775
+ /// The results of calling this function:
776
+ /// - the pending redemptions value for the wallet will be decreased
777
+ /// by the requested amount (minus treasury fee),
778
+ /// - the tokens taken from the redeemer on redemption request will
779
+ /// be returned to the redeemer,
780
+ /// - the request will be moved from pending redemptions to
781
+ /// timed-out redemptions,
782
+ /// - if the state of the wallet is `Live` or `MovingFunds`, the
783
+ /// wallet operators will be slashed and the notifier will be
784
+ /// rewarded,
785
+ /// - if the state of wallet is `Live`, the wallet will be closed or
786
+ /// marked as `MovingFunds` (depending on the presence or absence
787
+ /// of the wallet's main UTXO) and the wallet will no longer be
788
+ /// marked as the active wallet (if it was marked as such).
789
+ /// @param walletPubKeyHash 20-byte public key hash of the wallet
790
+ /// @param walletMembersIDs Identifiers of the wallet signing group members
791
+ /// @param redeemerOutputScript The redeemer's length-prefixed output
792
+ /// script (P2PKH, P2WPKH, P2SH or P2WSH)
793
+ /// @dev Requirements:
794
+ /// - The wallet must be in the Live or MovingFunds or Terminated state
795
+ /// - The redemption request identified by `walletPubKeyHash` and
796
+ /// `redeemerOutputScript` must exist
797
+ /// - The expression `keccak256(abi.encode(walletMembersIDs))` must
798
+ /// be exactly the same as the hash stored under `membersIdsHash`
799
+ /// for the given `walletID`. Those IDs are not directly stored
800
+ /// in the contract for gas efficiency purposes but they can be
801
+ /// read from appropriate `DkgResultSubmitted` and `DkgResultApproved`
802
+ /// events of the `WalletRegistry` contract
803
+ /// - The amount of time defined by `redemptionTimeout` must have
804
+ /// passed since the redemption was requested (the request must be
805
+ /// timed-out)
806
+ function notifyRedemptionTimeout(
807
+ BridgeState.Storage storage self,
808
+ bytes20 walletPubKeyHash,
809
+ uint32[] calldata walletMembersIDs,
810
+ bytes calldata redeemerOutputScript
811
+ ) external {
812
+ uint256 redemptionKey = uint256(
813
+ keccak256(abi.encodePacked(walletPubKeyHash, redeemerOutputScript))
814
+ );
815
+ Redemption.RedemptionRequest memory request = self.pendingRedemptions[
816
+ redemptionKey
817
+ ];
818
+
819
+ require(request.requestedAt > 0, "Redemption request does not exist");
820
+ require(
821
+ /* solhint-disable-next-line not-rely-on-time */
822
+ request.requestedAt + self.redemptionTimeout < block.timestamp,
823
+ "Redemption request has not timed out"
824
+ );
825
+
826
+ // Update the wallet's pending redemptions value
827
+ Wallets.Wallet storage wallet = self.registeredWallets[
828
+ walletPubKeyHash
829
+ ];
830
+ wallet.pendingRedemptionsValue -=
831
+ request.requestedAmount -
832
+ request.treasuryFee;
833
+
834
+ require(
835
+ wallet.state == Wallets.WalletState.Live ||
836
+ wallet.state == Wallets.WalletState.MovingFunds ||
837
+ wallet.state == Wallets.WalletState.Terminated,
838
+ "The wallet must be in Live, MovingFunds or Terminated state"
839
+ );
840
+
841
+ // It is worth noting that there is no need to check if
842
+ // `timedOutRedemption` mapping already contains the given redemption
843
+ // key. There is no possibility to re-use a key of a reported timed-out
844
+ // redemption because the wallet responsible for causing the timeout is
845
+ // moved to a state that prevents it to receive new redemption requests.
846
+
847
+ // Move the redemption from pending redemptions to timed-out redemptions
848
+ self.timedOutRedemptions[redemptionKey] = request;
849
+ delete self.pendingRedemptions[redemptionKey];
850
+
851
+ if (
852
+ wallet.state == Wallets.WalletState.Live ||
853
+ wallet.state == Wallets.WalletState.MovingFunds
854
+ ) {
855
+ // Propagate timeout consequences to the wallet
856
+ self.notifyWalletTimedOutRedemption(walletPubKeyHash);
857
+
858
+ // Slash the wallet operators and reward the notifier
859
+ self.ecdsaWalletRegistry.seize(
860
+ self.redemptionTimeoutSlashingAmount,
861
+ self.redemptionTimeoutNotifierRewardMultiplier,
862
+ msg.sender,
863
+ wallet.ecdsaWalletID,
864
+ walletMembersIDs
865
+ );
866
+ }
867
+
868
+ // slither-disable-next-line reentrancy-events
869
+ emit RedemptionTimedOut(walletPubKeyHash, redeemerOutputScript);
870
+
871
+ // Return the requested amount of tokens to the redeemer
872
+ self.bank.transferBalance(request.redeemer, request.requestedAmount);
873
+ }
874
+ }