Skip to content

pokt-network/go-dleq

 
 

Repository files navigation

go-dleq

Cross-group discrete logarithm equality implementation per MRL-0010 with dual secp256k1 backends for 3x performance gains.

Overview

Implementation of cross-group discrete logarithm equality with proof of knowledge signatures on both curves. Supports secp256k1 and ed25519.

Key Feature: Pluggable secp256k1 backends - choose between portability (pure Go) or 3x performance (libsecp256k1).

Quick Start

Run make to see all available targets.

# Auto-detect and build optimal backend
make build_auto

# Run benchmarks
make benchmark_all

# Run tests (both backends)
make test_all

# Test cross-backend compatibility
make test_compatibility

API Usage

import (
    "github.com/pokt-network/go-dleq"
    "github.com/pokt-network/go-dleq/ed25519"
    "github.com/pokt-network/go-dleq/secp256k1"
)

// Create curves
curveA := secp256k1.NewCurve()
curveB := ed25519.NewCurve()

// Generate secret
secret, _ := dleq.GenerateSecretForCurves(curveA, curveB)

// Create and verify proof
proof, _ := dleq.NewProof(curveA, curveB, secret)
err := proof.Verify(curveA, curveB)

API is identical between backends - just change build tags.

Performance

Operation Decred (Pure Go) Ethereum (libsecp256k1) Improvement
ScalarMul 125 μs 43 μs 3x faster
ECDSA Sign 93 μs 36 μs 2.6x faster
ECDSA Verify 212 μs 42 μs 5x faster
DLEQ Proof 485 ms 157 ms 3x faster
📊 Full Benchmark Results

Apple M1 Max Results

Operation Decred Ethereum Improvement
ScalarBaseMul 36 μs 43 μs Similar
ScalarMul 125 μs 43 μs 3.0x faster
Sign 93 μs 36 μs 2.6x faster
Verify 212 μs 42 μs 5.0x faster
DLEQ Proof Generation 485 ms 157 ms 3.1x faster
DLEQ Proof Verification 413 ms 131 ms 3.2x faster
Parallel ScalarMul 18 μs 6 μs 3.0x faster

Memory Usage

  • Decred: 136 B/op, 2 allocations
  • Ethereum: 328 B/op, 8 allocations (optimized with sync.Pool)

Run Your Own Benchmarks

make benchmark_all              # Full comparison
go run cmd/benchmark/main.go -compare -duration=10s

Backend Selection

Build Commands

# Pure Go (Default) - Maximum portability
CGO_ENABLED=0 go build

# High Performance - Requires libsecp256k1
CGO_ENABLED=1 go build -tags="ethereum_secp256k1"

# Auto-select optimal backend
make build_auto

Installation

📦 Installing libsecp256k1

macOS:

brew install libsecp256k1

Ubuntu/Debian:

sudo apt install libsecp256k1-dev

Alpine:

apk add libsecp256k1-dev

Technical Details

🔧 Implementation Details

Architecture

  • Backend selection: Build-time via tags (not runtime)
  • Files:
    • secp256k1/curve_decred.go - Pure Go implementation
    • secp256k1/curve_ethereum.go - libsecp256k1 wrapper (build tag: ethereum_secp256k1)
    • secp256k1/curve_ethereum_pooling.go - Memory optimization pools for Ethereum backend

Optimizations

The Ethereum backend replaces critical operations:

Decred (Pure Go) Ethereum (libsecp256k1)
secp256k1.ScalarMultNonConst ethsecp256k1.S256().ScalarMult
secp256k1.ScalarBaseMultNonConst ethsecp256k1.S256().ScalarBaseMult
ecdsa.SignASN1 ethsecp256k1.Sign
ecdsa.VerifyASN1 ethsecp256k1.VerifySignature

About

go implementation of cross-group discrete logarithm equality proofs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 93.5%
  • Makefile 6.5%