Skip to content

[Misc] Code cleanup & docs#21

Open
Olshansk wants to merge 8 commits into
noot:masterfrom
pokt-network:master
Open

[Misc] Code cleanup & docs#21
Olshansk wants to merge 8 commits into
noot:masterfrom
pokt-network:master

Conversation

@Olshansk

@Olshansk Olshansk commented Jun 18, 2024

Copy link
Copy Markdown
Collaborator

Some DevEx improvements from https://github.com/pokt-network/ring-go

@Olshansk Olshansk changed the title Merging upstream [Misc] Code cleanup & docs Jun 18, 2024
@Olshansk Olshansk requested a review from noot June 18, 2024 00:57
@Olshansk Olshansk self-assigned this Jun 18, 2024
@Olshansk Olshansk added the enhancement New feature or request label Jun 18, 2024
Olshansk and others added 4 commits July 15, 2024 15:13
…ance (#2)

```bah
make benchmark_report
🔬 Benchmarking ring signature crypto backends...
======================================================================

Running benchmarks with Decred backend (Pure Go)...
Running benchmarks with Ethereum backend (CGO + libsecp256k1)...

🔍 SIGN PERFORMANCE (Ring Signatures):
Ring  Decred          Ethereum        Improvement
Size  (Pure Go)       (libsecp256k1)  (% faster)
----  --------------- --------------- -----------
2     1.5 ms          607.3 µs        59%
4     2.6 ms          1.0 ms          60%
8     4.5 ms          1.9 ms          57%
16    8.5 ms          3.7 ms          57%
32    17.3 ms         7.2 ms          58%

🔍 VERIFY PERFORMANCE (Ring Signatures):
Ring  Decred          Ethereum        Improvement
Size  (Pure Go)       (libsecp256k1)  (% faster)
----  --------------- --------------- -----------
2     1.0 ms          400.1 µs        61%
4     2.0 ms          841.2 µs        58%
8     4.0 ms          1.7 ms          58%
16    8.0 ms          3.4 ms          58%
32    16.5 ms         6.9 ms          58%
```
Add an off-chain signing optimization while keeping the default path
byte-for-byte deterministic for on-chain / gas-metered use.

Signing paths:
- Sign/Verify are unchanged in work profile vs the previous implementation:
  hash-to-curve computed inline, self-checks on, no cache, no shared mutable
  state on Ring. Cost is deterministic across nodes -> safe for consensus.
- SignWithContext(m, privKey, ctx) is a new off-chain fast path. A
  SignerContext precomputes, once, the values constant across messages for a
  (privKey, ring): the signer's public key, key image, and the hash-to-curve
  of every ring member; repeated signing reuses them.

Security:
- SignerContext holds no secret material. Every field is derived from public
  data (key image and pubkey are already published in signatures). The private
  key is passed per call, not retained, so the context is safe to hold/reuse.
- A key that does not match the context yields an invalid (not forged)
  signature, rejected by the closing self-check unless SkipSelfCheck is set.

Other:
- challenge() builds its hash input in a single preallocated buffer, removing
  the append(m[:], ...) aliasing and cutting allocations. Stateless; safe on
  the shared path.
- Bump go 1.24.3 -> 1.26. Upgrade deps: edwards25519 1.2.0, decred secp256k1
  4.4.1, testify 1.11.1, x/crypto 0.53.0, x/sys 0.46.0, and go-ethereum
  1.14.12 -> 1.17.4 (CVE fixes; indirect, optional cgo backend).
- Docs: README "Signing paths" section with the consensus caveat and
  benchmarked allocation gains; runnable examples; godoc Example tests; 14
  SignWithContext benchmarks.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <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.

2 participants