The Protocol breaks the Allowance Mechanism of the NFTs
The protocol transfers NFT positions to itself and back to the owner to execute actions, which clears any existing approvals for those tokens. As a result, users lose approvals they had granted to other entities, potentially leaving positions unattended.
This breaks the allowance mechanism of ERC721 for every action taken on the platform and it omits the allowances given from the token owners to the approved entities.
For every NFT transfer, the allowances are zeroed out:
Contract: ERC721.sol
333: function _transfer(address from, address to, uint256 tokenId) internal virtual {
334: require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
335: require(to != address(0), "ERC721: transfer to the zero address");
336:
337: _beforeTokenTransfer(from, to, tokenId, 1);
338:
339: // Check that tokenId was not transferred by `_beforeTokenTransfer` hook
340: require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
341:
342: // Clear approvals from the previous owner
343: >> delete _tokenApprovals[tokenId];
344:
345: unchecked {
346: // `_balances[from]` cannot overflow for the same reason as described in `_burn`:
347: // `from`'s balance is the number of token held, which is at least one before the current
348: // transfer.
349: // `_balances[to]` could overflow in the conditions described in `_mint`. That would require
350: // all 2**256 token ids to be minted, which in practice is impossible.
351: _balances[from] -= 1;
352: _balances[to] += 1;
353: }
354: _owners[tokenId] = to;
355:
356: emit Transfer(from, to, tokenId);
357:
358: _afterTokenTransfer(from, to, tokenId, 1);
359: }
E.g.:
Alice is on her flight to attend DSS Bangkok
She already approved Bob to take care of her positions until she arrives during the long flight
Bob interacts with Krystal to collect the LP fees.
Bob loses his approval
Alice´s position remains unattended and one of the pool tokens takes a nose dive before Bob can withdraw the liquidity and sell it.
ERC721 implementation allows only one spender on a token at a time, therefore taking user’s approval for our contract will also clear other approval on the same token
Another approach is to use setApprovalForAll function in ERC721, which poses another concern of allowing our contract to use all user’s positions.
With that in mind, we think that using onERC721Received hook is still the safest option for our users and Krystal is able to provide convenient user experience.
The original report as published on Code4rena, by Dup1337. 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
Likely the protocol transfers the NFT to itself and back, which triggers the ERC721 standard behaviour of clearing approvals on each transfer.
Impact
Users lose approvals they granted to other entities, which could leave their positions unattended and exposed to market risks.
What the attacker needed
User has approved another entity for the NFT; user interacts with the protocol
The fix
The protocol should take approval from token owners rather than using the onERC721Received hook, though the team notes that any approval method will clear other approvals.
How it was found
Alice approves Bob to manage her position NFT.
Bob interacts with Krystal to collect LP fees.
The protocol transfers the NFT from Alice to itself and back, clearing Bob's approval.
Bob loses his approval and can no longer manage the position.
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
When you own an NFT, you can approve someone else to manage it for you. This report says that when the protocol performs an action on your NFT, it moves the NFT to itself and then back, and this movement automatically cancels any approvals you had given to others. So other people you trusted to manage your NFT lose access.
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.