Omniscia Boson Protocol Audit
DisputeBase Code Style Findings
DisputeBase Code Style Findings
DBE-01C: Repetitive Invocations of Getter Function
Type | Severity | Location |
---|---|---|
Gas Optimization | ![]() | DisputeBase.sol:L35, L52 |
Description:
The linked statements repetitively invoke the same getter function whilst its return value remains unchanged.
Example:
contracts/protocol/bases/DisputeBase.sol
35require(elapsed < fetchOfferDurations(_exchange.offerId).fulfillmentPeriod, FULFILLMENT_PERIOD_HAS_ELAPSED);36
37// Make sure the caller is buyer associated with the exchange38checkBuyer(_exchange.buyerId);39
40// Set the exchange state to disputed41_exchange.state = ExchangeState.Disputed;42
43// Fetch the dispute and dispute dates44(, Dispute storage dispute, DisputeDates storage disputeDates) = fetchDispute(_exchange.id);45
46// Set the initial values47dispute.exchangeId = _exchange.id;48dispute.state = DisputeState.Resolving;49
50// Update the disputeDates51disputeDates.disputed = block.timestamp;52disputeDates.timeout = block.timestamp + fetchOfferDurations(_exchange.offerId).resolutionPeriod;
Recommendation:
We advise the getter function to be invoked once and its result to be stored to a local variable that is consequently utilized optimizing the gas cost of the statements significantly.
Alleviation (44009967e4f68092941d841e9e0f5dd2bb31bf0b):
The offer durations are now correctly cached to local variable declarations thus optimizing the codebase's gas cost.