code-423n4 / 2024-07-traitforge-findings

2 stars 1 forks source link

Upgraded Q -> 2 from #1076 [1725567784981] #1080

Closed c4-judge closed 2 months ago

c4-judge commented 2 months ago

Judge has assessed an item in Issue #1076 as 2 risk. The relevant finding follows:

[L-3] The Golden God NFT can appear twice in one generation The Golden God entity in the TraitForge protocol is a unique entity that has the highest entropy of 999999 and is the most sought-after of all entities. Based on the protocol documentation this entity should only appear once per generation, however there is a small chance for it to appear twice:

Imagine the following scenario:

slotIndexSelectionPoint = 600, numberIndexSelectionPoint = 5, and entropySlots[700] = 123456999999123456789012345678901234567890123456789012345678901234567890 getNextEntropy() is called. Call 1: currentSlotIndex = 0, currentNumberIndex = 0

getEntropy(0, 0): position = 0 6 = 0 slotValue = entropySlots[0] (let's say it's 987654321987654321...) entropy = (987654321987654321... / 10^72) % 1000000 = 987654 paddedEntropy = 987654 (10^(6 - 6)) = 987654 Return: 987654 …(many calls later)…

Call 7806: currentSlotIndex = 600, currentNumberIndex = 5

getEntropy(600, 5): if (600 == slotIndexSelectionPoint && 5 == numberIndexSelectionPoint): return 999999 Return: 999999 Call 9101: currentSlotIndex = 700, currentNumberIndex = 6

getEntropy(700, 6): position = 6 6 = 36 slotValue = 123456999999123456789012345678901234567890123456789012345678901234567890 entropy = (123456999999123456789012345678901234567890123456789012345678901234567890 / 10^(72-36)) % 1000000 = (123456999999123456... / 10^36) % 1000000 = 999999 paddedEntropy = 999999 (10^(6 - 6)) = 999999 Return: 999999 From the above, it can be seen that in a very small percentage of entropies, the Golden God can be produced twice. The chance is around 1%. This is a tough issue to handle, but maybe an easy solution will be to have a kind of storage to keep track of how many Golden Gods have been produced per generation.

c4-judge commented 2 months ago

koolexcrypto marked the issue as duplicate of #229

c4-judge commented 2 months ago

koolexcrypto marked the issue as satisfactory