EthosReview reviewIdsBySubjectAddress() function returns incorrect result if address is registered to another profileId.
Summary
EthosReview reviewIdsBySubjectAddress() function returns incorrect result if address is registered to another profileId.
Root Cause
When users are adding a review to an address, but the address is not bind to a profileId yet, a mock profileId will be created. The review for that address would be recorded in reviewIdsBySubjectProfileId[subjectProfileId], with the subjectProfileId being the profileId of the address.
However, if this address is later registered to another ProfileId, it's profileId will change. This means all previous reviewIds in EthosReview would not be accessible anymore. Specifically this function used to look up address reviews: reviewIdsBySubjectAddress(). This function will lookup the reviewIds of the address's new profileId, but the old reviews (which was recorded on the mock profileId) will not be returned.
This is a very normal use case, and reviews would not be correctly returned. Considering that the EthosContract serve as a database layer to serve the upper level frontend apps, this is a critical issue.
pkqs90
Medium
EthosReview
reviewIdsBySubjectAddress()
function returns incorrect result if address is registered to another profileId.Summary
EthosReview
reviewIdsBySubjectAddress()
function returns incorrect result if address is registered to another profileId.Root Cause
When users are adding a review to an address, but the address is not bind to a profileId yet, a mock profileId will be created. The review for that address would be recorded in
reviewIdsBySubjectProfileId[subjectProfileId]
, with thesubjectProfileId
being the profileId of the address.However, if this address is later registered to another ProfileId, it's profileId will change. This means all previous reviewIds in EthosReview would not be accessible anymore. Specifically this function used to look up address reviews:
reviewIdsBySubjectAddress()
. This function will lookup the reviewIds of the address's new profileId, but the old reviews (which was recorded on the mock profileId) will not be returned.This is a very normal use case, and reviews would not be correctly returned. Considering that the EthosContract serve as a database layer to serve the upper level frontend apps, this is a critical issue.
https://github.com/sherlock-audit/2024-10-ethos-network/blob/main/ethos/packages/contracts/contracts/EthosReview.sol#L173-L249
Internal pre-conditions
External pre-conditions
N/A
Attack Path
N/A
Impact
Review ids are not correctly returned for the address, and some reviews would be lost.
PoC
Run the following code in a new file.
The output is the following, proving the review ids are lost.
Mitigation
Record the reviewIds by address rather than profileIds.