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

Refactor - Script stores bytes, not strings #50

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

DaMatrix
Copy link

@DaMatrix DaMatrix commented Aug 2, 2024

Description

This PR depends on #42 (placeholders).

Our scripts can contain "byte array" constants, however they are actually represented as UTF-8 strings which in practice always contain hexadecimal data. This is not only inefficient, but also means that many of the stack operations behave in unexpected ways (e.g. the indices passed to OP_SUBSTR are effectively in units of half-bytes rather than bytes). This PR changes them into actual byte vectors, although for now they are still temporarily converted to hex strings in order to emulate the original behavior when performing cryptographic operations on the stack. In the future (preferably before all of these refactor PRs get merged), it would be ideal if this hex string translation could be eliminated, as it will likely be a major source of bugs for other developers attempting to work with our system.

Changelog

  • Changed StackEntry::Bytes to contain a Vec<u8> instead of a String
  • Updated all code which uses StackEntry::Bytes from hex strings to byte arrays, as necessary

Type of Change

Please mark the appropriate option by putting an "x" inside the brackets:

  • Bug fix
  • New feature
  • Enhancement or optimization
  • Documentation update
  • Other (please specify)

Checklist

Put an "x" in the boxes that apply. If you're unsure about any of these, don't hesitate to ask. We're here to help!

  • I have tested the changes locally and they work as expected.
  • I have added necessary documentation or updated existing documentation.
  • My code follows the project's coding standards and style guidelines.
  • I have added/updated relevant tests to ensure the changes are properly covered.
  • I have checked for and resolved any merge conflicts.
  • My commits have clear and descriptive messages.

Screenshots (if applicable)

If the changes affect the UI or have visual effects, please provide screenshots or GIFs showcasing the changes.

Additional Context (if applicable)

Add any additional context or information about the changes that may be helpful in understanding the pull request.

Related Issues (if applicable)

If this pull request is related to any existing issues, please list them here.

Requested Reviewers

Mention any specific individuals or teams you would like to request a review from.

@DaMatrix DaMatrix requested a review from a team as a code owner August 2, 2024 13:08
@DaMatrix DaMatrix mentioned this pull request Aug 2, 2024
11 tasks
Copy link
Contributor

@BHouwens BHouwens left a comment

Choose a reason for hiding this comment

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

This one will require testing against existing chain data to ensure you've got all the edge cases in handling legacy stacks. Otherwise, looks all good

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.

2 participants