Skip to content
Smart contracts Audit finding Beginner

Incorrect implementation of ownerOf makes veALC

The VotingEscrow contract's ownerOf function returns the zero address for non-existent token IDs instead of reverting, which breaks the ERC721 specification. This makes the veALCX token non-compliant with ERC721, which could cause integrating protocols that expect standard behaviour to malfunction.

marchev Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

30918 - [SC - Insight] Incorrect implementation of ownerOf makes veALC...

Submitted on May 8th 2024 at 04:15:13 UTC by @marchev for Boost | Alchemix

Report ID: #30918

Report type: Smart Contract

Report severity: Insight

Target: https://github.com/alchemix-finance/alchemix-v2-dao/blob/main/src/VotingEscrow.sol

Impacts:

  • Contract fails to deliver promised returns, but doesn't lose value

Description

Brief/Intro

As per the ERC721 specification, NFTs assigned to zero address are considered invalid, and ownerOf() queries about them must revert. However, the implementation of VotingEscrow#ownerOf() returns address(0) for such NFTs and not comply with that and thus makes veALCX not compliant with ERC721.

Vulnerability Details

The ERC721 specification states the following:

    /// @notice Find the owner of an NFT
    /// @dev NFTs assigned to zero address are considered invalid, and queries
    ///  about them do throw.
    /// @param _tokenId The identifier for an NFT
    /// @return The address of the owner of the NFT
    function ownerOf(uint256 _tokenId) external view returns (address);

This means that every compliant ERC721 token must implement the ownerOf() function so that it throws if a _tokenId is passed that belongs to address(0). However, VotingEscrow's implementation looks like this:

SOL
    /// @inheritdoc IVotingEscrow
    function ownerOf(uint256 _tokenId) public view override(IERC721, IVotingEscrow) returns (address) {
        return idToOwner[_tokenId];
    }

For a non-existent _tokenId, this implementation will return address(0) instead of reverting. This behavior is not compliant with the ERC721 specification.

Impact Details

Due to the incorrect implementation of the ownerOf() function, the veALCX token does not conform to the ERC721 standard. This leads to problems with composability and interoperability. Other protocols that integrate with the veALCX token may malfunction since they expect standard behaviors the token does not support, potentially leading to operational disruptions.

References

Problematic implementation:

https://github.com/alchemix-finance/alchemix-v2-dao/blob/f1007439ad3a32e412468c4c42f62f676822dc1f/src/VotingEscrow.sol#L230-L232

Docs references which state that ERC721 compliance is expected:

Proof of Concept

Add the following test to src/test/VotingEscrow.t.sol:

SOL

	function test_erc721_compliance_is_broken_due_to_incorrect_owner_of_implementation() public {
        hevm.expectRevert();
        address noSuchOwner = veALCX.ownerOf(31337); // Invalid tokenId must throw
    }

Make sure the following entries are updated in Makefile:

Shell
# file to test 
FILE=VotingEscrow

# specific test to run
TEST=test_erc721_compliance_is_broken_due_to_incorrect_owner_of_implementation

Run the PoC via make test_file_test

The original report as published on Immunefi, by marchev. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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 ownerOf function reads the owner mapping directly without checking that the token ID exists, so a missing entry returns the default zero address instead of reverting.

Impact

The token does not conform to ERC721, so other protocols integrating with veALCX may malfunction, potentially causing operational disruptions; the report notes no loss of value.

What the attacker needed

None

The fix

The ownerOf function should be changed to revert when the token ID has no owner, so the token complies with ERC721.

How it was found

  1. Add a test to the VotingEscrow test file that expects a revert when calling ownerOf with an invalid token ID.
  2. Update the Makefile to point at the VotingEscrow file and the new test.
  3. Run the test via the make target and observe that no revert occurs.

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.

ERC721 is the standard for non-fungible tokens (NFTs) on Ethereum. The standard says that asking who owns a token that does not exist must cause an error, but this contract simply answers with the zero address, which is treated as 'nobody'. Because of that, other programs that rely on the standard may behave incorrectly when they interact with this token.

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 marchev

View all

9 more disclosed reports, best first.

More from Alchemix

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.