Overview
FHERC20Permit extends the base FHERC20 contract with signature-based operator approval, allowing users to grant operator permissions without sending a transaction. This is similar to EIP-2612 (Permit for ERC20) but adapted for the operator model.Gasless Approvals
Users can approve operators by signing messages off-chain, eliminating the need for approval transactions and saving gas.
EIP-712 Standard
Uses the battle-tested EIP-712 standard for structured data signing, providing security and wallet compatibility.
Meta-Transactions
Enable meta-transaction patterns where relayers can submit permits on behalf of users.
Improved UX
Users can approve and transfer in a single transaction, or approve without needing ETH for gas.
How It Works
Traditional Operator Approval (2 transactions)
With Permit (1 transaction)
The Permit Function
Function Signature
owner: Address that is granting operator permissionspender: Address receiving operator permissionuntil: Unix timestamp when operator permission expires (uint48)deadline: Unix timestamp when the signature itself expires (uint256)v,r,s: ECDSA signature components
How Permit Works
1
User Signs Off-Chain
User signs a structured message containing owner, spender, until, nonce, and deadline using their wallet.
2
Signature Submitted
Anyone (usually the operator or a relayer) submits the signature along with the permit parameters to the blockchain.
3
Signature Verification
Contract verifies the signature matches the owner’s address and hasn’t expired.
4
Operator Granted
If valid, the contract calls
setOperator(spender, until) on behalf of the owner.5
Nonce Incremented
The owner’s nonce is incremented to prevent signature replay.
EIP-712 Domain and Types
Domain Separator
Permit Type Hash
Nonces
Function Signature
Meta-Transaction Pattern
Permits enable meta-transactions where users sign approvals and a relayer submits them:Security Considerations
Signature Expiration
Signature Expiration
Always set a reasonable Expired signatures are automatically rejected by the contract.
deadline for signatures:Nonce Management
Nonce Management
Front-Running
Front-Running
Since permits can be submitted by anyone, there’s a risk of front-running:Mitigation: Ensure the
spender parameter in your signature is the intended operator.Signature Malleability
Signature Malleability
ECDSA signatures can be malleable. FHERC20Permit uses the standard EIP-712 approach which includes built-in protections, but always:
- Validate
vis 27 or 28 - Use ethers.js or viem signature utilities
- Don’t manually construct signatures
Permit vs SetOperator
| Feature | setOperator() | permit() |
|---|---|---|
| Gas Cost | User pays | Relayer or operator pays |
| Transactions | 1 (from user) | 1 (from anyone) |
| UX | Requires user transaction | User signs off-chain |
| Immediate | Yes | Yes (once submitted) |
| Expiration | Operator until time | Signature deadline + Operator until time |
| Best For | Direct user interactions | Relayed/batched transactions |
Complete Example Contract
Related Topics
- Learn about Operators for the permission model
- Explore Transfer Callbacks for safe transfers
- Review Best Practices for secure implementations