ERC-8377 Execution-time reference price slippage protection (Reference-Relative Slippage Bounds)
Draft · Vaults & DeFi · created 2026-08-05
A swap protection standard that calculates the slippage floor using the real-time reference price at execution time, instead of a minimum receive amount fixed at signing time, narrowing the window for sandwich attacks.
Why it is needed
Swaps are usually protected by a single minAmountOut set when the transaction is created. This value is set based on the price of the block at signing time, but actual execution happens several blocks later, so even if a sandwich bot moves the pool price in between, the attack succeeds as long as the received amount stays above that fixed minimum, and the user has no way to notice. To avoid failed trades during volatility, wallets set slippage tolerance generously at 1 to 3 percent, and that margin becomes exactly what an attacker can take. Also, because routers, aggregators, and wallets each implement slippage differently, there is no way to compare or improve the level of protection across them.
What to implement
error SlippageExceeded(uint256 realizedOut, uint256 floor);: An error that reverts when the realized output amount (realizedOut) is less than the floor.error InvalidPolicy(uint32 expectedCostBps, uint32 maxDeviationBps);: An error that reverts when expectedCostBps or maxDeviationBps exceeds 10,000bps as an invalid policy.error InvalidRecipient();: An error that reverts when recipient is set to the zero address.error DeadlineExpired(uint256 deadline, uint256 timestamp);: An error that reverts when policy.deadline is nonzero and already in the past.function swapWithPolicy( address tokenIn, address tokenOut, uint256 amountIn, address recipient, SlippagePolicy calldata policy, bytes calldata routeData ) external returns (uint256 amountOut);: The core function that executes a swap given a policy and route data, and reverts if the actual output amount is less than the floor calculated from the execution-time reference price.
In depth
SlippagePolicy struct
The policy consists of quoteOracle (the ERC-7726 oracle address), expectedCostBps (the normal cost combining fees and price impact, capped at 10,000), maxDeviationBps (the additional adversarial shortfall allowed on top of that, capped at 10,000), hardFloor (the absolute minimum output accepted regardless of the reference price), and deadline (the last Unix timestamp at which this transaction intent is valid, unlimited if 0). The floor actually applied is whichever is larger between the reference-price-based floor and hardFloor.
Why expectedCostBps and maxDeviationBps are separated
Because the reference price returned by ERC-7726 is a mid price with no fees or price impact mixed in, even a normal fill always comes in lower than that. If there were only a single tolerance, it would have to absorb that normal cost too, pushing it well past 100bps and bringing back the wide attack margin this standard is meant to reduce. Separating the normal cost (expectedCostBps) from the adversarial shortfall (maxDeviationBps) lets honest execution cost be subtracted first, leaving only the adversarial deviation to monitor.
Floor calculation procedure
The execution contract gets referenceOut from IERC7726(quoteOracle).getQuote(amountIn, tokenIn, tokenOut). It subtracts the normal cost to get the expected output with expectedOut = referenceOut * (10,000 - expectedCostBps) / 10,000, and sets the final floor with floor = max(expectedOut * (10,000 - maxDeviationBps) / 10,000, hardFloor). If the actual output amount is less than this floor, it reverts with SlippageExceeded(realizedOut, floor).
Oracle freshness and independence requirements
Because ERC-7726's getQuote itself is stateless and does not guarantee freshness, this standard requires using only an oracle that enforces a freshness limit and reverts when it cannot be trusted. Also, quoteOracle cannot be the spot price of the pool where the current trade is being executed. If an attacker moves that pool, the reference price and the floor move together, and the protection falls into a self-referential contradiction.
Output amount is measured, not reported
swapWithPolicy does not trust the number reported by the route (routeData). Instead, it directly measures the change in the recipient's tokenOut balance before and after route execution and uses that as amountOut. Even if a malicious or buggy route reports success for an amount it never actually paid out, this measurement approach catches it. The measurement target is also set to recipient rather than the execution contract itself, so protection is not broken even if the execution contract intercepts the output in between.
The role of deadline
Because the reference-price-based floor is recalculated at execution time, there is no problem from a stale price, but the decision to trade itself can still become stale. deadline sets the last moment at which this signed intent is valid, so after that point it reverts immediately with DeadlineExpired before reading the oracle or executing the route. If deadline is 0, it is unlimited. However, this does not guarantee inclusion itself, and it cannot stop builders or relays from holding the transaction until the expiration point.
Relationship to ERC-5143
ERC-5143 is a standard that attaches a fixed minimum value set directly by the caller to an ERC-4626 vault's deposit, mint, withdraw, and redeem. This standard is complementary to ERC-5143 in that it widens the scope from vaults to general swaps and derives the floor from a real-time reference price read from ERC-7726 instead of a fixed value.
Interface detection and standard status
Implementations must support ERC-165 and supportsInterface must return true for 0x41b46b60, the interface ID of ISlippageBoundedSwap. This proposal is currently in Draft status, still undergoing community discussion and review, so details may change or progress may stall.
Things to watch out for
- The oracle is the root of trust: If the reference price is manipulated or stale, the floor is manipulated along with it. Because ERC-7726's getQuote itself does not guarantee freshness, callers must verify directly that the oracle instance the policy points to actually enforces a freshness limit. A TWAP window suited to the trade size should be chosen so that the cost of moving the price exceeds the gain from a sandwich attack.
- Output is measured, not reported: Because the realized output amount is measured from the change in the recipient's tokenOut balance, malicious or buggy routeData cannot pass the floor with an amount it never paid out.
- deadline only guarantees intent: It only limits the period during which the signed decision is valid; it cannot stop builders or relays from holding the transaction right up until expiration. Expiration should be treated as a signal to reassess, not as a failure.
- It does not eliminate MEV: This standard only reduces the margin that can be taken by a sandwich attack; it does not prevent reordering or extraction that occurs within maxDeviationBps. It should be used together with private mempools or PBS-level protection.
- Oracle outages and legitimate price differences: If the oracle fails to produce a trustworthy value, the transaction either reverts or falls through to the hardFloor path, so callers must set hardFloor to a worst case they can accept. If the reference price and the price at the actual execution pool legitimately diverge due to low liquidity or similar reasons, even normal trades can revert, so maxDeviationBps should be set to match that pool's usual deviation.