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

getRandomTokenIdFromFund not really random #21

Closed
code423n4 opened this issue May 9, 2021 · 1 comment
Closed

getRandomTokenIdFromFund not really random #21

code423n4 opened this issue May 9, 2021 · 1 comment
Labels
3 (High Risk) bug Something isn't working duplicate This issue or pull request already exists

Comments

@code423n4
Copy link
Contributor

Handle

gpersoon

Vulnerability details

Impact

The function getRandomTokenIdFromFund of NFTXVaultUpgradeable.sol is not really random, as noted in the name of the function getPseudoRand.
The value of the blockhash(block.number - 1) is fully determined for al the transactions in the same block.
The result is that the retrieval of NFS's (via redeemTo, swapTo, withdrawNFTsTo, while enableDirectRedeem==false) can be manipulated.
You can make a smart contract that tries to call redeemTo or swapTo, checks the resulting NFTs and reverts if it has NFTs that are unwanted.

Proof of Concept

function getPseudoRand(uint256 modulus) internal virtual returns (uint256) {
    randNonce += 1;
    return
        uint256(
            keccak256(
                abi.encodePacked(blockhash(block.number - 1), randNonce)
            )
        ) %
        modulus;
}

Tools Used

Editor

Recommended Mitigation Steps

If the value or desirability of the NFT's are different then it's important to use other ways to randomize, for example via a random oracle or a commit/reveal schema.

@code423n4 code423n4 added 3 (High Risk) bug Something isn't working labels May 9, 2021
code423n4 added a commit that referenced this issue May 9, 2021
@0xKiwi 0xKiwi added the duplicate This issue or pull request already exists label May 20, 2021
@0xKiwi 0xKiwi closed this as completed May 20, 2021
@cemozerr
Copy link
Collaborator

Duplicate of #78

@cemozerr cemozerr marked this as a duplicate of #78 May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants