Skip to content

fix: validate Fairycloak integer responses - #12

Open
Kewe63 wants to merge 1 commit into
Fairblock:mainfrom
Kewe63:fix/11-strict-relay-integer-parsing
Open

Kewe63 wants to merge 1 commit into
Fairblock:mainfrom
Kewe63:fix/11-strict-relay-integer-parsing

Conversation

@Kewe63

@Kewe63 Kewe63 commented Sep 18, 2026

Copy link
Copy Markdown

Fixes #11

Summary

  • replace the catch-all BigInt fallback with strict unsigned-integer response validation
  • reject malformed, negative, fractional, unsafe-number, and missing required Fairycloak values instead of converting them to 0n
  • apply the validation consistently to account counters, all anonymous/non-anonymous fee getters, and prepaid balances
  • preserve the existing 0n compatibility default only for absent counters on accounts that do not exist

Why

The previous helper caught every BigInt(...) conversion error and returned 0n. That made malformed relay data indistinguishable from a legitimate zero fee, nonce, transaction ID, or balance, allowing later logic to proceed with false state.

Verification

  • regression suite on the previous implementation: 5 tests run, 4 failed with missing expected rejections
  • node --test test/relay-integer-parsing.test.mjs — 5 passed
  • npm run check — ABI check passed; 70 tests passed
  • git diff --check — passed

The regression matrix covers decimal and hex strings, bigint/number values, explicit zero, malformed and whitespace strings, negative/fractional/unsafe numbers, booleans/objects, missing counters on absent versus existing accounts, and malformed prepaid balances.

Compatibility

Valid non-negative integer strings, safe integer numbers, bigints, hexadecimal values, and explicit zero retain their existing results. Only malformed or missing required response fields now fail closed with a field-specific error.

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.

Malformed Fairycloak integer fields are silently coerced to zero

1 participant