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).
2 Answers
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– JonahCommented Dec 22, 2018 at 22:29