Weak PRNG found in randomPool.randomNumber() #1291
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-1901
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
Lines of code
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/XRandoms.sol#L36
Vulnerability details
Impact
If the PRNG is weak, the sequence of generated random numbers may be predictable or easy to guess by the attacker. This predictability can be exploited by attackers to gain an unfair advantage or manipulate the contract's behavior.
In situations where randomness is used to determine outcomes, especially in decentralized finance (DeFi) applications, a weak PRNG can lead to front-running attacks. Malicious actors could anticipate random number generation and act strategically to exploit the system.
In financial applications, a weak PRNG can lead to a loss of funds if attackers can predict outcomes or manipulate random choices in their favor.
Proof of Concept
randomPool.randomNumber() (smart-contracts/XRandoms.sol#35-38) uses a weak PRNG: "randomNum = uint256(keccak256(bytes)(abi.encodePacked(block.prevrandao,blockhash(uint256)(block.number - 1),block.timestamp))) % 1000 (smart-contracts/XRandoms.sol#36)"
Tools Used
Manual code review
Recommended Mitigation Steps
Weak PRNG due to a modulo on
block.timestamp
,now
orblockhash
. These can be influenced by miners to some extent so they should be avoided. Do not useblock.timestamp
,now
orblockhash
as a source of randomness.Consider using cryptographic libraries that provide strong randomness guarantees. In Ethereum-based smart contracts, try using external services like Chainlink VRF, which provides a decentralized and verifiable source of randomness.
Assessed type
Other
The text was updated successfully, but these errors were encountered: