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

Recumbent Cerulean Fish - EthosVouch.sol contract might run out of gas due following wrong pattern #711

Open
sherlock-admin2 opened this issue Dec 5, 2024 · 0 comments

Comments

@sherlock-admin2
Copy link
Contributor

Recumbent Cerulean Fish

Medium

EthosVouch.sol contract might run out of gas due following wrong pattern

Summary

In EthosVouch.sol:slash() func we are copying storage mapping data to the storage array

    uint256 totalSlashed; 
    uint256[] storage vouchIds = vouchIdsByAuthor[authorProfileId]; //

    for (uint256 i = 0; i < vouchIds.length; i++) {//
      Vouch storage vouch = vouches[vouchIds[i]]; //
      // Only slash active vouches
      if (!vouch.archived) {
        uint256 slashAmount = vouch.balance.mulDiv(
          slashBasisPoints,
          BASIS_POINT_SCALE,
          Math.Rounding.Floor
        );
        if (slashAmount > 0) {
          vouch.balance -= slashAmount;
          totalSlashed += slashAmount;
        }

what we exactly does here, we accessing storage mapping = 2k of gas per unit, and writing the value to the storage array 20k gas per unit, after all of this we going throw for loop accessing it once again
This mappings we accessing might have up to 256 values, which we are coppying to array, it hugely consumes our gas.
Such pattern persist in EthosVouch.sol:slash(), EthosVouch.sol: _rewardPreviousVouchers(), EthosVouch.sol:_removeVouchFromArrays(),

Root Cause

EthosVouch.sol:slash(), EthosVouch.sol: _rewardPreviousVouchers(), EthosVouch.sol:_removeVouchFromArrays()

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

Run function above for ProfileIds which have big amount of vouchers

Impact

Contract won't be able to execute functions above

PoC

No response

Mitigation

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant