0

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).

1

2 Answers 2

0

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.

0

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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