Omniscia Tren Finance Audit
TrenBoxStorage Code Style Findings
TrenBoxStorage Code Style Findings
TBS-01C: Inefficient mapping
Lookups
Type | Severity | Location |
---|---|---|
Gas Optimization | TrenBoxStorage.sol:L132, L142, L253, L255, L258, L260, L263, L266, L378, L379, L381, L399, L400, L402, L421, L422, L424 |
Description:
The linked statements perform key-based lookup operations on mapping
declarations from storage multiple times for the same key redundantly.
Example:
376function _updateActiveDebt(address _collateral, uint256 _amount, bool _isIncrease) private {377 uint256 newDebt;378 if (_isIncrease) newDebt = debtBalances[_collateral].active + _amount;379 else newDebt = debtBalances[_collateral].active - _amount;380
381 debtBalances[_collateral].active = newDebt;382 emit ActiveDebtBalanceUpdated(_collateral, newDebt);383}
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.
As the compiler's optimizations may take care of these caching operations automatically at-times, we advise the optimization to be selectively applied, tested, and then fully adopted to ensure that the proposed caching model indeed leads to a reduction in gas costs.
Alleviation (f6f1ad0b8f24a96ade345db1dd05a1878eb0f761):
All referenced inefficient mapping
lookups have been optimized to the greatest extent possible, significantly reducing the gas cost of the functions the statements were located in.
TBS-02C: Redundant Parenthesis Statement
Type | Severity | Location |
---|---|---|
Code Style | TrenBoxStorage.sol:L454 |
Description:
The referenced statement is redundantly wrapped in parenthesis (()
).
Example:
454return (_account == stabilityPool);
Recommendation:
We advise them to be safely omitted, increasing the legibility of the codebase.
Alleviation (f6f1ad0b8f24a96ade345db1dd05a1878eb0f761):
The redundant parenthesis in the referenced statement have been safely omitted.