precompile

package
v1.17.27 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ML-DSA (FIPS 204) range: 0x0110-0x0119
	MLDSAStartAddress = "0x0110"
	MLDSAEndAddress   = "0x0119"

	// ML-KEM (FIPS 203) range: 0x0120-0x0129
	MLKEMStartAddress = "0x0120"
	MLKEMEndAddress   = "0x0129"

	// SLH-DSA (FIPS 205) range: 0x0130-0x0139
	SLHDSAStartAddress = "0x0130"
	SLHDSAEndAddress   = "0x0139"

	// SHAKE (FIPS 202) range: 0x0140-0x0149
	SHAKEStartAddress = "0x0140"
	SHAKEEndAddress   = "0x0149"

	// Lamport signatures range: 0x0150-0x0159
	LamportStartAddress = "0x0150"
	LamportEndAddress   = "0x0159"
)

Address ranges for different crypto standards

Variables

View Source
var (
	// BLS12-381 operations
	BLSVerifyAddress          = HexToAddress("0x0000000000000000000000000000000000000160")
	BLSAggregateVerifyAddress = HexToAddress("0x0000000000000000000000000000000000000161")
	BLSFastAggregateAddress   = HexToAddress("0x0000000000000000000000000000000000000162")

	// Threshold BLS operations
	BLSThresholdVerifyAddress  = HexToAddress("0x0000000000000000000000000000000000000163")
	BLSThresholdCombineAddress = HexToAddress("0x0000000000000000000000000000000000000164")

	// BLS key operations
	BLSPublicKeyAggregateAddress = HexToAddress("0x0000000000000000000000000000000000000165")
	BLSHashToPointAddress        = HexToAddress("0x0000000000000000000000000000000000000166")
)

BLS precompile addresses

View Source
var (
	LamportVerifySHA256Address = HexToAddress("0x0000000000000000000000000000000000000150")
	LamportVerifySHA512Address = HexToAddress("0x0000000000000000000000000000000000000151")
	LamportBatchVerifyAddress  = HexToAddress("0x0000000000000000000000000000000000000152")
	LamportMerkleRootAddress   = HexToAddress("0x0000000000000000000000000000000000000153")
	LamportMerkleVerifyAddress = HexToAddress("0x0000000000000000000000000000000000000154")
)

Lamport precompile addresses

View Source
var (
	// SHAKE128 precompiles
	SHAKE128Address     = HexToAddress("0x0000000000000000000000000000000000000140")
	SHAKE128_256Address = HexToAddress("0x0000000000000000000000000000000000000141")
	SHAKE128_512Address = HexToAddress("0x0000000000000000000000000000000000000142")

	// SHAKE256 precompiles
	SHAKE256Address      = HexToAddress("0x0000000000000000000000000000000000000143")
	SHAKE256_256Address  = HexToAddress("0x0000000000000000000000000000000000000144")
	SHAKE256_512Address  = HexToAddress("0x0000000000000000000000000000000000000145")
	SHAKE256_1024Address = HexToAddress("0x0000000000000000000000000000000000000146")

	// cSHAKE precompiles
	CSHAKE128Address = HexToAddress("0x0000000000000000000000000000000000000147")
	CSHAKE256Address = HexToAddress("0x0000000000000000000000000000000000000148")
)

SHAKE precompile addresses

View Source
var PostQuantumRegistry = NewRegistry()

Global registry for all post-quantum precompiles

Functions

func EnableCGO

func EnableCGO() bool

EnableCGO checks if CGO optimizations are available

func GetAllPostQuantumPrecompiles

func GetAllPostQuantumPrecompiles() map[Address]PrecompiledContract

GetAllPostQuantumPrecompiles returns all post-quantum precompiles This includes SHAKE, Lamport, and the three NIST standards

func GetGasEstimate

func GetGasEstimate(addr Address, inputSize int) uint64

GetGasEstimate returns an estimated gas cost for a precompile

func Info

func Info() map[string]interface{}

Info returns information about all registered precompiles

func RegisterBLS

func RegisterBLS(registry *Registry)

RegisterBLS registers all BLS precompiles

func RegisterLamport

func RegisterLamport(registry *Registry)

RegisterLamport registers all Lamport precompiles

func RegisterSHAKE

func RegisterSHAKE(registry *Registry)

RegisterSHAKE registers all SHAKE precompiles

