SiloEntrance Code Style Findings

SiloEntrance Code Style Findings

SEE-01C: Inefficient Length Lookups

Type Severity Location
Gas Optimization SiloEntrance.sol:L95, L104

Description:

The linked code performs a storage lookup for the length member on each iteration.

Example:

protocol/contracts/farm/facets/SiloFacet/SiloEntrance.sol
93function incrementBipRoots(address account, uint256 roots) internal {
94 if (s.a[account].lockedUntil >= season()) {
95 for (uint256 i = 0; i < s.g.activeBips.length; i++) {
96 uint32 bip = s.g.activeBips[i];
97 if (s.g.voted[bip][account]) s.g.bips[bip].roots = s.g.bips[bip].roots.add(roots);
98 }
99 }
100}
101
102function decrementBipRoots(address account, uint256 roots) internal {
103 if (s.a[account].lockedUntil >= season()) {
104 for (uint256 i = 0; i < s.g.activeBips.length; i++) {
105 uint32 bip = s.g.activeBips[i];
106 if (s.g.voted[bip][account]) s.g.bips[bip].roots = s.g.bips[bip].roots.sub(roots);
107 }
108 }
109}

Recommendation:

We advise the length member to be stored to an in-memory variable that is consequently utilised to significantly optimise the gas cost of those functions.

Alleviation:

The relevant code was relocated to the LibSilo library and was updated to cache the length to a local variable optimizing the codebase.

View Fix on GitHub

SEE-02C: Redundant Usage of SafeMath

Type Severity Location
Gas Optimization SiloEntrance.sol:L88

Description:

The linked SafeMath operations are guaranteed to be performed safely by their surrounding if clauses and general logical constraints.

Example:

protocol/contracts/farm/facets/SiloFacet/SiloEntrance.sol
87if (s.a[account].roots < s.a[account].sop.roots) {
88 s.r.roots = s.r.roots.sub(s.a[account].sop.roots.sub(s.a[account].roots));

Recommendation:

We advise them to be performed without the usage of SafeMath to optimise the code.

Alleviation:

The relevant code was relocated to the LibSilo library and the SafeMath instance listed has been safely omitted optimizing the codebase.

View Fix on GitHub

SEE-03C: Ternary Operator Optimization

Type Severity Location
Gas Optimization SiloEntrance.sol:L117

Description:

The linked ternary operators (a ? b : c) can be optimized to a single one by adjusting their structure.

Example:

protocol/contracts/farm/facets/SiloFacet/SiloEntrance.sol
115function reserves() internal view returns (uint256, uint256) {
116 (uint112 reserve0, uint112 reserve1,) = pair().getReserves();
117 return (index() == 0 ? reserve1 : reserve0,index() == 0 ? reserve0 : reserve1);
118}

Recommendation:

We advise them to be adjusted by evaluating the s.index() == 0 equality once and then returning a tuple of the two values (i.e. either (reserve0, reserve1) or (reserve1, reserve0) depending on the required case).

Alleviation:

The relevant code is no longer present in the codebase rendering this exhibit nullified.

Navigated to SiloEntrance Code Style Findings