The openBox()
function in the contract contains a vulnerability related to weak randomness. The current implementation uses keccak256
with block timestamp and the message sender's address to generate random values, which is predictable and can be manipulated by miners. This weak randomness exposes the contract to manipulation and attacks, especially for operations involving rewards distribution. A more secure solution, such as using Chainlink VRF (Verifiable Random Function), should be implemented to ensure unpredictability and fairness in randomness generation.
The vulnerability lies in the way the contract generates random values. In the function:
The randomness is based on block.timestamp
and msg.sender
, which are predictable and manipulatable:
block.timestamp
can be influenced by miners within a small range.
msg.sender
is a known value as it represents the address initiating the transaction.
As a result, an attacker or miner could manipulate the block timestamp or repeatedly call the function from different addresses until they receive a favorable outcome. This introduces a significant risk, particularly because the rewards structure involves Ether payouts, making it financially exploitable.
This vulnerability can lead to unfair manipulation of the rewards system, allowing malicious actors to repeatedly open boxes and increase their chances of getting high-value rewards like "Silver Coin" or "Gold Coin." The potential consequences include:
Unfair Distribution of Rewards: Attackers could gain more valuable rewards than intended by exploiting predictable randomness.
Financial Loss: Since rewards are tied to Ether values (e.g., 0.5 or 1 Ether), a successful exploitation could result in substantial financial loss for the contract's owner or the dApp's users.
Reduced Trust in the System: Users may lose confidence in the fairness of the system if they suspect that the randomness can be manipulated.
Code Review: Manual inspection of the code to identify the weak randomness pattern.
Solidity Static Analyzers (e.g., aderyn): To identify weak randomness and security vulnerabilities in the code.
Implement Chainlink VRF: Replace the current random value generation with Chainlink's Verifiable Random Function (VRF). This ensures that randomness is cryptographically secure and cannot be manipulated by miners or users.
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.