sherlock-audit / 2024-10-ethos-network-judging

0 stars 0 forks source link

Acrobatic Burlap Lizard - Function `EthosProfile:bulkInviteAddresses()`wastes a lot of gas #330

Closed sherlock-admin2 closed 2 weeks ago

sherlock-admin2 commented 2 weeks ago

Acrobatic Burlap Lizard

Low/Info

Function EthosProfile:bulkInviteAddresses()wastes a lot of gas

Summary

When cycling because performing a bulk operation, it's important to avoid repeating the same logic on every iteration

Root Cause

If EthosProfile:bulkInviteAddresses() calls inviteAddress() n times, the following logic inside inviteAddress() could be executed just once, while it's executed n times wasting gas:

   (bool verified, bool archived, bool mock, uint256 profileId) = profileStatusByAddress(
      msg.sender
    );

    if (!verified || archived || mock) {
      revert InvalidSender();
    }

    uint256 profile = profileIdByAddress[msg.sender];

    _profileShouldHaveInvites(profile);

    ...
}

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

No response

Impact

No response

PoC

No response

Mitigation

  1. refactor inviteAddress() and put the logic that could be executed just once in a dedicated function
  2. make sure that bulkInviteAddresses()calls the refactored function and no repeated code is executed