EthRouter.sell , EthRouter.deposit , and EthRouter.change functions can be DOS’ed for some ERC721 tokens
The EthRouter contract calls setApprovalForAll on ERC721 tokens every time sell, deposit, or change is used. For tokens like Axie that revert when setting the same approval twice, this causes the router functions to revert on subsequent calls, blocking users from selling or depositing those NFTs to the same pool.
function sell(Sell[] calldata sells, uint256 minOutputAmount, uint256 deadline, bool payRoyalties) public {
...
// loop through and execute the sells
for (uint256 i = 0; i < sells.length; i++) {
...
// approve the pair to transfer NFTs from the router
ERC721(sells[i].nft).setApprovalForAll(sells[i].pool, true);
...
}
...
}
function change(Change[] calldata changes, uint256 deadline) public payable {
...
// loop through and execute the changes
for (uint256 i = 0; i < changes.length; i++) {
Change memory _change = changes[i];
...
// approve pair to transfer NFTs from router
ERC721(_change.nft).setApprovalForAll(_change.pool, true);
...
}
...
}
For ERC721 tokens like Axie, which its setApprovalForAll function is shown below, calling their setApprovalForAll functions with the same msg.sender-_operator-_approved combination would revert because of requirements like require(_tokenOperator[msg.sender][_operator] != _approved).
For these ERC721 tokens, calling the EthRouter.sell, EthRouter.deposit, and EthRouter.change functions for the first time, which call such tokens’ setApprovalForAll functions for the first time, can succeed; however, calling the EthRouter.sell, EthRouter.deposit, and EthRouter.change functions again, which call such tokens’ setApprovalForAll functions with the same pool as _operator and true as _approved again, will revert. In this case, the EthRouter.sell, EthRouter.deposit, and EthRouter.change functions are DOS’ed for such ERC721 tokens.
The following steps can occur for the described scenario.
Alice calls the EthRouter.sell function to sell 1 Axie NFT to a private pool, which succeeds.
Alice calls the EthRouter.sell function again to sell another Axie NFT to the same private pool. However, this function call’s execution of ERC721(sells[i].nft).setApprovalForAll(sells[i].pool, true) reverts because Axie’s require(_tokenOperator[msg.sender][_operator] != _approved) reverts.
Bob tries to repeat Step 2 but his EthRouter.sell function call also reverts.
Hence, the EthRouter.sell function is DOS’ed for selling any Axie NFTs to the same private pool for any users.
Tools Used
VS Code
Recommended Mitigation Steps
The EthRouter.sell, EthRouter.deposit, and EthRouter.change functions can be respectively updated to check if the EthRouter contract has approved the corresponding pool to spend any of the corresponding ERC721 tokens received by itself. If not, the corresponding ERC721’s setApprovalForAll function can be called; otherwise, the corresponding ERC721’s setApprovalForAll function should not be called.
Proposed fix is to skip the approval step if the pool has already been approved to transfer the NFTs from the EthRouter.
function _approveNfts(address nft, address target) internal {
// check if the router is already approved to transfer NFTs from the caller
if (ERC721(nft).isApprovedForAll(address(this), target)) return;
// approve the target to transfer NFTs from the router
ERC721(nft).setApprovalForAll(target, true);
}
The Warden has shown how, the always re-approve pattern can cause reverts, this is contingent on the specific NFT used, however, AXIE is in my opinion a sufficiently relevant token for this finding to be valid.
Due to it’s reliance on token implementation I agree with Medium Severity.
The original report as published on Code4rena, by rbserver. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
The router unconditionally calls setApprovalForAll on the NFT contract for each operation, without checking if the approval already exists, which reverts for tokens that disallow redundant approvals.
Impact
For affected ERC721 tokens like Axie, the sell, deposit, and change functions become unusable for any user trying to interact with the same pool after the first approval, effectively denying service.
What the attacker needed
Use of an ERC721 token that reverts on redundant approvals…; The pool must have been previously approved by the router…
The fix
The router should check if the pool is already approved for the NFT and skip the setApprovalForAll call if so; this was fixed by the Caviar team.
How it was found
Alice calls EthRouter.sell to sell one Axie NFT to a private pool, which succeeds.
Alice calls EthRouter.sell again to sell another Axie NFT to the same private pool, but the call reverts because setApprovalForAll reverts.
Bob tries the same and his call also reverts.
As a result, the sell function is blocked for any Axie NFT sales to that pool.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
Some NFT contracts, like Axie, have a rule that you cannot approve the same operator twice in a row. The router always tries to approve the pool every time, so after the first successful sale, later attempts fail because the approval is already set. This means users cannot sell more of those NFTs to the same pool.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.