GroupBuy can be drained of all ETH.
The purchase function in GroupBuy lacks re-entrancy protection and sets the success flag only after an external call, allowing an attacker to re-enter and drain all ETH from the contract.
Submitted by Trust, also found by Lambda
purchase() in GroupBuy faciilitates the purchasing of an NFT after enough contributions were gathered. Another report titled “Attacker can steal the amount collected so far in the GroupBuy for NFT purchase” describes a high impact bug in purchase. It is advised to read that first for context.
Additionally, purchase() is vulnerable to a re-entrancy exploit which can be chained or not chained to the \_market issue to steal the entire ETH stored in GroupBuy, rather than being capped to minReservePrices[_poolId] * filledQuantities[_poolId].
Attacker may take control of execution using this call:
// Executes purchase order transaction through market buyer contract and deploys new vault
address vault = IMarketBuyer(_market).execute{value: _price}(_purchaseOrder);
It could occur either by exploiting the unvalidated \_market vulnerability , or by abusing an existing market that uses a user address in \_purchaseOrder.
There is no re-entrancy protection in purchase() call:
function purchase(
uint256 _poolId,
address _market,
address _nftContract,
uint256 _tokenId,
uint256 _price,
bytes memory _purchaseOrder,
bytes32[] memory _purchaseProof
) external {
\_verifyUnsuccessfulState() needs to not revert for purchase call. It checks the pool.success flag: if (pool.success || block.timestamp > pool.terminationPeriod) revert InvalidState();
However, success is only set as the last thing in purchase():
// Stores mapping value of poolId to newly deployed vault
poolToVault[_poolId] = vault;
// Sets pool state to successful
poolInfo[_poolId].success = true;
// Emits event for purchasing NFT at given price
emit Purchase(_poolId, vault, _nftContract, _tokenId, _price);
}
Therefore, attacker can re-enter purchase() function multiple times, each time extracting the maximum allowed price. If attacker uses the controlled \_market exploit, the function will return the current NFT owner, so when all the functions unwind they will keep setting success to true and exit nicely.
Impact
GroupBuy can be drained of all ETH.
Proof of Concept
-
GroupBuy holds 1500 ETH, from various bids
-
maximum allowed price (
minReservePrices[_poolId] * filledQuantities[_poolId]) is 50 * 20 = 1000 ETH -
purchase(1000 ETH) is called
-
GroupBuy sends attacker 1000 ETH and calls
execute()-
execute()calls purchase(500ETH)-
GroupBuy sends attacker 500 ETH and calls
execute()- execute returns NFT owner address
-
GroupBuy sees returned address is NFT owner. Marks success and returns
-
-
execute returns NFT owner address
-
-
GroupBuy sees returned address is NFT owner. Marks success and returns
-
-
Attacker is left with 1500 ETH. Previous exploit alone can only net 1000ETH. Additionally, this exploit can be chained to any trusted MarketBuyer which passes control to user for purchasing and storing in vault, and then returns a valid vault.
Recommended Mitigation Steps
Add a re-entrancy guard to purchase() function. Also, change success variable before performing external contract calls.
mehtaculous (Tessera) confirmed and commented:
Agree with High severity. Instead of adding
re-entrancytag topurchasefunction, pool state simply needs to be updated tosuccessbefore execution.In regards to:
or by abusing an existing market that uses a user address in _purchaseOrder.
This is not considered an issue since users will most likely NOT contribute to a pool where they are not familiar with the NFT and / or contract. Since the NFT contract is set when the pool is created, it should not matter whether the contract is malicious or is for an existing market that uses a user address, the pool will just be disregarded.
stevennevins (Tessera) mitigated:
https://github.com/fractional-company/modular-fractional/pull/201
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 purchase function makes an external call before updating the pool's success state, and it lacks a re-entrancy guard.
What the attacker needed
A GroupBuy pool with ETH contributions; ability to trigger purchase with a malicious market or…
The fix
The fix was to update the pool state to success before making the external call, as confirmed by the mitigation.
How it was found
- GroupBuy holds 1500 ETH from various bids.
- The maximum allowed price is calculated as 1000 ETH.
- purchase(1000 ETH) is called.
- GroupBuy sends 1000 ETH and calls execute(), which re-enters purchase(500 ETH).
- The inner purchase sends 500 ETH and calls execute(), which returns the NFT owner address.
- The inner purchase marks success and returns, then the outer purchase marks success and returns, leaving the attacker with 1500 ETH.
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.
A re-entrancy attack happens when a contract calls another contract before updating its own records. The attacker's contract can call back into the original function repeatedly, each time taking funds, because the contract still thinks the first operation is not finished.
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.