OZ Contracts v4 + SafeMath

I chose solc 0.8.4 and upgraded contracts to v4 for a project which previously used solc 0.7.6 + SafeMath.

If I leave the (v4) SafeMath function in place, do I actually double check and burn double gas ?

The safemath version that you can add to the upgrade is available at the link below. It would be appropriate to upgrade to the version that works with 8.4.

If you have already upgraded to this version and are still worried; No need to worry. Safety is more important than gas. If you upgrade to the above version, the answer to your question is; unless there is an unusual condition for soundness 8.4; I don’t think your project will spend twice as much for gas. I wish you success in your project.

Sorry for the noob question. If I am not wrong from 0.8.0 Safemath is no needed anymore. So do you advice to still use it or no?

1 Like

wondering the same thing as FreezyEx, 0.8+ versions prevent overflow/underflow, so is using SafeMath a good practice now?

In Solidity 0.8 SafeMath is no longer needed. It remains in OZ Contracts v4 as a no-op to ease migration to the new version. See the relevant discussion in this issue:


Leaving SafeMath in v4 will not check for overflow twice, so it will not burn double gas. Although there may be a small overhead if the compiler doesn't optimize the function call away.