Raisebox Faucet

First Flight #50
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Impact: low
Likelihood: low
Invalid

Use of Manual Time Calculation Instead of Named Units in `RaiseBoxFaucet::claimFaucetTokens`

Root + Impact

Description

In the ETH drip section of claimFaucetTokens, the code calculates the current day as uint256 currentDay = block.timestamp / 24 hours; to check for daily resets (if (currentDay > lastDripDay)). Here, 24 hours equals 86400 seconds, matching 1 days, but using the manual multiplication (implied as 24 * 3600) obscures the intent of a full day reset.

Solidity supports named time units like 1 days for brevity and readability, explicitly equating to 86400 seconds. While 24 hours works identically, it requires readers to recall the conversion, potentially introducing minor confusion in time-based logic. Best practices favor named units to make code more intuitive and less error-prone during reviews or modifications.

// @> Root cause in the codebase
if (!hasClaimedEth[faucetClaimer] && !sepEthDripsPaused) {
// @> Manual calculation reduces readability
uint256 currentDay = block.timestamp / 24 hours;
if (currentDay > lastDripDay) {
lastDripDay = currentDay;
dailyDrips = 0;
// dailyClaimCount = 0;
}
// ...
}

Risk

Likelihood:

  • Low: The calculation is numerically correct and compiles without issues, so it rarely causes functional errors.

  • Confusion arises mainly during code reviews or when adapting the logic for other time periods.

Impact:

  • Low: No security vulnerabilities or gas inefficiencies, but it slightly increases cognitive load for maintainers, potentially slowing development.

  • In larger codebases, inconsistent time unit styles can lead to overlooked bugs in similar calculations.

Proof of Concept

The two expressions produce identical results, confirming functional equivalence but highlighting readability differences. A simple test verifies this:

// Test to show equivalence
function test_TimeUnitsEquivalent() public {
uint256 ts = block.timestamp;
assertEq(ts / 24 hours, ts / 1 days); // Passes: both yield the same day number
}

Running this in Foundry outputs true, proving no behavioral difference, but the named unit 1 days is clearer for intent.

Explanation

  • Setup: Use a current timestamp and divide by both units.

  • Issue Demonstration: The assertion passes, but 24 hours requires mental math (24 * 3600 = 86400), while 1 days directly conveys "one full day."

  • Result: Code works, but adopting named units improves long-term clarity without changes.

Recommended Mitigation

Replace 24 hours with 1 days for better readability and adherence to Solidity conventions. This simple swap enhances self-documentation without altering behavior.

if (!hasClaimedEth[faucetClaimer] && !sepEthDripsPaused) {
- uint256 currentDay = block.timestamp / 24 hours;
+ uint256 currentDay = block.timestamp / 1 days; // Use named unit for clarity
if (currentDay > lastDripDay) {
lastDripDay = currentDay;
dailyDrips = 0;
// dailyClaimCount = 0;
}
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 10 days ago
Submission Judgement Published
Invalidated
Reason: Lack of quality

Support

FAQs

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