Skip to content

fix(genesis): reject non-canonical validator override ids - #328

Open
Kewe63 wants to merge 1 commit into
circlefin:mainfrom
Kewe63:fix-322-strict-validator-id-override
Open

fix(genesis): reject non-canonical validator override ids#328
Kewe63 wants to merge 1 commit into
circlefin:mainfrom
Kewe63:fix-322-strict-validator-id-override

Conversation

@Kewe63

@Kewe63 Kewe63 commented Sep 3, 2026

Copy link
Copy Markdown

Summary

Fixes #322

This makes LocalDevAccountCreator validate overridePublicKeys validator IDs as canonical decimal integers before converting them with Number(...).

Previously, parseOverridePublicKeys converted the validator ID with Number(...) and only rejected NaN or values below 1. That allowed non-canonical numeric strings such as 1.5, 1e0, and 01 to be accepted.


Changes

  • Add explicit validator ID syntax validation before numeric conversion.
  • Require overridePublicKeys IDs to match canonical positive decimal integer form.
  • Keep the existing safe integer check after conversion.
  • Add unit coverage for accepted and rejected overridePublicKeys IDs.

Accepted examples:

  • 1:<key>
  • 42:<key>

Rejected examples:

  • 1.5:<key>
  • 1e0:<key>
  • 01:<key>
  • -1:<key>
  • NaN:<key>
  • Infinity:<key>
  • :<key>

Why

validator_id is an identifier, not a loose numeric expression. Accepting alternate encodings can create ambiguous mappings:

  • 1e0 resolves to 1
  • 01 resolves to 1
  • 1.5 is accepted as a non-integer Map key

Strict parsing catches malformed localdev/genesis configuration early and avoids confusing overridePublicKeys behavior.


Tests

Regression test before the fix:

npx mocha -r ts-node/register ./tests/unit/localdev-account-creator.test.ts

Result before fix:

1 passing
1 failing

Failure:

AssertionError: 1.5 should be rejected: expected [Function] to throw an error

After the fix:

npx mocha -r ts-node/register ./tests/unit/localdev-account-creator.test.ts

Result:

2 passing

Unit test file sweep:

npx mocha -r ts-node/register ./tests/unit/*.test.ts

Result:

16 passing

Formatting:

npx prettier --config ./.prettierrc --check scripts/genesis/AccountCreator.ts tests/unit/localdev-account-creator.test.ts

Result:

All matched files use Prettier code style!

Lint:

npx eslint scripts/genesis/AccountCreator.ts tests/unit/localdev-account-creator.test.ts

Result:

passed


Checklist

  • Tests pass — 2/2 targeted, 16/16 full unit suite, confirmed failing before fix
  • Prettier / ESLint clean
  • Follows Conventional Commits
  • Changes scoped to this fix only

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LocalDevAccountCreator should reject non-canonical validator IDs in overridePublicKeys

1 participant