Skip to content
Race condition Audit finding Intermediate

Malicious registrant can front-run `RFPSimpleStrategy._allocate()` in order to change the `proposalBid` and get a bigger payout in the distribution

A malicious registrant could front-run the pool manager's allocation transaction to change their proposal bid to a higher amount, causing the manager to accept a non-agreed bid. This could lead to a larger payout during distribution, potentially draining the pool.

0xbepresent Follow with 0xdeadbeef, WATCHPUG and 6 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/497

Found by

0xbepresent, 0xdeadbeef, WATCHPUG, detectiveking, honeymewn, jah, jkoppel, qbs, rvierdiiev The RFPSimpleStrategy::_allocate() function can be frontrun by a malicious registrant chainging the proposalBid and get a bigger payout in the RFPSimpleStrategy::_distribute() function.

Vulnerability Detail

Users can register to the pool strategy using the RFPSimpleStrategy::_registerRecipient() function specifying the proposalBid in the registration. Then the pool manager accepts the registrant recipient using the RFPSimpleStrategy::_allocate() function.

The problem is that the execution of the RFPSimpleStrategy::_allocate() function by the pool manager can be frontun by a malicious registrant recipient. Consider the next scenario:

  1. UserA call the RFPSimpleStrategy::_registerRecipient() using a proposalBid=10.
  2. Pool manager accepts the proposal by UserA and call the RFPSimpleStrategy::_allocate() function.
  3. UserA monitors the mempool and frontrun the manager _allocate() execution changing the proposal now proposalBid=50.
  4. The step 2 call finally is executed but the using non-agreed proposal proposalBid=50.

Now the UserA is accepted registrant recipient with non-agreed proposal bid (proposalBid=50).

Impact

Malicious registrant can change the proposalBid to a non-agreed term causing that he can receive a bigger payout in the RFPSimpleStrategy::_distribute() function because in the code line 435 the proposalBid is used to calculate the amount to pay to the accepted registrant recipient:

Solidity
File: RFPSimpleStrategy.sol
417:     function _distribute(address[] memory, bytes memory, address _sender)
418:         internal
419:         virtual
420:         override
421:         onlyInactivePool
422:         onlyPoolManager(_sender)
423:     {
...
...
433: 
434:         // Calculate the amount to be distributed for the milestone
435:         uint256 amount = (recipient.proposalBid * milestone.amountPercentage) / 1e18;
436: 
437:         // Get the pool, subtract the amount and transfer to the recipient
438:         poolAmount -= amount;
439:         _transferAmount(pool.token, recipient.recipientAddress, amount);
...
...
450:     }

The malicious accepted registrant can drain all funds from the pool strategy using one milestone.

Code Snippet

Tool used

Manual review

Recommendation

Verify the proposalBid when the _allocate() occurs:

Diff
    function _allocate(bytes memory _data, address _sender)
        internal
        virtual
        override
        nonReentrant
        onlyActivePool
        onlyPoolManager(_sender)
    {
        // Decode the '_data'
--      acceptedRecipientId = abi.decode(_data, (address));
++      (acceptedRecipientId, uint256 expectedProposalBid) = abi.decode(_data, (address, uint256));

        Recipient storage recipient = _recipients[acceptedRecipientId];

--      if (acceptedRecipientId == address(0) || recipient.recipientStatus != Status.Pending) {
++      if (acceptedRecipientId == address(0) || recipient.recipientStatus != Status.Pending || recipient.proposalBid != expectedProposalBid) {
            revert RECIPIENT_ERROR(acceptedRecipientId);
        }

        // Update status of acceptedRecipientId to accepted
        recipient.recipientStatus = Status.Accepted;

        _setPoolActive(false);

        IAllo.Pool memory pool = allo.getPool(poolId);

        // Emit event for the allocation
        emit Allocated(acceptedRecipientId, recipient.proposalBid, pool.token, _sender);
    }

Discussion

thelostone-mc

Yup this does feel safer. The only downside is that the pool manager could now put in a big lower than what was proposed by the recipient but this seems alright as the pool manager is a trusted actor

kadenzipfel

Escalate This is simply a less severe version of frontrunning _distribute by flipping the unprotected setPoolActive flag, as described in https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/458.

There are two directions which may be reasonable in reclassifying this:

  1. Reduce the severity to medium since the pool manager can become aware of this attack vector and not fulfill distributions for attackers (note that there is a withdraw function and thus not all funds must be distributed). This is inline with the medium severity classifications as, "There is a viable scenario (even if unlikely) that could cause the protocol to enter a state where a material amount of funds can be lost." Whereas for https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/458, the high severity classification of, "This vulnerability would result in a material loss of funds" is true because the pool manager cannot prevent distribution after already submitting the transaction.

  2. If however, this vulnerability is maintained as high severity (which I would disagree with), it should be duplicated with https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/458 as they are both fundamentally the same attack vector, although this one is less significant.

sherlock-admin2

Escalate This is simply a less severe version of frontrunning _distribute by flipping the unprotected setPoolActive flag, as described in https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/458.

There are two directions which may be reasonable in reclassifying this:

  1. Reduce the severity to medium since the pool manager can become aware of this attack vector and not fulfill distributions for attackers (note that there is a withdraw function and thus not all funds must be distributed). This is inline with the medium severity classifications as, "There is a viable scenario (even if unlikely) that could cause the protocol to enter a state where a material amount of funds can be lost." Whereas for https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/458, the high severity classification of, "This vulnerability would result in a material loss of funds" is true because the pool manager cannot prevent distribution after already submitting the transaction.

  2. If however, this vulnerability is maintained as high severity (which I would disagree with), it should be duplicated with https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/458 as they are both fundamentally the same attack vector, although this one is less significant.

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.

jkoppel

Similar attack vector, different issue. Fixing #458 does not fix this. The proposed fix of this issue has no impact on #458. See #378 for a way to use this attack which is far harder to defend against.

neeksec

Side with @jkoppel and sugguest to keep the orginal judging.

jacksanford1

https://github.com/allo-protocol/allo-v2/pull/346

Evert0x

Planning to reject escalation and keep issue state as is.

Evert0x

Result: High Has Duplicates

sherlock-admin2

Escalations have been resolved successfully!

Escalation status:

jack-the-pug

Fixed.

A better fix would be to make it impossible to change the proposal once it is in the allocation stage: https://github.com/sherlock-audit/2023-09-Gitcoin-judging/issues/657

The original report as published on Sherlock, by 0xbepresent. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

The allocation function does not verify that the proposal bid matches the value the manager intended to accept, allowing it to be changed via front-running.

Impact

The malicious registrant could receive a larger payout during distribution, potentially draining all funds from the pool strategy using one milestone.

What the attacker needed

Malicious registrant; pool manager allocates to that registrant; front-running capability

The fix

The allocation function should verify that the proposal bid matches an expected value provided by the pool manager.

How it was found

  1. UserA registers with a proposal bid of 10.
  2. Pool manager accepts UserA's proposal by calling the allocate function.
  3. UserA monitors the mempool and front-runs the manager's allocate call, changing the proposal bid to 50.
  4. The manager's allocate call executes, accepting the non-agreed bid of 50.

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 a smart contract, a registrant submits a bid to a pool. The pool manager later approves that bid by sending a transaction. Because transactions are visible before they are confirmed, the registrant can send their own transaction first to change the bid to a higher number. The manager's approval then applies to the higher bid, so the registrant gets paid more than agreed.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by 0xbepresent

View all

13 more disclosed reports, best first.

More from Allo V2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.