Repository navigation
Conversation
🦋 Changeset detectedLatest commit: c0cdbcc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SBytewas the only signed primitive without a serialize-time range check. Every other signed writer throws aRangeErrorfor out-of-range values —writeI16,writeI32,writeI64andwriteI256inSigmaByteWriter, plus the VLQ writers — but the data serializer wrote byte constants through the rawwrite()method:A plain
numberhas no byte range in JS, and the underlyingUint8Arrayassignment silently wraps, so an out-of-rangeSByteconstant did not round-trip:SByte(200)serialized to the byte0xc8, whichreadI8parses back as-56SByte(128)parsed back as-128SByte(256)serialized to0x00and parsed back as0SByte(511)became-1,SByte(-129)became127, non-integers were truncatedIn Scala the
Bytetype itself makes these values unrepresentable, so this gap only exists in the JS port.Fix
SigmaByteWriter.writeI8, mirroringwriteI16: it throwsRangeError("out of range for an 8-bit integer") outsideMIN_I8..MAX_I8and writes negative values as their two's complement byte, which is exactly the conversionreadI8applies when reading.writeI8. In-range encodings are byte-identical to before (the existingbyteVectors, including-128→0280and127→027f, pass unchanged).Deliberate non-change:
SColl[Byte]is unaffected — its elements are carried as aUint8Arrayof raw bytes and serialized withwriteBytes, not through the per-element signed-byte path.Tests
Tests-first: on pristine
master,SByte(200)parses back as-56andSByte(256)as0(probe spec, both assertions failed), and the new specs fail with the fix stashed (3 failures) while passing with it.sigmaByteWriter.spec: new "Should put Byte" vectors (0, 1, 76,MAX_I8, -1,MIN_I8) and byte cases added to the existing out-of-range testsigmaConstant.spec: serializing 128, 200, 255, 256, -129 and -256 asSBytenow throwsFull monorepo suite: 1134/1134 tests pass (66 files); serializer package 375/375. Biome check clean on the changed files.
Submitted by @Kshot9000 — Ergo ecosystem work. If this is useful, tips in ERG are welcome: 9fcM5RWnAjmP4vx5bnW6yohB6H9bLq8sJbaPLHtwZLtQPB32Pvy