Skip to content
Smart contracts Audit finding Beginner

Violation of ERC-721 Standard in VerbsToken:tokenURI Implementation

The VerbsToken contract's tokenURI function does not revert for non-existent token IDs, violating the ERC-721 standard. An attacker could call tokenURI with an invalid token ID and receive a response instead of a revert, breaking the expected behaviour.

pep7siup Follow with shaka, hals and 4 others

Originally disclosed on Code4rena

Submitted by pep7siup, also found by shaka, imare (1, 2), hals, XDZIBECX, ZanyBonzy, _eperezok, and Ocean_Sky

The VerbsToken contract deviates from the ERC-721 standard, specifically in the tokenURI implementation. According to the standard, the tokenURI method must revert if a non-existent tokenId is passed. In the VerbsToken contract, this requirement was overlooked, leading to a violation of the EIP-721 specification and breaking the invariants declared in the protocol’s README.

Proof of Concept

The responsibility for checking whether a token exists may be argued to be placed on the descriptor. However, the core VerbsToken contract, which is expected to adhere to the invariant stated in the Protocol’s README, does not follow the specification.

// File: README.md
414:## EIP conformity
415:
416:- [VerbsToken](https://github.com/code-423n4/2023-12-revolutionprotocol/blob/main/packages/revolution/src/VerbsToken.sol): Should comply with `ERC721`

Note: the original NounsToken contract, which VerbsToken was forked from, did implement the tokenURI function properly.

Recommended Mitigation Steps

It is recommended to strictly adopt the implementation from the original NounsToken contract to ensure compliance with the ERC-721 standard.

    function tokenURI(uint256 tokenId) public view override returns (string memory) {
+        require(_exists(tokenId));
        return descriptor.tokenURI(tokenId, artPieces[tokenId].metadata);
    }

References

  1. EIP-721 Standard
  2. Code 423n4 Finding - Caviar
  3. Code 423n4 Finding - OpenDollar
  4. NounsToken Contract Implementation

0xTheC0der (Judge) commented:

I felt obliged to award with Medium severity due to precedent EIP-721 tokenUri cases (see https://github.com/code-423n4/2023-12-revolutionprotocol-findings/issues/511#issuecomment-1883512625, one judged by Alex).

This should be discussed during the next SC round.


The original report as published on Code4rena, by pep7siup. 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.

How it worked

Root cause

Likely the tokenURI function lacks a check that the token ID exists before returning the URI.

Impact

The contract violates the ERC-721 standard and the protocol's own invariant, which could lead to unexpected behaviour for integrators relying on the standard.

What the attacker needed

None

The fix

The tokenURI function should be updated to require that the token ID exists, as in the original NounsToken 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.

ERC-721 is a standard for non-fungible tokens on Ethereum. The standard says that asking for the web address (tokenURI) of a token that does not exist should cause an error. This contract does not do that, so it breaks the standard.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by pep7siup

View all

2 more disclosed reports, best first.

More from Revolution Protocol

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.