Lux Standard

Precompiles

Native EVM precompiles for cryptography, DEX, and cross-chain messaging

Precompiles

Lux EVM includes custom precompiles for post-quantum cryptography, threshold signatures, DEX operations, and cross-chain messaging.

Architecture Overview

┌─────────────────────────────────────────────────────────────────────────────────────────┐
│                          LUX PRECOMPILE ARCHITECTURE                                    │
├─────────────────────────────────────────────────────────────────────────────────────────┤
│                                                                                         │
│  POST-QUANTUM CRYPTOGRAPHY              THRESHOLD SIGNATURES                            │
│  ┌─────────────┐ ┌─────────────┐        ┌─────────────┐ ┌─────────────┐               │
│  │   ML-DSA    │ │   SLH-DSA   │        │    FROST    │ │  CGGMP21    │               │
│  │   0x0006    │ │   0x0007    │        │   0x000C    │ │   0x000D    │               │
│  │ FIPS 204    │ │ FIPS 205    │        │  Schnorr    │ │   ECDSA     │               │
│  └─────────────┘ └─────────────┘        └─────────────┘ └─────────────┘               │
│  ┌─────────────┐ ┌─────────────┐        ┌─────────────┐ ┌─────────────┐               │
│  │   ML-KEM    │ │  PQCrypto   │        │  Ringtail   │ │     LSS     │               │
│  │   0x0008    │ │   0x0009    │        │   0x000B    │ │   0x000E    │               │
│  │ FIPS 203    │ │ Multi-algo  │        │ PQ Thresh   │ │  Shamir SS  │               │
│  └─────────────┘ └─────────────┘        └─────────────┘ └─────────────┘               │
│                                                                                         │
│  CROSS-CHAIN & CONSENSUS                DEX PRECOMPILES                                │
│  ┌─────────────┐ ┌─────────────┐        ┌─────────────┐ ┌─────────────┐               │
│  │    Warp     │ │   Quasar    │        │PoolManager  │ │   Hooks     │               │
│  │   0x0005    │ │   0x000A    │        │   0x0400    │ │   0x0402    │               │
│  │ BLS Aggr    │ │ Quantum Fin │        │ Singleton   │ │  Callbacks  │               │
│  └─────────────┘ └─────────────┘        └─────────────┘ └─────────────┘               │
│  ┌─────────────┐ ┌─────────────┐                                                       │
│  │     BLS     │ │ secp256r1   │        ZK PRECOMPILES (EIP-1108, EIP-2537)           │
│  │   0x000F    │ │   0x0010    │        ┌─────────────┐ ┌─────────────┐               │
│  │  BLS12-381  │ │  P-256 Sig  │        │  BN254 ZK   │ │ BLS12-381   │               │
│  └─────────────┘ └─────────────┘        │  0x06-0x08  │ │ 0x0b-0x11   │               │
│                                         └─────────────┘ └─────────────┘               │
└─────────────────────────────────────────────────────────────────────────────────────────┘

Precompile Address Map

Lux Custom Precompiles (0x02...)

AddressNameDescriptionGas
0x0200...0005WarpCross-chain messaging via BLS20,375 + 8/byte
0x0200...0006ML-DSAPost-quantum signatures (FIPS 204)100,000 base
0x0200...0007SLH-DSAStateless hash-based PQ sigs (FIPS 205)150,000 base
0x0200...0008ML-KEMPost-quantum key encapsulation (FIPS 203)50,000 base
0x0200...0009PQCryptoMulti-algorithm PQ operationsVariable
0x0200...000AQuasarQuantum consensus operationsVariable
0x0200...000BRingtailPQ threshold signatures150,000 + 10,000/party
0x0200...000CFROSTSchnorr threshold signatures50,000 + 5,000/signer
0x0200...000DCGGMP21ECDSA threshold signatures75,000 + 10,000/signer
0x0200...000ELSSLattice secret sharingVariable
0x0200...000FBLSBLS12-381 operationsVariable
0x0200...0010secp256r1P-256 signature verification3,450

DEX Precompiles (0x04...)

AddressNameDescription
0x0400PoolManagerSingleton pool manager with flash accounting
0x0401SwapRouterOptimized swap routing
0x0402HooksRegistryHook contract registry
0x0403FlashLoanFlash loan facility

ZK Precompiles (Ethereum Standard)

AddressNameGasStandard
0x06ECADD150EIP-1108
0x07ECMUL6,000EIP-1108
0x08ECPAIRING45,000 + 34,000/pairEIP-1108
0x0b-0x11BLS12-381VariableEIP-2537

Post-Quantum Cryptography

ML-DSA (FIPS 204)

Module-Lattice Digital Signature Algorithm. Quantum-resistant signatures.

