Files
zeekay 6f22a39b18 refactor(precompileconfig)!: warp v1.22.0 — AddMessage takes *warp.Message
Track the warp rename Core -> Message. WarpMessageWriter.AddMessage now takes
*warp.Message (the cross-chain message); doc comment updated to match.
2026-06-27 00:39:50 -07:00

75 lines
3.2 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// Defines the stateless interface for unmarshalling an arbitrary config of a precompile
package precompileconfig
import (
"context"
"github.com/luxfi/geth/common"
"github.com/luxfi/runtime"
"github.com/luxfi/warp"
)
// StatefulPrecompileConfig defines the interface for a stateful precompile to
// be enabled via a network upgrade.
type Config interface {
// Key returns the unique key for the stateful precompile.
Key() string
// Timestamp returns the timestamp at which this stateful precompile should be enabled.
// 1) 0 indicates that the precompile should be enabled from genesis.
// 2) n indicates that the precompile should be enabled in the first block with timestamp >= [n].
// 3) nil indicates that the precompile is never enabled.
Timestamp() *uint64
// IsDisabled returns true if this network upgrade should disable the precompile.
IsDisabled() bool
// Equal returns true if the provided argument configures the same precompile with the same parameters.
Equal(Config) bool
// Verify is called on startup and an error is treated as fatal. Configure can assume the Config has passed verification.
Verify(ChainConfig) error
}
// PredicateContext is the context passed in to the Predicater interface to verify
// a precompile predicate within a specific ProposerVM wrapper.
type PredicateContext struct {
// Runtime provides chain wiring and optional P-Chain height for block-specific checks.
Runtime *runtime.Runtime
}
// Predicater is an optional interface for StatefulPrecompileContracts to implement.
// If implemented, the predicate will be called for each predicate included in the
// access list of a transaction.
type Predicater interface {
PredicateGas(predicateBytes []byte) (uint64, error)
VerifyPredicate(predicateContext *PredicateContext, predicateBytes []byte) error
}
// WarpMessageWriter queues a precompile-emitted cross-chain message for the
// validator set to attest. The unsigned subject is the warp.Message: the
// canonical value whose digest D = keccak256(DST ‖ zap_c14n(message)) is what the
// BLS Beam / Corona Pulse / ML-DSA lanes sign. Build one via
// warp.NewMessage(networkID, sourceChainID, payload).
type WarpMessageWriter interface {
AddMessage(msg *warp.Message) error
}
// AcceptContext defines the context passed in to a precompileconfig's Accepter
type AcceptContext struct {
Ctx context.Context
Warp WarpMessageWriter
}
// Accepter is an optional interface for StatefulPrecompiledContracts to implement.
// If implemented, Accept will be called for every log with the address of the precompile when the block is accepted.
type Accepter interface {
Accept(acceptCtx *AcceptContext, blockHash common.Hash, blockNumber uint64, txHash common.Hash, logIndex int, topics []common.Hash, logData []byte) error
}
// ChainConfig defines an interface that provides information to a stateful precompile
// about the chain configuration. Under activate-all-implicitly there are no
// upgrade gates left to ask about; the interface is intentionally empty.
// Precompiles that need to discriminate runtime behaviour should declare
// their own typed input rather than piggy-back on the chain config.
type ChainConfig interface{}