Skip to content

tlock: reject invalid characters in fromHex #175

Description

@karagozemin

Summary

Make fromHex in packages/tlock/src/commitment.ts reject malformed hexadecimal input instead of silently converting invalid byte pairs to zero.

Why this matters

parseInt("zz", 16) returns NaN, and assigning that value to a Uint8Array produces 0. Today an invalid value such as "zz" can therefore be accepted as a different byte sequence, which is risky in commitment and nonce tooling.

Scope

  • Validate the full input after removing an optional 0x prefix.
  • Preserve support for uppercase and lowercase hex.
  • Keep the existing odd-length rejection.
  • Add focused tests in packages/tlock/src/commitment.test.ts.
  • Do not change seal or commitment encoding.

Acceptance criteria

  • Invalid characters are rejected with a clear error.
  • Odd-length input is rejected.
  • Valid uppercase, lowercase, and 0x-prefixed values decode correctly.
  • Empty-input behavior is explicitly tested and documented by the test name.
  • pnpm --filter @sub-rosa/tlock test and typecheck pass.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26area: tlockDrand tlock sealing and auditor blobbugSomething isn't workinggood first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions