Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Underutilized Named Returns #77

Open
code423n4 opened this issue Nov 28, 2021 · 1 comment
Open

Underutilized Named Returns #77

code423n4 opened this issue Nov 28, 2021 · 1 comment
Labels
bug Something isn't working G (Gas Optimization) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons

Comments

@code423n4
Copy link
Contributor

Handle

ye0lde

Vulnerability details

Impact

Using the existing named returns more efficiently can reduce gas usage and improve code clarity.

Proof of Concept

Use the existing named returns more efficiently:

Change line 91 to collateralReserves = maltReserves.mul(price).div(priceTarget);
https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/MaltDataLab.sol#L91

Delete the return at line #234
https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/RewardSystem/RewardDistributor.sol#L234

I suggest changing requestCapital from
https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/RewardSystem/RewardOverflowPool.sol#L39-L62
to

  function requestCapital(uint256 amount)
    external
    onlyRole(REWARD_THROTTLE_ROLE, "Must have Reward throttle privs")
    returns (uint256 fulfilledAmount)  // @audit unnamed-unique
  {
    uint256 balance = auctionRewardToken.balanceOf(address(this));

    if (balance != 0) {
      // This is the max amount allowable
      fulfilledAmount = balance.mul(maxFulfillment).div(1000);

      if (amount <= fulfilledAmount) {
        fulfilledAmount = amount;
      } 

      auctionRewardToken.safeTransfer(throttler, fulfilledAmount);

      emit FulfilledRequest(fulfilledAmount);
    }
  }

I suggest changing outstandingArbTokens from
https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/AuctionParticipant.sol#L104-L117
to

  function outstandingArbTokens() public view returns (uint256 outstanding) { 
    
    for (uint256 i = replenishingIndex; i < auctionIds.length; i = i + 1) {
      uint256 claimable = auction.balanceOfArbTokens(
        auctionIds[i],
        address(this)
      );

      outstanding += claimable;
    }
  }

Tools Used

Visual Studio Code, Remix

Recommended Mitigation Steps

See POC

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Nov 28, 2021
code423n4 added a commit that referenced this issue Nov 28, 2021
@0xScotch 0xScotch added the sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons label Dec 9, 2021
@GalloDaSballo
Copy link
Collaborator

I agree that you don't need to return the namedReturn variable.

I believe the optimizer will eat this gas inefficiency away though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Projects
None yet
Development

No branches or pull requests

3 participants