FV-SOL-5-C4 Misordered Calculations
TLDR
Errors from improper indexing or referencing in mappings, often due to incorrect key choices or updates
Game
Review the calculation order in calculateReward
// 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 LogicMisorderGame {
uint256 public finalReward;
uint256 public constant BONUS = 50;
uint256 public constant TAX_PERCENT = 10;
// Function to calculate the final reward based on balance with bonus and tax applied
function calculateReward(uint256 balance) public {
uint256 doubledBalance = balance * 2;
uint256 rewardWithBonus = doubledBalance + BONUS;
finalReward = rewardWithBonus - (rewardWithBonus * TAX_PERCENT / 100);
}
}
Last updated
Was this helpful?