import "@luxfi/contracts/precompile/interfaces/IMLDSA.sol";

// Verify post-quantum signature
IMLDSA mldsa = IMLDSA(0x0200000000000000000000000000000000000006);
bool valid = mldsa.verify(publicKey, message, signature);

// Using library with revert on failure
MLDSALib.verifyOrRevert(publicKey, message, signature);

Key Sizes (ML-DSA-65):

  • Public Key: 1952 bytes
  • Signature: 3309 bytes
  • Security: NIST Level 3 (AES-192 equivalent)

ML-KEM (FIPS 203)

Module-Lattice Key Encapsulation Mechanism. Quantum-resistant key exchange.

import "@luxfi/contracts/precompile/interfaces/IMLKEM.sol";

// Encapsulate shared secret
IMLKEM mlkem = IMLKEM(0x0200000000000000000000000000000000000008);
(bytes memory ciphertext, bytes32 sharedSecret) = mlkem.encapsulate(publicKey);

// Decapsulate on recipient side
bytes32 recoveredSecret = mlkem.decapsulate(privateKey, ciphertext);

SLH-DSA (FIPS 205)

Stateless Hash-based Digital Signature Algorithm. Conservative PQ choice.

import "@luxfi/contracts/precompile/interfaces/ISLHDSA.sol";

ISLHDSA slhdsa = ISLHDSA(0x0200000000000000000000000000000000000007);
bool valid = slhdsa.verify(publicKey, message, signature);

Threshold Signatures

FROST (Schnorr Threshold)

Flexible Round-Optimized Schnorr Threshold signatures. Efficient t-of-n signing.

import "@luxfi/contracts/precompile/interfaces/IFROST.sol";

// Verify 2-of-3 threshold signature
IFROST frost = IFROST(0x020000000000000000000000000000000000000C);
bool valid = frost.verify(
    2,              // threshold (t)
    3,              // total signers (n)
    publicKey,      // 32-byte aggregated key
    messageHash,    // 32-byte message hash
    signature       // 64-byte Schnorr signature
);

// Using library
FROSTLib.verifyOrRevert(2, 3, publicKey, messageHash, signature);

Use Cases:

  • Bitcoin Taproot multisig
  • Cross-chain bridge guardians
  • DAO governance

CGGMP21 (ECDSA Threshold)

State-of-the-art threshold ECDSA with identifiable aborts.

import "@luxfi/contracts/precompile/interfaces/ICGGMP21.sol";

// Verify 3-of-5 threshold ECDSA
ICGGMP21 cggmp = ICGGMP21(0x020000000000000000000000000000000000000D);
bool valid = cggmp.verify(
    3,              // threshold
    5,              // total signers
    publicKey,      // 65-byte uncompressed pubkey
    messageHash,    // 32-byte message hash
    signature       // 65-byte ECDSA signature (r, s, v)
);

Use Cases:

  • Ethereum-compatible custody
  • Institutional wallet management
  • Standard ECDSA compatibility required

Ringtail (Post-Quantum Threshold)

Lattice-based threshold signatures for quantum resistance.

import "@luxfi/contracts/precompile/interfaces/IRingtailThreshold.sol";

// Verify quantum-resistant threshold signature
IRingtailThreshold ringtail = IRingtailThreshold(0x020000000000000000000000000000000000000B);
bool valid = ringtail.verify(
    3,              // threshold
    5,              // total parties
    publicKey,      // aggregated lattice public key
    messageHash,    // message hash
    signature       // lattice signature (~4KB)
);

Algorithm Comparison

AlgorithmSignature SizeGas (3-of-5)Quantum SafeUse Case
FROST64 bytes75,000Bitcoin Taproot
CGGMP2165 bytes125,000ECDSA required
Ringtail~4 KB200,000Future-proof

Cross-Chain Messaging

Warp Messaging

Cross-chain communication with BLS signature aggregation.

import "@luxfi/contracts/precompile/interfaces/IWarp.sol";

// Get current blockchain ID
IWarp warp = IWarp(0x0200000000000000000000000000000000000005);
bytes32 chainId = warp.getBlockchainID();

// Send cross-chain message
bytes32 messageId = warp.sendWarpMessage(payload);

// Receive verified message on destination
(IWarp.WarpMessage memory msg, bool valid) = warp.getVerifiedWarpMessage(0);
require(valid, "Message not verified");

Message Flow:

  1. Source chain calls sendWarpMessage(payload)
  2. Validators sign using BLS aggregation
  3. Relayer submits signed message to destination
  4. Destination calls getVerifiedWarpMessage(index)

Quasar Consensus

Quantum-finality consensus operations.

import "@luxfi/contracts/precompile/interfaces/IQuasar.sol";

IQuasar quasar = IQuasar(0x020000000000000000000000000000000000000A);

