Anchor contract is unable to receive NFTs of any kind
The Anchor contract lacks the onERC721Received and onERC1155Received functions, so it cannot receive NFTs sent via safeTransferFrom or safeMint. An attacker could not directly exploit this, but it prevents the contract from receiving such tokens, potentially causing a denial of service for intended functionality.
0xnirlin Follow with sashik_eth
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/883
Found by
0xnirlin, sashik_eth
Vulnerability Detail
Anchor.sol essentially works like a wallet, and also attached to profile to give it extra credibility and profile owner more functionality.
As intended this contract will receive nfts, from different strategies and protocols. However, as it is currently implemented thee contracts will not be able to receive NFTs sent with safeTransferFrom(), because they do not implement the necessary functions to safely receive these tokens..
While in many cases such a situation would be Medium severity, looking at these wallets will be used could lead to more serious consequences. For example, having an anchor that is entitled to high value NFTs but is not able to receive them is clearly a loss of funds risk, and a High severity issue.
implement the onERC721Received() and onERC1155Received() functions in following code:
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.19;
// Core Contracts
import {Registry} from "./Registry.sol";
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣿⣿⣿⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⢿⣿⣿⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⣿⣿⣿⣿⣿⣿⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⡟⠘⣿⣿⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⣀⣴⣾⣿⣿⣿⣿⣾⠻⣿⣿⣿⣿⣿⣿⣿⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⡿⠀⠀⠸⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠀⠀⢀⣠⣴⣴⣶⣶⣶⣦⣦⣀⡀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⣴⣿⣿⣿⣿⣿⣿⡿⠃⠀⠙⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⠁⠀⠀⠀⢻⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⡀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⡿⠁⠀⠀⠀⠘⣿⣿⣿⣿⣿⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⠃⠀⠀⠀⠀⠈⢿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⣰⣿⣿⣿⡿⠋⠁⠀⠀⠈⠘⠹⣿⣿⣿⣿⣆⠀⠀⠀
// ⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⣿⣿⡿⠀⠀⠀⠀⠀⠀⠈⢿⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⣿⣿⣿⠏⠀⠀⠀⠀⠀⠀⠘⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⢰⣿⣿⣿⣿⠁⠀⠀⠀⠀⠀⠀⠀⠘⣿⣿⣿⣿⡀⠀⠀
// ⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣟⠀⡀⢀⠀⡀⢀⠀⡀⢈⢿⡟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⡇⠀⠀
// ⠀⠀⣠⣿⣿⣿⣿⣿⣿⡿⠋⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⣿⡿⢿⠿⠿⠿⠿⠿⠿⠿⠿⠿⢿⣿⣿⣿⣷⡀⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠸⣿⣿⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⢠⣿⣿⣿⣿⠂⠀⠀
// ⠀⠀⠙⠛⠿⠻⠻⠛⠉⠀⠀⠈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⣿⣿⣿⣧⠀⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⢻⣿⣿⣿⣷⣀⢀⠀⠀⠀⡀⣰⣾⣿⣿⣿⠏⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⣿⣿⣿⣧⠀⠀⢸⣿⣿⣿⣗⠀⠀⠀⢸⣿⣿⣿⡯⠀⠀⠀⠀⠹⢿⣿⣿⣿⣿⣾⣾⣷⣿⣿⣿⣿⡿⠋⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⠙⠋⠛⠙⠋⠛⠙⠋⠛⠙⠋⠃⠀⠀⠀⠀⠀⠀⠀⠀⠠⠿⠻⠟⠿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠟⠿⠟⠿⠆⠀⠸⠿⠿⠟⠯⠀⠀⠀⠸⠿⠿⠿⠏⠀⠀⠀⠀⠀⠈⠉⠻⠻⡿⣿⢿⡿⡿⠿⠛⠁⠀⠀⠀⠀⠀⠀
// allo.gitcoin.co
/// @title Anchor contract
/// @author @thelostone-mc <[email protected]>, @0xKurt <[email protected]>, @codenamejason <[email protected]>, @0xZakk <[email protected]>, @nfrgosselin <[email protected]>
/// @notice Anchors are associated with profiles and are accessible exclusively by the profile owner. This contract ensures secure
/// and authorized interaction with external addresses, enhancing the capabilities of profiles and enabling controlled
/// execution of operations. The contract leverages the `Registry` contract for ownership verification and access control.
contract Anchor {
/// ==========================
/// === Storage Variables ====
/// ==========================
/// @notice The registry contract on any given network/chain
Registry public immutable registry;
/// @notice The profileId of the allowed profile to execute calls
bytes32 public immutable profileId;
/// ==========================
/// ======== Errors ==========
/// ==========================
/// @notice Throws when the caller is not the owner of the profile
error UNAUTHORIZED();
/// @notice Throws when the call to the target address fails
error CALL_FAILED();
/// ==========================
/// ======= Constructor ======
/// ==========================
/// @notice Constructor
/// @dev We create an instance of the 'Registry' contract using the 'msg.sender' and set the profileId.
/// @param _profileId The ID of the allowed profile to execute calls
constructor(bytes32 _profileId) {
registry = Registry(msg.sender);
profileId = _profileId;
}
/// ==========================
/// ======== External ========
/// ==========================
/// @notice Execute a call to a target address
/// @dev 'msg.sender' must be profile owner
/// @param _target The target address to call
/// @param _value The amount of native token to send
/// @param _data The data to send to the target address
/// @return Data returned from the target address
function execute(address _target, uint256 _value, bytes memory _data) external returns (bytes memory) {
// Check if the caller is the owner of the profile and revert if not
if (!registry.isOwnerOfProfile(profileId, msg.sender)) revert UNAUTHORIZED();
// Check if the target address is the zero address and revert if it is
if (_target == address(0)) revert CALL_FAILED();
// Call the target address and return the data
(bool success, bytes memory data) = _target.call{value: _value}(_data);
// Check if the call was successful and revert if not
if (!success) revert CALL_FAILED();
return data;
}
/// @notice This contract should be able to receive native token
receive() external payable {}
}
Impact
Any time an ERC721 or ERC1155 is attempted to be transferred with safeTransferFrom() or minted with safeMint(), the call will fail.
Code Snippet
Tool used
Manual Review
Recommendation
implement the onERC721Received() and onERC1155Received() functions
Discussion
sherlock-admin
1 comment(s) were left on this issue during the judging contest.
n33k commented:
invalid, README says non ERC721 tokens will interact with the smart contracts
AhmadDecoded
Escalate
This is a valid high, yes the readme mentions that no erc721 will interact with the contract.
But as described many times by sponsor, the anchor should be able to receive nfts, that also adds to the reputation of the anchor and in general anchor are meant to receive nfts, both erc721 and erc1155.
sherlock-admin2
Escalate
This is a valid high, yes the readme mentions that no erc721 will interact with the contract.
But as described many times by sponsor, the anchor should be able to receive nfts, that also adds to the reputation of the anchor and in general anchor are meant to receive nfts, both erc721 and erc1155.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
nevillehuang
This ones a tough one. The new hierachy of truth based on sherlock docs states that:
Hierarchy of truth: Contest README > Sherlock rules for valid issues > Historical decisions. While considering the validity of an issue in case of any conflict the sources of truth are prioritized in the above order. For example: In case of conflict between Sherlock rules vs Sherlock's historical decision, Sherlock criteria for issues must be considered the source of truth. In case of conflict between information in the README vs Sherlock rules, the README overrides Sherlock rules.
But it should be noted that the gitcoin docs is part of the README too, and under the anchor contract information, explicitly states here that:
The anchor can accrue reputation for the project. It can represent the project in any attestations, be used as a soul-bound token, or used as a pointer in a registry
So i am inclined to think this is a valid issue. Sidenote: #731 is a duplicate of this issue
AhmadDecoded
Also the argument by sashik that read me did not mention about erc1155 is valid too.
AhmadDecoded
Hey @neeksec, appreciate your judging effort.
It should be valid high based on following arguments:
-
Registery for an achor is set on deployment, so specific anchor code js attached to the registery forever.
-
Anchor contract is not upgradable, so it can not be changed later and add the required receiving functions.
-
Historically the inability to receive nfts have been given the high status by sherlock. See splits contest example given in #731
-
Sherlock rules does not consider if something can be upgraded later on, audit vulnerability is given status based on current implementation unlike immunefi.
So it clearly breaks the core functionality and goes against the docs and team have already confirmed and implemented the fix, so should be given high status. It is one of the functionality that alloe will be highly reliant on.
neeksec
I deleted my initial response.
I re-read the conflicting docs.
The anchor can accrue reputation for the project. It can represent the project in any attestations, be used as a soul-bound token, or used as a pointer in a registry
Since the NFTs are representing reputations or represent the project in any attestations, losing them dosen't sound like a material lost of funds.
AhmadDecoded
And also it makes the concept of anchor useless too than, breaking the core functionality.
Also strategies are highly cutomizible, so nfts can have the material value, sponsor confirmed this. So as more public strategies will be added this inability to receive nfts can also lead to loss of funds and definitely loss of opportunity.
High sounds more reasonable.
jacksanford1
https://github.com/allo-protocol/allo-v2/pull/378
Evert0x
Other protocols can just use transferFrom instead of safeTransferFrom, correct?
nevillehuang
Other protocols can just use
transferFrominstead ofsafeTransferFrom, correct?
Correction, you are right users can simply call transferFrom() for ERC721. But for ERC1155, only safeTransferFrom() options exists. So this DoS only applies to ERC1155 tokens
See here: https://eips.ethereum.org/EIPS/eip-1155#erc-1155-token-receiver
Evert0x
Planning to make medium as this issue only exists for ERC1155. With #731 as a duplicate
sashik-eth
Planning to make medium as this issue only exists for ERC1155. With #731 as a duplicate
I'm afraid I have to disagree that applicability to only ERC1155 decreases the severity of this issue. The ERC1155 token is not necessarily less valuable than the ERC721 token. Moreover, the popularity of ERC1155 contracts is constantly increasing during the last two years as we can see on the chart from this page:
https://dune.com/ilemi/erc-and-eip-starter-kit
Also, it is worth mentioning that the external sender could be a protocol that has utilized only the safeTransferFrom function on the ERC721 contract, in this case, the problem with the ERC721 token would also occur.
Evert0x
Also, it is worth mentioning that the external sender could be a protocol that has utilized only the safeTransferFrom function on the ERC721 contract, in this case, the problem with the ERC721 token would also occur.
This is not a valid reason to validate issues, also safeTransferFrom is not necessarily better to use in comparison to transferFrom.
Issues that result out of a future integration/implementation that was not intended (mentioned in the docs/README) or because of a future change in the code (as a fix to another issue) are not valid issues.
I'm not stating that ERC1155 is less valuable or less popular. But looking at it again, to become a High severity it's very important that material funds are risked of being lost. Which is not the case here.
sashik-eth
I'm not stating that ERC1155 is less valuable or less popular. But looking at it again, to become a High severity it's very important that material funds are risked of being lost. Which is not the case here.
What do you define as material funds? Only ERC20 tokens and native ETH? In my opinion, the ERC1155 token can also be a material fund or hold access to other tokens or ETH.
Evert0x
@sashik-eth but ERC1155 are not lost in this scenario, that just can not be used in the protocol.
nevillehuang
Hi @sashik-eth, there is no loss of funds here, just a permanent DoS of intended functionality of transferring ERC1155 tokens, so in favor of medium severity.
AhmadDecoded
@nevillehuang my point was, strategies are highly customizable and as allo plan in future they would approved community developed strategies too, so you never know the implementation and the problems it may lead to.
Evert0x
Result: Medium Has Duplicates
sherlock-admin2
Escalations have been resolved successfully!
Escalation status:
- ahmaddecoded: accepted
AhmadDecoded
@Evert0x i think the excluded tag should be removed.
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 Anchor contract does not implement the onERC721Received and onERC1155Received functions required by the ERC721 and ERC1155 standards for safe transfers.
Impact
The contract cannot receive ERC721 or ERC1155 tokens sent via safeTransferFrom or safeMint, which could prevent it from holding valuable NFTs and disrupt intended functionality.
What the attacker needed
None
The fix
The fix is to implement the onERC721Received and onERC1155Received functions in the Anchor contract.
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.
The Anchor contract is like a wallet that can hold tokens. Some tokens, when sent, check that the receiver is a wallet that knows how to handle them. The Anchor contract does not have the code to answer that check, so those tokens cannot be sent to it. This means the contract cannot receive certain NFTs, which could be a problem if it is supposed to hold them.
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.