fix(genesis): reject non-canonical validator override ids - #328
Open
Kewe63 wants to merge 1 commit into
Open
Conversation
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
Fixes #322
This makes
LocalDevAccountCreatorvalidateoverridePublicKeysvalidator IDs as canonical decimal integers before converting them withNumber(...).Previously,
parseOverridePublicKeysconverted the validator ID withNumber(...)and only rejectedNaNor values below 1. That allowed non-canonical numeric strings such as1.5,1e0, and01to be accepted.Changes
overridePublicKeysIDs to match canonical positive decimal integer form.overridePublicKeysIDs.Accepted examples:
1:<key>42:<key>Rejected examples:
1.5:<key>1e0:<key>01:<key>-1:<key>NaN:<key>Infinity:<key>:<key>Why
validator_idis an identifier, not a loose numeric expression. Accepting alternate encodings can create ambiguous mappings:1e0resolves to101resolves to11.5is accepted as a non-integer Map keyStrict parsing catches malformed localdev/genesis configuration early and avoids confusing
overridePublicKeysbehavior.Tests
Regression test before the fix:
Result before fix:
1 passing
1 failing
Failure:
AssertionError: 1.5 should be rejected: expected [Function] to throw an error
After the fix:
Result:
2 passing
Unit test file sweep:
npx mocha -r ts-node/register ./tests/unit/*.test.tsResult:
16 passing
Formatting:
Result:
All matched files use Prettier code style!
Lint:
Result:
passed
Checklist
Risk & Impact
Low. The added syntax validation only rejects previously-ambiguous non-canonical numeric forms — canonical decimal integer IDs (
0,1,42, etc.) are accepted exactly as before. Verified the regression test fails against the old parser and passes with the fix, confirming it exercises the actual ambiguity.Type: 🐛 Bug fix
Fixes: #322