bosonprotocol / contracts

[DEPRECATED] Boson Protocol v1
GNU Lesser General Public License v3.0
69 stars 17 forks source link

Statement Execution Optimization #332

Closed zajck closed 2 years ago

zajck commented 2 years ago

VKL-01C: Statement Execution Optimization

Type Severity Location
Gas Optimization Informational VoucherKernel.sol:L735, L737-L740

Description:

The linked statements will result in no-ops if the _amount that is passed to setDepositsReleased is zero.

Example:

/**
 * @notice Mark voucher token that the deposits were released
 * @param _tokenIdVoucher   ID of the voucher token
 * @param _to               recipient, one of {ISSUER, HOLDER, POOL}
 * @param _amount           amount that was released in the transaction
 */
function setDepositsReleased(uint256 _tokenIdVoucher, Entity _to, uint256 _amount)
    external
    override
    onlyFromCashier
{
    require(_tokenIdVoucher != 0, "UNSPECIFIED_ID");

    vouchersStatus[_tokenIdVoucher].depositReleased.status |= (ONE << uint8(_to));

    vouchersStatus[_tokenIdVoucher].depositReleased.releasedAmount = vouchersStatus[_tokenIdVoucher].depositReleased.releasedAmount.add(_amount);

    if (vouchersStatus[_tokenIdVoucher].depositReleased.releasedAmount == getTotalDeposits(_tokenIdVoucher)) {
        vouchersStatus[_tokenIdVoucher].isDepositsReleased = true;
        emit LogFundsReleased(_tokenIdVoucher, 1); 
    }        
}

Recommendation:

We advise a conditional to be introduced before the linked statements that will halt execution of the function if the _amount is zero.