Types

type Address

type Address [20]byte

Address represents a 20-byte Ethereum address

func GetPrecompileAddresses

func GetPrecompileAddresses() []Address

GetPrecompileAddresses returns all registered addresses

func HexToAddress

func HexToAddress(s string) Address

HexToAddress returns Address with byte values of s.

func (Address) Bytes

func (a Address) Bytes() []byte

Bytes returns the byte representation of the address

func (Address) String

func (a Address) String() string

String returns the hex string representation of the address

type BLSAggregateVerify

type BLSAggregateVerify struct{}

BLSAggregateVerify verifies multiple signatures with different messages

func (*BLSAggregateVerify) RequiredGas

func (b *BLSAggregateVerify) RequiredGas(input []byte) uint64

func (*BLSAggregateVerify) Run

func (b *BLSAggregateVerify) Run(input []byte) ([]byte, error)

type BLSFastAggregate

type BLSFastAggregate struct{}

BLSFastAggregate verifies aggregate signature with same message

func (*BLSFastAggregate) RequiredGas

func (b *BLSFastAggregate) RequiredGas(input []byte) uint64

func (*BLSFastAggregate) Run

func (b *BLSFastAggregate) Run(input []byte) ([]byte, error)

type BLSHashToPoint

type BLSHashToPoint struct{}

BLSHashToPoint hashes message to BLS12-381 G2 point

func (*BLSHashToPoint) RequiredGas

func (b *BLSHashToPoint) RequiredGas(input []byte) uint64

func (*BLSHashToPoint) Run

func (b *BLSHashToPoint) Run(input []byte) ([]byte, error)

type BLSPublicKeyAggregate

type BLSPublicKeyAggregate struct{}

BLSPublicKeyAggregate aggregates multiple BLS public keys

func (*BLSPublicKeyAggregate) RequiredGas

func (b *BLSPublicKeyAggregate) RequiredGas(input []byte) uint64

func (*BLSPublicKeyAggregate) Run

func (b *BLSPublicKeyAggregate) Run(input []byte) ([]byte, error)

type BLSThresholdCombine

type BLSThresholdCombine struct{}

BLSThresholdCombine combines threshold signature shares

func (*BLSThresholdCombine) RequiredGas

func (b *BLSThresholdCombine) RequiredGas(input []byte) uint64

func (*BLSThresholdCombine) Run

func (b *BLSThresholdCombine) Run(input []byte) ([]byte, error)

type BLSThresholdVerify

type BLSThresholdVerify struct{}

BLSThresholdVerify verifies threshold signature

func (*BLSThresholdVerify) RequiredGas

func (b *BLSThresholdVerify) RequiredGas(input []byte) uint64

func (*BLSThresholdVerify) Run

func (b *BLSThresholdVerify) Run(input []byte) ([]byte, error)

type BLSVerify

type BLSVerify struct{}

BLSVerify implements single BLS signature verification

func (*BLSVerify) RequiredGas

func (b *BLSVerify) RequiredGas(input []byte) uint64

func (*BLSVerify) Run

func (b *BLSVerify) Run(input []byte) ([]byte, error)

type CSHAKE128

type CSHAKE128 struct{}

cSHAKE128 with customization string

func (*CSHAKE128) RequiredGas

func (c *CSHAKE128) RequiredGas(input []byte) uint64

func (*CSHAKE128) Run

func (c *CSHAKE128) Run(input []byte) ([]byte, error)

type CSHAKE256

type CSHAKE256 struct{}

func (*CSHAKE256) RequiredGas

func (c *CSHAKE256) RequiredGas(input []byte) uint64

func (*CSHAKE256) Run

func (c *CSHAKE256) Run(input []byte) ([]byte, error)

type LamportBatchVerify

type LamportBatchVerify struct{}

LamportBatchVerify implements batch verification

func (*LamportBatchVerify) RequiredGas

func (l *LamportBatchVerify) RequiredGas(input []byte) uint64

func (*LamportBatchVerify) Run

func (l *LamportBatchVerify) Run(input []byte) ([]byte, error)

type LamportMerkleRoot

type LamportMerkleRoot struct{}

LamportMerkleRoot computes Merkle root of Lamport public keys

func (*LamportMerkleRoot) RequiredGas

func (l *LamportMerkleRoot) RequiredGas(input []byte) uint64

