Quiet Cyan Hyena
Medium
When an address is deleted from a profile, it is pushed to the removedAddresses
array.
However, when the same address is registered again to the profile, it is not popped out from the removeAddresses
array.
As a result, the number of addresses tied to the profile becomes inflated, preventing the user from adding max number of addresses allowed to his own profile.
When an address is deleted, it is popped out from addresses
array and pushed into the removeAddresses
array, using the following EthosProfile.checkMaxAddresses()
function.
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();
}
When the deleted address is registered again to the profile, it is pushed back into the addresses
but not popped out from the removeAddresses
, in the following EthosProfile.registerAddress()
function.
function registerAddress(
address addressStr,
uint256 profileId,
uint256 randValue,
bytes calldata signature
) external whenNotPaused onlyNonZeroAddress(addressStr) {
...SKIP...
profiles[profileId].addresses.push(addressStr);
profileIdByAddress[addressStr] = profileId;
checkMaxAddresses(profileId);
emit AddressClaim(profileId, addressStr, AddressClaimStatus.Claimed);
}
As a result, the same address exists in the addresses
and removeAddresses
arrays. This causes the total number of addresses tied to the profile to be inflated, and the user is unable to add max number of addresses allowed to his own profile due to the following EthosProfile.checkMaxAddresses()
function.
function checkMaxAddresses(uint256 profileId) internal view {
uint256 sum = profiles[profileId].addresses.length;
sum += profiles[profileId].removedAddresses.length;
if (sum > maxNumberOfAddresses) {
revert MaxAddressesReached(profileId);
}
}
No response
No response
- Assume that
maxNumberOfAddresses = 10
and a user has added10
addresses to his own profile. - The user delete address
addr1
from his profile.addr1
is popped fromaddresses
and pushed intoremoveAddresses
. Now,addresses.length = 9
andremoveAddresses.length = 1
. - The user register
addr1
again to his own profile.addr1
is pushed back intoaddresses
but not popped out fromremoveAddresses
. - With 10 addresses in
addresses
and 1 address inremoveAddresses
, the registration reverts in thecheckMaxAddresses()
function because the combined total sum exceeds the maximum allowed.
Breaks core contract functionality because users are unable to register maximum number of addresses to their profile.
Assume that user added addr1 to addr10 and removed addr1 to addr5. In this case, user can't add addr11 but user can't add addr1 back as well. But he should be able to add removed addresses back.
In the registerAddress()
function, if the address has previously been deleted, it should be removed from the removedAddresses
array when it is registered again.