ERC-8255 Expiring token approvals
Draft · Tokens · created 2026-05-06
A standard that adds an expiration time to ERC-20 approve so that a token approval automatically disappears after a set period without any special action.
Why it is needed
Once set, ERC-20's approve remains valid forever unless the user changes or cancels it themselves. Approvals are often granted far larger than actually needed, sometimes unlimited, so old approvals the user has long forgotten about remain in place. If the spender contract that received that approval is later hacked, maliciously upgraded, or has its frontend tampered with, an attacker can exploit that old approval to drain tokens from the user's wallet. Approval revocation services have tracked hundreds of millions of dollars in losses from this kind of incident over the years. The problem is that even though an approval was created for a specific interaction, it remains a standing privilege of value to an attacker long after that interaction ends.
What to implement
event ApprovalExpiration( address indexed owner, address indexed spender, uint64 expiration );: An optional event that may be emitted when an approval's expiration time is set.function maxApprovalDuration() external pure returns (uint32);: Returns the default maximum approval validity period (in seconds) set by the token contract.function allowanceAndExpiration(address owner, address spender) external view returns (uint64 expiration, uint256 allowance);: Returns the stored expiration time and allowance value as is, regardless of whether it has expired.function approveForDuration(address spender, uint256 amount, uint32 duration) external returns (bool success);: Grants the spender an approval valid only for the specified duration (in seconds).
In depth
Added functions and events
A contract supporting ERC-8255 must implement, in addition to ERC-20, the three functions maxApprovalDuration, allowanceAndExpiration, and approveForDuration, plus the optional ApprovalExpiration event. maxApprovalDuration returns the maximum approval duration (in seconds) fixed by the contract, and allowanceAndExpiration returns the stored expiration time and allowance value as is, regardless of whether it has expired.
Default expiration rule for approve
When a call to approve(spender, amount) with a nonzero amount succeeds, the contract must set the allowance to amount and set the expiration time to block.timestamp + maxApprovalDuration(). In other words, even without using a separate function, an ordinary approve call itself becomes a time-limited approval.
Specifying a shorter duration with approveForDuration
The duration in approveForDuration(spender, amount, duration) must be less than or equal to maxApprovalDuration(); if it exceeds that, the call must revert or return false. If duration is 0, the expiration time becomes equal to the current block.timestamp, but this case is still treated as 'not expired,' allowing approval and use within the same block. If amount is 0, the allowance is set to 0.
The same default duration applies to permit (ERC-2612) as well
If the contract also implements ERC-2612, the permit function's signature, signed data, and nonce handling are completely unchanged. When a permit call with a nonzero value succeeds, the allowance is set to value and the expiration time is set to block.timestamp + maxApprovalDuration(). ERC-2612's deadline is only the last time at which the signature can be submitted and must not be treated as the approval's expiration time.
Difference between allowance and allowanceAndExpiration
allowance(owner, spender) must return 0 if expired, or the stored value otherwise. If the expiration time equals the current block.timestamp, it is still treated as not yet expired; it is only treated as expired once the expiration time is less than block.timestamp. allowanceAndExpiration shows the stored expiration time and allowance as is regardless of expiration status, so to know the actually usable allowance you must call allowance or compare the two values yourself. transferFrom treats an expired allowance as 0 and reduces the allowance by the amount used, while leaving the expiration time unchanged.
The legacy-compatible spender exception
An implementation may optionally provide a mechanism to designate a specific spender as legacy-compatible, and the method of designation (e.g., an admin designates it, or the spender designates itself) is outside the scope of this standard. No spender is treated as legacy-compatible by default. For a designated spender, allowanceAndExpiration may return the current block.timestamp as if it were the expiration time, and the allowance may be treated as not expired, but the stored allowance amount itself does not change, and the owner must always be able to reduce or revoke it.
Optional packed storage layout
This standard does not mandate a specific storage layout, but it offers as an example a packing scheme that stores the expiration time in the upper 64 bits and the allowance in the lower 192 bits of a single uint256 storage slot. Allowance values exceeding 192 bits must be rejected or represented separately, and type(uint256).max can be used to reserve a specific value in the lower 192 bits as an 'unlimited' sentinel.
Migrating existing storage and standard status
An upgradeable contract that has already been storing allowance as a single uint256 can migrate by reinterpreting the existing slot as a packed (expiration, allowance) structure. If the existing value is less than type(uint192).max, the expiration time is interpreted as 0, meaning it is treated as already expired immediately upon deployment; if past approvals must be preserved, a separate legacy slot can be kept as a fallback. This ERC-8255 is currently in Draft status, meaning it has not yet been finalized and its details may change or the proposal may be discontinued depending on further discussion.
Things to watch out for
- The approval race condition still remains: Expiration only shortens the period during which an approval remains in a risky state; it does not eliminate ERC-20's approve race condition itself, so existing guidance must still be followed when changing a nonzero allowance to another nonzero value.
- It can expire during transaction execution: Contracts that take tokens via transferFrom must keep in mind that an approval can expire between when a transaction is written and when it actually executes, which matters especially in public mempools or delayed execution environments.
- Too short a duration can cause failures: A shorter approval duration helps safety, but if use is delayed the transaction may fail, so wallets and apps should choose durations that account for expected delays.
- Packed storage must not silently truncate values: Implementations using a packed storage layout must not silently truncate allowance values that do not fit in 192 bits; such values must be rejected or represented using a different approach.
- The legacy-compatible list can roll back security: A spender designated as legacy-compatible can effectively restore the old risk of indefinite approvals, so the default must be disabled and its scope must be limited to only the spenders that truly need it.