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

0 stars 0 forks source link

Prefix increaments are cheaper than postfix increaments #40

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

pants

Vulnerability details

These functions use prefix increaments (x++) instead of postfix increaments (++x):

Impact

Prefix increaments are cheaper than postfix increaments.

Tool Used

Manual code review.

Recommended Mitigation Steps

Change all prefix increaments to postfix increaments where it doesn't affects the functionality.

RedFox20 commented 2 years ago

Indeed, this is the case, however it would be good if actual gas usage was checked by the report.

i++ gas used: 95
++i gas used: 87

It uses 8 gas less, so it's a very small difference, also it is only relevant for one single function TempusAMM.getSwapAmountToEndWithEqualShares, so the impact is extremely low.