FV-SOL-3-C4 Misuse of Environment Variables

TLDR

Environmental variables like block.timestamp are sometimes used in arithmetic, which can lead to unintended outcomes if assumptions about their values change

Game

In this contract, startGame uses block.timestamp to enforce a 1-day delay between game starts. What do you think?

// SPDX-License-Identifier: MIT
// Open me in VSCode and really think before opening the hints!
// Add @audit tags wherever suspicious
// Go to the solidity docs to complete missing knowledge of what's happening here
// Solve by drafting a fix!
pragma solidity ^0.8.0;

contract TimestampGame {
    uint256 public lastPlayed;

    // Function to start a time-based game
    function startGame() public {
        require(block.timestamp >= lastPlayed + 1 days, "Game can only be started once a day");
        lastPlayed = block.timestamp;
    }
}

Last updated