What is permit front running?
Permit front running is when someone copies a user's EIP-2612 permit signature from a pending transaction and submits it first. The signature is valid no matter who sends it, so the approval still happens, but the nonce is used and the user's own transaction, which calls permit inside a deposit or a swap, reverts. Wrap the permit call in try/catch, carry on if the allowance is already there, and credit the signer, never the caller.
How does permit front running work?
EIP-2612 adds permit to ERC-20 tokens: the owner signs an approval off-chain and anyone can submit it, which saves the owner a separate approve transaction. Each signature carries the owner's current nonce, and a successful permit increments it, so a signature works exactly once.
Protocols often bundle it. A depositWithPermit function calls permit and then transferFrom in one transaction, and that transaction waits in a public mempool with the signature in its calldata. Two things can go wrong:
- Griefing. Someone submits the same signature straight to the token first. The approval goes through, the nonce moves on, and the bundled call reverts when it tries to use the signature again. The user's tokens are safe, but the deposit fails and the gas is lost. For a collateral top-up or an auction bid, a failed transaction at the wrong moment costs far more than gas.
- Theft. If the protocol takes the owner as a parameter and credits whoever called it, the front-runner submits the signature through the protocol instead, and the deposit is booked to the front-runner.
Tokens without permit add a third trap. A token whose fallback function doesn't revert can accept a call to permit and do nothing, so code that treats a successful call as an approval is wrong for those tokens.
What does vulnerable code look like?
Vulnerable: a permit call that reverts on a used signature, and a deposit credited to the caller (illustrative, not audited code) PermitVault.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
interface IERC20Permit {
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
external;
function transferFrom(address from, address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
}
contract PermitVault {
IERC20Permit public immutable token;
mapping(address => uint256) public deposits;
constructor(IERC20Permit token_) {
token = token_;
}
// If anyone submits this signature first, the nonce is spent, permit reverts
// here, and the whole deposit fails.
function depositWithPermit(uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external {
token.permit(msg.sender, address(this), amount, deadline, v, r, s);
require(token.transferFrom(msg.sender, address(this), amount), "transfer failed");
deposits[msg.sender] += amount;
}
// Worse: the owner comes from calldata and the deposit goes to the caller,
// so whoever submits a copied signature first takes the owner's tokens.
function depositFor(address owner, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external {
token.permit(owner, address(this), amount, deadline, v, r, s);
require(token.transferFrom(owner, address(this), amount), "transfer failed");
deposits[msg.sender] += amount;
}
}
depositWithPermit fails for anyone whose signature was submitted first. depositFor is worse: an attacker who copies a pending signature calls it with the victim as owner, moves the victim's tokens into the vault and has the deposit credited to the attacker's address. In a Foundry test with a mock permit token, the first function reverted after a front-run and the second credited the attacker with the victim's 100 tokens.
How do you fix it?
Fixed: permit inside try/catch, an allowance check, and deposits credited to the signer (illustrative, not audited code) TolerantPermitVault.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
interface IERC20Permit {
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
external;
function transferFrom(address from, address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
}
contract TolerantPermitVault {
IERC20Permit public immutable token;
mapping(address => uint256) public deposits;
constructor(IERC20Permit token_) {
token = token_;
}
function depositWithPermit(uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external {
_usePermit(msg.sender, amount, deadline, v, r, s);
require(token.transferFrom(msg.sender, address(this), amount), "transfer failed");
deposits[msg.sender] += amount;
}
// Anyone may submit the signature, but the deposit always belongs to its signer.
function depositFor(address owner, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external {
_usePermit(owner, amount, deadline, v, r, s);
require(token.transferFrom(owner, address(this), amount), "transfer failed");
deposits[owner] += amount;
}
// A permit someone else already submitted is fine, as long as the allowance it
// set is there. The allowance check also catches tokens that accept a permit
// call through a fallback function and do nothing.
function _usePermit(address owner, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) private {
try token.permit(owner, address(this), amount, deadline, v, r, s) {} catch {}
require(token.allowance(owner, address(this)) >= amount, "permit not applied");
}
}
- Let permit fail. Wrap it in try/catch. If someone else already submitted the signature, the allowance it set is still there, and the deposit goes ahead.
- Check the allowance, not the call. After the attempt, require the allowance you need. That also catches tokens that accept
permitthrough a fallback and grant nothing. - Credit the signer. A function that spends an owner's tokens through a permit must credit that owner, or require that
msg.senderis the owner. - Bind the signature to the action when it matters. A permit only approves a spender. If the user's signature must also fix the recipient, the amount or the price, have them sign that intent as your own EIP-712 message instead of relying on the token's permit.
In the same test, the fixed vault completed the user's deposit after a front-run permit, and a depositFor submitted by the attacker credited the signer and left the attacker with nothing.
Has permit front running been exploited?
We know of no exploit with a published loss. It is a documented weakness, written into the standard itself and into OpenZeppelin's docs:
| Protocol | EIP-2612 and OpenZeppelin warnings (a documented weakness, not an exploit) |
|---|---|
| Date | 13 April 2020 |
| Chain | Any EVM chain |
| Loss | None reported; the cost is failed transactions and griefing |
| What happened | EIP-2612, created on 13 April 2020 and now Final, says in its security considerations that another party can always front run a permit transaction and call permit before the intended party, and that the end result is the same for the signer (EIP-2612). OpenZeppelin's documentation for IERC20Permit spells out the consequence for integrators: permits can be submitted by anyone, so they can be front-run, and a protocol that uses them should let a permit call fail. It recommends the same try/catch pattern as the fixed vault above (OpenZeppelin). |
| Sources | Ethereum Improvement Proposals, OpenZeppelin docs |
What should a reviewer check?
- Find every call to
permit. Does a revert there stop the whole transaction? - After the permit attempt, does the code check the allowance it actually needs?
- When the owner is a parameter, who is credited: the owner or
msg.sender? - Can a token without
permitreach this code, and would its fallback accept the call silently? - Is the deadline checked and short, and does the front end show users what they are signing?
- Do tests submit the same signature twice, from two callers, and expect the user's action to succeed once?
How does QuillShield check for permit front running?
Permit bugs sit at the boundary between your contracts and the tokens they accept, so put every entry point that takes a signature in scope, routers and zap contracts included. QuillShield runs a full audit of a Solidity codebase in a Foundry project. It builds a security graph of the code and lists the invariants the code must keep.
For this class the invariant is short: tokens that leave an owner's wallet through a permit are credited to that owner. A separate reviewer agent tries to disprove every finding before you see it, and each finding that holds up comes with the exact lines, the impact, a recommended fix and, on full audits, a proof of concept.
It then checks every pull request on GitHub or GitLab.com against that graph. A new withPermit function is usually a small diff, the kind that slips through review. Start free. New accounts get $50 in credit, good for up to half of an order.
FAQ
Can permit front running steal tokens?
Not by itself. The front-runner can only submit the approval the owner signed, for the spender the owner chose. Theft needs a second bug, such as a function that spends an owner's tokens and credits the caller.
Why doesn't the nonce stop it?
The nonce stops a signature from working twice. The front-runner uses it once, first, and the user's own transaction becomes the second use.
Is try/catch around permit safe?
Yes, if the code then checks the allowance it needs. When a permit fails for a real reason, such as a bad signature, the allowance check fails and the transaction reverts.
How do I test for permit front running in Foundry?
Sign a permit with vm.sign, submit it straight to the token from another address, then call your function with the same signature. Assert that the action still succeeds and that the deposit belongs to the signer.
Sources
- ERC-2612: Permit Extension for EIP-20 Signed Approvals, Ethereum Improvement Proposals checked 3 December 2026
- ERC 20 API, OpenZeppelin docs checked 3 December 2026
- Smart Contract Weakness Classification Registry, SWC Registry checked 3 December 2026