Lux EVM Precompiled Contracts
Custom Stateful Precompiles
Overview
The Lux EVM provides two layers of precompiled contracts: chain-integrated precompiles in github.com/luxfi/evm/precompile/contracts/ (deployer allowlist, fee manager, native minter, reward manager, tx allowlist, warp) and extended precompiles in github.com/luxfi/precompile (50+ contracts spanning post-quantum cryptography, zero-knowledge proofs, threshold signatures, FHE, AI mining, cross-chain bridges, and a native DEX). All precompiles follow the LP (Lux Proposal) address scheme defined in LP-0099.
Modules
| Module | Go | Key Dependencies |
|---|---|---|
github.com/luxfi/evm (precompile/) | 1.26.1 | luxfi/geth@v1.16.75, luxfi/crypto@v1.17.40, luxfi/warp@v1.18.5, luxfi/vm@v1.0.38 |
github.com/luxfi/precompile | 1.26.1 | luxfi/geth@v1.16.73, luxfi/fhe@v1.7.6, luxfi/lattice/v7, luxfi/threshold@v1.5.0, luxfi/ringtail@v0.2.0, cloudflare/circl@v1.6.3, consensys/gnark-crypto@v0.19.2 |
Address Scheme (LP-0099)
All Lux-native precompiles use 20-byte addresses with an LP-aligned encoding:
Format: 0x0000000000000000000000000000000000PCIIR
P = Family page (LP-Pxxx first digit)
C = Chain slot (0-A)
II = Item/function (8 bits)Family Pages (P nibble)
| P | Range | Family |
|---|---|---|
| 0 | Core | Chain config precompiles (deployer, tx, minter, reward) |
| 1 | LP-1xxx | Fee management |
| 2 | LP-2xxx | PQ Identity (post-quantum signatures, KEM, hybrid) |
| 3 | LP-3xxx | EVM/Crypto (hashing, classical signatures, encryption) |
| 4 | LP-4xxx | Privacy/ZK (SNARKs, STARKs, commitments, FHE) |
| 5 | LP-5xxx | Threshold/MPC (FROST, CGGMP21, DKG, secret sharing) |
| 6 | LP-6xxx | Bridges (Warp messaging, token bridges, fee collection) |
| 7 | LP-7xxx | AI (GPU attestation, inference, mining sessions) |
| 9 | LP-9xxx | DEX/Markets (AMM, orderbook, lending, liquidation) |
Chain Slots (C nibble)
| C | Chain | C | Chain |
|---|---|---|---|
| 0 | P-Chain | 6 | Z-Chain |
| 1 | X-Chain | 7 | M-Chain (reserved) |
| 2 | C-Chain (main EVM) | 8 | Zoo |
| 3 | Q-Chain (quantum) | 9 | Hanzo |
| 4 | A-Chain (AI) | A | SPC |
| 5 | B-Chain (bridge) |
Helper functions: PrecompileAddress(p, c, ii), ChainSlot(name), FamilyPage(name).
Contract Framework
StatefulPrecompiledContract
The core execution interface. Each precompile implements Run:
// github.com/luxfi/evm/precompile/contract/interfaces.go
type StatefulPrecompiledContract interface {
Run(accessibleState AccessibleState, caller common.Address, addr common.Address,
input []byte, suppliedGas uint64, readOnly bool) (ret []byte, remainingGas uint64, err error)
}AccessibleState
Provides precompiles with EVM state access:
type AccessibleState interface {
GetStateDB() StateDB
GetBlockContext() BlockContext
GetConsensusContext() context.Context
GetChainConfig() precompileconfig.ChainConfig
}StateDB exposes: GetState, SetState, GetBalance, AddBalance, GetNonce, SetNonce, CreateAccount, Exist, AddLog, GetPredicateStorageSlots, GetTxHash, Snapshot, RevertToSnapshot.
Function Selector Dispatch
Contracts are built from StatefulPrecompileFunction entries, dispatched by 4-byte ABI selector:
// github.com/luxfi/evm/precompile/contract/contract.go
contract, err := contract.NewStatefulPrecompileContract(
fallback, // optional: called when input is empty
[]*contract.StatefulPrecompileFunction{
contract.NewStatefulPrecompileFunction(selector, executeFunc),
contract.NewStatefulPrecompileFunctionWithActivator(selector, executeFunc, activationFunc),
},
)ActivationFunc allows gating functions behind network upgrades (e.g., IsDurangoActivated).
Gas Constants
const (
WriteGasCostPerSlot = 20_000
ReadGasCostPerSlot = 5_000
LogGas = 375
LogTopicGas = 375
LogDataGas = 8
)Config Interface
Every precompile has a config implementing precompileconfig.Config:
type Config interface {
Key() string
Timestamp() *uint64 // nil = never enabled, 0 = genesis, n = enable at timestamp >= n
IsDisabled() bool
Equal(Config) bool
Verify(ChainConfig) error
}Module Registration
Precompiles self-register in init() via modules.RegisterModule:
var Module = modules.Module{
ConfigKey: "contractDeployerAllowListConfig",
Address: common.HexToAddress("0x10201"),
Contract: ContractDeployerAllowListPrecompile,
Configurator: &configurator{},
}
func init() {
if err := modules.RegisterModule(Module); err != nil {
panic(err)
}
}Modules are stored sorted by address for deterministic iteration. Registration validates: not blackhole address, within a reserved range, no duplicate key or address.
Configurator Interface
type Configurator interface {
MakeConfig() precompileconfig.Config
MakeGenesisConfig() precompileconfig.Config
Configure(chainConfig ChainConfig, cfg Config, state StateDB, blockContext ConfigurationBlockContext) error
}Chain-Integrated Precompiles (luxfi/evm)
AllowList Pattern
The AllowList abstraction (precompile/allowlist/) provides role-based access control used by multiple precompiles:
| Role | Value | Permissions |
|---|---|---|
NoRole | 0 | No access |
EnabledRole | 1 | Can call the precompile |
AdminRole | 2 | Can modify the allowlist AND call |
ManagerRole | 3 | Can add/remove Enabled only (Durango+) |
ABI methods: setAdmin(address), setManager(address), setEnabled(address), setNone(address), readAllowList(address).
Role modification rules:
- Admin can modify anyone to any role
- Manager can only toggle between Enabled and NoRole
- Enabled and NoRole cannot modify the list
Events are emitted on role changes (Durango+) with gas cost AllowListEventGasCost.
Contract Deployer AllowList
| Field | Value |
|---|---|
| ConfigKey | contractDeployerAllowListConfig |
| Address | 0x10201 |
| Gas | Read: 5,000 / Write: 20,000 |
Controls which addresses can deploy contracts. Configured in genesis or via network upgrade.
Transaction AllowList
| Field | Value |
|---|---|
| ConfigKey | txAllowListConfig |
| Address | 0x10301 |
| Gas | Read: 5,000 / Write: 20,000 |
Controls which addresses can submit transactions.
Native Minter
| Field | Value |
|---|---|
| ConfigKey | contractNativeMinterConfig |
| Address | 0x10401 |
| Gas | Mint: 30,000 |
Allows permissioned addresses to mint native tokens. ABI method: mintNativeCoin(address, uint256). Supports InitialMint map in config for genesis minting.
Fee Manager
| Field | Value |
|---|---|
| ConfigKey | feeManagerConfig |
| Address | 0x13F01 |
| Gas | Set: ~160,000 / Get: ~40,000 / GetLastChangedAt: 5,000 |
Controls dynamic fee configuration. Fee config fields: gasLimit, targetBlockRate, minBaseFee, targetGas, baseFeeChangeDenominator, minBlockGasCost, maxBlockGasCost, blockGasCostStep. Stores feeConfigLastChangedAt timestamp. Supports InitialFeeConfig in config or falls back to chain genesis fee config.
Reward Manager
| Field | Value |
|---|---|
| ConfigKey | rewardManagerConfig |
| Address | 0x10205 |
| Gas | Read: 5,000 / Write: 20,000 |
Controls block reward distribution. Three modes: AllowFeeRecipients (validators set fee recipient), DisableFeeRewards (burn all fees), or custom InitialRewardConfig.
Warp Messenger
| Field | Value |
|---|---|
| ConfigKey | warpConfig |
| Address | 0x16201 |
| Gas | Send: ~41,000 base + 8/byte / GetVerified: 2 base + per-signer/byte costs |
Cross-chain messaging via BLS aggregate signatures. ABI methods: sendWarpMessage(bytes), getVerifiedWarpMessage(uint32), getVerifiedWarpBlockHash(uint32), getBlockchainID().
Gas breakdown for verification:
GasCostPerWarpSigner: 500GasCostPerWarpMessageBytes: 100GasCostPerSignatureVerification: 200,000
Implements Predicater (validates warp predicates in access lists) and Accepter (writes messages on block acceptance).
Extended Precompiles (luxfi/precompile)
Registered via registry/registry.go force-imports in init():
// registry/registry.go
_ "github.com/luxfi/precompile/mldsa" // ML-DSA (FIPS 204)
_ "github.com/luxfi/precompile/mlkem" // ML-KEM (FIPS 203)
_ "github.com/luxfi/precompile/pqcrypto" // Unified PQ crypto
_ "github.com/luxfi/precompile/slhdsa" // SLH-DSA (FIPS 205)
_ "github.com/luxfi/precompile/ecies" // EC Integrated Encryption
_ "github.com/luxfi/precompile/fhe" // Fully Homomorphic Encryption
_ "github.com/luxfi/precompile/hpke" // Hybrid Public Key Encryption
_ "github.com/luxfi/precompile/ring" // Ring signatures
_ "github.com/luxfi/precompile/cggmp21" // Threshold ECDSA
_ "github.com/luxfi/precompile/frost" // Threshold Schnorr
_ "github.com/luxfi/precompile/ringtail" // Threshold lattice (PQ)
_ "github.com/luxfi/precompile/kzg4844" // KZG commitments
_ "github.com/luxfi/precompile/zk" // ZK proofs
_ "github.com/luxfi/precompile/secp256r1" // P-256 verification
_ "github.com/luxfi/precompile/ai" // AI mining
_ "github.com/luxfi/precompile/dex" // Native DEX
_ "github.com/luxfi/precompile/graph" // GraphQL query
_ "github.com/luxfi/precompile/blake3" // Blake3 hash
_ "github.com/luxfi/precompile/dead" // Dead/burn address
)PQ Identity (P=2, LP-2xxx)
| Name | Gas | Description |
|---|---|---|
| ML-DSA | 50,000 | NIST ML-DSA post-quantum signatures (FIPS 204) |
| ML-KEM | 25,000 | NIST ML-KEM key encapsulation (FIPS 203) |
| SLH-DSA | 75,000 | NIST SLH-DSA hash-based signatures (FIPS 205) |
| HYBRID_SIGN | 75,000 | ECDSA+ML-DSA hybrid signatures |
EVM/Crypto (P=3, LP-3xxx)
| Name | Gas | Description |
|---|---|---|
| BLAKE3 | 5,000 | High-performance hash |
| ED25519_VERIFY | 3,000 | Ed25519 (Solana/TON compat) |
| ECIES | 25,000 | Elliptic Curve Integrated Encryption |
Privacy/ZK (P=4, LP-4xxx)
| Name | Gas | Description |
|---|---|---|
| GROTH16 | 150,000 | Groth16 proof verification |
| PLONK | 175,000 | PLONK proof verification |
| STARK | 200,000 | STARK proof verification |
| KZG | 50,000 | KZG polynomial commitments (EIP-4844 extension) |
| FHE | 500,000 | Fully Homomorphic Encryption (TFHE, CKKS, BGV) |
Threshold/MPC (P=5, LP-5xxx)
| Name | Gas | Description |
|---|---|---|
| FROST | 25,000 | Schnorr threshold signatures |
| CGGMP21 | 50,000 | ECDSA threshold signatures |
| RINGTAIL | 75,000 | Threshold lattice signatures (post-quantum) |
Bridges (P=6, LP-6xxx)
| Name | Gas | Description |
|---|---|---|
| WARP_SEND | 50,000 | Cross-chain message send |
| WARP_RECEIVE | 50,000 | Cross-chain message receive |
| TELEPORT | 100,000 | Instant token teleport (LP-6010) |
AI (P=7, LP-7xxx)
| Name | Gas | Description |
|---|---|---|
| GPU_ATTEST | 100,000 | GPU compute attestation |
| TEE_VERIFY | 75,000 | TEE attestation verification |
| INFERENCE | 150,000 | AI inference verification |
| SESSION | 50,000 | AI mining session management |
DEX/Markets (LP-9xxx -- QuantumSwap Native DEX)
| Address Suffix | Name | Gas | Description |
|---|---|---|---|
0x...9010 | LX_POOL | 50,000 | Uniswap v4-style singleton AMM (PoolManager) |
0x...9011 | LX_ORACLE | 15,000 | Multi-source price oracle aggregation |
0x...9012 | LX_ROUTER | 10,000 | Optimized swap routing |
0x...9013 | LX_HOOKS | 10,000 | Hook contract registry |
0x...9014 | LX_FLASH | 50,000 | Flash loan facility |
0x...9020 | LX_BOOK | 25,000 | Central limit order book + matching engine |
0x...9030 | LX_VAULT | 50,000 | Custody, margin, and position management |
0x...9040 | LX_FEED | 10,000 | Computed price feeds (mark/index) |
0x...9050 | LX_LEND | 25,000 | Lending pool (Aave-style) |
0x...9060 | LX_LIQUID | 30,000 | Self-repaying loans (Alchemix-style) |
0x...9070 | LIQUIDATOR | 50,000 | Position liquidation engine |
0x...9080 | LIQUID_FX | 25,000 | Transmuter (liquid token conversion) |
Predicates and Accepters
Optional interfaces precompiles can implement:
- Predicater:
PredicateGas(bytes) (uint64, error)+VerifyPredicate(ctx, bytes) error-- validate access list entries before execution. Gas is added to intrinsic gas. Verification results are stored in the block as a bitset. - Accepter:
Accept(ctx, blockHash, blockNum, txHash, logIndex, topics, data) error-- triggered when block is accepted, for each log matching the precompile address.
How to Add a New Precompile
- Create package under
precompile/contracts/(chain-integrated) or as separateluxfi/precompile/subpackage (extended) - Define a
Modulewith uniqueConfigKeyand LP-alignedAddress - Implement
contract.StatefulPrecompiledContractwith function selectors - Implement
contract.ConfiguratorwithMakeConfig,MakeGenesisConfig,Configure - Register in
init()viamodules.RegisterModule(Module) - Add force-import to
registry/registry.go - Create ABI file (embedded via
//go:embed contract.abi) - Optionally implement
Predicaterand/orAccepter - Write config with AllowList if access control is needed
Chain Precompile Assignments
| Chain | Focus | Precompile Families |
|---|---|---|
| C-Chain | Main EVM | All families |
| Q-Chain | Quantum | PQ Identity, Threshold |
| A-Chain | AI | AI, Bridges |
| B-Chain | Bridge | Bridges, Fee Collection |
| Z-Chain | Privacy | Crypto, Privacy/ZK, FHE |
| Zoo | DeFi | DEX, Bridges |
| Hanzo | AI compute | AI (GPU, Inference, Session), Bridges |