Omniscia Beanstalk Audit

Dibbler Code Style Findings

Dibbler Code Style Findings

DIB-01C: Code Duplication

Description:

The linked statements are identical.

Example:

protocol/contracts/farm/facets/FieldFacet/Dibbler.sol
32function _sow(uint256 amount, address account) internal returns (uint256) {
33 require(amount > 0, "Field: Must purchase non-zero amount.");
34 s.f.soil = s.f.soil.sub(amount, "Field: Not enough outstanding Soil.");
35 uint256 pods = beansToPods(amount, s.w.yield);
36 sowPlot(account, amount, pods);
37 s.f.pods = s.f.pods.add(pods);
38 saveSowTime();
39 return pods;
40}
41
42function _sowNoSoil(uint256 amount, address account) internal returns (uint256) {
43 require(amount > 0, "Field: Must purchase non-zero amount.");
44 uint256 pods = beansToPods(amount, s.w.yield);
45 sowPlot(account, amount, pods);
46 s.f.pods = s.f.pods.add(pods);
47 saveSowTime();
48 return pods;
49}

Recommendation:

We advise them to be refactored to an internal or private function and utilized in their place.

Alleviation:

The contract's code has been relocated under the LibDibbler contract and the optimization advised has been properly applied.

DIB-02C: Conditional Reorder Optimization

Description:

The linked conditional should evaluate the direct comparisons first in order prior to the calculations performed on the first comparator to optimise gas cost in most cases.

Example:

protocol/contracts/farm/facets/FieldFacet/Dibbler.sol
74if (
75 soilPercent <= C.getUpperBoundPodRate().mul(s.w.lastSoilPercent).asUint256() &&
76 !s.w.didSowFaster &&
77 s.w.lastSowTime != MAX_UINT32 &&
78 s.w.lastDSoil != 0
79) {

Recommendation:

We advise the comparisons to be re-ordered as advised.

Alleviation:

The contract's code has been relocated under the LibDibbler contract and now properly validates the simple conditionals instead of the percentage calculations optimizing the codebase.

DIB-03C: Deprecated Representation Style

TypeSeverityLocation
Code StyleDibbler.sol:L24

Description:

The linked code contains the representation of the maximum value of a uint32 in the 2**32 - 1 format which has been officially deprecated and no longer compiles in recent pragma versions.

Example:

protocol/contracts/farm/facets/FieldFacet/Dibbler.sol
24uint32 private constant MAX_UINT32 = 2**32-1;

Recommendation:

We advise the type(uint32).max standardised representational style to be utilised instead.

Alleviation:

The contract's code has been relocated under the LibDibbler contract and the literal has been omitted from the codebase with all its instances replaced by the type(uint32).max representation style alleviating this exhibit.