Omniscia Euler Finance Audit
UserStorage Code Style Findings
UserStorage Code Style Findings
USE-01C: Inconsistent Bit Clearance Style
Type | Severity | Location |
---|---|---|
Code Style | UserStorage.sol:L50, L56, L62 |
Description:
The BALANCE_FORWARDER_MASK
configuration function will clear its bit by performing a bitwise AND (&
) operation between the unwrapped data point and the negated value of the BALANCE_FORWARDER_MASK
, whereas the two other functions for the OWED_MASK
and SHARES_MASK
respectively will use a bitwise AND (&
) operation with a bitwise OR (|
) combination of other masks.
Example:
47function setBalanceForwarder(UserStorage storage self, bool newValue) internal {48 self.data = newValue49 ? PackedUserSlot.wrap(PackedUserSlot.unwrap(self.data) | BALANCE_FORWARDER_MASK)50 : PackedUserSlot.wrap(PackedUserSlot.unwrap(self.data) & ~BALANCE_FORWARDER_MASK);51}52
53function setOwed(UserStorage storage self, Owed owed) internal {54 uint256 data = PackedUserSlot.unwrap(self.data);55
56 self.data = PackedUserSlot.wrap((owed.toUint() << 112) | (data & (BALANCE_FORWARDER_MASK | SHARES_MASK)));57}58
59function setBalance(UserStorage storage self, Shares balance) internal {60 uint256 data = PackedUserSlot.unwrap(self.data);61
62 self.data = PackedUserSlot.wrap(balance.toUint() | (data & (BALANCE_FORWARDER_MASK | OWED_MASK)));63}
Recommendation:
We advise a uniform bit erasure style to be adopted in the codebase, and we advise the former to be adopted as it results in less operations and thus higher legibility.
Specifically, we advise the negated form of the mask being written-to to be utilized in each referenced bitwise AND (&
) clause (i.e. data & ~OWED_MASK
instead of data & (BALANCE_FORWARDER_MASK | SHARES_MASK)
)
Alleviation (fb2dd77a6ff9b7f710edb48e7eb5437e0db4fc1a):
A uniform bit clearance style has been adopted by the library, utilizing a bitwise AND
(&
) operation with the inverse (i.e. bitwise NOT
, a.k.a. ~
) of the desired mask. As such, we consider this exhibit fully addressed.
USE-02C: Repetitive Value Literal
Type | Severity | Location |
---|---|---|
Code Style | UserStorage.sol:L28, L56 |
Description:
The linked value literal is repeated across the codebase multiple times.
Example:
28uint256 constant OWED_OFFSET = 112;
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 (fb2dd77a6ff9b7f710edb48e7eb5437e0db4fc1a):
The statement within UserStorageLib::setOwed
properly utilizes the OWED_OFFSET
constant that already existed, optimizing the maintainability and legibility of the codebase.