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

There is no way to resend a request to the randomizer #1355

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

There is no way to resend a request to the randomizer #1355

c4-submissions opened this issue Nov 12, 2023 · 6 comments
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-1307 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/NextGenCore.sol#L178-L184

Vulnerability details

Impact

In the contract, when minting NFT, a request is sent to the randomizer to obtain a random hash. In cases where a randomizer from chainlink or arrng is used, then the hash request is an asynchronous operation. The hash is established after several blocks after the NFT mint. There may be several situations when it is necessary to re-send the request to the randomizer. But there is no such possibility in the contract.

Chainlink uses a subscription method to pay for its work. First you need to top up your subscription balance with tokens and with each hash request, chainlink tokens will be debited from the subscription balance. If the balance is not sufficient to pay for the request, it is enough to top up the subscription balance within the next 24 hours. And after that, the chainlink itself will send a random number to the contract.

If you do not replenish the balance within 24 hours, then in order to receive a random number, it is necessary for the contract to send a request to the chainlink again. But there is no such possibility. Even the project administrator.

It may happen that the subscription balance runs out, and the project owner does not have time to replenish it. In this case, NFTs that users have without a hash will remain forever without it.

This is not about the fact that the project owner will not replenish the account on purpose, but about the fact that this can happen by accident, under different circumstances. There is a risk that the administrator simply will not have time to top up the subscription account within 24 hours. And it must be taken into account.

Proof of Concept

The request to the randomizer is sent only from internal function NextGenCore._mintProcessing() such when minting NFT and it is impossible to send it again

    function _mintProcessing(uint256 _mintIndex, address _recipient, string memory _tokenData, uint256 _collectionID, uint256 _saltfun_o) internal {
        tokenData[_mintIndex] = _tokenData;
        // HERE
        collectionAdditionalData[_collectionID].randomizer.calculateTokenHash(_collectionID, _mintIndex, _saltfun_o);
        tokenIdsToCollectionIds[_mintIndex] = _collectionID;
        _safeMint(_recipient, _mintIndex);
    }

Tools Used

Manual review

Recommended Mitigation Steps

Add function, which give opportunity to admin resend request to randomizer.
It is safe opportunity, because in function NextGenCore.setTokenHash() there is check, that hash is still bytes32(0). So, if even admin call function after success request to randomizer, it will not cause problem.

Assessed type

Oracle

@c4-submissions c4-submissions added 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 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 #1307

@141345
Copy link

141345 commented Nov 27, 2023

related to #1464

@c4-judge
Copy link

c4-judge commented Dec 6, 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 6, 2023
@SovaSlava
Copy link

Thanks for judging.
In #1464 (comment) sponsor said:
"if it fails due to lack of funds it will fail also when re executed".
Its wrong, because, if second request will be done, when chainlink subscription have enough funds, it will not revert.
My issue is about opportunity for users, to have special function - resendRequest, which could be called manualy by users. Not automatically. So, If request to vrf fail by insufficiently funds, user can call function resend after 1 day(for example) and if after 1 day subscription will have enough funds, call will be success.

Also, sponsor said: "If the tokenHash has not been set an admin can deploy a contract that can call the RNG for that specific id, the hash will be generated and stored".

RNG randoms is not the same as VRF. If before this, randomizer was VRF, users would like, that hash will set exactly by VRF.
Also, if will be big amount of users, if will be expensive recall for all of them randomizer again.

"The contracts will be fully funded to cover the costs." - its just promise, Yes, owner is trusted, but could be different situations ..

@alex-ppg
Copy link

alex-ppg commented Dec 9, 2023

Hey @SovaSlava, thanks for your contribution! Your recommended course of action is to permit the administrator to resend a randomness request, meaning that they will have to supply the necessary funds to fulfill it.

In any case, I believe such a recommendation is better suited under an Analysis or QA submission and cannot constitute a medium-severity vulnerability, rendering my initial verdict to remain.

@SovaSlava
Copy link

@alex-ppg Thanks for answer. So..may be you can grade this issue as qa grade-b, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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-1307 unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

6 participants