bosonprotocol / contracts

[DEPRECATED] Boson Protocol v1

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CAS-04C: Redundant Cleanup Instruction

cliffhall opened this issue · comments

CAS-04C: Redundant Cleanup Instruction

Type Severity Location
Gas Optimization Informational Cashier.sol:L268, L489

Description:

The linked delete statement and 0 assignment are both redundant as the variables they are performed with no longer live outside the local scope of the function's / statement's block.

Example:

function withdraw(uint256 _tokenIdVoucher)
    external
    override
    nonReentrant
    whenNotPaused
{
    VoucherDetails memory voucherDetails;

    require(_tokenIdVoucher != 0, "UNSPECIFIED_ID"); //hex"20" FISSION.code(FISSION.Category.Find, FISSION.Status.NotFound_Unequal_OutOfRange)

    voucherDetails.tokenIdVoucher = _tokenIdVoucher;
    voucherDetails.tokenIdSupply = IVoucherKernel(voucherKernel)
        .getIdSupplyFromVoucher(voucherDetails.tokenIdVoucher);
    voucherDetails.paymentMethod = IVoucherKernel(voucherKernel)
        .getVoucherPaymentMethod(voucherDetails.tokenIdSupply);

    require(
        voucherDetails.paymentMethod > 0 &&
            voucherDetails.paymentMethod <= 4,
        "INVALID PAYMENT METHOD"
    );

    (
        voucherDetails.currStatus.status,
        voucherDetails.currStatus.isPaymentReleased,
        voucherDetails.currStatus.isDepositsReleased,
        ,
    ) = IVoucherKernel(voucherKernel).getVoucherStatus(
        voucherDetails.tokenIdVoucher
    );

    (
        voucherDetails.price,
        voucherDetails.depositSe,
        voucherDetails.depositBu
    ) = IVoucherKernel(voucherKernel).getOrderCosts(
        voucherDetails.tokenIdSupply
    );

    voucherDetails.issuer = payable(
        IVoucherKernel(voucherKernel).getSupplyHolder(
            voucherDetails.tokenIdSupply
        )
    );
    voucherDetails.holder = payable(
        IVoucherKernel(voucherKernel).getVoucherHolder(
            voucherDetails.tokenIdVoucher
        )
    );

    //process the RELEASE OF PAYMENTS - only depends on the redeemed/not-redeemed, a voucher need not be in the final status
    if (!voucherDetails.currStatus.isPaymentReleased) {
        releasePayments(voucherDetails);
    }

    //process the RELEASE OF DEPOSITS - only when vouchers are in the FINAL status
    if (
        !voucherDetails.currStatus.isDepositsReleased &&
        isStatus(voucherDetails.currStatus.status, IDX_FINAL)
    ) {
        releaseDeposits(voucherDetails);
    }

    if (voucherDetails.deposit2pool > 0) {
        _withdrawDeposits(
            owner(),
            voucherDetails.deposit2pool,
            voucherDetails.paymentMethod,
            voucherDetails.tokenIdSupply
        );
    }

    if (voucherDetails.price2issuer > 0) {
        _withdrawPayments(
            voucherDetails.issuer,
            voucherDetails.price2issuer,
            voucherDetails.paymentMethod,
            voucherDetails.tokenIdSupply
        );
    }

    if (voucherDetails.deposit2issuer > 0) {
        _withdrawDeposits(
            voucherDetails.issuer,
            voucherDetails.deposit2issuer,
            voucherDetails.paymentMethod,
            voucherDetails.tokenIdSupply
        );
    }

    if (voucherDetails.price2holder > 0) {
        _withdrawPayments(
            voucherDetails.holder,
            voucherDetails.price2holder,
            voucherDetails.paymentMethod,
            voucherDetails.tokenIdSupply
        );
    }

    if (voucherDetails.deposit2holder > 0) {
        _withdrawDeposits(
            voucherDetails.holder,
            voucherDetails.deposit2holder,
            voucherDetails.paymentMethod,
            voucherDetails.tokenIdSupply
        );
    }

    delete voucherDetails;
}

Recommendation:

We advise them to be safely omitted.

Remediation Strategy

  • Follow recommendation to remove unnecessary linked delete and zero assignment to local variables.