Level 5 - Token ⏺⏺
Last updated
Last updated
The goal of this level is for you to hack the basic token contract below.
You are given 20 tokens to start with and you will beat the level if you somehow manage to get your hands on any additional tokens. Preferably a very large amount of tokens.
Things that might help:
What is an odometer?
The exploit is due to unsafe math in older versions of Solidity. The balance can underflow and cause a huge amount of tokens to be transferred.
Sending just 1 more token than the user balance causes the value to underflow.
Submit instance... 🥳
NOT NEEDED IN SOLIDITY 0.8.0 AND HIGHER
Overflows are very common in solidity and must be checked for with control statements such as:
An easier alternative is to use OpenZeppelin's SafeMath library that automatically checks for overflows in all the mathematical operators. The resulting code looks like this:
If there is an overflow, the code will revert.
Integer overflow/underflow in Solidity v0.6.0
This could easily be fixed using a different check instead of comparing to zero.