feat: export P256Verify precompile (#222)

## Why this should be merged

Allows direct access to the P-256 verification precompile. Currently the
only alternative is to rely on the planned but not guaranteed address
that Ethereum will use.

## How this works

Embed the non-exported `p256verify` type in an exported struct to allow
its methods to be exposed.

## How this was tested

Run the test suite for `p256verify` on `P256Verify`.
This commit is contained in:
Arran Schlosberg 2025-09-04 19:01:42 +01:00 committed by GitHub
parent e4220c7ed4
commit 72e9ad7962
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 0 deletions

View file

@ -31,6 +31,14 @@ import (
"github.com/ava-labs/libevm/params"
)
// P256Verify is a [PrecompiledContract] implementation of P-256 (secp256r1)
// ECDSA verification, as defined by [EIP-7951].
//
// [EIP-7951]: https://eips.ethereum.org/EIPS/eip-7951
type P256Verify struct {
p256Verify
}
// ActivePrecompiles returns the precompiles enabled with the current configuration.
func ActivePrecompiles(rules params.Rules) []common.Address {
orig := activePrecompiles(rules) // original, upstream implementation

View file

@ -0,0 +1,33 @@
// Copyright 2025 the libevm authors.
//
// The libevm additions to go-ethereum are free software: you can redistribute
// them and/or modify them 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 libevm additions are distributed in the hope that they 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 (
"testing"
"github.com/ava-labs/libevm/common"
)
func TestExportedP256Verify(t *testing.T) {
addr := common.Address{'p', '2', '5', '6', 'l', 'i', 'b', 'e', 'v', 'm'}
allPrecompiles[addr] = &P256Verify{}
t.Cleanup(func() {
delete(allPrecompiles, addr)
})
testJson("p256Verify", addr.Hex(), t)
}