seen-haus / seen-contracts

Seen Haus contract suite
GNU General Public License v3.0
8 stars 2 forks source link

ARF-03C: Redundant Value Assignment #23

Closed JayWelsh closed 2 years ago

JayWelsh commented 2 years ago

ARF-03C: Redundant Value Assignment

Type Severity Location
Gas Optimization Informational AuctionRunnerFacet.sol:L148

Description:

The value of endTime is written to redundantly as it is not re-used.

Example:

    // If this was the first successful bid...
    if (auction.state == State.Pending) {

        // First bid updates auction state to Running
        auction.state = State.Running;

        // For auctions where clock is triggered by first bid, update start time
        if (auction.clock == Clock.Trigger) {

            // Set start time
            auction.start = block.timestamp;
            endTime = auction.start + auction.duration;

        }

        // Notify listeners of state change
        emit AuctionStarted(consignment.id);

    } else {

        // Should not apply to first bid
        // For bids placed within the extension window
        // Extend the duration so that auction still lasts for the length of the extension window
        if ((block.timestamp + extensionWindow) >= endTime) {
            auction.duration += (extensionWindow - (endTime - block.timestamp));
            emit AuctionExtended(_consignmentId);
        }

    }

    mhs.auctions[_consignmentId] = auction;

    // Announce the bid
    emit BidAccepted(_consignmentId, auction.buyer, auction.bid);

}

Recommendation:

We advise the assignment to be omitted from the codebase.

JayWelsh commented 2 years ago

Resolved by https://github.com/seen-haus/seen-contracts/pull/38