@keep-network/tbtc-v2 0.1.1-dev.8 → 0.1.1-dev.80

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 (112) hide show
  1. package/README.adoc +12 -0
  2. package/artifacts/Bank.json +757 -0
  3. package/artifacts/Bridge.json +2644 -0
  4. package/artifacts/Deposit.json +117 -0
  5. package/artifacts/DepositSweep.json +77 -0
  6. package/artifacts/EcdsaDkgValidator.json +532 -0
  7. package/artifacts/EcdsaInactivity.json +156 -0
  8. package/artifacts/EcdsaSortitionPool.json +1004 -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/T.json +1148 -0
  22. package/artifacts/TBTC.json +27 -26
  23. package/artifacts/TBTCToken.json +27 -26
  24. package/artifacts/TBTCVault.json +462 -0
  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 +1843 -0
  32. package/artifacts/WalletRegistryGovernance.json +2754 -0
  33. package/artifacts/Wallets.json +186 -0
  34. package/artifacts/solcInputs/4f6d4f5cd1e3d835e20ed55926a445cd.json +311 -0
  35. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
  36. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.json +2 -2
  37. package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
  38. package/build/contracts/bank/Bank.sol/Bank.json +25 -2
  39. package/build/contracts/bank/IReceiveBalanceApproval.sol/IReceiveBalanceApproval.dbg.json +4 -0
  40. package/build/contracts/bank/IReceiveBalanceApproval.sol/IReceiveBalanceApproval.json +34 -0
  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 +2516 -196
  45. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +4 -0
  46. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +226 -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 +108 -0
  73. package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
  74. package/build/contracts/vault/IVault.sol/IVault.json +24 -1
  75. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
  76. package/build/contracts/vault/TBTCVault.sol/TBTCVault.json +126 -7
  77. package/contracts/GovernanceUtils.sol +4 -4
  78. package/contracts/bank/Bank.sol +45 -20
  79. package/contracts/bank/IReceiveBalanceApproval.sol +45 -0
  80. package/contracts/bridge/BitcoinTx.sol +232 -10
  81. package/contracts/bridge/Bridge.sol +1601 -244
  82. package/contracts/bridge/BridgeState.sol +739 -0
  83. package/contracts/bridge/Deposit.sol +269 -0
  84. package/contracts/bridge/DepositSweep.sol +571 -0
  85. package/contracts/bridge/EcdsaLib.sol +45 -0
  86. package/contracts/bridge/Fraud.sol +604 -0
  87. package/contracts/bridge/Heartbeat.sol +112 -0
  88. package/contracts/bridge/IRelay.sol +28 -0
  89. package/contracts/bridge/MovingFunds.sol +1089 -0
  90. package/contracts/bridge/Redemption.sol +867 -0
  91. package/contracts/bridge/VendingMachine.sol +1 -1
  92. package/contracts/bridge/Wallets.sol +553 -0
  93. package/contracts/hardhat-dependency-compiler/.hardhat-dependency-compiler +1 -0
  94. package/contracts/hardhat-dependency-compiler/@keep-network/ecdsa/contracts/WalletRegistry.sol +3 -0
  95. package/contracts/hardhat-dependency-compiler/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol +3 -0
  96. package/contracts/hardhat-dependency-compiler/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol +3 -0
  97. package/contracts/token/TBTC.sol +1 -1
  98. package/contracts/vault/DonationVault.sol +125 -0
  99. package/contracts/vault/IVault.sol +19 -13
  100. package/contracts/vault/TBTCVault.sol +58 -8
  101. package/deploy/00_resolve_relay.ts +28 -0
  102. package/deploy/04_deploy_bank.ts +27 -0
  103. package/deploy/05_deploy_bridge.ts +80 -0
  104. package/deploy/06_deploy_tbtc_vault.ts +30 -0
  105. package/deploy/07_bank_update_bridge.ts +19 -0
  106. package/deploy/08_transfer_ownership.ts +15 -0
  107. package/deploy/09_transfer_governance.ts +20 -0
  108. package/deploy/10_transfer_proxy_admin_ownership.ts +30 -0
  109. package/deploy/11_deploy_proxy_admin_with_deputy.ts +33 -0
  110. package/export.json +15993 -475
  111. package/package.json +32 -25
  112. package/artifacts/solcInputs/4cf328e09411ac69d75a3c381680bc2c.json +0 -128
