filecoin-saturn / contracts

contracts
6 stars 0 forks source link

Potential Unbounded Loop in Payout Contract #74

Open AmeanAsad opened 11 months ago

AmeanAsad commented 11 months ago

Description:

There are a few external view functions in the PayoutFactory contract that loop over all previous payouts, for example:

  /**
     * @dev Returns the total claimable amount over all previously generated payout contracts.
     * @param account The address of the payee.
     */
    function releasable(
        address account
    ) external view returns (uint256 totalValue) {
        uint256 length = _payouts.length;
        for (uint256 i = 0; i < length; i++) {
            PaymentSplitter rewards = PaymentSplitter(payable(_payouts[i]));
            totalValue += rewards.releasable(account);
        }
    }

The above function loops over all previously generated payouts to find the number of releasable payments for a given payee. This causes an issue because as the number of payees grow, the gas fees on calling this function will also grow. The amount of gas spendable on a given FVM transaction is limited by the block limit of the FVM. Therefore, at some point, it is likely that the gas costs to run this function are higher than the actual block limit, which would cause this function to effectively revert forever.

It is important to note that this would not lock the contract for node operators though. Deployed earnings will still be safe and claimable by node operators. Node operators would be able to still claim their earnings through the releaseAll function by modifying the offset. Node operators can also individually interact with the deployed PaymentSplitter contracts to claim their rewards.

This however, significantly impacts the UX for claiming earnings, as users will no longer certain information from the contract.

Potential Solutions

lordshashank commented 10 months ago

Can't we just cap the length to a certain number to avoid this problem?