`QVBaseStrategy::reviewRecipients()` doesn't check if the recipient is already accepted or rejected, and overwrites the current status
The reviewRecipients function in QVBaseStrategy does not check the recipient's current status and overwrites it as soon as a new status reaches the review threshold, ignoring previous votes. This allows a recipient to be accepted even if more managers rejected them, as long as a later set of votes for acceptance reaches the threshold.
0x00ffDa Follow with BenRai, gkrastenov and 2 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/699
Found by
0x00ffDa, BenRai, gkrastenov, osmanozdemir1, xAriextz
Vulnerability Detail
In the QV strategy contracts, recipients register themselves and wait for a pool manager to accept the registration. Pool managers can accept or reject recipients with the reviewRecipients() function. There is also a threshold (reviewThreshold) for recipients to be accepted. For example, if the reviewThreshold is 2, a pending recipient gets accepted when two managers accept this recipient and the recipientStatus is updated.
However, QVBaseStrategy::reviewRecipients() function doesn't check the recipient's current status. This one alone may not be an issue because managers may want to change the status of the recipient etc.
But on top of that, the function also doesn't take the previous review counts into account when updating the status, and overwrites the status immediately after reaching the threshold. I'll share a scenario later about this below.
Here is the reviewRecipients() function:
https://github.com/sherlock-audit/2023-09-Gitcoin/blob/main/allo-v2/contracts/strategies/qv-base/QVBaseStrategy.sol#L254C1-L288C6
file: QVBaseStrategy.sol
function reviewRecipients(address[] calldata _recipientIds, Status[] calldata _recipientStatuses)
external
virtual
onlyPoolManager(msg.sender)
onlyActiveRegistration
{
// make sure the arrays are the same length
uint256 recipientLength = _recipientIds.length;
if (recipientLength != _recipientStatuses.length) revert INVALID();
for (uint256 i; i < recipientLength;) {
Status recipientStatus = _recipientStatuses[i];
address recipientId = _recipientIds[i];
// if the status is none or appealed then revert
if (recipientStatus == Status.None || recipientStatus == Status.Appealed) { //@audit these are the input parameter statuse not the recipient's status.
revert RECIPIENT_ERROR(recipientId);
}
reviewsByStatus[recipientId][recipientStatus]++;
--> if (reviewsByStatus[recipientId][recipientStatus] >= reviewThreshold) { //@audit recipientStatus is updated right after the threshold is reached. It can overwrite if the status is already set.
Recipient storage recipient = recipients[recipientId];
recipient.recipientStatus = recipientStatus;
emit RecipientStatusUpdated(recipientId, recipientStatus, address(0));
}
emit Reviewed(recipientId, recipientStatus, msg.sender);
unchecked {
++i;
}
}
}
As I mentioned above, the function updates the recipientStatus immediately after reaching the threshold. Here is a scenario of why this might be an issue.
Example Scenario
The pool has 5 managers and the reviewThreshold is 2.
-
The first manager rejects the recipient
-
The second manager accepts the recipient
-
The third manager rejects the recipient. ->
recipientStatusupdated ->status = REJECTED -
The fourth manager rejects the recipient -> status still
REJECTED -
The last manager accepts the recipient ->
recipientStatusupdated again ->status = ACCEPTED
3 managers rejected and 2 managers accepted the recipient but the recipient status is overwritten without checking the recipient's previous status and is ACCEPTED now.
Coded PoC
You can prove the scenario above with the PoC. You can use the protocol's own setup for this.
- Copy the snippet below and paste it into the QVBaseStrategy.t.sol test file.
- Run forge test --match-test test_reviewRecipient_reviewTreshold_OverwriteTheLastOne
//@audit More managers rejected but the recipient is accepted
function test_reviewRecipient_reviewTreshold_OverwriteTheLastOne() public virtual {
address recipientId = __register_recipient();
// Create rejection status
address[] memory recipientIds = new address[](1);
recipientIds[0] = recipientId;
IStrategy.Status[] memory Statuses = new IStrategy.Status[](1);
Statuses[0] = IStrategy.Status.Rejected;
// Reject three times with different managers
vm.startPrank(pool_manager1());
qvStrategy().reviewRecipients(recipientIds, Statuses);
vm.startPrank(pool_manager2());
qvStrategy().reviewRecipients(recipientIds, Statuses);
vm.startPrank(pool_manager3());
qvStrategy().reviewRecipients(recipientIds, Statuses);
// Three managers rejected. Status will be rejected.
assertEq(uint8(qvStrategy().getRecipientStatus(recipientId)), uint8(IStrategy.Status.Rejected));
assertEq(qvStrategy().reviewsByStatus(recipientId, IStrategy.Status.Rejected), 3);
// Accept two times after three rejections
Statuses[0] = IStrategy.Status.Accepted;
vm.startPrank(pool_admin());
qvStrategy().reviewRecipients(recipientIds, Statuses);
vm.startPrank(pool_manager4());
qvStrategy().reviewRecipients(recipientIds, Statuses);
// 3 Rejected, 2 Accepted, but status is Accepted because it overwrites right after passing threshold.
assertEq(uint8(qvStrategy().getRecipientStatus(recipientId)), uint8(IStrategy.Status.Accepted));
assertEq(qvStrategy().reviewsByStatus(recipientId, IStrategy.Status.Rejected), 3);
assertEq(qvStrategy().reviewsByStatus(recipientId, IStrategy.Status.Accepted), 2);
}
You can find the test results below:
Running 1 test for test/foundry/strategies/QVSimpleStrategy.t.sol:QVSimpleStrategyTest
[PASS] test_reviewRecipient_reviewTreshold_OverwriteTheLastOne() (gas: 249604)
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 10.92ms
Impact
Recipient status might be overwritten with less review counts.
Code Snippet
file: QVBaseStrategy.sol
function reviewRecipients(address[] calldata _recipientIds, Status[] calldata _recipientStatuses)
external
virtual
onlyPoolManager(msg.sender)
onlyActiveRegistration
{
// make sure the arrays are the same length
uint256 recipientLength = _recipientIds.length;
if (recipientLength != _recipientStatuses.length) revert INVALID();
for (uint256 i; i < recipientLength;) {
Status recipientStatus = _recipientStatuses[i];
address recipientId = _recipientIds[i];
// if the status is none or appealed then revert
if (recipientStatus == Status.None || recipientStatus == Status.Appealed) { //@audit these are the input parameter statuse not the recipient's status.
revert RECIPIENT_ERROR(recipientId);
}
reviewsByStatus[recipientId][recipientStatus]++;
--> if (reviewsByStatus[recipientId][recipientStatus] >= reviewThreshold) { //@audit recipientStatus is updated right after the threshold is reached. It can overwrite if the status is already set.
Recipient storage recipient = recipients[recipientId];
recipient.recipientStatus = recipientStatus;
emit RecipientStatusUpdated(recipientId, recipientStatus, address(0));
}
emit Reviewed(recipientId, recipientStatus, msg.sender);
unchecked {
++i;
}
}
}
Tool used
Manual Review
Recommendation
Checking the review counts before updating the state might be helpful to mitigate this issue
Discussion
0xKurt
@nfrgosselin How to deal with this depends of how the pool admin wants to approve or reject applications:
- Count each status --> 4 accepted and 2 rejected with threshold at 8 this would be approved
- Whatever the last status set is --> the last manager to set the status
- Once the status is set it cannot be changed
These are a couple example we thought of. WDYT?
sherlock-admin2
Escalate
#589 and #699 are essentially describing the same root cause. All relevant dupes associated with this two issues should be combined, as both are describing the possibility of pool manager reviewing a recipient multiple times leading to overwritten recipient status.
You've deleted an escalation for this issue.
osmanozdemir1
Escalate
#589 and #699 are essentially describing the same root cause. All relevant dupes associated with this two issues should be combined, as both are describing the possibility of pool manager reviewing a recipient multiple times leading to overwritten recipient status.
This issue doesn't describe same manager reviewing a recipient multiple times. As you can see in the coded PoC above, every review is made by different managers. This issue is far different than the #589 and describes recipient can be changed even with less review counts.
nevillehuang
I still stand that both are duplicates. Both are describing the same root cause of not checking the previous status and not respecting review threshold, allowing overwriting of recipient status
BenRai1
I would side with @osmanozdemir1 on that. The issues https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/589 and https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/699 are different since they describe two different issues where the fix is different.
The first issue would be fixed by tracking what manager already voted for what recipient. This would not fix the issue where the last manager who reviews a recipient can turn the result even if more managers voted for an other result. Just becasue both issues are in the same function this does not mean that they are the same
nevillehuang
I would side with @osmanozdemir1 on that. The issues #589 and #699 are different since they describe two different issues where the fix is different.
The first issue would be fixed by tracking what manager already voted for what recipient. This would not fix the issue where the last manager who reviews a recipient can turn the result even if more managers voted for an other result. Just becasue both issues are in the same function this does not mean that they are the same
On second thought, you are right, the issues are not duplicates. One is talking about pool managers potentially casting many votes influencing recipient status by bypassing reviewThreshold, while the other is pool managers casting votes as expected but doesn't respect the majority outcome. Removing escalation
0xf1b0
In my report #315, I mentioned both cases described in #589 and this one. If it's not a duplicate I should be added to the #699 "found by" list.
nevillehuang
Escalate
On third thought, report #315 mentions both issues, and again convinces me that #589 and #699 are stemming from the same root cause of ineffective reviewThresholds. Both issues stems from overriding recipient status, regardless it being the same pool manager or multiple different pool manager. #315 should be made a primary issue and all other issues should be dupped under it.
sherlock-admin2
Escalate
On third thought, report #315 mentions both issues, and again convinces me that #589 and #699 are stemming from the same root cause of ineffective reviewThresholds. Both issues stems from overriding recipient status, regardless it being the same pool manager or multiple different pool manager. #315 should be made a primary issue and all other issues should be dupped under it.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
osmanozdemir1
Escalate
On third thought, report #315 mentions both issues, and again convinces me that #589 and #699 are stemming from the same root cause of ineffective reviewThresholds. Both issues stems from overriding recipient status, regardless it being the same pool manager or multiple different pool manager. #315 should be made a primary issue and all other issues should be dupped under it.
I disagree with this comment and disagree with both of these issues being duplicates. The solution of the first issue is tracking which manager reviewed which recipient with a mapping. This solution is implemented in this fix. The fix of the first issue does not solve the second issue. The solution of the second issue can be implemented in different ways depending on the developer team's intentions. Which is mentioned here, and the fix is implemented here. As you can see the fixes of these two issues are quite different.
Just because one submission (#315) mentioning two different issues together doesn't mean those two issues are the same, and doesn't mean all of them should be duped together. It only means that the submitter preferred to submit them together to strengthen his/her submission. As you can see in the Sherlock documentation, best practices number 3: "Do not submit multiple issues in a single submission. Even if the 2 completely different issues occur on the same line, please make sure to separately submit them"
I'm not sure if the Sherlock allows labelling one submission with two different duplicate labels in these kind of situations. #315 might be duped under both of these two primary issues or it can be duped under the one with less duplicates according to the Sherlock rules and the judge's decision.
0xf1b0
By the way, my report #315 also includes a mention of and a proposed fix for #729 issue. Since it's my first time participating in a contest and I don't have the capability to escalate, I'll leave it here with the hope that it will be taken into consideration.
0xf1b0
I will certainly need to reconsider the issue submission process.
However, it's important to note that "best practices" should not be interpreted as rigid rules. The documentation does not explicitly state that deviating from these practices will result in no rewards or that only a single issue will be acknowledged.
Moreover, the question of whether these issues are truly separate remains a subject of debate.
neeksec
I suggest to keep the orignal judging.
Both are describing the same root cause of not checking the previous status and not respecting review threshold
This one is not checking the previous status and #589 is not respecting review threshold. Although these two bugs both alow to manipulate review status, the root cause is different. The fixes are also different which was well described by https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/699#issuecomment-1763517995.
jacksanford1
https://github.com/allo-protocol/allo-v2/pull/349
Evert0x
Planning to reject escalation and keep issue state.
Root cause is different in the mentioned issues.
Evert0x
Result: Medium Has Duplicates
sherlock-admin2
Escalations have been resolved successfully!
Escalation status:
- nevillehuang: rejected
jack-the-pug
Not Fixed.
Managers who haven't voted yet can still change a recipient's status by voting for another status.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the function updates the recipient status immediately when the count for a given status reaches the threshold, without checking the existing status or considering votes for other statuses.
Impact
Recipient status might be overwritten with less review counts, potentially allowing a recipient to be accepted despite more managers rejecting them.
What the attacker needed
Pool with multiple managers; reviewThreshold set; managers vote on recipient
The fix
The code should check the review counts before updating the state, as suggested in the recommendation.
How it was found
- The first manager rejects the recipient.
- The second manager accepts the recipient.
- The third manager rejects the recipient, causing the status to be updated to REJECTED.
- The fourth manager rejects the recipient, but the status remains REJECTED.
- The last manager accepts the recipient, causing the status to be updated again to ACCEPTED.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In this smart contract, pool managers vote to accept or reject recipients. The contract is supposed to change a recipient's status only when enough managers agree. But the code doesn't look at the current status or previous votes; it just changes the status as soon as any group of votes reaches the threshold. So a recipient can end up accepted even if most managers rejected them, because later votes for acceptance overwrite the rejection.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.