Omniscia Euler Finance Audit
PegStabilityModule Code Style Findings
PegStabilityModule Code Style Findings
PSM-01C: Inefficient Re-Calculation of Fee Percentages
Type | Severity | Location |
---|---|---|
Gas Optimization | PegStabilityModule.sol:L26, L27, L67, L71, L75, L79 |
Description:
The referenced statements will constantly perform a known subtraction due to mixing constant
and immutable
values.
Example:
src/Synths/PegStabilityModule.sol
66function quoteToUnderlyingGivenIn(uint256 amountIn) public view returns (uint256) {67 return amountIn * (BPS_SCALE - TO_UNDERLYING_FEE) / BPS_SCALE;68}69
70function quoteToUnderlyingGivenOut(uint256 amountOut) public view returns (uint256) {71 return amountOut * BPS_SCALE / (BPS_SCALE - TO_UNDERLYING_FEE);72}73
74function quoteToSynthGivenIn(uint256 amountIn) public view returns (uint256) {75 return amountIn * (BPS_SCALE - TO_SYNTH_FEE) / BPS_SCALE;76}77
78function quoteToSynthGivenOut(uint256 amountOut) public view returns (uint256) {79 return amountOut * BPS_SCALE / (BPS_SCALE - TO_SYNTH_FEE);80}
Recommendation:
We advise the code to instead assign the result of the subtraction to the relevant immutable
variables, optimizing each referenced statement by one subtraction operation.
Alleviation (fb2dd77a6ff9b7f710edb48e7eb5437e0db4fc1a):
The Euler Finance team evaluated this exhibit and opted to acknowledge it as they do not believe the minimal gas savings to justify the introduction of extra code and an immutable
variable.