Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weak PRNG found in randomPool.randomNumber() #1291

Closed
c4-submissions opened this issue Nov 12, 2023 · 4 comments
Closed

Weak PRNG found in randomPool.randomNumber() #1291

c4-submissions opened this issue Nov 12, 2023 · 4 comments
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

Comments

@c4-submissions
Copy link
Contributor

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 or blockhash. These can be influenced by miners to some extent so they should be avoided. Do not use block.timestamp, now or blockhash 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

@c4-submissions c4-submissions added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Nov 12, 2023
c4-submissions added a commit that referenced this issue Nov 12, 2023
@c4-pre-sort
Copy link

141345 marked the issue as duplicate of #163

@c4-judge
Copy link

c4-judge commented Dec 4, 2023

alex-ppg marked the issue as duplicate of #1901

@c4-judge
Copy link

c4-judge commented Dec 5, 2023

alex-ppg marked the issue as unsatisfactory:
Invalid

@c4-judge c4-judge added the unsatisfactory does not satisfy C4 submission criteria; not eligible for awards label Dec 5, 2023
@c4-judge
Copy link

c4-judge commented Dec 5, 2023

alex-ppg marked the issue as unsatisfactory:
Invalid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

3 participants