Skip to content

Commit 025dcb7

Browse files
authored
Fix getRandomInt boundaries (crytic#1348)
n-bit signed integers on two's complement systems range from -(2^(n-1)) to 2^(n-1)-1
1 parent 044cf4d commit 025dcb7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/Echidna/ABI.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ getRandomUint n =
186186

187187
-- | Generate a random signed integer with the following distribution:
188188
-- * 10% uniformly from the range -1023 to 1023.
189-
-- * 90% uniformly from the range -1 * 2 ^ n to 2 ^ (n - 1).
189+
-- * 90% uniformly from the range -1 * 2 ^ (n - 1) to 2 ^ (n - 1) - 1.
190190
getRandomInt :: MonadRandom m => Int -> m Integer
191191
getRandomInt n =
192192
getRandomR =<< Random.weighted
193193
[ ((-1023, 1023), 1)
194-
, ((-1 * 2 ^ n, 2 ^ (n - 1)), 9)
194+
, ((-1 * 2 ^ (n - 1), 2 ^ (n - 1) - 1), 9)
195195
]
196196

197197
-- | Synthesize a random 'AbiValue' given its 'AbiType'. Doesn't use a dictionary.

0 commit comments

Comments
 (0)