code-423n4 / 2021-10-tracer-findings

0 stars 0 forks source link

Gas: Inefficient modulo computation #22

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

cmichel

Vulnerability details

PoolFactory.uint2str computes i % 10 as uint8(_i - (_i / 10) * 10). This intuitively seems more gas-expensive than doing i % 10. Consider using i % 10 instead which also makes the code simpler to read.

CalabashSquash commented 3 years ago

Confirmed, but we will be using the OpenZeppelin library to replace this function anyway.

GalloDaSballo commented 3 years ago

Agree with the warden, as per: https://github.com/crytic/evm-opcodes MOD will cost 5 gas which is the same cost as one division

Screenshot 2021-10-29 at 20 20 38