Permit doesn’t work with DAI
The VaultRouter contract calls a standard permit function that does not match DAI's permit signature, which includes extra nonce and allowed parameters. As a result, any attempt to use permit with DAI tokens will revert, preventing users from using the permit feature for DAI.
0xlemon Follow with MrPotatoMagic
Originally disclosed on Code4rena
Submitted by 0xlemon, also found by MrPotatoMagic
https://github.com/code-423n4/2024-12-bakerfi/blob/main/contracts/core/VaultRouter.sol#L114
Vulnerability Details
VaultRouter allows users to use permit transactions for convenience. This router is supposed to work with any ERC20 tokens. We can see in pullTokensWithPermit how the permit is utilized:
function pullTokensWithPermit(
IERC20Permit token,
uint256 amount,
address owner,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal virtual {
// Permit the VaultRouter to spend tokens on behalf of the owner
@-> IERC20Permit(token).permit(owner, address(this), amount, deadline, v, r, s);
// Transfer the tokens from the owner to this contract
IERC20(address(token)).safeTransferFrom(owner, address(this), amount);
}
However this .permit doesn’t work with DAI tokens because DAI token’s permit signature is different. From the contract at address 0x6B175474E89094C44Da98b954EedeAC495271d0F, we see the permit function:
function permit(address holder, address spender, uint256 nonce, uint256 expiry, bool allowed, uint8 v, bytes32 r, bytes32 s) external
The nonce and allowed arguments are added to DAI’s permit that means calling pullTokensWithPermit where DAI is the token will revert.
Impact
Permit cannot be used with DAI tokens
Recommended mitigation steps
For the special case of DAI token, allow a different implementation of the permit function which allows nonce and allowed variables.
chefkenji (BakerFi) acknowledged
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The router calls a single permit function signature that does not match DAI's non-standard permit implementation, which requires additional nonce and allowed parameters.
Impact
Permit cannot be used with DAI tokens, so users must use the standard approval flow instead.
What the attacker needed
DAI token used with VaultRouter; permit feature used
The fix
The router should handle DAI specially by calling a permit function that includes the nonce and allowed parameters.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Some tokens like DAI have a different way of approving spending than most tokens. The router assumes all tokens use the same approval method, so when it tries to approve DAI, the call fails and the transaction is cancelled. This means users cannot use the convenient permit feature with DAI.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.