I have this code:

contract A {
    using SafeMath for uint;

contract B is A {

Does my contract B herits from "using SafeMath for uint;"?

1 Answer 1


No, you have to declare library usage for every contract explicitly.

In case of SafeMath, you don't have to use it, if you use solidity 0.8.0 and after. Overflow/underflow checks are included in that versions. See https://docs.soliditylang.org/en/v0.8.9/080-breaking-changes.html :

Arithmetic operations revert on underflow and overflow. You can use unchecked { ... } to use the previous wrapping behaviour.

Checks for overflow are very common, so we made them the default to increase readability of code, even if it comes at a slight increase of gas costs.


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.