Skip to content
Business logic Audit finding Intermediate

Winning agent id may be uninitialized when game is over, locking grand prize

The winning agent's identifier in the Infiltration contract is only set when agents are swapped, so if the first agent is never swapped its identifier remains zero. This makes the grand prize unclaimable because the ownership check always fails for a zero identifier.

cergyk Follow with detectiveking

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-10-looksrare-judging/issues/31

Found by

cergyk, detectiveking In the Infiltration contract, the agents mapping holds all of the agents structs, and encodes the ranking of the agents (used to determine prizes at the end of the game).

This mapping records are lazily initialized when two agents are swapped (an agent is either killed or escapes):

  • The removed agent goes to the end of currently alive agents array with the status Killed/Escaped and its agentId is set
  • The last agent of the currently alive agents array is put in place of the previously removed agent and its agentId is set

This is the only moment when the agentId of an agent record is set.

This means that if the first agent in the array ends up never being swapped, it keeps its agentId as zero, and the grand prize is unclaimable.

Vulnerability Detail

We can see in the implementation of claimGrandPrize that: https://github.com/sherlock-audit/2023-10-looksrare/blob/main/contracts-infiltration/contracts/Infiltration.sol#L658

The field Agent.agentId of the struct is used to determine if the caller can claim. Since the id is zero, and it is and invalid id for an agent, there is no owner for it and the condition:

https://github.com/sherlock-audit/2023-10-looksrare/blob/main/contracts-infiltration/contracts/Infiltration.sol#L1666-L1670

Always reverts.

Impact

The grand prize ends up locked/unclaimable by the winner

Code Snippet

Tool used

Manual Review

Recommendation

In claimGrandPrize use 1 as the default if agents[1].agentId == 0:

Diff
function claimGrandPrize() external nonReentrant {
    _assertGameOver();
    uint256 agentId = agents[1].agentId;
+   if (agentId == 0)
+       agentId = 1;
    _assertAgentOwnership(agentId);

    uint256 prizePool = gameInfo.prizePool;

    if (prizePool == 0) {
        revert NothingToClaim();
    }

    gameInfo.prizePool = 0;

    _transferETHAndWrapIfFailWithGasLimit(WETH, msg.sender, prizePool, gasleft());

    emit PrizeClaimed(agentId, address(0), prizePool);
}

Discussion

0xhiroshi

https://github.com/LooksRare/contracts-infiltration/pull/153

0xhiroshi

https://github.com/LooksRare/contracts-infiltration/pull/178

@nevillehuang

SergeKireev

Fix LGTM

The original report as published on Sherlock, by cergyk. 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 agentId field is lazily initialised only during swaps, so the first agent's record can remain at the default zero value.

Impact

The grand prize could be permanently locked and unclaimable by the winner.

What the attacker needed

Game reaches completion; first agent never swapped

The fix

The contract was fixed by treating a zero agentId as agent 1 in claimGrandPrize, as shown in the linked pull requests.

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 contract, each agent has a number that says who owns it. That number is only filled in when an agent is removed and another takes its place. If the top agent is never removed, its number stays at zero, which is not a real owner, so the winner cannot prove ownership and cannot collect 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.

More by cergyk

View all

29 more disclosed reports, best first.

More from LooksRare YOLO

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.