The P256 precompile implements secp256r1 (P-256/prime256v1) elliptic curve signature verification as defined in EIP-7212. It allows smart contracts to verify signatures from devices like WebAuthn authenticators, secure enclaves, and hardware security modules (HSMs).
Key Details:
- Address:
0x0000000000000000000000000000000000000100 - Gas Cost: Fixed at 3,450 gas (constant regardless of input).
- Interface: Operates at a low level via
staticcall. It accepts a 160-byte raw input and returns a 32-byte verification result. - Output: Returns
0x00...01 (1) on success. Returns empty data or 32 zero bytes on failure. Returns empty data if input length is invalid.
contract P256Verifier {
address constant P256_PRECOMPILE = 0x0000000000000000000000000000000000000100;
function verifySignature(
bytes32 messageHash,
bytes32 r,
bytes32 s,
bytes32 x,
bytes32 y
) public view returns (bool) {
bytes memory input = abi.encodePacked(messageHash, r, s, x, y);
(bool success, bytes memory result) = P256_PRECOMPILE.staticcall(input);
if (success && result.length == 32) {
uint256 verification = abi.decode(result, (uint256));
return verification == 1;
}
return false;
}
}