func (*LamportMerkleRoot) Run

func (l *LamportMerkleRoot) Run(input []byte) ([]byte, error)

type LamportMerkleVerify

type LamportMerkleVerify struct{}

LamportMerkleVerify verifies Merkle proof for a Lamport public key

func (*LamportMerkleVerify) RequiredGas

func (l *LamportMerkleVerify) RequiredGas(input []byte) uint64

func (*LamportMerkleVerify) Run

func (l *LamportMerkleVerify) Run(input []byte) ([]byte, error)

type LamportVerifySHA256

type LamportVerifySHA256 struct{}

LamportVerifySHA256 implements SHA256-based Lamport verification

func (*LamportVerifySHA256) RequiredGas

func (l *LamportVerifySHA256) RequiredGas(input []byte) uint64

func (*LamportVerifySHA256) Run

func (l *LamportVerifySHA256) Run(input []byte) ([]byte, error)

type LamportVerifySHA512

type LamportVerifySHA512 struct{}

LamportVerifySHA512 implements SHA512-based Lamport verification

func (*LamportVerifySHA512) RequiredGas

func (l *LamportVerifySHA512) RequiredGas(input []byte) uint64

func (*LamportVerifySHA512) Run

func (l *LamportVerifySHA512) Run(input []byte) ([]byte, error)

type PrecompiledContract

type PrecompiledContract interface {
	RequiredGas(input []byte) uint64  // Calculate gas cost
	Run(input []byte) ([]byte, error) // Execute the precompile
}

PrecompiledContract is the interface for EVM precompiled contracts

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry contains all available precompiled contracts

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new precompile registry

func (*Registry) Addresses

func (r *Registry) Addresses() []Address

Addresses returns all registered precompile addresses

func (*Registry) Contracts

func (r *Registry) Contracts() map[Address]PrecompiledContract

Contracts returns the map of all contracts

func (*Registry) Get

func (r *Registry) Get(addr Address) (PrecompiledContract, bool)

Get returns a precompiled contract by address

func (*Registry) Register

func (r *Registry) Register(addr Address, contract PrecompiledContract)

Register adds a precompiled contract to the registry

type SHAKE128

type SHAKE128 struct{}

SHAKE128 implements variable-output SHAKE128

func (*SHAKE128) RequiredGas

func (s *SHAKE128) RequiredGas(input []byte) uint64

func (*SHAKE128) Run

func (s *SHAKE128) Run(input []byte) ([]byte, error)

type SHAKE128_256

type SHAKE128_256 struct{}

func (*SHAKE128_256) RequiredGas

func (s *SHAKE128_256) RequiredGas(input []byte) uint64

func (*SHAKE128_256) Run

func (s *SHAKE128_256) Run(input []byte) ([]byte, error)

type SHAKE128_512

type SHAKE128_512 struct{}

Fixed size implementations

func (*SHAKE128_512) RequiredGas

func (s *SHAKE128_512) RequiredGas(input []byte) uint64

func (*SHAKE128_512) Run

func (s *SHAKE128_512) Run(input []byte) ([]byte, error)

type SHAKE256

type SHAKE256 struct{}

SHAKE256 implements variable-output SHAKE256

func (*SHAKE256) RequiredGas

func (s *SHAKE256) RequiredGas(input []byte) uint64

func (*SHAKE256) Run

func (s *SHAKE256) Run(input []byte) ([]byte, error)

type SHAKE256_1024

type SHAKE256_1024 struct{}

func (*SHAKE256_1024) RequiredGas

func (s *SHAKE256_1024) RequiredGas(input []byte) uint64

func (*SHAKE256_1024) Run

func (s *SHAKE256_1024) Run(input []byte) ([]byte, error)

type SHAKE256_256

type SHAKE256_256 struct{}

func (*SHAKE256_256) RequiredGas

func (s *SHAKE256_256) RequiredGas(input []byte) uint64

func (*SHAKE256_256) Run

func (s *SHAKE256_256) Run(input []byte) ([]byte, error)

type SHAKE256_512

type SHAKE256_512 struct{}

func (*SHAKE256_512) RequiredGas

func (s *SHAKE256_512) RequiredGas(input []byte) uint64

func (*SHAKE256_512) Run

func (s *SHAKE256_512) Run(input []byte) ([]byte, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL