1

Will (a+b) work and be safe in solidity 0.8.0? Or do I have to do something like a.add(b)?

Ron Antes
  • 11
  • 1

1 Answers1

4

You don't need safemath in 0.8+, prior to that version, solidity's "+" operator wouldnt check for overflows, leading to type(uint256).max + 1 = 0, and we'd use the safeMath library to avoid that. Now, type(uint256).max + 1 reverts with Panic(0x11), and safeMath isnt needed anymore. If you want to reproduce pre-0.8 behavior, you can put your operations inside and unchecked{} block, saves gas, so is recommended if you know your operation is safe already.

Foxxxey
  • 4,307
  • 1
  • 6
  • 22