Is Tezos vulnerable to overflow/ underflow attacks on the smart contracts? If yes, how do you recommend to test whether a particular smart contract suffers from it.
1 Answer
If you have two amounts (mutez
): t1
and t2
; t1 - t2
underflows when t2
is bigger than t1
.
There is a similar overflow on mutez
(they are 64 bits values).
Shifts are also problematic (LSL
and LSR
in Michelson).
When such an event happens, an exception is raised and that cancels the whole transaction.
Testing is not easy. For these cases, I personally think that they are a very good use case for automatic static analysis.
-
Why wouldn't testing be easy? If you set up a testing environment, you can call the contracts from a JavaScript environment and the calls to the contract should throw on overflows. Aug 3, 2020 at 8:17
-
If
t1 - t2
becomes negative, it's still considered overflow. Underflow refers to floats becoming so small that they are rounded to 0. Aug 3, 2020 at 8:36 -
You call it what you wish. It’s called underflow in the tezos documentation that you may wish to read.– FFFAug 3, 2020 at 14:56
-
In that case, that is an error in the documentation that should be fixed. It is a pretty bad idea for projects to start inventing their own definitions. Aug 3, 2020 at 15:22
-
1