Omniscia Astrolab DAO Audit
AsArrays Code Style Findings
AsArrays Code Style Findings
AAS-01C: Ineffectual Usage of Safe Arithmetics
Type | Severity | Location |
---|---|---|
Language Specific | ![]() | AsArrays.sol:L149 |
Description:
The linked mathematical operation is guaranteed to be performed safely by surrounding conditionals evaluated in either require
checks or if-else
constructs.
Example:
146require(begin < end && end <= self.length);147
148// Calculate the number of elements in the slice149uint256 sliceLength = end - begin;
Recommendation:
Given that safe arithmetics are toggled on by default in pragma
versions of 0.8.X
, we advise the linked statement to be wrapped in an unchecked
code block thereby optimizing its execution cost.
Alleviation (59b75fbee1d8f3dee807c928f18be41c58b904e1):
The referenced statement is no longer present in the codebase in any shape or form rendering this exhibit inapplicable.
AAS-02C: Inefficient Iteration of Search Loops
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | AsArrays.sol:L47, L68 |
Description:
The referenced loops will iterate from 0
to identify the maximum and minimum respectively, however, their value
entries are already initialized with the first entry of the array.
Example:
36/**37 * @notice Returns the max value in an array.38 * @param self Storage array containing uint256 type variables39 * @return value The highest value in the array40 */41function max(uint256[] storage self) public view returns (uint256 value) {42 assembly {43 mstore(0x60, self.slot)44 value := sload(keccak256(0x60, 0x20))45
46 for {47 let i := 048 } lt(i, sload(self.slot)) {49 i := add(i, 1)50 } {51 switch gt(sload(add(keccak256(0x60, 0x20), i)), value)52 case 1 {53 value := sload(add(keccak256(0x60, 0x20), i))54 }55 }56 }57}58
59/// @notice Returns the minimum value in an array.60/// @param self Storage array containing uint256 type variables61/// @return value The highest value in the array62function min(uint256[] storage self) public view returns (uint256 value) {63 assembly {64 mstore(0x60, self.slot)65 value := sload(keccak256(0x60, 0x20))66
67 for {68 let i := 069 } lt(i, sload(self.slot)) {70 i := add(i, 1)71 } {72 switch gt(sload(add(keccak256(0x60, 0x20), i)), value)73 case 0 {74 value := sload(add(keccak256(0x60, 0x20), i))75 }76 }77 }78}
Recommendation:
We advise the loops to begin at 1
, optimizing each function's gas cost by one iteration.
Alleviation (cf5194da53ebf026da6c8efa74daada96719cc71):
Both loops will now begin iteration at the 1
index, optimizing their gas cost by one iteration.
AAS-03C: Inefficient Iterator Type
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | AsArrays.sol:L169, L173, L177 |
Description:
The referenced for
loops utilize a uint64
variable as an iterator which is inefficient.
Example:
169arr = new uint8[](n); for (uint64 i = 0; i < n; i++) arr[i] = a;
Recommendation:
As the EVM is built to operate on 32-byte (256-bit) data types, we advise the iterator types to be bumped to uint256
, optimizing their gas cost.
Alleviation (59b75fbee1d8f3dee807c928f18be41c58b904e1):
All referenced iterators have been updated to the uint256
data type, optimizing the codebase as advised.
AAS-04C: Inexistent Error Messages
Type | Severity | Location |
---|---|---|
Code Style | ![]() | AsArrays.sol:L131, L146 |
Description:
The linked require
checks have no error messages explicitly defined.
Example:
131require(begin < end && end <= self.length);
Recommendation:
We advise each to be set so to increase the legibility of the codebase and aid in validating the require
checks' conditions.
Alleviation (59b75fbee1d8f3dee807c928f18be41c58b904e1):
In-line documentation was introduced to clarify what the error is. Given that the contracts of the Astrolab DAO codebase tread closely to the bytecode size limit, we consider this approach as an adequate alleviation.
AAS-05C: Loop Iterator Optimizations
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | AsArrays.sol:L114, L155, L169, L173, L177 |
Description:
The linked for
loops increment / decrement their iterator "safely" due to Solidity's built - in safe arithmetics (post-0.8.X
).
Example:
114for (uint i = 0; i < dt.length; i++) {
Recommendation:
We advise the increment / decrement operations to be performed in an unchecked
code block as the last statement within each for
loop to optimize their execution cost.
Alleviation (59b75fbee1d8f3dee807c928f18be41c58b904e1):
The referenced loop iterator increment statements have been relocated at the end of each respective for
loop's body and have been unwrapped in an unchecked
code block, optimizing their gas cost.