Omniscia Euler Finance Audit
ScaleUtils Code Style Findings
ScaleUtils Code Style Findings
SUS-01C: Inefficient Erasure of Upper Bits
Type | Severity | Location |
---|---|---|
Gas Optimization | ScaleUtils.sol:L75 |
Description:
The referenced statement is meant to zero out the upper bits of the scale
variable's raw representation to acquire its lower 128
bits, however, it does so inefficiently as it performs two bitwise shift operations.
Example:
75uint256 priceScale = (Scale.unwrap(scale) << 128) >> 128;
Recommendation:
We advise a bitwise mask to be utilized via an AND
(&
) operation, requiring a single EVM instruction to acquire the desired value.
Alleviation:
The code was updated to utilize a PRICE_SCALE_MASK
with a bitwise AND
operation as advised, optimizing the code's gas cost whilst increasing the statement's legibility.
SUS-02C: Repetitive Value Literal
Type | Severity | Location |
---|---|---|
Code Style | ScaleUtils.sol:L25, L75, L76 |
Description:
The linked value literal is repeated across the codebase multiple times.
Example:
25return Scale.wrap((10 ** feedExponent << 128) | 10 ** priceExponent);
Recommendation:
We advise it to be set to a constant
variable instead, optimizing the legibility of the codebase.
In case the constant
has already been declared, we advise it to be properly re-used across the code.
Alleviation:
The Euler Finance team evaluated this recommendation and opted to not relocate the value of 10
to a constant
declaration as they do not consider it a legibility enhancement.
We concur with this assessment and in view of the overall codebase's style and thus mark this exhibit as invalid.