Skip to content
Crypto Audit finding Intermediate

Almost all rarity rank combinations cannot be, and are not uniformly, generated

The code derives six rarity ranks from a single DNA value by dividing by fixed divisors and taking modulo 100, which makes only a tiny fraction of all possible rank combinations reachable and biases the distribution. An attacker could predict or exploit the non-uniform rarity of generated fighters, undermining the game's fairness and economy.

d3e4 Follow with niser93 and fnanni

Originally disclosed on Code4rena

Submitted by d3e4, also found by niser93 and fnanni

Only a tiny fraction, 0.0002427%, of all rarity rank combinations are possible. The probability distribution of the possible combinations (assuming the DNA is uniformly random) is not uniform: 24% of combinations are twice as likely as the rest.

Proof of Concept

AiArenaHelper.createPhysicalAttributes() may set six finalAttributeProbabilityIndexes using the following calculation.

uint256 rarityRank = (dna / attributeToDnaDivisor[attributes[i]]) % 100;
uint256 attributeIndex = dnaToIndex(generation, rarityRank, attributes[i]);
finalAttributeProbabilityIndexes[i] = attributeIndex;

attributeToDnaDivisor is by default (2, 3, 5, 7, 11, 13). Each rarityRank by itself is in the range 0..99, and ostensibly the total number of combinations of the six rarityRanks should then be 100^6. However, only 2,427,000 different combinations are possible, which is only 0.0002427% of all combinations that should be possible.

As a function of dna the vector of the six rarityRanks repeats every 3,003,000 integers (=2 • 3 • 5 • 7 • 11 • 13 • 100). But it turns out that 576,000 of these appear twice. For example, a dna of 0 or 1 yield the same combination of rarityRanks ([0,0,0,0,0,0]), as do 16 and 17 ([8,5,3,2,1,1]), and 22 and 23 ([11,7,4,3,2,1]), etc. That is, about 24% of the combinations are twice as likely as the rest.

The rarityRanks are input to dnaToIndex() which then will also be biased and restricted in output (depending on the attribute probabilities).

Recommended Mitigation Steps

Extract multiple small random numbers by repeatedly taking the modulo and dividing. I.e.

- uint256 rarityRank = (dna / attributeToDnaDivisor[attributes[i]]) % 100;
+ uint256 rarityRank = dna % 100;
+ dna /= 100;

hickuphh3 (judge) commented:

Agree that rarityRank determination isn’t uniformly random.


The original report as published on Code4rena, by d3e4. 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 use of a single DNA value divided by fixed divisors and then modulo 100, which creates correlated and overlapping outputs instead of independent random numbers.

Impact

The rarity distribution is not uniform and most combinations are impossible, which could let attackers predict or manipulate character rarity, affecting game fairness and value.

What the attacker needed

None

The fix

The code should be fixed by extracting multiple independent random numbers using repeated modulo and division, as suggested in the report.

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 game creates characters from a random number, but the way it splits that number into six 'rarity' values is flawed. Instead of each value being independent, they are linked, so most combinations never appear and some appear twice as often. This means players could get rarer characters more easily than intended, or predict outcomes.

What is Crypto?

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.

More by d3e4

View all

19 more disclosed reports, best first.

More from AI Arena

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.