re-al-Foundation / rwa-contracts

0 stars 0 forks source link

[RSE-02C] Inefficient Claim/Expiry Processing System #96

Closed chasebrownn closed 5 months ago

chasebrownn commented 5 months ago

RSE-02C: Inefficient Claim/Expiry Processing System

Type Severity Location
Gas Optimization RevenueStreamETH.sol:L169-L174, L196-L201, L298, L299, L300, L331, L334

Description:

The RevenueStreamETH::claimETH and RevenueStreamETH::skimExpiredRevenue functions are significantly inefficient as they will maintain multiple arrays within their RevenueStreamETH::_claimable and RevenueStreamETH::_checkForExpiredRevenue functions respectively that will be iterated once again redundantly.

Example:

/**
 * @notice This method allows eligible VE shareholders to claim their revenue rewards by account.
 * @param account Address of shareholder that is claiming rewards.
 */
function claimETH(address account) external returns (uint256 amount) {
    require(account == msg.sender, "RevenueStreamETH: Not authorized");

    uint256 cycle = currentCycle();

    uint256[] memory cyclesClaimable;
    uint256[] memory amountsClaimable;
    uint256 num;

    (amount, cyclesClaimable, amountsClaimable, num) = _claimable(account);

    require(amount > 0, "no claimable amount");

    lastClaim[account] = cycle;

    for (uint256 i; i < num;) {
        revenueClaimed[cyclesClaimable[i]] += amountsClaimable[i];
        unchecked {
            ++i;
        }
    }

    (bool sent,) = payable(msg.sender).call{value: amount}("");
    if (!sent) revert ETHTransferFailed(msg.sender, amount);

    emit RevenueClaimed(msg.sender, account, cycle, amount);
}

Recommendation:

We advise the code of the internal functions referenced to immediately update the revenueClaimed and expiredRevClaimed values, thereby rendering the arrays as well as lengths yielded redundant and significantly optimizing the overall function flows.

chasebrownn commented 5 months ago

Acknowledged