2

I'm going over some protocol contracts, and I've seen they check pretty obvious math operations with a require() statement. This contract uses solidity 0.8.11

uint256 id = vaultCount;
vaultCount = vaultCount + 1;
require(vaultCount >= id);

What is the reason for this? I understand that this was needed before 0.8 due to under and overflows. But why is it needed now?

4

1 Answer 1

1

There are 2 explanations, both of which are more of excuses than justifications

  1. They wrote the contracts for Solidity < 0.8, which means it wouldn't have built-in overflow checking. Then when they ported to 0.8.11, they didn't notice this (I have been guilty of this in the past.)

  2. They just don't know that Solidity >= 0.8 has built in overflow checking

To be extra clear, to answer your question, it absolutely isn't necessary, and it's wasting gas redoing a check that the compiler already did

Your Answer

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

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