Solidity中的算术溢出

Arithmetic Overflow in Solidity
2023-03-22 13:00:06
hashnode

Overflow basically occurs when a number is too big and the part that exceeds the maximum range is count from zero again and hence we end up with a number that is smaller than what we started with.

Underflow occurs when the number is smaller than the minimum range it starts counting back from the maximum number and you end up with a number that is greater than what you started with.

For example consider uint8. As the name indicates it is a 8 bit number that has a range from 0 to 2^8 -1 which is 0 to 255. However if we try to represent the number 256 then it

For example:

Obviously the addition these two numbers is greater than 255.Hence in such a case when the addition function is called the transaction is reverted

© 2022 开源博客 京ICP备20030565号-2 Powered by Quick API team