Omniscia Astrolab DAO Audit
As4626 Code Style Findings
As4626 Code Style Findings
A62-01C: Inefficient mapping
Lookups
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | As4626.sol:L166, L182 |
Description:
The linked statements perform key-based lookup operations on mapping
declarations from storage multiple times for the same key redundantly.
Example:
166Erc7540Request storage request = req.byOwner[_owner];167uint256 claimable = claimableRedeemRequest(_owner);168last.sharePrice = sharePrice();169
170uint256 price = (claimable >= _shares)171 ? AsMaths.min(last.sharePrice, request.sharePrice) // worst of if pre-existing request172 : last.sharePrice; // current price173
174// amount/shares cannot be higher than the share price (dictated by the inline convertToAssets below)175if (_amount > _shares.mulDiv(price * weiPerAsset, weiPerShare ** 2))176 revert AmountTooHigh(_amount);177
178if (msg.sender != _owner)179 _spendAllowance(_owner, msg.sender, _shares);180
181if (claimable >= _shares) {182 req.byOwner[_owner].shares -= _shares;183 req.totalRedemption -= AsMaths.min(_shares, req.totalRedemption); // min 0184 req.totalClaimableRedemption -= AsMaths.min(185 _shares,186 req.totalClaimableRedemption187 ); // min 0188} else {
Recommendation:
As the lookups internally perform an expensive keccak256
operation, we advise the lookups to be cached wherever possible to a single local declaration that either holds the value of the mapping
in case of primitive types or holds a storage
pointer to the struct
contained.
Alleviation (59b75fbee1d8f3dee807c928f18be41c58b904e1):
The optimization has been applied per our recommendation, using the request
storage pointer that already exists for the shares
member mutation in the second highlighted line.
A62-02C: Redundant Duplication of Code
Type | Severity | Location |
---|---|---|
Code Style | ![]() | As4626.sol:L146 |
Description:
The referenced statement will locally perform the statements of the As4626::previewDeposit
function redundantly.
Example:
146shares = _deposit(_amount, convertToShares(_amount, false).subBp(exemptionList[_receiver] ? 0 : fees.entry), _receiver);
Recommendation:
We advise the function to be invoked directly, optimizing the legibility of the code.
Alleviation (59b75fbee1d8f3dee807c928f18be41c58b904e1):
The referenced statements are no longer part of the As4626::safeDeposit
function, rendering this exhibit no longer applicable.
A62-03C: Redundant Parenthesis Statements
Type | Severity | Location |
---|---|---|
Code Style | ![]() | As4626.sol:L170, L801 |
Description:
The referenced statements are redundantly wrapped in parenthesis' (()
).
Example:
170uint256 price = (claimable >= _shares)
Recommendation:
We advise them to be safely omitted, increasing the legibility of the codebase.
Alleviation (59b75fbee1d8f3dee807c928f18be41c58b904e1):
The first of the two referenced instances is no longer applicable whilst the second instance has been corrected in its updated form rendering this exhibit fully addressed.
A62-04C: Repetitive Value Literal
Type | Severity | Location |
---|---|---|
Code Style | ![]() | As4626.sol:L96, L175, L190, L200 |
Description:
The linked value literal is repeated across the codebase multiple times.
Example:
96if (_amount > maxDeposit(address(0)) || _shares > _amount.mulDiv(weiPerShare ** 2, last.sharePrice * weiPerAsset))
Recommendation:
We advise it to be set to a constant
variable instead optimizing the legibility of the codebase.
Alleviation (59b75fbee1d8f3dee807c928f18be41c58b904e1):
All referenced instances of weiPerShare ** 2
have been replaced by a _WEI_PER_SHARE_SQUARED
constant per our recommendation, optimizing the code's legibility.