@@ -0,0 +1,867 @@
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
+ // Validate if redeemer output script is a correct standard type
296
+ // (P2PKH, P2WPKH, P2SH or P2WSH). This is done by building a stub
297
+ // output with 0 as value and using `BTCUtils.extractHash` on it. Such
298
+ // a function extracts the payload properly only from standard outputs
299
+ // so if it succeeds, we have a guarantee the redeemer output script
300
+ // is proper. Worth to note `extractHash` ignores the value at all
301
+ // so this is why we can use 0 safely. This way of validation is the
302
+ // same as in tBTC v1.
303
+ bytes memory redeemerOutputScriptPayload = abi
304
+ .encodePacked(bytes8(0), redeemerOutputScript)
305
+ .extractHash();
306
+ require(
307
+ redeemerOutputScriptPayload.length > 0,
308
+ "Redeemer output script must be a standard type"
309
+ );
310
+ // Check if the redeemer output script payload does not point to the
311
+ // wallet public key hash.
312
+ require(
313
+ keccak256(abi.encodePacked(walletPubKeyHash)) !=
314
+ keccak256(redeemerOutputScriptPayload),
315
+ "Redeemer output script must not point to the wallet PKH"
316
+ );
317
+
318
+ require(
319
+ amount >= self.redemptionDustThreshold,
320
+ "Redemption amount too small"
321
+ );
322
+
323
+ // The redemption key is built on top of the wallet public key hash
324
+ // and redeemer output script pair. That means there can be only one
325
+ // request asking for redemption from the given wallet to the given
326
+ // BTC script at the same time.
327
+ uint256 redemptionKey = uint256(
328
+ keccak256(abi.encodePacked(walletPubKeyHash, redeemerOutputScript))
329
+ );
330
+
331
+ // Check if given redemption key is not used by a pending redemption.
332
+ // There is no need to check for existence in `timedOutRedemptions`
333
+ // since the wallet's state is changed to other than Live after
334
+ // first time out is reported so making new requests is not possible.
335
+ // slither-disable-next-line incorrect-equality
336
+ require(
337
+ self.pendingRedemptions[redemptionKey].requestedAt == 0,
338
+ "There is a pending redemption request from this wallet to the same address"
339
+ );
340
+
341
+ // No need to check whether `amount - treasuryFee - txMaxFee > 0`
342
+ // since the `redemptionDustThreshold` should force that condition
343
+ // to be always true.
344
+ uint64 treasuryFee = self.redemptionTreasuryFeeDivisor > 0
345
+ ? amount / self.redemptionTreasuryFeeDivisor
346
+ : 0;
347
+ uint64 txMaxFee = self.redemptionTxMaxFee;
348
+
349
+ // The main wallet UTXO's value doesn't include all pending redemptions.
350
+ // To determine if the requested redemption can be performed by the
351
+ // wallet we need to subtract the total value of all pending redemptions
352
+ // from that wallet's main UTXO value. Given that the treasury fee is
353
+ // not redeemed from the wallet, we are subtracting it.
354
+ wallet.pendingRedemptionsValue += amount - treasuryFee;
355
+ require(
356
+ mainUtxo.txOutputValue >= wallet.pendingRedemptionsValue,
357
+ "Insufficient wallet funds"
358
+ );
359
+
360
+ self.pendingRedemptions[redemptionKey] = RedemptionRequest(
361
+ msg.sender,
362
+ amount,
363
+ treasuryFee,
364
+ txMaxFee,
365
+ /* solhint-disable-next-line not-rely-on-time */
366
+ uint32(block.timestamp)
367
+ );
368
+
369
+ emit RedemptionRequested(
370
+ walletPubKeyHash,
371
+ redeemerOutputScript,
372
+ msg.sender,
373
+ amount,
374
+ treasuryFee,
375
+ txMaxFee
376
+ );
377
+
378
+ self.bank.transferBalanceFrom(msg.sender, address(this), amount);
379
+ }
380
+
381
+ /// @notice Used by the wallet to prove the BTC redemption transaction
382
+ /// and to make the necessary bookkeeping. Redemption is only
383
+ /// accepted if it satisfies SPV proof.
384
+ ///
385
+ /// The function is performing Bank balance updates by burning
386
+ /// the total redeemed Bitcoin amount from Bridge balance and
387
+ /// transferring the treasury fee sum to the treasury address.
388
+ ///
389
+ /// It is possible to prove the given redemption only one time.
390
+ /// @param redemptionTx Bitcoin redemption transaction data.
391
+ /// @param redemptionProof Bitcoin redemption proof data.
392
+ /// @param mainUtxo Data of the wallet's main UTXO, as currently known on
393
+ /// the Ethereum chain.
394
+ /// @param walletPubKeyHash 20-byte public key hash (computed using Bitcoin
395
+ /// HASH160 over the compressed ECDSA public key) of the wallet which
396
+ /// performed the redemption transaction.
397
+ /// @dev Requirements:
398
+ /// - `redemptionTx` components must match the expected structure. See
399
+ /// `BitcoinTx.Info` docs for reference. Their values must exactly
400
+ /// correspond to appropriate Bitcoin transaction fields to produce
401
+ /// a provable transaction hash,
402
+ /// - The `redemptionTx` should represent a Bitcoin transaction with
403
+ /// exactly 1 input that refers to the wallet's main UTXO. That
404
+ /// transaction should have 1..n outputs handling existing pending
405
+ /// redemption requests or pointing to reported timed out requests.
406
+ /// There can be also 1 optional output representing the
407
+ /// change and pointing back to the 20-byte wallet public key hash.
408
+ /// The change should be always present if the redeemed value sum
409
+ /// is lower than the total wallet's BTC balance,
410
+ /// - `redemptionProof` components must match the expected structure.
411
+ /// See `BitcoinTx.Proof` docs for reference. The `bitcoinHeaders`
412
+ /// field must contain a valid number of block headers, not less
413
+ /// than the `txProofDifficultyFactor` contract constant,
414
+ /// - `mainUtxo` components must point to the recent main UTXO
415
+ /// of the given wallet, as currently known on the Ethereum chain.
416
+ /// Additionally, the recent main UTXO on Ethereum must be set,
417
+ /// - `walletPubKeyHash` must be connected with the main UTXO used
418
+ /// as transaction single input.
419
+ /// Other remarks:
420
+ /// - Putting the change output as the first transaction output can
421
+ /// save some gas because the output processing loop begins each
422
+ /// iteration by checking whether the given output is the change
423
+ /// thus uses some gas for making the comparison. Once the change
424
+ /// is identified, that check is omitted in further iterations.
425
+ function submitRedemptionProof(
426
+ BridgeState.Storage storage self,
427
+ BitcoinTx.Info calldata redemptionTx,
428
+ BitcoinTx.Proof calldata redemptionProof,
429
+ BitcoinTx.UTXO calldata mainUtxo,
430
+ bytes20 walletPubKeyHash
431
+ ) external {
432
+ // The actual transaction proof is performed here. After that point, we
433
+ // can assume the transaction happened on Bitcoin chain and has
434
+ // a sufficient number of confirmations as determined by
435
+ // `txProofDifficultyFactor` constant.
436
+ bytes32 redemptionTxHash = self.validateProof(
437
+ redemptionTx,
438
+ redemptionProof
439
+ );
440
+
441
+ // Process the redemption transaction input. Specifically, check if it
442
+ // refers to the expected wallet's main UTXO.
443
+ OutboundTx.processWalletOutboundTxInput(
444
+ self,
445
+ redemptionTx.inputVector,
446
+ mainUtxo,
447
+ walletPubKeyHash
448
+ );
449
+
450
+ Wallets.Wallet storage wallet = self.registeredWallets[
451
+ walletPubKeyHash
452
+ ];
453
+
454
+ Wallets.WalletState walletState = wallet.state;
455
+ require(
456
+ walletState == Wallets.WalletState.Live ||
457
+ walletState == Wallets.WalletState.MovingFunds,
458
+ "Wallet must be in Live or MovingFunds state"
459
+ );
460
+
461
+ // Process redemption transaction outputs to extract some info required
462
+ // for further processing.
463
+ RedemptionTxOutputsInfo memory outputsInfo = processRedemptionTxOutputs(
464
+ self,
465
+ redemptionTx.outputVector,
466
+ walletPubKeyHash
467
+ );
468
+
469
+ if (outputsInfo.changeValue > 0) {
470
+ // If the change value is grater than zero, it means the change
471
+ // output exists and can be used as new wallet's main UTXO.
472
+ wallet.mainUtxoHash = keccak256(
473
+ abi.encodePacked(
474
+ redemptionTxHash,
475
+ outputsInfo.changeIndex,
476
+ outputsInfo.changeValue
477
+ )
478
+ );
479
+ } else {
480
+ // If the change value is zero, it means the change output doesn't
481
+ // exists and no funds left on the wallet. Delete the main UTXO
482
+ // for that wallet to represent that state in a proper way.
483
+ delete wallet.mainUtxoHash;
484
+ }
485
+
486
+ wallet.pendingRedemptionsValue -= outputsInfo.totalBurnableValue;
487
+
488
+ emit RedemptionsCompleted(walletPubKeyHash, redemptionTxHash);
489
+
490
+ self.bank.decreaseBalance(outputsInfo.totalBurnableValue);
491
+ self.bank.transferBalance(self.treasury, outputsInfo.totalTreasuryFee);
492
+ }
493
+
494
+ /// @notice Processes the Bitcoin redemption transaction output vector.
495
+ /// It extracts each output and tries to identify it as a pending
496
+ /// redemption request, reported timed out request, or change.
497
+ /// Reverts if one of the outputs cannot be recognized properly.
498
+ /// This function also marks each request as processed by removing
499
+ /// them from `pendingRedemptions` mapping.
500
+ /// @param redemptionTxOutputVector Bitcoin redemption transaction output
501
+ /// vector. This function assumes vector's structure is valid so it
502
+ /// must be validated using e.g. `BTCUtils.validateVout` function
503
+ /// before it is passed here.
504
+ /// @param walletPubKeyHash 20-byte public key hash (computed using Bitcoin
505
+ // HASH160 over the compressed ECDSA public key) of the wallet which
506
+ /// performed the redemption transaction.
507
+ /// @return info Outcomes of the processing.
508
+ function processRedemptionTxOutputs(
509
+ BridgeState.Storage storage self,
510
+ bytes memory redemptionTxOutputVector,
511
+ bytes20 walletPubKeyHash
512
+ ) internal returns (RedemptionTxOutputsInfo memory info) {
513
+ // Determining the total number of redemption transaction outputs in
514
+ // the same way as for number of inputs. See `BitcoinTx.outputVector`
515
+ // docs for more details.
516
+ (
517
+ uint256 outputsCompactSizeUintLength,
518
+ uint256 outputsCount
519
+ ) = redemptionTxOutputVector.parseVarInt();
520
+
521
+ // To determine the first output starting index, we must jump over
522
+ // the compactSize uint which prepends the output vector. One byte
523
+ // must be added because `BtcUtils.parseVarInt` does not include
524
+ // compactSize uint tag in the returned length.
525
+ //
526
+ // For >= 0 && <= 252, `BTCUtils.determineVarIntDataLengthAt`
527
+ // returns `0`, so we jump over one byte of compactSize uint.
528
+ //
529
+ // For >= 253 && <= 0xffff there is `0xfd` tag,
530
+ // `BTCUtils.determineVarIntDataLengthAt` returns `2` (no
531
+ // tag byte included) so we need to jump over 1+2 bytes of
532
+ // compactSize uint.
533
+ //
534
+ // Please refer `BTCUtils` library and compactSize uint
535
+ // docs in `BitcoinTx` library for more details.
536
+ uint256 outputStartingIndex = 1 + outputsCompactSizeUintLength;
537
+
538
+ // Calculate the keccak256 for two possible wallet's P2PKH or P2WPKH
539
+ // scripts that can be used to lock the change. This is done upfront to
540
+ // save on gas. Both scripts have a strict format defined by Bitcoin.
541
+ //
542
+ // The P2PKH script has the byte format: <0x1976a914> <20-byte PKH> <0x88ac>.
543
+ // According to https://en.bitcoin.it/wiki/Script#Opcodes this translates to:
544
+ // - 0x19: Byte length of the entire script
545
+ // - 0x76: OP_DUP
546
+ // - 0xa9: OP_HASH160
547
+ // - 0x14: Byte length of the public key hash
548
+ // - 0x88: OP_EQUALVERIFY
549
+ // - 0xac: OP_CHECKSIG
550
+ // which matches the P2PKH structure as per:
551
+ // https://en.bitcoin.it/wiki/Transaction#Pay-to-PubkeyHash
552
+ bytes32 walletP2PKHScriptKeccak = keccak256(
553
+ abi.encodePacked(hex"1976a914", walletPubKeyHash, hex"88ac")
554
+ );
555
+ // The P2WPKH script has the byte format: <0x160014> <20-byte PKH>.
556
+ // According to https://en.bitcoin.it/wiki/Script#Opcodes this translates to:
557
+ // - 0x16: Byte length of the entire script
558
+ // - 0x00: OP_0
559
+ // - 0x14: Byte length of the public key hash
560
+ // which matches the P2WPKH structure as per:
561
+ // https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#P2WPKH
562
+ bytes32 walletP2WPKHScriptKeccak = keccak256(
563
+ abi.encodePacked(hex"160014", walletPubKeyHash)
564
+ );
565
+
566
+ return
567
+ processRedemptionTxOutputs(
568
+ self,
569
+ redemptionTxOutputVector,
570
+ walletPubKeyHash,
571
+ RedemptionTxOutputsProcessingInfo(
572
+ outputStartingIndex,
573
+ outputsCount,
574
+ walletP2PKHScriptKeccak,
575
+ walletP2WPKHScriptKeccak
576
+ )
577
+ );
578
+ }
579
+
580
+ /// @notice Processes all outputs from the redemption transaction. Tries to
581
+ /// identify output as a change output, pending redemption request
582
+ // or reported redemption. Reverts if one of the outputs cannot be
583
+ /// recognized properly. Marks each request as processed by removing
584
+ /// them from `pendingRedemptions` mapping.
585
+ /// @param redemptionTxOutputVector Bitcoin redemption transaction output
586
+ /// vector. This function assumes vector's structure is valid so it
587
+ /// must be validated using e.g. `BTCUtils.validateVout` function
588
+ /// before it is passed here.
589
+ /// @param walletPubKeyHash 20-byte public key hash (computed using Bitcoin
590
+ // HASH160 over the compressed ECDSA public key) of the wallet which
591
+ /// performed the redemption transaction.
592
+ /// @param processInfo RedemptionTxOutputsProcessingInfo identifying output
593
+ /// starting index, the number of outputs and possible wallet change
594
+ /// P2PKH and P2WPKH scripts.
595
+ function processRedemptionTxOutputs(
596
+ BridgeState.Storage storage self,
597
+ bytes memory redemptionTxOutputVector,
598
+ bytes20 walletPubKeyHash,
599
+ RedemptionTxOutputsProcessingInfo memory processInfo
600
+ ) internal returns (RedemptionTxOutputsInfo memory resultInfo) {
601
+ // Helper flag indicating whether there was at least one redemption
602
+ // output present (redemption must be either pending or reported as
603
+ // timed out).
604
+ bool redemptionPresent = false;
605
+
606
+ // Outputs processing loop.
607
+ for (uint256 i = 0; i < processInfo.outputsCount; i++) {
608
+ // TODO: Check if we can optimize gas costs by adding
609
+ // `extractValueAt` and `extractHashAt` in `bitcoin-spv-sol`
610
+ // in order to avoid allocating bytes in memory.
611
+ // https://github.com/keep-network/tbtc-v2/issues/257
612
+ uint256 outputLength = redemptionTxOutputVector
613
+ .determineOutputLengthAt(processInfo.outputStartingIndex);
614
+ bytes memory output = redemptionTxOutputVector.slice(
615
+ processInfo.outputStartingIndex,
616
+ outputLength
617
+ );
618
+
619
+ // Extract the value from given output.
620
+ uint64 outputValue = output.extractValue();
621
+ // The output consists of an 8-byte value and a variable length
622
+ // script. To extract that script we slice the output starting from
623
+ // 9th byte until the end.
624
+ bytes memory outputScript = output.slice(8, output.length - 8);
625
+
626
+ if (
627
+ resultInfo.changeValue == 0 &&
628
+ (keccak256(outputScript) ==
629
+ processInfo.walletP2PKHScriptKeccak ||
630
+ keccak256(outputScript) ==
631
+ processInfo.walletP2WPKHScriptKeccak) &&
632
+ outputValue > 0
633
+ ) {
634
+ // If we entered here, that means the change output with a
635
+ // proper non-zero value was found.
636
+ resultInfo.changeIndex = uint32(i);
637
+ resultInfo.changeValue = outputValue;
638
+ } else {
639
+ // If we entered here, that the means the given output is
640
+ // supposed to represent a redemption.
641
+ (
642
+ uint64 burnableValue,
643
+ uint64 treasuryFee
644
+ ) = processNonChangeRedemptionTxOutput(
645
+ self,
646
+ walletPubKeyHash,
647
+ outputScript,
648
+ outputValue
649
+ );
650
+ resultInfo.totalBurnableValue += burnableValue;
651
+ resultInfo.totalTreasuryFee += treasuryFee;
652
+ redemptionPresent = true;
653
+ }
654
+
655
+ // Make the `outputStartingIndex` pointing to the next output by
656
+ // increasing it by current output's length.
657
+ processInfo.outputStartingIndex += outputLength;
658
+ }
659
+
660
+ // Protect against the cases when there is only a single change output
661
+ // referring back to the wallet PKH and just burning main UTXO value
662
+ // for transaction fees.
663
+ require(
664
+ redemptionPresent,
665
+ "Redemption transaction must process at least one redemption"
666
+ );
667
+ }
668
+
669
+ /// @notice Processes a single redemption transaction output. Tries to
670
+ /// identify output as a pending redemption request or reported
671
+ /// redemption timeout. Output script passed to this function must
672
+ /// not be the change output. Such output needs to be identified
673
+ /// separately before calling this function.
674
+ /// Reverts if output is neither requested pending redemption nor
675
+ /// requested and reported timed-out redemption.
676
+ /// This function also marks each pending request as processed by
677
+ /// removing them from `pendingRedemptions` mapping.
678
+ /// @param walletPubKeyHash 20-byte public key hash (computed using Bitcoin
679
+ // HASH160 over the compressed ECDSA public key) of the wallet which
680
+ /// performed the redemption transaction.
681
+ /// @param outputScript Non-change output script to be processed.
682
+ /// @param outputValue Value of the output being processed.
683
+ /// @return burnableValue The value burnable as a result of processing this
684
+ /// single redemption output. This value needs to be summed up with
685
+ /// burnable values of all other outputs to evaluate total burnable
686
+ /// value for the entire redemption transaction. This value is 0
687
+ /// for a timed-out redemption request.
688
+ /// @return treasuryFee The treasury fee from this single redemption output.
689
+ /// This value needs to be summed up with treasury fees of all other
690
+ /// outputs to evaluate the total treasury fee for the entire
691
+ /// redemption transaction. This value is 0 for a timed-out
692
+ /// redemption request.
693
+ function processNonChangeRedemptionTxOutput(
694
+ BridgeState.Storage storage self,
695
+ bytes20 walletPubKeyHash,
696
+ bytes memory outputScript,
697
+ uint64 outputValue
698
+ ) internal returns (uint64 burnableValue, uint64 treasuryFee) {
699
+ // This function should be called only if the given output is
700
+ // supposed to represent a redemption. Build the redemption key
701
+ // to perform that check.
702
+ uint256 redemptionKey = uint256(
703
+ keccak256(abi.encodePacked(walletPubKeyHash, outputScript))
704
+ );
705
+
706
+ if (self.pendingRedemptions[redemptionKey].requestedAt != 0) {
707
+ // If we entered here, that means the output was identified
708
+ // as a pending redemption request.
709
+ RedemptionRequest storage request = self.pendingRedemptions[
710
+ redemptionKey
711
+ ];
712
+ // Compute the request's redeemable amount as the requested
713
+ // amount reduced by the treasury fee. The request's
714
+ // minimal amount is then the redeemable amount reduced by
715
+ // the maximum transaction fee.
716
+ uint64 redeemableAmount = request.requestedAmount -
717
+ request.treasuryFee;
718
+ // Output value must fit between the request's redeemable
719
+ // and minimal amounts to be deemed valid.
720
+ require(
721
+ redeemableAmount - request.txMaxFee <= outputValue &&
722
+ outputValue <= redeemableAmount,
723
+ "Output value is not within the acceptable range of the pending request"
724
+ );
725
+ // Add the redeemable amount to the total burnable value
726
+ // the Bridge will use to decrease its balance in the Bank.
727
+ burnableValue = redeemableAmount;
728
+ // Add the request's treasury fee to the total treasury fee
729
+ // value the Bridge will transfer to the treasury.
730
+ treasuryFee = request.treasuryFee;
731
+ // Request was properly handled so remove its redemption
732
+ // key from the mapping to make it reusable for further
733
+ // requests.
734
+ delete self.pendingRedemptions[redemptionKey];
735
+ } else {
736
+ // If we entered here, the output is not a redemption
737
+ // request but there is still a chance the given output is
738
+ // related to a reported timed out redemption request.
739
+ // If so, check if the output value matches the request
740
+ // amount to confirm this is an overdue request fulfillment
741
+ // then bypass this output and process the subsequent
742
+ // ones. That also means the wallet was already punished
743
+ // for the inactivity. Otherwise, just revert.
744
+ RedemptionRequest storage request = self.timedOutRedemptions[
745
+ redemptionKey
746
+ ];
747
+
748
+ require(
749
+ request.requestedAt != 0,
750
+ "Output is a non-requested redemption"
751
+ );
752
+
753
+ uint64 redeemableAmount = request.requestedAmount -
754
+ request.treasuryFee;
755
+
756
+ require(
757
+ redeemableAmount - request.txMaxFee <= outputValue &&
758
+ outputValue <= redeemableAmount,
759
+ "Output value is not within the acceptable range of the timed out request"
760
+ );
761
+ }
762
+ }
763
+
764
+ /// @notice Notifies that there is a pending redemption request associated
765
+ /// with the given wallet, that has timed out. The redemption
766
+ /// request is identified by the key built as
767
+ /// `keccak256(walletPubKeyHash | redeemerOutputScript)`.
768
+ /// The results of calling this function:
769
+ /// - the pending redemptions value for the wallet will be decreased
770
+ /// by the requested amount (minus treasury fee),
771
+ /// - the tokens taken from the redeemer on redemption request will
772
+ /// be returned to the redeemer,
773
+ /// - the request will be moved from pending redemptions to
774
+ /// timed-out redemptions,
775
+ /// - if the state of the wallet is `Live` or `MovingFunds`, the
776
+ /// wallet operators will be slashed and the notifier will be
777
+ /// rewarded,
778
+ /// - if the state of wallet is `Live`, the wallet will be closed or
779
+ /// marked as `MovingFunds` (depending on the presence or absence
780
+ /// of the wallet's main UTXO) and the wallet will no longer be
781
+ /// marked as the active wallet (if it was marked as such).
782
+ /// @param walletPubKeyHash 20-byte public key hash of the wallet.
783
+ /// @param walletMembersIDs Identifiers of the wallet signing group members.
784
+ /// @param redeemerOutputScript The redeemer's length-prefixed output
785
+ /// script (P2PKH, P2WPKH, P2SH or P2WSH).
786
+ /// @dev Requirements:
787
+ /// - The wallet must be in the Live or MovingFunds or Terminated state,
788
+ /// - The redemption request identified by `walletPubKeyHash` and
789
+ /// `redeemerOutputScript` must exist,
790
+ /// - The expression `keccak256(abi.encode(walletMembersIDs))` must
791
+ /// be exactly the same as the hash stored under `membersIdsHash`
792
+ /// for the given `walletID`. Those IDs are not directly stored
793
+ /// in the contract for gas efficiency purposes but they can be
794
+ /// read from appropriate `DkgResultSubmitted` and `DkgResultApproved`
795
+ /// events of the `WalletRegistry` contract,
796
+ /// - The amount of time defined by `redemptionTimeout` must have
797
+ /// passed since the redemption was requested (the request must be
798
+ /// timed-out).
799
+ function notifyRedemptionTimeout(
800
+ BridgeState.Storage storage self,
801
+ bytes20 walletPubKeyHash,
802
+ uint32[] calldata walletMembersIDs,
803
+ bytes calldata redeemerOutputScript
804
+ ) external {
805
+ uint256 redemptionKey = uint256(
806
+ keccak256(abi.encodePacked(walletPubKeyHash, redeemerOutputScript))
807
+ );
808
+ Redemption.RedemptionRequest memory request = self.pendingRedemptions[
809
+ redemptionKey
810
+ ];
811
+
812
+ require(request.requestedAt > 0, "Redemption request does not exist");
813
+ require(
814
+ /* solhint-disable-next-line not-rely-on-time */
815
+ request.requestedAt + self.redemptionTimeout < block.timestamp,
816
+ "Redemption request has not timed out"
817
+ );
818
+
819
+ // Update the wallet's pending redemptions value
820
+ Wallets.Wallet storage wallet = self.registeredWallets[
821
+ walletPubKeyHash
822
+ ];
823
+ wallet.pendingRedemptionsValue -=
824
+ request.requestedAmount -
825
+ request.treasuryFee;
826
+
827
+ require(
828
+ wallet.state == Wallets.WalletState.Live ||
829
+ wallet.state == Wallets.WalletState.MovingFunds ||
830
+ wallet.state == Wallets.WalletState.Terminated,
831
+ "The wallet must be in Live, MovingFunds or Terminated state"
832
+ );
833
+
834
+ // It is worth noting that there is no need to check if
835
+ // `timedOutRedemption` mapping already contains the given redemption
836
+ // key. There is no possibility to re-use a key of a reported timed-out
837
+ // redemption because the wallet responsible for causing the timeout is
838
+ // moved to a state that prevents it to receive new redemption requests.
839
+
840
+ // Move the redemption from pending redemptions to timed-out redemptions
841
+ self.timedOutRedemptions[redemptionKey] = request;
842
+ delete self.pendingRedemptions[redemptionKey];
843
+
844
+ if (
845
+ wallet.state == Wallets.WalletState.Live ||
846
+ wallet.state == Wallets.WalletState.MovingFunds
847
+ ) {
848
+ // Propagate timeout consequences to the wallet
849
+ self.notifyWalletTimedOutRedemption(walletPubKeyHash);
850
+
851
+ // Slash the wallet operators and reward the notifier
852
+ self.ecdsaWalletRegistry.seize(
853
+ self.redemptionTimeoutSlashingAmount,
854
+ self.redemptionTimeoutNotifierRewardMultiplier,
855
+ msg.sender,
856
+ wallet.ecdsaWalletID,
857
+ walletMembersIDs
858
+ );
859
+ }
860
+
861
+ // slither-disable-next-line reentrancy-events
862
+ emit RedemptionTimedOut(walletPubKeyHash, redeemerOutputScript);
863
+
864
+ // Return the requested amount of tokens to the redeemer
865
+ self.bank.transferBalance(request.redeemer, request.requestedAmount);
866
+ }
867
+ }