Skip to content
Business logic Audit finding Intermediate

Golden God tokens can be minted twice per generation

The entropy generator could produce two Golden God tokens (entropy 999999) in a single generation, because one is hard-coded at a fixed slot and number position while another can arise from the batch-written entropy data. This undermines the intended uniqueness and rarity of the token, affecting game fairness and economy.

waydou Follow with 0xb0k0, Decap and 40 others

Originally disclosed on Code4rena

Submitted by waydou, also found by 0xb0k0, Decap, robertodf99, Autosaida, 0x3b, Tomas0707 (1, 2), _karanel, Trooper, rndquu, D_Auditor, MKVsentry, samuraii77, unnamed, yaioxy, ogKapten, anonymousjoe, peanuts, y4y, LeFy, MrValioBg, shikhar229169 (1, 2), artilugio0, Phoenix_x, 0xR360, cryptomoon, Coinymous, pfapostol, 0xPwned, Yunaci, Nihavent, 3n0ch, Xcrypt, Quaternion2691, perseus, Udsen, LonelyWolfDemon, den-sosnowsky, Shahil_Hussain, nnez, Zac, ke1caM, shaka, 4rdiii, and Kalogerone

The current implementation of the EntropyGenerator contract allows for the possibility of having two “Golden God” tokens (tokens with an entropy value of 999999) per generation. This duplicity undermines the intended uniqueness and rarity of the Golden God token, potentially disrupting the game’s economy and fairness. The predictability of one Golden God token, combined with the chance of a second one, could lead to exploitation and loss of player trust.

Proof of Concept

The vulnerability stems from two separate mechanisms that can produce a Golden God token:

  1. Predetermined Golden God:
function getEntropy(uint256 slotIndex, uint256 numberIndex) private view returns (uint256) {
  if (slotIndex == slotIndexSelectionPoint && numberIndex == numberIndexSelectionPoint) {
    return 999999;
  }
  1. Entropy Calculation from the valued given by writeBatch:
uint256 slotValue = entropySlots[slotIndex];
uint256 entropy = (slotValue / (10 ** (72 - position))) % 1000000;
uint256 paddedEntropy = entropy * (10 ** (6 - numberOfDigits(entropy)));

The predetermined Golden God is set during initialization, and the other Golden God token is set in the writeEntropyBatch3. Since the math in the getEntropy doesn’t affect 6 figure digits, this means if writeEntropyBatch3 does write a slot with golden number 999999; it’s only a matter of time before someone gets since the nfts are attributed the slot sequentially. (Token 1 will get slotIndex and numberIndex [0,0], token 2 will get [0,1], token 3 will get [0,2], and so on).

Recommended Mitigation Steps:

Add a boolean to check if a golden god token has already been issued.

Assessed type

Context

TForge1 (TraitForge) acknowledged and commented:

Although it is technically an issue, it is definitely not high risk. Low at most as it doesn’t affect the game that much, just doesn’t make the golden god as cool.

Koolex (judge) decreased severity to Medium and commented:

Based on the given criteria, This would be categorized as Medium.

Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements

https://docs.code4rena.com/awarding/judging-criteria/severity-categorization

Reasoning:

  • Assets are not at direct risk, which rules out a High severity categorization.
  • The function of the protocol is impacted, as the uniqueness and rarity of the “Golden God” token are compromised.
  • The issue could impact the game fairness, which are core aspects of the protocol’s intended function.

Abdessamed (warden) commented:

This is an intended behavior and a design choice. It is explicitly mentioned in the docs that Golden entropy can be selected at random slots and indexes:

The getEntropy function calculates an entropy value based on a given slot and number index. It first verifies that the provided slot index is within bounds. If the slot and number indices match the predefined selection points, a special value of 999999 is returned. Otherwise, it computes the position for slicing the entropy value from the selected slot in the entropySlots array.

Koolex (judge) commented:

@Abdessamed - I don’t see where it mentions two Gods are allowed (even implicitly).

Abdessamed (warden) commented:

@Koolex - Golden entropy is generated on the third batch, so it exists on the entropySlots for every generation. The documentation I linked explicitly says that when the function getEntropy is called, it can return 999999 directly without consulting the entropySlots state which makes the fact that golden entropies can be found twice per generation.

Note: For full discussion, see here.


The original report as published on Code4rena, by waydou. 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

Likely the entropy logic has two independent paths to the special value: a hard-coded selection point and the batch-written slot data, with no check preventing both from occurring in the same generation.

Impact

The uniqueness and rarity of the Golden God token could be compromised, potentially disrupting the game's economy and fairness; the project considered it low risk, and the judge rated it medium.

What the attacker needed

None beyond normal minting

The fix

A boolean flag should be added to track whether a Golden God token has already been issued and block a second one.

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.

Each NFT in this game gets a random-looking number called entropy, and one very special value marks a rare 'Golden God' token. The code has two separate ways to produce that special value, so a generation could end up with two of them instead of one. That makes the rare token less special and could distort the game's economy.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More from TraitForge

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.