Skip to content

feat: add SignerContext for optimized repeated signing#3

Open
jorgecuesta wants to merge 1 commit intomasterfrom
perf/sign-precompute
Open

feat: add SignerContext for optimized repeated signing#3
jorgecuesta wants to merge 1 commit intomasterfrom
perf/sign-precompute

Conversation

@jorgecuesta
Copy link
Copy Markdown

Summary

Add SignerContext struct and SignWithContext method to pre-compute cryptographic values that remain constant across multiple sign operations with the same private key:

  • Public key (G * privKey)
  • Hash-to-curve result (H_p(pubkey))
  • Key image (privKey * H_p(pubkey))
  • Signer index in the ring

Performance Results

Ring Size Sign SignWithContext Improvement
2 1.02ms 0.84ms 17.4%
4 1.77ms 1.54ms 12.6%
8 3.20ms 3.02ms 5.7%
16 6.00ms 5.85ms 2.5%

Use Case

This optimization is particularly beneficial for gateway/relay systems (like PATH) that sign many requests with the same key during a session. The SignerContext can be created once when a session starts and reused for all subsequent sign operations.

Usage

// Create context once (e.g., at session start)
ctx, err := ring.NewSignerContext(privKey)

// Reuse for multiple sign operations
sig1, _ := ring.SignWithContext(msg1, ctx)
sig2, _ := ring.SignWithContext(msg2, ctx)  // much faster

Test plan

  • All existing tests pass
  • New tests for SignWithContext (validity, linkability, error cases)
  • Benchmarks show improvement

Add SignerContext struct and SignWithContext method to pre-compute
cryptographic values that remain constant across multiple sign operations
with the same private key:

- Public key (G * privKey)
- Hash-to-curve result (H_p(pubkey))
- Key image (privKey * H_p(pubkey))
- Signer index in the ring

Performance improvement for typical ring sizes:
- Ring size 2: ~17% faster (1.02ms → 0.84ms)
- Ring size 4: ~13% faster (1.77ms → 1.54ms)
- Ring size 8: ~6% faster (3.20ms → 3.02ms)

This optimization is particularly beneficial for gateway/relay systems
that sign many requests with the same key during a session.

🤖 Generated with [Claude Code](https://claude.ai/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant