The openBox() function generates repeated rewards due to the reliance on block.timestamp and msg.sender for randomness.
Block Timestamp Dependency: Transactions occurring within the same block share identical block.timestamp values, reducing the randomness of reward allocation.
User Address Influence: Utilizing msg.sender in the randomness calculation can lead to repeated rewards for users executing multiple transactions in a single block.
This design flaw allows users to exploit the openBox() function, potentially receiving the same reward multiple times when transacting within the same block.
The current code snippet is as follows:
Since block.timestamp only updates with each new block and msg.sender remains constant for the same user, transactions that happen within the same block can produce identical random values. This can lead to users receiving the same reward multiple times.
The predictable nature of the random number generation results in users receiving the same rewards if they interact with the contract multiple times within the same block. This undermines the intended randomness of the reward distribution and could allow certain malicious users to manipulate the system to their favor.
Economic Impact: Repeated rewards of high tier rewards can distort the economic model of the application, affecting sustainability.
Unit testing with Forge
Add this code to your test suite:
Secure Randomness Source: Implement a verifiable randomness source like Chainlink VRF to ensure reliable randomness.
Incorporate Additional Variables: Use other variables (e.g., nonce) in the randomness calculation to ensure diverse rewards.
Transaction Frequency Limitation: Limit the number of times a user can call openBox() within a block to prevent exploitation.
Implement a Delay Mechanism: Introduce a cooldown period to restrict rapid successive calls to the openBox() function.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.