Incorrect implementation of ERC721 may have bad consequences for receiver
The ERC721 enforcer contract passed its own address as the operator argument when calling onERC721Received on a receiving contract, instead of the actual caller of safeTransferFrom. A receiving contract that relies on that argument for bookkeeping or to decide whether to accept the transfer would act on false information, so transfers could be wrongly rejected or credited incorrectly.
Submitted by Trust, also found by adriro
HolographERC721.sol is an enforcer contract that fully implements ERC721. In its safeTransferFromFunction there is the following code:
if (_isContract(to)) {
require(
(ERC165(to).supportsInterface(ERC165.supportsInterface.selector) &&
ERC165(to).supportsInterface(ERC721TokenReceiver.onERC721Received.selector) &&
ERC721TokenReceiver(to).onERC721Received(address(this), from, tokenId, data) ==
ERC721TokenReceiver.onERC721Received.selector),
"ERC721: onERC721Received fail"
);
}
If the target address is a contract, the enforcer requires the target’s onERC721Received() to succeed. However, the call deviates from the standard:
interface ERC721TokenReceiver {
/// @notice Handle the receipt of an NFT
/// @dev The ERC721 smart contract calls this function on the recipient
/// after a `transfer`. This function MAY throw to revert and reject the
/// transfer. Return of other than the magic value MUST result in the
/// transaction being reverted.
/// Note: the contract address is always the message sender.
/// @param _operator The address which called `safeTransferFrom` function
/// @param _from The address which previously owned the token
/// @param _tokenId The NFT identifier which is being transferred
/// @param _data Additional data with no specified format
/// @return `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`
/// unless throwing
function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes _data) external returns(bytes4);
}
The standard mandates that the first parameter will be the operator - the caller of safeTransferFrom. The enforcer passes instead the address(this) value, in other words the Holographer address. The impact is that any bookkeeping done in target contract, and allow / disallow decision of the transaction, is based on false information.
Impact
ERC721 transferFrom’s “to” contract may fail to accept transfers, or record credit of transfers incorrectly.
Recommended Mitigation Steps
Pass the msg.sender parameter, as the ERC721 standard requires.
alexanderattar (Holograph) commented:
This will be updated to pass msg.sender instead of Holograph address to match the standard.
ACC01ADE (Holograph) linked a PR:
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
Likely the call to onERC721Received hardcodes address(this) as the operator argument rather than forwarding msg.sender as the ERC721 standard requires.
Impact
A receiving contract may fail to accept transfers or record credit of transfers incorrectly, because its bookkeeping and accept/reject decision are based on a wrong operator address.
What the attacker needed
A receiving contract implementing onERC721Received; a transfer via safeTransferFrom
The fix
The operator argument should be msg.sender, and the project said this would be updated and linked a pull request for the fix.
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.
When a non-fungible token is sent to a smart contract, the token contract calls a notification function on the receiver so it can accept or reject the transfer. That function receives several arguments, including who triggered the transfer. Here the token contract filled in its own address instead of the real caller, so the receiver was told the wrong person started the transfer.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.