Files
evmgpu/accounts/abi/bind/precompilebind/precompile_module_template.go
zeekayandHanzo Dev e50df1e4ca accounts/abi/bind: generate against this tree, and emit a Configurator that compiles
Two separate faults, both in the code generator's own coverage.

The precompile module template never emitted MakeGenesisConfig, which
contract.Configurator has required for some time. Every precompile generated by
precompilebind therefore failed to compile against the interface it is generated
to satisfy. The template now emits it, matching the config template's NewConfig
signature in both the plain and allow-list shapes. The test's stand-in address
also predated the LP-aligned reserved range, so registration panicked with
"not in a reserved range" the moment the generated code did compile; it now sits
at the top of 0x10000-0x1ffff, clear of every precompile this repo registers.

The binding test built its generated module against github.com/luxfi/evmgpu
resolved from the proxy, so it measured the last published release rather than
the working tree -- it fails when the release has drifted and, worse, passes
when the tree is broken. Pointing it at the tree alone was not enough: a
from-scratch tidy re-resolves every version, because the go command ignores
exclude and replace directives in a module that is not the main one. That
pulled warp v1.24.1, which this repository does not build with and where
warp.UnsignedMessage no longer exists. The test now copies go.mod and go.sum
across and renames the module, so the generated code builds against the same
build list the repository uses.

accounts/abi/bind and accounts/abi/bind/precompilebind now pass.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-28 23:43:53 -07:00

89 lines
3.2 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package precompilebind
// tmplSourcePrecompileModuleGo is the Go precompiled module source template.
const tmplSourcePrecompileModuleGo = `
// Code generated
// This file is a generated precompile contract config with stubbed abstract functions.
// The file is generated by a template. Please inspect every code and comment in this file before use.
package {{.Package}}
import (
"fmt"
"github.com/luxfi/evmgpu/precompile/precompileconfig"
"github.com/luxfi/evmgpu/precompile/contract"
"github.com/luxfi/evmgpu/precompile/modules"
"github.com/luxfi/geth/common"
)
var _ contract.Configurator = (*configurator)(nil)
// ConfigKey is the key used in json config files to specify this precompile config.
// must be unique across all precompiles.
const ConfigKey = "{{decapitalise .Contract.Type}}Config"
// ContractAddress is the defined address of the precompile contract.
// This should be unique across all precompile contracts.
// See precompile/registry/registry.go for registered precompile contracts and more information.
var ContractAddress = common.HexToAddress("{ASUITABLEHEXADDRESS}") // SET A SUITABLE HEX ADDRESS HERE
// Module is the precompile module. It is used to register the precompile contract.
var Module = modules.Module{
ConfigKey: ConfigKey,
Address: ContractAddress,
Contract: {{.Contract.Type}}Precompile,
Configurator: &configurator{},
}
type configurator struct{}
func init() {
// Register the precompile module.
// Each precompile contract registers itself through [RegisterModule] function.
if err := modules.RegisterModule(Module); err != nil {
panic(err)
}
}
// MakeConfig returns a new precompile config instance.
// This is required to Marshal/Unmarshal the precompile config.
func (*configurator) MakeConfig() precompileconfig.Config {
return new(Config)
}
// MakeGenesisConfig returns a precompile config for genesis activation (timestamp = 0).
// This is used by AllGenesisPrecompiles() to enumerate all precompiles with default configs.
func (*configurator) MakeGenesisConfig() precompileconfig.Config {
var zero uint64
return NewConfig(&zero{{if .Contract.AllowList}}, nil, nil, nil{{end}})
}
// Configure configures [state] with the given [cfg] precompileconfig.
// This function is called by the EVM once per precompile contract activation.
// You can use this function to set up your precompile contract's initial state,
// by using the [cfg] config and [state] stateDB.
func (*configurator) Configure(chainConfig precompileconfig.ChainConfig, cfg precompileconfig.Config, state contract.StateDB, blockContext contract.ConfigurationBlockContext) error {
// CUSTOM CODE STARTS HERE
{{- if .Contract.AllowList}}
config, ok := cfg.(*Config)
if !ok {
return fmt.Errorf("expected config type %T, got %T: %v", &Config{}, cfg, cfg)
}
// AllowList is activated for this precompile. Configuring allowlist addresses here.
return config.AllowListConfig.Configure(chainConfig, ContractAddress, state, blockContext)
{{- else}}
if _, ok := cfg.(*Config); !ok {
return fmt.Errorf("expected config type %T, got %T: %v", &Config{}, cfg, cfg)
}
return nil
{{- end}}
}
`