Skip to content
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

doc: replace remaining "520" magic nums with MAX_SCRIPT_ELEMENT_SIZE #30024

Merged
merged 1 commit into from May 3, 2024

Conversation

jonatack
Copy link
Contributor

@jonatack jonatack commented May 2, 2024

Noticed these while reviewing BIPs yesterday.

It would be clearer and more future-proof to refer to their constant name.

@DrahtBot
Copy link
Contributor

DrahtBot commented May 2, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK instagibbs, glozow, sipa, achow101
Concept NACK GregTonoski

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #28307 (rpc, wallet: fix incorrect segwit redeem script size limit by furszy)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@DrahtBot DrahtBot added the Docs label May 2, 2024
@instagibbs
Copy link
Member

maybe just replace 520 with MAX_SCRIPT_ELEMENT_SIZE and nothing else? concept ACK otherwise. I can confirm they're all referring to the same limit at least.

@jonatack jonatack force-pushed the 2024-05-MAX_SCRIPT_ELEMENT_SIZE branch from e37e1ab to ffc6745 Compare May 2, 2024 19:17
@jonatack
Copy link
Contributor Author

jonatack commented May 2, 2024

maybe just replace 520 with MAX_SCRIPT_ELEMENT_SIZE and nothing else?

Thanks @instagibbs, done.

@instagibbs
Copy link
Member

ACK ffc6745

Copy link
Contributor

@MarnixCroes MarnixCroes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm ffc6745

@GregTonoski
Copy link

NACK unless clearly explained (reference to specification like BIP or relevant disucssion would be highly appreciated). Why not fixing the policy standard rules so that "Nodes must NEVER send a data item > 520 bytes"?

See also: https://bitcoin.stackexchange.com/questions/38937/what-was-the-original-rationale-for-limiting-the-maximum-push-size

Copy link
Member

@glozow glozow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK ffc6745, agree it's clearer for these comments to refer to the greppable name of the limit rather than the number

@GregTonoski
Copy link

What is the meaning and the purpose of the both the "520" and the "MAX_SCRIPT_ELEMENT_SIZE"? In particular, is the "520" and "MAX_SCRIPT_ELEMENT_SIZE" meant to describe limit of size of any element in order to disregard transactions that would have overused resources (similarily to MAX_SCRIPT_SIZE albeit on a level deeper)?

@instagibbs
Copy link
Member

instagibbs commented May 3, 2024

@GregTonoski MAX_SCRIPT_ELEMENT_SIZE is a constant that describes a consensus rule that has been around since satoshi-era where nothing can be pushed to the stack that is larger than 520 bytes. There are knock-on effects like due to this, p2sh redeemScripts couldn't be larger(since they had to be pushed on the stack), and bip37 bloom filters.

Unless there is an instance of 520 being replaced here that is erroneous, this is a strict grepping improvement.

reasoning motivation(which doesn't effect this PR): https://bitcoin.stackexchange.com/questions/38937/what-was-the-original-rationale-for-limiting-the-maximum-push-size

@GregTonoski
Copy link

GregTonoski commented May 3, 2024

There are knock-on effects like due to this, p2sh redeemScripts couldn't be larger(since they had to be pushed on the stack), and bip37 bloom filters.

Are they "knock-on effects" or are the effects intentional?

Unless there is an instance of 520 being replaced here that is erroneous, this is a strict grepping improvement.

Is the suggested name the best option? Why not another constant with another name, perhaps?

Why weren't the constants combined in Satoshi era and later?

Is the use case of OP_PUSHDATA4 the only one affected by the constant?

@instagibbs
Copy link
Member

Are they "knock-on effects" or are the effects intentional?

Doesn't matter for this PR, frankly. We need to be descriptive about the consensus bits in the code. I linked some historical background for your edification.

Is the suggested name the best option? Why not another constant with another name, perhaps?

Probaby, because it's the constant that has been used for over a decade to describe a consensus-critical constant.

@sipa
Copy link
Member

sipa commented May 3, 2024

ACK ffc6745

Is the suggested name the best option? Why not another constant with another name, perhaps?

The constant with this exact name and value already exists, it was introduced 11 years ago. There are just a few places in comments where the raw value 520 is used instead so far. This PR fixes that.

@jonatack
Copy link
Contributor Author

jonatack commented May 3, 2024

Thanks for the interesting links!

@GregTonoski it turns out that this patch is just a continuation of commit 192cc91 doing the same thing, per review #2188 (comment) requesting this, both back in 2013.

The idea is to clarify that these hardcoded numbers all refer to the same thing and to reduce potential head-scratching by future readers of this code.

@achow101
Copy link
Member

achow101 commented May 3, 2024

ACK ffc6745

@achow101 achow101 merged commit f5b6f62 into bitcoin:master May 3, 2024
16 checks passed
@jonatack jonatack deleted the 2024-05-MAX_SCRIPT_ELEMENT_SIZE branch May 3, 2024 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants