0x0000000000000000000000000000000000001011
This is the implementation of RIP-7212, which provides a precompiled contract for verifying signatures in the secp256r1 or P-256 elliptic curve.
Overview
The P256 precompile enables efficient signature verification for thesecp256r1 curve, which is widely used in modern security systems including:
- Apple’s Secure Enclave
- WebAuthn/FIDO2
- Android Keychain
- Various hardware security modules (HSMs)
- PassKeys
Interface
Implementation Library
Here’s a complete implementation of the P256 library that provides a convenient wrapper around the precompile:Basic Usage
Using the P256 Library
Direct Precompile Usage
For more control, you can call the precompile directly:Signature Format
The signature verification requires the following components:digest: 32 bytes of the signed data hashsignature: Contains the r and s components of the signaturepublicKey: Contains the x and y coordinates of the public key
- First 32 bytes: message hash
- Next 32 bytes:
rcomponent of the signature - Next 32 bytes:
scomponent of the signature - Next 32 bytes:
xcoordinate of the public key - Next 32 bytes:
ycoordinate of the public key
Gas Costs
The precompile is highly gas efficient compared to Solidity implementations. The exact gas cost per byte of verified data is set toGasCostPerByte = 300, which gives us:
- Total Cost: 300 × 160 = 48,000 gas per verification
- Efficiency: Up to 60x more efficient than pure Solidity implementations
Real-World Use Cases
WebAuthn/PassKeys Authentication
Apple Secure Enclave Integration
Multi-Signature with Hardware Keys
Security Considerations
Public Key Validation
Signature Malleability
P256 signatures can be malleable. If your application requires unique signatures, implement additional checks:JavaScript Integration
Preparing Input Data
Error Handling
The P256 precompile returns no data on failure. Becauseverify is declared as returning bytes, a high-level Solidity interface call reverts when it tries to decode that empty return data — always use a low-level staticcall (as in the examples above) so invalid signatures resolve to false instead of reverting. Common failure cases include:
- Invalid Input Length: Input must be exactly 160 bytes
- Invalid Public Key: Point not on the P256 curve
- Invalid Signature: r or s values out of valid range
- Verification Failure: Signature doesn’t match message and public key
Testing
Unit Tests
Performance Considerations
- Gas Efficiency: 48,000 gas per verification vs 2M+ gas for Solidity implementations
- Batch Operations: Consider batching multiple verifications in a single transaction
- Caching: Cache public keys on-chain to reduce calldata for repeated verifications
- Hardware Integration: Particularly efficient for applications using hardware-backed keys
For more information about the P256 precompile implementation, visit the Sei Chain repository.