After writing a few contracts in Solidity, I've noticed a reoccurring theme of always having to think about possible integer overflow/underflow attacks. It seems to me that Solidity should be as secure as possible by default, so that the most naive implentation tends to be secure (without having to actively add protections against common attack vecors).


Adding overflow/underflow check in every arithmetic operation incurs in a performance hint, and it increases the VM attack surface (ie the code that checks the overflow/underflow).

It was prefered to keep the VM simple and leave the more complex features for high level languages.


Underflow and overflow aren't flaws or bugs, they're just properties of integer types. If your contract needs to prevent them, consider implementing something like OpenZeppelin's SafeMath library.

  • I understand that it's a purposeful design choice, just wondering why. Yes I'm aware of that very useful library – Jonah Dec 22 '18 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.