Skip to content

fix(drand-tools): verify configured chain hash at startup - #697

Open
Adediwura-dev wants to merge 1 commit into
Sub-Rosa-Issue:mainfrom
Adediwura-dev:fix/verify-drand-chain-hash
Open

Adediwura-dev wants to merge 1 commit into
Sub-Rosa-Issue:mainfrom
Adediwura-dev:fix/verify-drand-chain-hash

Conversation

@Adediwura-dev

Copy link
Copy Markdown
Contributor

fix(drand-tools): verify configured chain hash at startup

Summary

  • Closes drand-tools(high/easy): verify the configured chain hash at startup #662: drand-tools now requires the expected Drand chain hash in configuration and validates fetched chain info against it before any round data is requested or accepted.
  • Adds a typed DrandConfig loader that rejects missing or malformed DRAND_CHAIN_HASH before any network call, normalizes hex casing, and trims trailing slashes from DRAND_API_URL.
  • Adds assertChainHashMatches() and DrandChainHashMismatchError with the stable, non-secret message drand chain hash mismatch and code DRAND_CHAIN_HASH_MISMATCH.
  • Uses the configured hash in both /info and /public/<round> API paths, so an operator cannot silently validate a different chain than the one requested.
  • Emits a dedicated chain-hash-mismatch diagnostic event from the validation harness and keeps the process exit code at 1.
  • Documents DRAND_CHAIN_HASH as required in .env.example.

Acceptance criteria

  • Require the expected chain hash in Drand tool configuration — loadDrandConfig() fails closed when DRAND_CHAIN_HASH is absent or not a 64-character hex digest.
  • Compare the fetched chain info before round data is accepted — getChainInfo() verifies info.hash immediately after the response is parsed; getBeacon() is only called afterwards by index.ts and vectors.ts.
  • Fail with a stable non-secret error — a fixed message and error code; neither the expected nor the fetched hash is interpolated into the error.
  • Add matching and mismatching fixture tests — new src/chain-hash.test.ts uses the frozen test-vectors/quicknet.json fixture with stubbed fetch, plus missing/malformed config cases, and is wired into the package test script.

Verification

  • pnpm drand-tools:test — 10 tests pass (4 new chain-hash tests, 6 existing tests).
  • pnpm env:check, pnpm workspaces:check, pnpm docs:check, pnpm snapshot:check, pnpm time:guard, pnpm line-lengths:check — pass.
  • pnpm drand-tools:typecheck — the changed drand-tools sources typecheck cleanly once the pre-existing upstream packages/tlock/src/seal.ts merge break is restored (missing assertSealRoundWindow import and revealRound destructure). That unrelated upstream baseline issue is not modified in this PR.
  • pnpm logging:check, pnpm errors:normalize:check, and pnpm errors:check currently fail on upstream main before this change due unrelated existing drifts in scripts/web/contract files; no files in those areas are touched here.

close #662

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.

drand-tools(high/easy): verify the configured chain hash at startup

1 participant