-
Notifications
You must be signed in to change notification settings - Fork 42
txOutputVector expected to have less than 252 elements but not enforced #647
Comments
PS2: I guess UX-wise it'll be good to document the 252 max output index limitation (if it is not lifted), since I didn't realise about it from reading https://docs.keep.network/tbtc/. This may cause some issues if creating the funding from a wallet you have no complete control of, for instance an exchange that may batch redemptions into a transaction with many outputs. |
Exactly- in the mainnet dApp we made "not funding from a wallet I don't control" a click-through. Even without this issue there, exchange batching can grow the size of a tx beyond what we can verify in a block We'll make sure it's properly documented in #646 |
After carefully checking Summa's BTCUtils I found this has actually two issues that come from the fact that the I will update the issue to cover both. |
To check my overall understanding here, the core issue is that currently it's impossible to provide funding proof for output indexes >252. 253-255 ultimately fail the Continuing down that, the bad UTXO endpoint encoding cannot happen in tBTC due to the above, though it would be nice if bitcoin-spv handled this for completeness. Given that, is it fair to say that this is solely an issue for UX? Or is there a mitigation we need to implement in the contract that I missed? |
Ideally, Until then, as long as you have a way to prevent the user from funding from a wallet he does not control (as @mhluongo was referring in an earlier message) or make sure the user is aware that funding from a high output index will involve lose of funds, it should be OK. |
Yeah, the current implementation already maxes out the block gas limit before we hit 200 outputs, I believe (see this analysis of gas costs for on-chain SPV proofs that @NicholasDotSol did). Definitely hoping the memviews boost us past that for the next version, though I believe when we looked at Bitcoin transaction history that large-output-count transactions from exchanges could get very large indeed. Need to dig up some numbers from February. |
Closing this in favor of #646, which is a placeholder for the UX warnings around this. |
validateAndParseFundingSPVProof
expects to have a_txOutputVector
with no more than 252 (0xFC) values, but this is not enforced by_txOutputVector.validateVout()
.tbtc/solidity/contracts/deposit/DepositUtils.sol
Lines 190 to 216 in 100e5aa
BTCUtils defines
_nOutputs
as auint256
(https://github.com/summa-tx/bitcoin-spv/blob/master/solidity/contracts/BTCUtils.sol#L487-L489).Since
_fundingOutputIndex
is defined as auint8
, values over255
will fail, however values 253-255 will be wrongly parsed, creating at least two issues with the current code.findAndParseFundingOutput
will failfindAndParseFundingOutput
extracts the output that needs to be checked (extractOutputAtIndex
). This extraction implies avarint
parsing, that for output indexes0xFD, 0xFE and 0xFF
will return a data length of2, 4 and 8
respectively. Since the output passed is a single byte the function will return an error that will make this require to fail.Given that
findAndParseFundingOutput
is called as part ofprovideBTCFundingProof
, this will case funds to be potentially lost if the deposit is funded with an output in the 253th, 254th or 255th position (any other output further down will also fail, but this is expected given theuint8
restriction of_fundingOutputIndex
)._utxoOutpoint
will be wrongly encodedIf we ignore the previous issue, the incorrect parsing of the
_fundingOutputIndex
would make the contract store an invalid_utxoOutpoint
for the same value range:This will cause the redemption of the funds to fail, since the output that will be extracted and compared on redemption will not match the one stored in the contract.
tbtc/solidity/contracts/deposit/DepositRedemption.sol
Lines 345 to 348 in 100e5aa
The text was updated successfully, but these errors were encountered: