Skip to main content

What Is the Performance Impact of Using a Safe Math Library?

The performance impact of using a safe math library is a slight increase in gas consumption for every arithmetic operation. The library adds extra opcodes for the checks (e.g. a require statement and a comparison) before performing the actual calculation.

While this overhead is minimal, it is a trade-off for significantly increased security. In Solidity 0.8.0+, the built-in compiler checks also add a slight overhead compared to completely unchecked arithmetic, but it is optimized.

Why Is SafeMath Less Necessary in Solidity 0.8.0 and Later?
What Is the Difference between Gas Limit and Gas Price?
What Is the Role of the ‘EVM’ (Ethereum Virtual Machine) in Gas Consumption?
Explain the Difference between an Overflow and an Underflow