XRandoms.getWord is expected to return a word with a index between [0~99], including 0, and 99. But according to current implementation, the function will not work as expect.
Proof of Concept
Before calling randomPool.getWord, function randomPool.randomWord will generate a number between
[0, 99], include 0 and 99, then calling getWord with the generated number.
Based on randomWord, the parameter for getWord will be [0, 99], and in randomPool.getWord, it supposed that getWord should return a word from wordsList with a index between [0,99], but the code will return the first word Acai twice when id = 0 and id = 1, and the last word Watermelon will never be returned because of XRandoms.sol#L31
Lines of code
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/XRandoms.sol#L15-L33 https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/XRandoms.sol#L40-L43
Vulnerability details
Impact
XRandoms.getWord
is expected to return a word with a index between [0~99], including 0, and 99. But according to current implementation, the function will not work as expect.Proof of Concept
Before calling
randomPool.getWord
, function randomPool.randomWord will generate a number between [0, 99], include 0 and 99, then callinggetWord
with the generated number.Based on
randomWord
, the parameter forgetWord
will be [0, 99], and in randomPool.getWord, it supposed that getWord should return a word fromwordsList
with a index between [0,99], but the code will return the first word Acai twice whenid = 0
andid = 1
, and the last word Watermelon will never be returned because of XRandoms.sol#L31Following is little POC, run the following code in
chisel
with traces enabled, we can see thatRun the above code in chisel, and we can see that Acai is returned twice, and Watermelon is never returned ➜ A a = new A() ➜ !t Enabled traces! ➜ a.tr() ➜ a.tr(); Traces: [4082828] 0xBd770416a3345F91E4B34576cb804a576fa48EB1::run() ├─ [1325776] → new@0xf4D9599aFd90B5038b18e3B551Bc21a97ed21c37
│ └─ ← 6622 bytes of code
├─ [2723146] 0xf4D9599aFd90B5038b18e3B551Bc21a97ed21c37::tr()
│ ├─ emit Log(: Acai)
│ ├─ emit Log(: Acai)
│ ├─ emit Log(: Ackee)
│ ├─ emit Log(: Apple)
│ ├─ emit Log(: Apricot)
│ ├─ emit Log(: Avocado)
│ ├─ emit Log(: Babaco)
│ ├─ emit Log(: Banana)
│ ├─ emit Log(: Bilberry)
│ ├─ emit Log(: Blackberry)
│ ├─ emit Log(: Blackcurrant)
│ ├─ emit Log(: Blood Orange)
│ ├─ emit Log(: Blueberry)
│ ├─ emit Log(: Boysenberry)
│ ├─ emit Log(: Breadfruit)
│ ├─ emit Log(: Brush Cherry)
│ ├─ emit Log(: Canary Melon)
│ ├─ emit Log(: Cantaloupe)
│ ├─ emit Log(: Carambola)
│ ├─ emit Log(: Casaba Melon)
│ ├─ emit Log(: Cherimoya)
│ ├─ emit Log(: Cherry)
│ ├─ emit Log(: Clementine)
│ ├─ emit Log(: Cloudberry)
│ ├─ emit Log(: Coconut)
│ ├─ emit Log(: Cranberry)
│ ├─ emit Log(: Crenshaw Melon)
│ ├─ emit Log(: Cucumber)
│ ├─ emit Log(: Currant)
│ ├─ emit Log(: Curry Berry)
│ ├─ emit Log(: Custard Apple)
│ ├─ emit Log(: Damson Plum)
│ ├─ emit Log(: Date)
│ ├─ emit Log(: Dragonfruit)
│ ├─ emit Log(: Durian)
│ ├─ emit Log(: Eggplant)
│ ├─ emit Log(: Elderberry)
│ ├─ emit Log(: Feijoa)
│ ├─ emit Log(: Finger Lime)
│ ├─ emit Log(: Fig)
│ ├─ emit Log(: Gooseberry)
│ ├─ emit Log(: Grapes)
│ ├─ emit Log(: Grapefruit)
│ ├─ emit Log(: Guava)
│ ├─ emit Log(: Honeydew Melon)
│ ├─ emit Log(: Huckleberry)
│ ├─ emit Log(: Italian Prune Plum)
│ ├─ emit Log(: Jackfruit)
│ ├─ emit Log(: Java Plum)
│ ├─ emit Log(: Jujube)
│ ├─ emit Log(: Kaffir Lime)
│ ├─ emit Log(: Kiwi)
│ ├─ emit Log(: Kumquat)
│ ├─ emit Log(: Lemon)
│ ├─ emit Log(: Lime)
│ ├─ emit Log(: Loganberry)
│ ├─ emit Log(: Longan)
│ ├─ emit Log(: Loquat)
│ ├─ emit Log(: Lychee)
│ ├─ emit Log(: Mammee)
│ ├─ emit Log(: Mandarin)
│ ├─ emit Log(: Mango)
│ ├─ emit Log(: Mangosteen)
│ ├─ emit Log(: Mulberry)
│ ├─ emit Log(: Nance)
│ ├─ emit Log(: Nectarine)
│ ├─ emit Log(: Noni)
│ ├─ emit Log(: Olive)
│ ├─ emit Log(: Orange)
│ ├─ emit Log(: Papaya)
│ ├─ emit Log(: Passion fruit)
│ ├─ emit Log(: Pawpaw)
│ ├─ emit Log(: Peach)
│ ├─ emit Log(: Pear)
│ ├─ emit Log(: Persimmon)
│ ├─ emit Log(: Pineapple)
│ ├─ emit Log(: Plantain)
│ ├─ emit Log(: Plum)
│ ├─ emit Log(: Pomegranate)
│ ├─ emit Log(: Pomelo)
│ ├─ emit Log(: Prickly Pear)
│ ├─ emit Log(: Pulasan)
│ ├─ emit Log(: Quine)
│ ├─ emit Log(: Rambutan)
│ ├─ emit Log(: Raspberries)
│ ├─ emit Log(: Rhubarb)
│ ├─ emit Log(: Rose Apple)
│ ├─ emit Log(: Sapodilla)
│ ├─ emit Log(: Satsuma)
│ ├─ emit Log(: Soursop)
│ ├─ emit Log(: Star Apple)
│ ├─ emit Log(: Star Fruit)
│ ├─ emit Log(: Strawberry)
│ ├─ emit Log(: Sugar Apple)
│ ├─ emit Log(: Tamarillo)
│ ├─ emit Log(: Tamarind)
│ ├─ emit Log(: Tangelo)
│ ├─ emit Log(: Tangerine)
│ ├─ emit Log(: Ugli)
│ ├─ emit Log(: Velvet Apple)
│ └─ ← ()
└─ ← ()
Tools Used
VIM
Recommended Mitigation Steps
Assessed type
Other