FV-SOL-5-C2 Incorrect Conditionals

TLDR

Results from incorrect conditions in if statements, loops, or switches, causing unintended branching in code execution

e.g. a function meant to handle reward calculation might incorrectly check for block.number >= lastRewardBlock instead of block.number > lastRewardBlock, causing rewards to be skipped or duplicated

Game

Can you identify how this contract might cause certain balances to yield unexpected rewards?

// 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 IncorrectConditionalsGame {
    uint256 public reward;

    // Function to calculate rewards based on balance
    function calculateReward(uint256 balance) public {
        if (balance > 100) {
            reward = 10;
        } else if (balance > 500) {
            reward = 50;
        } else {
            reward = 0;
        }
    }
}

Last updated