Skip to content
Smart contracts Audit finding Intermediate

Incorrect check against golden entropy value in the first two batches

The entropy generation functions for the first two batches check the whole 256-bit slot value against the golden entropy number instead of checking each of the 13 packed entropy values inside it. As a result, a golden entropy can slip into the first two passes, contrary to the documented rule that it should only appear in the final pass.

Abdessamed Follow with DemoreX, anonymousjoe and 8 others

Originally disclosed on Code4rena

Submitted by Abdessamed, also found by DemoreX, anonymousjoe, 0xlemon, jesjupyter, Udsen, rbserver, 0rpse, KupiaSec, ZdravkoHr, and Kalogerone

Entropy is stored in uint256 slots, with each slot able to contain 13 concatenated entropies. Entropies are generated in three passes, and there is a golden entropy value 999999 that should not be generated in the first two passes, as specified in the documentation:

There is a certain entropy, “999999” which is referred to as “the Golden God”, since it has perfect parameters and will exceed all other entities if played correctly. The Golden God is scanned for and is kept out of the first 2 passes, but is deliberately set in the final pass (at some random point).

The issue is that writeEntropyBatch1 and writeEntropyBatch2 functions do not correctly check for the golden entropy:

function writeEntropyBatch1() public {
    require(lastInitializedIndex < batchSize1, 'Batch 1 already initialized.');

    uint256 endIndex = lastInitializedIndex + batchSize1; // calculate the end index for the batch
    unchecked {
      for (uint256 i = lastInitializedIndex; i < endIndex; i++) {
        uint256 pseudoRandomValue = uint256(
          keccak256(abi.encodePacked(block.number, i))
        ) % uint256(10) ** 78; // generate a  pseudo-random value using block number and index
        require(pseudoRandomValue != 999999, 'Invalid value, retry.'); // @audit INCORRECT check
        entropySlots[i] = pseudoRandomValue; // store the value in the slots array
      }
    }
    lastInitializedIndex = endIndex;
  }

The function (same for writeEntropyBatch2) attempts to ensure that no golden entropy is generated using the following check: require(pseudoRandomValue != 999999, 'Invalid value, retry.');. However, this check is incorrect because pseudoRandomValue does NOT represent a single entropy value but represents the entire slot value, which contains 13 entropies. For example, if the pseudo-randomly generated slot value is ........999999123345, the check will pass while it should not because the second entropy is a golden one.

Recommended Mitigation Steps

The current check incorrectly validates the entire slot value. Consider updating the check to validate each of the 13 entropies within the slot value.

Assessed type

Invalid Validation


The original report as published on Code4rena, by Abdessamed. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The validation compares the full packed slot value to the golden entropy constant instead of checking each of the 13 individual entropy values packed into that slot.

Impact

A golden entropy could be generated during the first two passes, breaking the documented game rule that it should only be set deliberately in the final pass.

What the attacker needed

None

The fix

The check should be updated to validate each of the 13 individual entropies within the packed slot value rather than the whole slot.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A smart contract stores many small random numbers packed together inside one large number. The code wanted to make sure a special number, called the golden entropy, never appeared early in the game, but it compared the special number against the whole packed container rather than against each small number inside it. So the special number could still be hidden inside the container and the check would not notice.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Abdessamed

View all

6 more disclosed reports, best first.

More from TraitForge

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.