From 3c87a31db83abbbbd1242df05a2d7d3d53e3a4c0 Mon Sep 17 00:00:00 2001 From: aryansonid Date: Thu, 5 Mar 2026 19:29:27 +0530 Subject: [PATCH] feat: add new precompile contract interface --- core/vm/contracts.go | 1 - core/vm/whitelist_precompile.go | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 core/vm/whitelist_precompile.go diff --git a/core/vm/contracts.go b/core/vm/contracts.go index a438a7ec83..816a65c7d8 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -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"), diff --git a/core/vm/whitelist_precompile.go b/core/vm/whitelist_precompile.go new file mode 100644 index 0000000000..22b0b0c82c --- /dev/null +++ b/core/vm/whitelist_precompile.go @@ -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 . + +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" +}