Examples
- Point Addition - Elliptic curve point addition
- Scalar Multiply - Scalar multiplication on curve
- ECDH - Diffie-Hellman key exchange
Secp256k1 Point Operations
Low-level elliptic curve point arithmetic operations underlying ECDSA signatures.Curve Definition
Secp256k1 uses the Weierstrass curve equation:- Prime field:
p = 2²⁵⁶ - 2³² - 977(SECP256K1_P) - Curve order:
n = 2²⁵⁶ - ~2³²(SECP256K1_N) - Coefficients:
a = 0, b = 7 - Generator:
G = (Gx, Gy)where:Gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798Gy = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8
Affine Coordinates
Points represented as(x, y) satisfying the curve equation.
Point Representation
Point Validation
Check if point lies on curve:Point Addition
Add two different points:R = P + Q
Algorithm
GivenP = (x₁, y₁) and Q = (x₂, y₂) where x₁ ≠ x₂:
- Calculate slope:
λ = (y₂ - y₁) / (x₂ - x₁) mod p - Compute x-coordinate:
x₃ = λ² - x₁ - x₂ mod p - Compute y-coordinate:
y₃ = λ(x₁ - x₃) - y₁ mod p
R = (x₃, y₃)
Implementation
Example
Point Doubling
Double a point:R = 2P
Algorithm
GivenP = (x₁, y₁):
- Calculate slope:
λ = (3x₁²) / (2y₁) mod p(tangent line slope) - Compute x-coordinate:
x₃ = λ² - 2x₁ mod p - Compute y-coordinate:
y₃ = λ(x₁ - x₃) - y₁ mod p
R = (x₃, y₃)
Implementation
Example
Point Negation
Negate a point:R = -P
Algorithm
GivenP = (x, y):
Implementation
Example
Scalar Multiplication
Multiply point by scalar:R = k * P
Double-and-Add Algorithm
Computek * P for scalar k:
Implementation
Example
Optimizations
Window Method (wNAF)
Precompute multiples of P for faster scalar multiplication:Fixed-Base Multiplication
When multiplying by generator G repeatedly, precompute multiples:Projective Coordinates
Avoid expensive modular inversions by using projective coordinates(X, Y, Z):
- No modular inversions required
- ~12 multiplications + 4 squarings
- No modular inversions required
- ~7 multiplications + 5 squarings
Coordinate Conversions
Affine to Compressed
Compressed to Affine
Security Considerations
⚠️ Constant-time operations required: All point operations must execute in constant time to prevent timing attacks: ❌ Vulnerable:- TypeScript (@noble/curves): ✅ Constant-time
- Zig (custom): ⚠️ NOT constant-time
Related
- Key Derivation - Public key derivation using scalar multiplication
- Signing - ECDSA uses point operations
- Verification - Verification algorithm
- Security - Constant-time requirements
- Performance - Optimization techniques

