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

Some simplification to script number types #594

Merged
merged 3 commits into from
Nov 13, 2024

Conversation

someone235
Copy link
Contributor

@someone235 someone235 commented Nov 12, 2024

Unifying OpcodeData<i32/i64/Kip10I64> to use SizedEncodeInt for serialization.

Critical lines and explanation:

  1. https://github.com/someone235/rusty-kaspa/blob/976313f0f4c492061689d84811b17ee1ea73cc8b/crypto/txscript/src/data_stack.rs#L178
    Here we limit any push_item<i32> to 4 bytes. This is fine since we nowhere use this method.
  2. https://github.com/someone235/rusty-kaspa/blob/976313f0f4c492061689d84811b17ee1ea73cc8b/crypto/txscript/src/data_stack.rs#L166
    Here we limit any push_item<i64> to 8 bytes. Explanation for safety is in the code.
  3. https://github.com/someone235/rusty-kaspa/blob/976313f0f4c492061689d84811b17ee1ea73cc8b/crypto/txscript/src/data_stack.rs#L173
    Here we limit any pop_items<i32> to 4 bytes, disallowing the use of i32::MIN. This is fine since in any place we use pop_items<i32> we also return an error if the number is negative.

Copy link
Collaborator

@biryukovmaxim biryukovmaxim left a comment

Choose a reason for hiding this comment

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

LGTM!

crypto/txscript/src/data_stack.rs Show resolved Hide resolved
crypto/txscript/src/data_stack.rs Outdated Show resolved Hide resolved
@michaelsutton
Copy link
Contributor

  1. https://github.com/someone235/rusty-kaspa/blob/976313f0f4c492061689d84811b17ee1ea73cc8b/crypto/txscript/src/data_stack.rs#L173
    Here we limit any pop_items<i32> to 4 bytes, disallowing the use of i32::MIN. This is fine since in any place we use pop_items<i32> we also return an error if the number is negative.

For the sake of accuracy, this was limited to 4 bytes also previously, through DEFAULT_SCRIPT_NUM_LEN.

@michaelsutton michaelsutton merged commit 116dfb0 into kaspanet:master Nov 13, 2024
6 checks passed
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 this pull request may close these issues.

3 participants