GivingThanks

First Flight #28
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: low
Invalid

Unchecked Increment of tokenCounter in GivingThanks Contract, Leading to Potential ID Manipulation

Summary

The GivingThanks contract increments the tokenCounter variable without any validation or control, using it as the unique token ID for new mints in the donate function. This unchecked increment could create gaps in token IDs and expose the contract to potential manipulation by allowing arbitrary ID generation.

Vulnerability Details

The tokenCounter variable is used to assign unique token IDs in each call to donate. However, the counter increments unchecked, meaning gaps can emerge if certain conditions (e.g., failed transactions or reentrancy issues) interrupt the process. Additionally, since there is no control mechanism over the incrementation or assignment of tokenCounter, a malicious actor could potentially exploit this by invoking the function repeatedly or by modifying the contract's code to secure specific token IDs or interfere with the sequence.

  • Root Cause: tokenCounter is incremented directly without validation or constraints.

  • Instances: tokenCounter incrementation in the donate function.

Impact

Unchecked increments of tokenCounter could lead to gaps in token IDs, which could complicate tracking and organization of minted tokens. Additionally, this lack of control may allow attackers to manipulate token ID assignments, possibly gaining access to preferred IDs or disrupting the intended sequence of IDs.

Tools Used

  • Manual Code Review

Recommendations

Implement Safe Counter Incrementation: Use OpenZeppelin’s Counters library to safely handle the incrementation of tokenCounter. This library provides overflow-safe increment operations and helps prevent gaps due to failed transactions.

import "@openzeppelin/contracts/utils/Counters.sol";
using Counters for Counters.Counter;
Counters.Counter private _tokenCounter;
Updates

Lead Judging Commences

n0kto Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.