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

feat: improve handling of u32 operations #1480

Merged
merged 8 commits into from
Sep 7, 2024
Merged

Commits on Sep 7, 2024

  1. feat: raise execution error on invalid u32 op inputs

    This commit modifies the way we handle invalid inputs to u32 operations.
    The behavior being modified here is documented as undefined, so is not a
    breaking change, and as you will see, should be an improvement in
    developer experience.
    
    Previously, virtually all of the u32 operations whose implementations
    rely on the operands being valid u32 values, would simply cause the VM
    to panic if that assumption was violated in an egregious enough fashion,
    namely if the operands happened to be large enough to cause the
    equivalent operation on u64 operands to fail.
    
    While somewhat limited in impact in practice, this is quite painful if
    you have a bug in your program that causes a very large value to be used
    as an operand to a u32 operation. Not only would this bring the entire
    VM down, it would also prevent you from identifying _why_ it failed,
    even if stepping cycle-by-cycle. This primarily impacts the arithmetic
    operators, but really just depends on how a given instruction is
    implemented.
    
    More problematic, in my opinion, is that while the behavior of the u32
    operations with invalid u32 operands is documented as undefined, we were
    relying on the undocumented behavior of the VM in various places,
    notably in the implementations of some of the more complex bitwise
    operations, e.g. clz/clo/rotr. As a result, if we were to ever change
    that undocumented behavior, subtle bugs could be introduced. In this
    case, we're making the behavior more strict, so we're immediately made
    aware that these operations are broken (and thus, fix them), but we
    could have easily done something different that would not have been so
    easy to detect.
    
    This commit specifically makes most of the u32 ops raise an execution
    error if an invalid u32 operand is given to them. This does _not_ make
    these checked operations in terms of the VM constraints, but it does
    make them behave like checked operations, in so far as they will cause
    the VM to trap if an invalid operand is used. This stricter behavior
    makes you aware immediately when your program relies on undefined
    behavior, and forces you to handle it properly.
    bitwalker committed Sep 7, 2024
    Configuration menu
    Copy the full SHA
    aa1ebe8 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    5b90e94 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    828451a View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    b8594c3 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    af96cf0 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    dd666c1 View commit details
    Browse the repository at this point in the history
  7. chore: update changelog

    bitwalker committed Sep 7, 2024
    Configuration menu
    Copy the full SHA
    8a51cd5 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    245e89c View commit details
    Browse the repository at this point in the history