Repository navigation
Conversation
🦋 Changeset detectedLatest commit: 81cb0ee 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.
Problem
writeBigVLQ/readBigVLQ— the codec behindwriteBigUInt/readBigUInt, i.e. every box value and token amount — placed no bound on the value at all:writeBigVLQ(2n ** 64n)happily emits a 10-byte encoding, andwriteBigVLQ(2n ** 100n)an even longer one. The referenceputULongin scorex-util takes a 64-bitLong, so values above 2^64 − 1 cannot be represented there at all.readBigVLQdecoded encodings of any length into arbitrarily large bigints. The referencegetULongreads at most 10 bytes (shifts 0..63) and errors on longer encodings; a 10-byte encoding whose high bits exceed 2^64 − 1 doesn't decode there to the value Fleet returned either — it wraps into a signedLongbit pattern. So a box value or token amount parsed by Fleet could be a value the node computes differently, or rejects outright, while Fleet's own writer would happily produce those same invalid bytes again on re-serialization.This is the same fail-open pattern as the
readI256gap (#221): Fleet accepted values its counterpart implementation cannot represent.Fix
writeBigVLQthrows aRangeErrorfor values above the newMAX_U64constant innumRanges.ts, mirroring the existing range checks in the other writers.readBigVLQthrows aRangeErroras soon as the decoded value exceedsMAX_U64(partial values only grow, so this is exact) or the encoding exceeds 10 bytes.@fleet-sdk/serializer: patch).Every in-range encoding is byte-identical to before. All internal callers are already inside the 64-bit domain: box values and token amounts are ULongs, and
zigZag64.encodewraps its output withasUintN(64)— the maximum zigzag encoding (forMIN_I64, exactly 2^64 − 1) still round-trips, as the existing SLong tests in the full suite confirm.One deliberate behavior change: an oversized encoding on the
readI64path previously flowed intozigZag64.decode's 64-bit truncation and returned a silently wrongLong. It now fails closed with aRangeErrorinstead, which matches the reference reader erroring on those bytes.Tests
Tests-first: the three new rejection tests fail on pristine
master(encode 2^64, decode 2^64, decode an 11-byte encoding — none threw), while the new maximum-value boundary vectors (encode/decode of 18446744073709551615, bytesff ff ff ff ff ff ff ff ff 01) already passed, pinning the behavior that must be preserved.vlq.spec: new encode/decode boundary and rejection tests; the BigVLQ round-trip property is widened fromNumber.MAX_SAFE_INTEGERto the full unsigned 64-bit range.Submitted by @Kshot9000 — Ergo ecosystem work. If this is useful, tips in ERG are welcome: 9fcM5RWnAjmP4vx5bnW6yohB6H9bLq8sJbaPLHtwZLtQPB32Pvy