fix(scan): reject non-canonical operation counts (#99)#100
Merged
Conversation
Finding #15. ExtractFromScript parsed the anchor-string op count with strconv.Atoi (only err/negative checked). The Sidetree reference accepts only /^[1-9][0-9]*$/; Atoi also accepts "+5", "007", "0", so ion-node indexed operations from crafted anchors canonical ION ignores — silently diverging DID resolution. - internal/scan/opreturn.go: canonicalCount(s) enforces ^[1-9][0-9]*$ (positive decimal, no sign, no leading zeros, no overflow), replacing the lenient Atoi. Also rejects "0"-count anchors at scan time (they no longer consume a per-block tx-cap slot — partial overlap with #26). - internal/scan/opreturn_test.go: TestExtractCanonicalOpCount table-tests accepted (5/1/100/10000) vs rejected (0, 007, +5, -5, whitespace, 0x5, overflow, empty). go test -race ./... green. Co-authored-by: Liran Cohen <liranlasvegas@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Closes audit finding #15 (consensus parity).
ExtractFromScriptparsed the anchor-string operation count withstrconv.Atoi(onlyerr/negative checked). The Sidetree reference accepts only/^[1-9][0-9]*$/;Atoialso accepts+5,007,0— so ion-node indexed and applied operations from crafted anchors that canonical ION ignores, silently diverging DID resolution.Fix
internal/scan/opreturn.go:canonicalCount(s)enforces^[1-9][0-9]*$(positive decimal, no sign, no leading zeros, no overflow), replacing the lenientAtoi. This also rejects0-count anchors at scan time, so they no longer consume a per-block tx-cap slot (partial overlap with feat(process): pending-CID retry loop with backoff + late splice (M4 U6) #26).internal/scan/opreturn_test.go:TestExtractCanonicalOpCounttable-tests accepted (5/1/100/10000) vs rejected (0,007,+5,-5, whitespace,0x5, overflow, empty).go test -race ./...green (26 packages). Existing indexer tests use canonical1.<cid>anchors, unaffected.Post-Deploy Monitoring & Validation
Closes #99
🤖 Generated with Claude Code