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

_recipients, _tokenData, _saltfun_o and _numberOfTokens should all have same length in airDropTokens #312

Closed
c4-submissions opened this issue Nov 5, 2023 · 4 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-1384 edited-by-warden unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@c4-submissions
Copy link
Contributor

c4-submissions commented Nov 5, 2023

Lines of code

https://github.com/code-423n4/2023-10-nextgen/blob/main/smart-contracts/MinterContract.sol#L181-L192

Vulnerability details

Impact

No check is being made on the length of the input arrays in the airDropTokens function, meaning the caller could get an unexpected behavior from the airdrop function with no warning in case of mistakes in the inputs.

We mark this vulnerability as MEDIUM as it could alter the good functioning of the NextGenCore contract.

Proof of Concept

Let’s have a closer look at the airDropTokens function below

function airDropTokens(address[] memory _recipients, string[] memory _tokenData, uint256[] memory _saltfun_o, uint256 _collectionID, uint256[] memory _numberOfTokens) public FunctionAdminRequired(this.airDropTokens.selector) {
        require(gencore.retrievewereDataAdded(_collectionID) == true, "Add data");
        uint256 collectionTokenMintIndex;
        for (uint256 y=0; y< _recipients.length; y++) {
            collectionTokenMintIndex = gencore.viewTokensIndexMin(_collectionID) + gencore.viewCirSupply(_collectionID) + _numberOfTokens[y] - 1;
            require(collectionTokenMintIndex <= gencore.viewTokensIndexMax(_collectionID), "No supply");
            for(uint256 i = 0; i < _numberOfTokens[y]; i++) {
                uint256 mintIndex = gencore.viewTokensIndexMin(_collectionID) + gencore.viewCirSupply(_collectionID);
                gencore.airDropTokens(mintIndex, _recipients[y], _tokenData[y], _saltfun_o[y], _collectionID);
            }
        }
    }

If a function admin calls this function with three arrays as input with, for example, _recipients.length == 3, _tokenData.length == 4, _saltfun_o.length == 4 and _numberOfTokens.length == 4 (this could mean the admin wanted to airdrop to 4 recipients but forgot one of the values in the _recipients array).
In that case, the function will go through fine, airdropping for the 3 recipients given in the _recipients array.

As the function will not revert in that case, the admin could think that he successfully airdropped for 4 recipients when in fact only 3 received the airdrop.

This is easily fixed so should be prevented.

Tools Used

Manual Review / Visual Studio

Recommended Mitigation Steps

Add a require statement to the airDropTokens function to avoid this situation.

The airDropTokens function could then look like this:

 function airDropTokens(address[] memory _recipients, string[] memory _tokenData, uint256[] memory _saltfun_o, uint256 _collectionID, uint256[] memory _numberOfTokens) public FunctionAdminRequired(this.airDropTokens.selector) {
        require((_recipients.length == _tokenData.length) && (_recipients._saltfun_o == _tokenData.length) && (_recipients._saltfun_o == _numberOfTokens.length), “wrong inputs”);
        require(gencore.retrievewereDataAdded(_collectionID) == true, "Add data");
        uint256 collectionTokenMintIndex;
        for (uint256 y=0; y< _recipients.length; y++) {
            collectionTokenMintIndex = gencore.viewTokensIndexMin(_collectionID) + gencore.viewCirSupply(_collectionID) + _numberOfTokens[y] - 1;
            require(collectionTokenMintIndex <= gencore.viewTokensIndexMax(_collectionID), "No supply");
            for(uint256 i = 0; i < _numberOfTokens[y]; i++) {
                uint256 mintIndex = gencore.viewTokensIndexMin(_collectionID) + gencore.viewCirSupply(_collectionID);
                gencore.airDropTokens(mintIndex, _recipients[y], _tokenData[y], _saltfun_o[y], _collectionID);
            }
        }
 }

meaning the call will revert if inputs are wrong.

Assessed type

Invalid Validation

@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 5, 2023
c4-submissions added a commit that referenced this issue Nov 5, 2023
@code4rena-admin code4rena-admin changed the title _recipients, _tokenData, _saltfun_o and _numberOfTokens should all have same length in airDropTokens _recipients, _tokenData, _saltfun_o and _numberOfTokens should all have same length in airDropTokens Nov 6, 2023
@code4rena-admin code4rena-admin changed the title _recipients, _tokenData, _saltfun_o and _numberOfTokens should all have same length in airDropTokens _recipients, _tokenData, _saltfun_o and _numberOfTokens should all have same length in airDropTokens Nov 6, 2023
@c4-pre-sort
Copy link

141345 marked the issue as duplicate of #478

@c4-judge
Copy link

c4-judge commented Dec 1, 2023

alex-ppg marked the issue as not a duplicate

@c4-judge c4-judge reopened this Dec 1, 2023
@c4-judge
Copy link

c4-judge commented Dec 1, 2023

alex-ppg marked the issue as duplicate of #1384

@c4-judge c4-judge closed this as completed Dec 1, 2023
@c4-judge c4-judge added duplicate-1384 unsatisfactory does not satisfy C4 submission criteria; not eligible for awards labels Dec 1, 2023
@c4-judge
Copy link

c4-judge commented Dec 6, 2023

alex-ppg marked the issue as unsatisfactory:
Out of scope

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-1384 edited-by-warden unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

4 participants