Skip to content

encodeNBits does not handle negative numbers correctly #1071

Description

@sethdusek

The current implementation of encodeNBits (used in v6.0) is not implemented correctly for negative numbers. Due to right shifts on signed numbers performing sign extension, a value like -1 gets encoded as 0xffffff00. This then gets interpreted as -0x7fff00 * 2^(8 * 252), producing a 2039 bit value.

This issue doesn't seem to be high priority; encoding negative values as nBits isn't very useful. However to match the reference behavior I've implemented the negative number quirk in sigma-rust (https://github.com/ergoplatform/sigma-rust/blob/3e3ed84707f9ec123a2a8280558f6a7b32821f63/ergo-chain-types/src/autolykos_pow_scheme.rs#L85).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    6.0C-bugCategory: This is a bugP3-lowPriority: Low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions