LSP8CompatibleERC721 ’s approve() deviates from ERC-721 specification
The approve() function in LSP8CompatibleERC721 only allows the token owner to call it, whereas the ERC-721 specification also permits an authorised operator of the owner to call it. This deviation could cause incompatibility with protocols that rely on ERC-721 behaviour, such as NFT exchanges where a router contract approved via setApprovalForAll() needs to grant approvals.
The LSP8CompatibleERC721 contract is a wrapper around LSP8, which is meant to function similarly to ERC-721 tokens. One of its implemented functions is ERC-721’s approve():
function authorizeOperator(
address operator,
bytes32 tokenId
) public virtual {
address tokenOwner = tokenOwnerOf(tokenId);
if (tokenOwner != msg.sender) {
revert LSP8NotTokenOwner(tokenOwner, tokenId, msg.sender);
}
However, the implementation above deviates from the ERC-721 specification, which mentions that an “authorized operator of the current owner” should also be able to call approve():
/// @notice Change or reaffirm the approved address for an NFT
/// @dev The zero address indicates there is no approved address.
/// Throws unless `msg.sender` is the current NFT owner, or an authorized
/// operator of the current owner.
/// @param _approved The new approved NFT controller
/// @param _tokenId The NFT to approve
function approve(address _approved, uint256 _tokenId) external payable;
This means, anyone who is an approved operator for tokenId’s owner through setApprovalForAll() should also be able to grant approvals. An example of such behaviour can be seen in Openzeppelin’s ERC721 implementation:
As LSP8CompatibleERC721’s approve() functions differently from ERC-721, protocols that rely on this functionality will be incompatible with LSP8 tokens that inherit from LSP8CompatibleERC721.
For example, in an NFT exchange, users might be required to call setApprovalForAll() for the protocol’s router contract. The router then approves a swap contract, which transfers the NFT from the user to the recipient using transferFrom().
Additionally, developers that expect LSP8CompatibleERC721 to behave exactly like ERC-721 tokens might introduce bugs in their contracts, due to the difference in approve().
Recommended Mitigation
Modify approve() to allow approved operators for tokenId’s owner to grant approvals:
However, the implementation above deviates from the ERC-721 specification, which mentions that an “authorized operator of the current owner” should also be able to call approve():
@MiloTruck - can you please point me to it in the standard because I could not find anything stipulating that?
The original report as published on Code4rena, by MiloTruck. 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 40 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 approve() function calls authorizeOperator(), which only checks if the caller is the token owner, ignoring approved operators for all tokens.
Impact
Protocols that rely on ERC-721 approve() behaviour, such as NFT exchanges where a router contract approved via setApprovalForAll() needs to grant approvals, will be incompatible with LSP8 tokens that inherit from LSP8CompatibleERC721.
What the attacker needed
Token owner has approved an operator via setApprovalForAll; protocol relies on ERC-721 approve() behaviour
The fix
Modify approve() to allow approved operators for the token owner to grant approvals, as shown in the recommended mitigation.
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 40 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
ERC-721 is a standard for NFTs on Ethereum. The standard says that if you have given someone permission to manage all your NFTs (via setApprovalForAll), that person should also be able to approve others to transfer a specific NFT. In this implementation, only the owner can do that, which breaks compatibility with some applications.
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.