// Get quantum-finalized block
bytes32 finalizedBlock = quasar.getQuantumFinalizedBlock();

// Verify quantum finality proof
bool valid = quasar.verifyQuantumFinality(blockHash, proof);

DEX Precompiles

PoolManager

Uniswap v4-style singleton pool manager with flash accounting.

import "@luxfi/contracts/precompile/interfaces/dex/IPoolManager.sol";
import "@luxfi/contracts/precompile/interfaces/dex/Types.sol";

IPoolManager poolManager = IPoolManager(0x0400);

// Initialize a new pool
PoolKey memory key = PoolKey({
    currency0: Currency.wrap(address(tokenA)),
    currency1: Currency.wrap(address(tokenB)),
    fee: 3000,           // 0.30%
    tickSpacing: 60,
    hooks: address(0)    // no hooks
});

int24 tick = poolManager.initialize(key, sqrtPriceX96, "");

// Execute swap within lock context
poolManager.lock(abi.encode(swapData));

Hooks System

Custom logic injection points for pool operations.

import "@luxfi/contracts/precompile/interfaces/dex/IHooks.sol";

contract MyHook is BaseHook {
    constructor(address _poolManager) BaseHook(_poolManager) {}

    function getHookPermissions() public pure override returns (HookPermissions) {
        return HookPermissionsLib.fromBitmap(
            1 << 6 |  // beforeSwap
            1 << 7    // afterSwap
        );
    }

    function beforeSwap(
        PoolKey calldata key,
        SwapParams calldata params,
        bytes calldata hookData
    ) external override returns (uint24 feeOverride) {
        // Custom pre-swap logic
        return 0; // no fee override
    }
}

Performance

OperationLatencyThroughput
Swap2.26μs443K ops/sec
ModifyLiquidity2.87μs348K ops/sec

ZK Precompiles

BN254 (EIP-1108)

Standard zkSNARK operations on alt_bn128 curve.

// ECADD - Point addition
(bool success, bytes memory result) = address(0x06).staticcall(
    abi.encodePacked(x1, y1, x2, y2)
);

// ECMUL - Scalar multiplication
(bool success, bytes memory result) = address(0x07).staticcall(
    abi.encodePacked(x, y, scalar)
);

// ECPAIRING - Pairing check
(bool success, bytes memory result) = address(0x08).staticcall(pairingInput);

BLS12-381 (EIP-2537)

Available with pragueTime upgrade.

// G1ADD - BLS12-381 G1 point addition
(bool success, bytes memory result) = address(0x0b).staticcall(g1Input);

// PAIRING - BLS12-381 pairing
(bool success, bytes memory result) = address(0x10).staticcall(pairingInput);

Interface Files

All precompile interfaces are available at:

contracts/crypto/precompiles/
├── IMLDSA.sol           # ML-DSA (FIPS 204)
├── ISLHDSA.sol          # SLH-DSA (FIPS 205)
├── IMLKEM.sol           # ML-KEM (FIPS 203)
├── IPQCrypto.sol        # Multi-PQ operations
├── IFROST.sol           # Schnorr threshold
├── ICGGMP21.sol         # ECDSA threshold
├── IRingtailThreshold.sol # PQ threshold
├── ILSS.sol             # Lattice secret sharing
├── IWarp.sol            # Cross-chain messaging
├── IQuasar.sol          # Quantum consensus
├── IBLS.sol             # BLS12-381 operations
├── ISecp256r1.sol       # P-256 signatures
└── dex/
    ├── Types.sol        # DEX types (Currency, PoolKey, etc.)
    ├── IPoolManager.sol # Singleton pool manager
    ├── IHooks.sol       # Hook interface + BaseHook
    └── ILRC20Minimal.sol # Minimal token interface

Import Paths

// Post-quantum
import "@luxfi/contracts/precompile/interfaces/IMLDSA.sol";
import "@luxfi/contracts/precompile/interfaces/IMLKEM.sol";

// Threshold
import "@luxfi/contracts/precompile/interfaces/IFROST.sol";
import "@luxfi/contracts/precompile/interfaces/ICGGMP21.sol";

// Cross-chain
import "@luxfi/contracts/precompile/interfaces/IWarp.sol";

// DEX
import "@luxfi/contracts/precompile/interfaces/dex/IPoolManager.sol";
import "@luxfi/contracts/precompile/interfaces/dex/IHooks.sol";

Security Considerations

  1. Gas Limits: PQ operations are computationally expensive
  2. Key Sizes: ML-DSA public keys are ~2KB, plan storage accordingly
  3. Threshold Selection: Use t > n/2 for Byzantine fault tolerance
  4. Message Hashing: Always hash messages before signing
  5. Cross-Chain: Verify source chain and sender addresses

On this page