feat: add new precompile contract interface

This commit is contained in:
aryansonid 2026-03-05 19:29:27 +05:30
parent efac930cf2
commit 3c87a31db8
2 changed files with 48 additions and 1 deletions

View file

@ -62,7 +62,6 @@ var PrecompiledContractsHomestead = PrecompiledContracts{
common.BytesToAddress([]byte{0x2}): &sha256hash{},
common.BytesToAddress([]byte{0x3}): &ripemd160hash{},
common.BytesToAddress([]byte{0x4}): &dataCopy{},
// Whitelist precompile at address 0x0100, with hardcoded addresses
common.BytesToAddress([]byte{0x01, 0x00}): NewWhitelistPrecompile([]common.Address{
common.HexToAddress("0x1111111111111111111111111111111111111111"),
common.HexToAddress("0x2222222222222222222222222222222222222222"),

View file

@ -0,0 +1,48 @@
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package vm
import (
"github.com/ethereum/go-ethereum/common"
)
// WhitelistPrecompile is a precompiled contract for address whitelisting.
type WhitelistPrecompile struct {
whitelist map[common.Address]struct{}
}
func NewWhitelistPrecompile(addresses []common.Address) *WhitelistPrecompile {
wl := make(map[common.Address]struct{})
for _, addr := range addresses {
wl[addr] = struct{}{}
}
return &WhitelistPrecompile{whitelist: wl}
}
func (w *WhitelistPrecompile) RequiredGas(input []byte) uint64 {
return 1000
}
func (w *WhitelistPrecompile) Run(input []byte) ([]byte, error) {
// Expect input: first 20 bytes = caller address
return []byte{}, nil
}
func (w *WhitelistPrecompile) Name() string {
return "WhitelistPrecompile"
}