Skip to content

fix: twisted/Edwards conversion for circom compatibility#4

Merged
nanaknihal merged 1 commit into
mainfrom
fix/twisted-edwards-conversion
Mar 19, 2026
Merged

fix: twisted/Edwards conversion for circom compatibility#4
nanaknihal merged 1 commit into
mainfrom
fix/twisted-edwards-conversion

Conversation

@nanaknihal

Copy link
Copy Markdown
Collaborator

Summary

  • parse_decrypt_args: Apply twisted_to_edwards() on ciphertext points received from circom, with on-curve validation assertions
  • msg_to_point: Return twisted-form coordinates so circom receives the correct representation
  • network_pubkey_for_circom() (new): Helper returning the network pubkey as [x, y] decimal strings in twisted Edwards form for circom's encryptedTo input
  • Bump SDK version to 0.3.3 to trigger NPM publish

Context

Circom (circomlib) uses twisted Edwards form (a=168700, d=168696) while arkworks Affine<EdwardsConfig> uses standard Edwards form (a=1). The isomorphism scales x by sqrt(168700) — y stays the same. Without conversion, points from circom are off the Edwards curve, causing "Point not on curve" panics on .encode().

See Slack thread for full debugging: https://holonymworkspace.slack.com/archives/C07A9MCSKG8/p1766056829885929

Test plan

  • All 17 encryption tests pass (including E2E twisted→Edwards decrypt test)
  • cargo check -p human-network-sdk compiles cleanly
  • Rebuild WASM and verify network_pubkey_for_circom() returns correct twisted-form coords
  • Test full circom encrypt → SDK decrypt flow with corrected pubkey

🤖 Generated with Claude Code

Circom (circomlib) uses twisted Edwards form (a=168700) while arkworks
uses standard Edwards form (a=1). Points flowing between circom and Rust
need twisted_to_edwards()/edwards_to_twisted() conversion.

- parse_decrypt_args: apply twisted_to_edwards() on ciphertext points
  from circom, with on-curve validation
- msg_to_point: return twisted-form coordinates for circom consumption
- Add network_pubkey_for_circom() helper for correct encryptedTo input
- Bump version to 0.3.3

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nanaknihal nanaknihal merged commit 4da80f4 into main Mar 19, 2026
2 checks passed
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.

1 participant