The RandomizerNXT.sol
doesn't provide randomness
#1902
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
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/RandomizerNXT.sol#L55-L59
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/NextGenCore.sol#L444-L446
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/NextGenCore.sol#L192-L193
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/NextGenCore.sol#L228-L229
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/RandomizerNXT.sol#L55-L59
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/XRandoms.sol#L35-L38
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/XRandoms.sol#L40-L43
Vulnerability details
Impact
The
RandomizerNXT.sol
contract doesn't provide a true randomness source. In a context where true randomness is required, this contract is not appropriate to deliver a random hash. The reason is because the minting and hash generation happen all within one transaction and if not satisfactory to the odds abuser could be reverted.The
mint()
function is here called,as we can see the mint function calls the
_mintProcessing()
The
randomizer
contract for the given collection is thereafter called...The hash can lastly be checked in the core contract by anyone in the
retrieveTokenHash()
.This is where the 'magic' happens. A
random
hash is calculated, through the combination of hashed block timestamps, block hashes and a string, calculation made in theXRandom
contractrandomWord()
andrandomNumber()
functions.Although it is true that it is hard to predict this number, this hash is calculated within one single transaction, an exploiter could easily revert, after not having a result that is not satisfactory. This means that this randomness source is not random, because it allows the for the executor to be selective.
As for the impact we could rank this issue as med, depending on how much an NFT collection relies on the randomness of this contract. It seems as if the protocol wanted to pursue randomness because it tries to be unpredictable, one could say that it is quite unpredicatble. however the minter has the last say in the hash that the nft will have.
Proof of Concept
Here is an example of a contract that could revert upon minting an NFT that doesn't have a suitable hash:
As we can see this implementation allows the exploiter to discard the nft if the hash is not favorable.
Tools Used
manual review
Recommended Mitigation Steps
For optimal randomness sources I would stick to the randomness that is created through
RNG
andVRF
contracts.If the protocol wants to impliment alternative randomness, one way would be to allow for the hash to be visible in the
retrieveTokenHash()
function only after the minting period is over. Here is a possible fix:The text was updated successfully, but these errors were encountered: