code-423n4 / 2022-09-frax-findings

2 stars 1 forks source link

Gas Optimizations #301

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

withholdRatio and currentWithheldETH are already 0, avoid to set variables with 0

frxETHMinter.sol#L63-L64:

withholdRatio = 0; // No ETH is withheld initially
currentWithheldETH = 0;

withholdRatio and currentWithheldETH are already 0

Instead of numValidators() use validators.length

Save gas avoiding calling a view function on: OperatorRegistry.sol#L136 OperatorRegistry.sol#L182

Use != 0 on requires instead of >0 to save gas

On: frxETHMinter.sol#L79 frxETHMinter.sol#L126

Use ++iinstead of i++, ++i costs less gas than i++

On:

Instead of ++i/i++ you should use unchecked{++i}/unchecked{i++} (when its safe)

On;

Use this pattern;

for (uint256 i = 0; i < numDeposits;) {
  ... code
  unchecked{ ++i; }
}