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

NextGenRandomizerNXT uses the PREVRANDAO opcode as source of randomness #1014

Closed
c4-submissions opened this issue Nov 11, 2023 · 4 comments
Closed
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/hardhat/smart-contracts/XRandoms.sol#L35-L43

Vulnerability details

Summary

The NextGenRandomizerNXT contract uses block.prevrandao as the source of randomness this value is not truly random, and validators who are chosen to propose new blocks will be able to know the value of the PREVRANDAO opcode.

Vulnerability Details

As the NextGenRandomizerNXT uses the block.prevrandao together with deterministic things like block.number to calculate the random hash. The result of minting an NFT can be deterministically calculated by validators. This creates unfair market conditions.

Here we can see that the flow of generating a random hash with the NextGenRandomizerNXT contract uses the PREVRANDAO opcode as the source of randomness:

function calculateTokenHash(uint256 _collectionID, uint256 _mintIndex, uint256 _saltfun_o) public {
    require(msg.sender == gencore);
    bytes32 hash = keccak256(abi.encodePacked(_mintIndex, blockhash(block.number - 1), randoms.randomNumber(), randoms.randomWord()));
    gencoreContract.setTokenHash(_collectionID, _mintIndex, hash);
}
function randomNumber() public view returns (uint256){
    uint256 randomNum = uint(keccak256(abi.encodePacked(block.prevrandao, blockhash(block.number - 1), block.timestamp))) % 1000;
    return randomNum;
}
string[100] memory wordsList = ["Acai", "Ackee", "Apple", ...];

function randomWord() public view returns (string memory) {
    uint256 randomNum = uint(keccak256(abi.encodePacked(block.prevrandao, blockhash(block.number - 1), block.timestamp))) % 100;
    return getWord(randomNum);
}

Impact

Validators are able to already know which NFT they would get if they mint now. This creates very unfair market conditions, as validators are able to cheat and depending on the NFT collection steal funds by doing so. It also destroys the rarity variables of the artist.

Tools Used

Manual Review

Recommendations

Do not use the PREVRANDAO opcode as a source of randomness, if the outcome of the random hash is not trivial.

Assessed type

MEV

@c4-submissions c4-submissions added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Nov 11, 2023
c4-submissions added a commit that referenced this issue Nov 11, 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