Skip to content

fix: enforce runtime constructor guard on KMSVerifier and InputVerifier#438

Closed
ghermet wants to merge 1 commit intomainfrom
fix/435-runtime-constructor-guard
Closed

fix: enforce runtime constructor guard on KMSVerifier and InputVerifier#438
ghermet wants to merge 1 commit intomainfrom
fix/435-runtime-constructor-guard

Conversation

@ghermet
Copy link
Copy Markdown
Collaborator

@ghermet ghermet commented Apr 8, 2026

Summary

Closes #435

  • Adds a runtime Symbol guard to KMSVerifier and InputVerifier constructors, enforcing that instances can only be created through loadFromChain() (and by extension createInstance())
  • TypeScript's private constructor is compile-time only — in the bundled JS, consumers like @zama-fhe/sdk can call new KMSVerifier({...}) directly, bypassing all loadFromChain() validation
  • When verifyingContract is null (e.g. from a broken RPC response in a worker_threads context), the unvalidated value propagates through the closure chain to the WASM layer, which crashes with a cryptic "addressnull" error
  • The static private #constructorGuard Symbol is inaccessible outside the class even at JS runtime, so direct construction now throws with an actionable message

Test plan

  • tsc --noEmit passes
  • All 49 KMSVerifier + InputVerifier unit tests pass
  • Full test suite passes (1327 tests, 68 suites)
  • Verify new KMSVerifier({...}) throws at runtime in a consumer context (e.g. @zama-fhe/sdk worker)
  • Verify createInstance() still works end-to-end in worker_threads

🤖 Generated with Claude Code

…er (#435)

TypeScript `private constructor` is a compile-time guard only. In the
bundled JS output, consumers can freely call `new KMSVerifier(...)` with
unvalidated data, bypassing `loadFromChain()` validation. When
`verifyingContract` is null, the WASM layer crashes with a cryptic
"addressnull" error.

Add a static private Symbol guard that both constructors check at
runtime. Since the Symbol is inaccessible outside the class, direct
construction always throws with an actionable message directing
consumers to `loadFromChain()` / `createInstance()`.

Closes #435

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cla-bot cla-bot bot added the cla-signed label Apr 8, 2026
@ghermet ghermet closed this Apr 8, 2026
@ghermet ghermet deleted the fix/435-runtime-constructor-guard branch April 8, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

userDecrypt resolves null verifyingContractAddressDecryption in Node.js worker_threads context

1 participant