How to resolve: Slither: calls-inside-a-loop?

  Kiến thức lập trình


After writing a function that computes a cumulative remaining return, Slither throws warning:

Helper.computeCumRemainingInvestorReturn(TierInvestment[]) (src/Helper.sol#61-76) has external calls inside a loop: cumRemainingInvestorReturn += tierInvestments[i].getRemainingReturn() (src/Helper.sol#71)

For function:

function computeCumRemainingInvestorReturn(
    TierInvestment[] memory tierInvestments
  ) public view override returns (uint256 cumRemainingInvestorReturn) {

    // Sum the returns of all tiers.
    uint256 nrOfTierInvestments = tierInvestments.length;
    for (uint256 i = 0; i < nrOfTierInvestments; ++i) {
      cumRemainingInvestorReturn += tierInvestments[i].getRemainingReturn();

    // TODO: assert no integer overflow has occurred.
    return cumRemainingInvestorReturn;


function getRemainingReturn() public view override returns (uint256 remainingReturn) {
    remainingReturn = _remainingReturn;
    return remainingReturn;


How can I resolve this issue? I thought about looping over the objects and copying them into a struct, however, I feel like that is quite convoluted, hence, I was wondering if there is a better way to handle this.