EIP-665 · Stagnant · Core · 2018-03-25
EIP-665: Add precompiled contract for Ed25519 signature verification
Proposed a cheap precompiled contract for verifying Ed25519 signatures in the EVM, so contracts could check signatures from SSH, DNSSEC, TLS and Ed25519-based blockchains.
What problem does it solve?
Ethereum natively verifies only secp256k1 signatures (via ecrecover). Much of the wider world signs with Ed25519, including OpenSSH keys, DNSSEC, TLS certificates, OpenPGP, software-signing tools and several proof-of-stake blockchains. You can verify Ed25519 in plain EVM bytecode, but its wide-word arithmetic is a poor fit for the EVM, so gas costs are very high.
A precompile would let contracts:
- prove that one person controls both an Ethereum account and an off-chain Ed25519 key (a server, a domain, an SSH identity),
- accept Ed25519-signed data relayed by any sender,
- verify headers or messages from Ed25519-based chains.
How it works
The proposal adds a precompile ED25519VFY:
| Item | Value |
|---|---|
| Address | 0x09 |
| Input | 128 bytes: 32-byte message, 32-byte public key, 64-byte signature |
| Output | 4 bytes: 0x00000000 if valid, any non-zero value if invalid |
| Gas | 2000 (cheaper than ecrecover's 3000, since Ed25519 is faster) |
Unlike ecrecover, the public key must be passed in, because Ed25519 does not let you recover a key from a signature. A zero return means success, so different non-zero codes can signal different failure reasons.
To avoid consensus bugs between clients, the author recommended every client use libsodium (or its bindings), and pointed to the IETF and NaCl test vectors. Implementation PRs were opened for Geth, Parity, pyethereum and cpp-ethereum.
Sample code
How a contract would have called it. This is hypothetical. On mainnet, address 0x09 is a different precompile, so this code does not work.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
library Ed25519Proposed {
address constant ED25519VFY = address(0x09); // as proposed in EIP-665 only
function verify(bytes32 message, bytes32 pubKey, bytes memory sig)
internal view returns (bool)
{
require(sig.length == 64, "bad sig length");
(bool ok, bytes memory out) =
ED25519VFY.staticcall(abi.encodePacked(message, pubKey, sig));
return ok && out.length == 4 && bytes4(out) == bytes4(0);
}
}
Things to know
- This proposal is Stagnant and was never adopted. Ethereum mainnet has no Ed25519 precompile.
- The address it asked for,
0x09, was later assigned to the BLAKE2 compression function (EIP-152). - The message input is a fixed 32 bytes, so callers would typically sign a hash rather than arbitrary-length data.
- Other curve precompiles did ship later: EIP-2537 for BLS12-381 and EIP-7951 for secp256r1 (P-256, used by passkeys). Without a precompile, Ed25519 verification in Solidity is possible but costly.