-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return tx validation errors, fix max script size #311
Return tx validation errors, fix max script size #311
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, the code is much cleaner!
concept ACK I'll add some review later, but there's one thing that's boggling me: We have two kinds of script size limits:
I think (TODO: check) that |
48fc33e
to
cd44c10
Compare
I have updated it with @jaoleal suggestions |
Surely this was my mistake when i did this code... Since 10k bytes(for p2wsh) was something so rare to happen and so expensive to do that i believed that this would never really happen... This version of the function should run fine /// Validates the script size and the number of sigops in a script.
fn validate_script_size(script: &ScriptBuf) -> Result<(), BlockValidationErrors> {
if script.count_sigops() > 80_000 {
return Err(BlockValidationErrors::ScriptError);
}
if script.is_p2tr() {
// We return early because Taproot scripts has unlimited sizes.
return Ok(());
}
let scriptpubkeysize = script.len();
let is_witness =
script.witness_version() == Some(WitnessVersion::V1) && scriptpubkeysize == 32;
if scriptpubkeysize > 520 || scriptpubkeysize < 2 && !is_witness {
//the scriptsig size must be between 2 and 100 bytes unless is taproot
return Err(BlockValidationErrors::ScriptError);
}
if scriptpubkeysize >= 10_000 && is_witness {
return Err(BlockValidationErrors::ScriptError);
}
Ok(())
} EDIT
Actually, if we want to do this type of things like bitcoin core, the function would be much simpler: const fn validate_script_size(script: &ScriptBuf) -> bool {
!(script.len() > 10_000)
} The input being the whole script(e.g. This is bitcoin 28 |
@Davidson-Souza actually it makes total sense that we may not need to perform the size check manually if we use the script validation logic from |
Yeah, it does perform most of the checks. One disadvantage of deferring everything to |
I'm creating some transactions we can use to test script sizes and limits (https://gist.github.com/Davidson-Souza/5c5cf707704ffdb20c65c0e230f4392b) |
Ok so the idea is to have the basic script resource and size limits implemented for |
Yes, I think it's valuable to have those implemented here. Otherwise, we wouldn't check script constraints on That can be another PR, tho. |
IMO we should only check if its less than |
cd44c10
to
abda06e
Compare
Rebased |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK. I'm just not sure about the script size thing, I think we should make one function for witness sizes (not here, tho) and remove this is_taproot
flag, see my comment bellow for an explanation
- Added a few `?` when needed. - Corrected the non-taproot max script size to 10,000 bytes. Then also fix some error return cases: - Check if the first tx is coinbase and return `FirstTxIsNotCoinbase` if it is not. `verify_coinbase` was previously only called if `transaction.is_coinbase() && n == 0` and the not coinbase case was not handled. - Previous `get_out_value` returned error when output had 0 sats value, but this is valid under the consensus rules. Removed it. - `consume_utxos` changed to `get_utxo`: the utxos are already consumed by the `verify_with_flags` method, since it takes a `utxos.remove(outpoint)` closure. - `UtxoAlreadySpent` error renamed to `UtxoNotFound`
abda06e
to
2fad23c
Compare
Removed the The future witness function may actually need the |
ACK fad23c9061830197c18380e66bd0a63c0d46e11 |
Proposing these changes as the BlockRules PR was closed.
?
when needed.validate_script_size
now takes ataproot_spend
bool.Then also fix some error return cases:
FirstTxIsNotCoinbase
if it is not.verify_coinbase
was previously only called iftransaction.is_coinbase() && n == 0
and the not coinbase case was not handled.get_out_value
returned error when output had 0 sats value, but this is valid under the consensus rules. Removed it.consume_utxos
changed toget_utxo
: the utxos are already consumed by theverify_with_flags
method, since it takes autxos.remove(outpoint)
closure.