There is a chance that tokenHash
is not set if using RandomizerVRF
#224
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-1464
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/MinterContract.sol#L236
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/NextGenCore.sol#L189-L200
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/NextGenCore.sol#L227-L232
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/RandomizerVRF.sol#L71-L75
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/RandomizerVRF.sol#L52-L68
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/NextGenCore.sol#L299-L303
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/NextGenCore.sol#L170-L174
Vulnerability details
Impact
There is a chance that
tokenHash
is not set if usingRandomizerVRF
Proof of Concept
According to the chainlink docs
If your fulfillRandomWords() implementation reverts, the VRF service will not attempt to call it a second time. Make sure your contract logic does not revert. Consider simply storing the randomness and taking more complex follow-on actions in separate contract calls made by you, your users, or an Automation Node.
If the
fulfillRandomWords
fails there is no way of setting thetokenHash
again and will remain0
. This can fail for one of two reasons. Let's take a lookMinterContract
with a functionmint
_mintProcessing
which calls thecalculateTokenHash
on the set randomizer.The first option of failure is here. It doesn't check that the
randomizer
is evenset
. If it is not set yet and isaddress(0)
any calls to it willsucceed
because it is anEOA
.randomizer
is set the execution flow continues and callscalculateTokenHash
requestRandomWords
request to chainlink we have to wait forrequestConfirmations
which in this case is3
, for the chainlink to call thefulfillRandomWords
. Once it gets called it will set thetokenHash
setTokenHash
function inside theNextGenCore
randomizerContract
that is set in thecollectionAdditionalData
.randomizerContract
for the collection is accidentally changed between the callsrequestRandomWords
andfulfillRandomWords
as it will receive the call from the oldrandomizerContract
and the require statement will fail causing thetokenToHash
mapping for token with index_mintIndex
to never be set. Maybe someone can intentionally frontrun the change of therandomizerContract
to receive a token without atokenHash
set making it more valuable.Tools Used
VS Code
Recommended Mitigation Steps
The simplest solution would be to implement the
unprocessedRequest
counter in theRandomizer
contract and require that the value is0
when changing a randomizer. Also, make sure therandomizer
is set when requesting random values.NextGenCore.sol
RandomizerVRF.sol
Assessed type
Invalid Validation
The text was updated successfully, but these errors were encountered: