Omniscia Beanstalk Audit

Bip Code Style Findings

Bip Code Style Findings

BIP-01C: Inefficient Assignment of Array

TypeSeverityLocation
Gas OptimizationBip.sol:L94, L95

Description:

The linked code is meant to assign all values of the input array to the storage array by pushing each element.

Example:

protocol/contracts/farm/facets/GovernanceFacet/Bip.sol
94for (uint i = 0; i < _diamondCut.length; i++)
95 s.g.diamondCuts[bipId].diamondCut.push(_diamondCut[i]);

Recommendation:

We advise the assignment to be performed directly as it is more optimal.

Alleviation:

After discussion with the Beanstalk team, we concluded that this type of optimization is not applicable in the compiler version they utilize and as such we consider this exhibit nullified.

BIP-02C: Inefficient Length Evaluation

TypeSeverityLocation
Gas OptimizationBip.sol:L107

Description:

The linked code reads the length member of an array from storage twice redundantly.

Example:

protocol/contracts/farm/facets/GovernanceFacet/Bip.sol
107if (i < s.g.activeBips.length-1) s.g.activeBips[i] = s.g.activeBips[s.g.activeBips.length-1];

Recommendation:

We advise the value to be stored to an in-memory variable reducing the SLOAD operations to 1 instead of 2.

Alleviation:

The length evaluation is now properly cached to a local variable prior to being utilized.