4

One of the functions of my smart contract can only be executed if three conditions are met. At the moment I have a single require which combines all the conditions like this:

  require(evalCond1() && evalCond2() && evalCond3());

But when I try to check my code coverage with solidity-coverage it only sees two branches: the one in which the require is met and the other, in which at least one of those conditions evaluates to false (no matter which one). I was wondering if there was any issue with breaking down the single require in three separate ones, one for each condition:

 require(evalCond1());
 require(evalCond2());
 require(evalCond3());

I think this improves readability (since the real function names are a bit more complex than evalCond) and helps showing the correct coverage for branches, but I'm not sure this doesn't have any side effects regarding gas usage and performance.

1 Answer 1

7

Comparing the bytecode generated by each approach, the second is 6 bytes longer - basically because the REVERT opcode and associate memory stuff appears 3 times instead of once. But since these instructions are not executed (unless something goes wrong!) this is irrelevant. Both approaches result in the same number of JUMPIs

In short, the gas usage will be near enough the same with either approach within half a dozen gas, so take your pick.

0

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.