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

Unnecessary internal function calls #296

Open
code423n4 opened this issue Dec 1, 2021 · 1 comment
Open

Unnecessary internal function calls #296

code423n4 opened this issue Dec 1, 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

WatchPug

Vulnerability details

https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/AbstractRewardMine.sol#L179-L191

  function _handleStakePadding(address account, uint256 amount) internal {
    uint256 totalRewardedWithStakePadding = totalDeclaredReward().add(totalStakePadding());

    uint256 INITIAL_STAKE_SHARE_MULTIPLE = 1e6;

    uint256 bondedTotal = totalBonded();

    uint256 newStakePadding = bondedTotal == 0 ?
      totalDeclaredReward() == 0 ? amount.mul(INITIAL_STAKE_SHARE_MULTIPLE) : 0 :
      totalRewardedWithStakePadding.mul(amount).div(bondedTotal);

    _addToStakePadding(account, newStakePadding);
  }

https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/AbstractRewardMine.sol#L107-L109

  function totalStakePadding() public view returns(uint256) {
    return _globalStakePadding;  
  }

In AbstractRewardMine.sol#_handleStakePadding(), at L180, the internal function call to totalStakePadding() is unnecessary, which can be replaced by direct storage read to save gas.

The same issue exists in _getFullyPaddedReward().

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Dec 1, 2021
code423n4 added a commit that referenced this issue Dec 1, 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

Finding is valid and would save a JUMP, personally don't mind a nofix to maintain readability (or you could switch to internal functions which the optimizer should inline)

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