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

ParthMandale - The incorrect address is removed in _deleteAddressAtIndexFromArray() #316

Open
sherlock-admin3 opened this issue Nov 4, 2024 · 1 comment
Labels
Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed

Comments

@sherlock-admin3
Copy link
Contributor

sherlock-admin3 commented Nov 4, 2024

ParthMandale

Medium

The incorrect address is removed in _deleteAddressAtIndexFromArray()

Summary

function _deleteAddressAtIndexFromArray - is used to delete the address of the user that is associated with that current profile id at that index.

And therefore this function is supposed to - remove that particular index of arrays(addresses) from the addresses array.

And at the same time that same particular address of index of arrays(addresses) is supposed to be added in removedAddresses array.

But here the last index is added in removedAddresses array -> removedAddresses.push(addr); which is completely wrong.

Root Cause

https://github.com/sherlock-audit/2024-10-ethos-network/blob/db37b9dc2b792e245eb683d8a956bcb7ef2f1a27/ethos/packages/contracts/contracts/EthosProfile.sol#L591

Whenever a user deletes an address at an index through deleteAddressAtIndex() it would delete wrong address.

function deleteAddressAtIndex(uint256 addressIndex) external whenNotPaused {
    uint256 profileId = profileIdByAddress[msg.sender];
    (bool verified, bool archived, bool mock) = profileStatusById(profileId);
    if (!verified) {
      revert ProfileNotFoundForAddress(msg.sender);
    }
    if (archived || mock) {
      revert ProfileAccess(profileId, "Profile is archived");
    }

    address[] storage addresses = profiles[profileId].addresses;
    address[] storage removedAddresses = profiles[profileId].removedAddresses;
    if (addresses.length <= addressIndex) {
      revert InvalidIndex();
    }

    address addressStr = addresses[addressIndex];
    isAddressCompromised[addressStr] = true;
    _addressShouldDifferFromSender(addressStr);

@>  _deleteAddressAtIndexFromArray(addressIndex, addresses, removedAddresses);

    emit AddressClaim(profileId, addressStr, AddressClaimStatus.Unclaimed);
  }

Then in function _deleteAddressAtIndexFromArray is getting executed -

  function _deleteAddressAtIndexFromArray(
    uint256 index,
    address[] storage addresses,
    address[] storage removedAddresses
  ) private {
@>    address addr = addresses[addresses.length - 1];
    addresses[index] = addr;
@>    removedAddresses.push(addr);
    addresses.pop();
  }

We can clearly see that, here the last index is added in removedAddresses array -> removedAddresses.push(addr); which is wrong and instead index that was passed was supposed to be push into this removedAddresses array.

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

No response

Impact

  1. The incorrect address is removed in _deleteAddressAtIndexFromArray()

  2. If someone has two addresses, one is compromised, but the other one is still valid. If removal of the wrong address is happening, the other account that was supposed to be removed index, is now has control over the account. The attacker can archive the profile and front-run any attempt to un-archive it, keeping the profile permanently out of the hands of the valid owner.

PoC

No response

Mitigation

Implement _deleteAddressAtIndexFromArray function like this -

  function _deleteAddressAtIndexFromArray(
    uint256 index,
    address[] storage addresses,
    address[] storage removedAddresses
  ) private {
    address addr = addresses[addresses.length - 1];
@>  removedAddresses.push(addresses[index]);
@>  addresses[index] = addr;
    addresses.pop();
  }
@sherlock-admin2
Copy link
Contributor

The protocol team fixed this issue in the following PRs/commits:
https://github.com/trust-ethos/ethos/pull/1759

@sherlock-admin3 sherlock-admin3 added Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed labels Nov 20, 2024
@sherlock-admin4 sherlock-admin4 changed the title Melodic Peanut Anteater - The incorrect address is removed in _deleteAddressAtIndexFromArray() ParthMandale - The incorrect address is removed in _deleteAddressAtIndexFromArray() Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Sponsor Confirmed The sponsor acknowledged this issue is valid Will Fix The sponsor confirmed this issue will be fixed
Projects
None yet
Development

No branches or pull requests

2 participants