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

Limit OP_NUM2BIN to 68 bytes #60

Closed
EyeOfPython opened this issue Mar 8, 2021 · 0 comments · Fixed by #67
Closed

Limit OP_NUM2BIN to 68 bytes #60

EyeOfPython opened this issue Mar 8, 2021 · 0 comments · Fixed by #67

Comments

@EyeOfPython
Copy link
Collaborator

OP_NUM2BIN can be used to generate a lot of zeros on the stack (520 bytes with 1 opcode and 3 bytes). Combined with OP_HASH256 or other opcodes, this can be quite slow.

Also, numbers will never be longer than 68 bytes, so it's kinda ridiculous to allow 520 bytes.

Why 68 bytes?

There's a neat trick for reducing the size of the preimage for the OP_CHECKDATASIG/OP_CHECKSIG transaction introspection. You use ANYONECANPAY, and then with 2 68 OP_NUM2BIN you generate parts 1. (nVersion, here 02000000), 2. (hashPrevouts, here a uint256 of 0x0000......0000) and 3. (hashSequence, here a uint256 of 0x0000......0000).

This saves around 64 bytes for a transaction and only costs 1 opcode. Reducing the OP_NUM2BIN size to 68 keeps that optimization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants