mirror of
https://github.com/luxfi/precompile.git
synced 2026-09-24 00:26:21 +00:00
docs/ is the Fumadocs site for precompile.lux.network — should not have been deleted. Package READMEs document input/output formats and gas costs referenced by the docs site.
3.1 KiB
3.1 KiB
secp256r1 (P-256) Signature Verification Precompile
Implementation of the secp256r1 (NIST P-256) signature verification precompile for the Lux Network EVM.
Overview
This precompile enables efficient verification of ECDSA signatures using the NIST P-256 curve, commonly used by:
- WebAuthn/Passkeys: Modern password-less authentication
- Apple Secure Enclave: Face ID / Touch ID
- Windows Hello: Biometric authentication
- Android Keystore: Device-backed keys
- Enterprise HSMs: NIST-approved cryptography
Precompile Details
| Property | Value |
|---|---|
| Address | 0x0000000000000000000000000000000000000100 |
| Gas Cost | 3,450 |
| Input Size | 160 bytes |
| Output Size | 32 bytes (success) or 0 bytes (failure) |
Input Format
[32 bytes] message hash
[32 bytes] r (signature component)
[32 bytes] s (signature component)
[32 bytes] x (public key x-coordinate)
[32 bytes] y (public key y-coordinate)
Output Format
- Success: 32 bytes with value
0x0000000000000000000000000000000000000000000000000000000000000001 - Failure: Empty (0 bytes)
Usage
Solidity
import {Secp256r1Lib, P256PublicKey} from "./ISecp256r1.sol";
contract MyContract {
using Secp256r1Lib for bytes32;
function verifyBiometric(
bytes32 hash,
bytes32 r,
bytes32 s,
bytes32 pubX,
bytes32 pubY
) external view returns (bool) {
return Secp256r1Lib.verify(hash, r, s, pubX, pubY);
}
}
Go
import "github.com/luxfi/precompiles/secp256r1"
func verify(hash []byte, r, s, x, y *big.Int) bool {
return secp256r1.Verify(hash, r, s, x, y)
}
Gas Comparison
| Method | Gas Cost | Savings |
|---|---|---|
| Solidity implementation | 200,000 - 330,000 | - |
| This precompile | 3,450 | 99% |
Use Cases
- Biometric Wallets: Sign transactions with Face ID/Touch ID
- Enterprise SSO: Integrate with corporate identity systems
- WebAuthn/Passkeys: Password-less authentication for dApps
- Cross-Chain Identity: Unified authentication across Lux chains
Standards Compliance
- EIP-7212: secp256r1 Curve Support
- RIP-7212: Rollup precompile
- NIST FIPS 186-3: Digital Signature Standard
- LP-3651: Lux Network specification
Testing
go test -v ./...
Benchmarks
go test -bench=. -benchmem
Typical results (Apple M1 Max):
BenchmarkContract_Run-10 100000 10.5 µs/op 0 B/op 0 allocs/op
BenchmarkVerify-10 100000 10.3 µs/op 0 B/op 0 allocs/op
Security Considerations
- Constant Time: Uses Go stdlib
crypto/ecdsawhich provides constant-time operations - Point Validation: Validates that public key is on curve before verification
- Range Checks: Validates r, s are in range [1, n-1]
- No Malleability Check: Follows NIST specification exactly
License
MIT License - Copyright (C) 2025, Lux Industries, Inc.