Failing to emit an event during a critical update like reward distribution, making it hard to track transactions or actions on-chain
Game
The wrong balance might be logged.
Can you identify how this misreporting could happen?
// 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!pragmasolidity ^0.8.0;contract EventMisreportingGame {uint256public totalDeposits;mapping(address=>uint256) public balances;eventDepositMade(addressindexed user, uint256 amount, uint256 totalDeposits);// Function to allow users to deposit and log the eventfunctiondeposit() publicpayable { balances[msg.sender] += msg.value; totalDeposits += msg.value;emitDepositMade(msg.sender, balances[msg.sender], totalDeposits); }}
Look carefully at the values emitted in the DepositMade event.
Consider whether the event is showing the current deposit amount or the userβs total balance.
Think about how you could adjust the parameters of emit DepositMade to reflect the accurate data intended for each transaction.
functiondeposit() publicpayable { balances[msg.sender] += msg.value; totalDeposits += msg.value;// Fix: Emit the actual deposit amount (msg.value) rather than the total balanceemitDepositMade(msg.sender, msg.value, totalDeposits);}