Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lack of parameter to check in ERC1155Minimal.sol makes this contract to be not compliant with ERC-1155 standard #226

Closed
c4-bot-2 opened this issue Apr 18, 2024 · 3 comments
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-500 grade-b QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_25_group AI based duplicate group recommendation

Comments

@c4-bot-2
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2024-04-panoptic/blob/833312ebd600665b577fbd9c03ffa0daf250ed24/contracts/tokens/ERC1155Minimal.sol#L112-L119
https://github.com/code-423n4/2024-04-panoptic/blob/833312ebd600665b577fbd9c03ffa0daf250ed24/contracts/tokens/ERC1155Minimal.sol#L163-L170

Vulnerability details

Impact

According to provided documentation, ERC1155Minimal.sol is A minimalist implementation of the ERC1155 token standard without metadata.
Docs straightforwardly mention that ERC1155 used by the protocol are SFPM and factory ERC1155 tokens

However, the current implementation does not comply with EIP-1155. Since the compliance requirement was straightforwardly mentioned as a requirement in the docs - I've evaluated this issue as Medium.

During the previous Code4rena contests, lack of compliance with EIP-1155 was evaluated as Medium too, e.g.:

Moreover, during the previous C4 contests, lack of EIP compliance was usually evaluated as High/Medium

Lack of compliance may cause unexpected behavior. Other protocols that integrate with contract may incorrectly assume that it's EIP-1155 compliant - especially that documentation states that it's ERC-1155. Any deviation from this standard will broke the composability and may lead to fund loss. While protocol's implements a contract and describes it as ERC-1155, it should fully conform to ERC-1155 standard.

Proof of Concept

According to EIP-1155

safeTransferFrom rules:

MUST revert if _to is the zero address.

[...]

safeBatchTransferFrom rules:

MUST revert if _to is the zero address.

None of these functions verify if _to is the zero address, which implies that contract is not compliant with EIP-1155.

File: ERC1155Minimal.sol

 if (to.code.length != 0) {
            if (
                ERC1155Holder(to).onERC1155Received(msg.sender, from, id, amount, data) !=
                ERC1155Holder.onERC1155Received.selector
            ) {
                revert UnsafeRecipient();
            }
        }

In function safeTransferFrom(), when parameter to is the address zero, to.code.length will return 0, thus we won't enter above conditional branch. The same issue occurs for safeBatchTransferFrom():

File: ERC1155Minimal.sol

        if (to.code.length != 0) {
            if (
                ERC1155Holder(to).onERC1155BatchReceived(msg.sender, from, ids, amounts, data) !=
                ERC1155Holder.onERC1155BatchReceived.selector
            ) {
                revert UnsafeRecipient();
            }
        }

This leads to conclusion that it's possible to safeTransferFrom() or safeBatchTransferFrom() to address(0), even though EIP-1155 straightforwardly states that every address(0) transfer should revert. This means that protocol violates EIP-1155.

Tools Used

Manual code review

Recommended Mitigation Steps

In both safeBatchTransferFrom() and safeTransferFrom() add additional line which will verify if parameter to is not address zero:

require(to != address(0), "Cannot transfer to address(0)");

Assessed type

Invalid Validation

@c4-bot-2 c4-bot-2 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Apr 18, 2024
c4-bot-2 added a commit that referenced this issue Apr 18, 2024
@c4-bot-11 c4-bot-11 added the 🤖_25_group AI based duplicate group recommendation label Apr 22, 2024
@c4-judge
Copy link
Contributor

Picodes marked the issue as primary issue

@c4-judge c4-judge added the primary issue Highest quality submission among a set of duplicates label Apr 25, 2024
@c4-judge
Copy link
Contributor

Picodes marked the issue as duplicate of #500

@c4-judge c4-judge added duplicate-500 and removed primary issue Highest quality submission among a set of duplicates labels Apr 25, 2024
@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels May 6, 2024
@c4-judge
Copy link
Contributor

c4-judge commented May 6, 2024

Picodes changed the severity to QA (Quality Assurance)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-500 grade-b QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_25_group AI based duplicate group recommendation
Projects
None yet
Development

No branches or pull requests

4 participants