Omniscia Morpho Audit
HeapOrdering Static Analysis Findings
HeapOrdering Static Analysis Findings
HOG-01S: Ineffectual Operations
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | HeapOrdering.sol:L223-L224 |
Description:
The linked operations are ineffectual as they are performed on a memory
reference that remains unutilized in the function body.
Example:
210/// @notice Increases the amount of an account in the `_heap`.211/// @dev Only call this function when `_id` is in the `_heap` with a smaller value than `_newValue`.212/// @param _heap The heap to modify.213/// @param _id The address of the account to increase the amount.214/// @param _newValue The new value of the account.215/// @param _maxSortedUsers The maximum size of the heap.216function increase(217 HeapArray storage _heap,218 address _id,219 uint256 _newValue,220 uint256 _maxSortedUsers221) private {222 uint256 rank = _heap.ranks[_id];223 Account memory account = getAccount(_heap, rank);224 account.value = _newValue;225 setAccountValue(_heap, rank, _newValue);226 uint256 nextSize = _heap.size + 1;227
228 if (rank < nextSize) shiftUp(_heap, rank);229 else {230 swap(_heap, nextSize, rank);231 shiftUp(_heap, nextSize);232 _heap.size = computeSize(nextSize, _maxSortedUsers);233 }234}
Recommendation:
We advise them to be safely omitted reducing the gas cost of the function.
Alleviation:
The redundant operations have been safely omitted from the codebase.
HOG-02S: Repetitive Value Literal
Type | Severity | Location |
---|---|---|
Code Style | ![]() | HeapOrdering.sol:L128, L285, L304 |
Description:
The linked literal 1
is utilized in the linked portions to signify the head of the heap array, i.e. the root of the heap tree.
Example:
297/// @notice Returns the address coming before `_id` in accounts.298/// @dev The account associated to the returned address does not necessarily have a lower value than the one of the account associated to `_id`.299/// @param _heap The heap to search in.300/// @param _id The address of the account.301/// @return The address of the previous account.302function getPrev(HeapArray storage _heap, address _id) internal view returns (address) {303 uint256 rank = _heap.ranks[_id];304 if (rank > 1) return getAccount(_heap, rank - 1).id;305 else return address(0);306}
Recommendation:
We advise this to be better illustrated by setting a contract-level constant
declaration (i.e. HEAP_ROOT
) in which the value of 1
is stored greatly improving the legibility of the codebase. To note, in the first linked line only the first instance of 1
should be replaced as the latter instance is a binary offset.
Alleviation:
The issue has been completely alleviated by replacing all instances of the value literal with its constant
declaration.