Skip to content
Business logic Audit finding Intermediate

Wound agent can't invoke heal in the next round

A smart contract's heal function compared the current round with the round an agent was wounded using a threshold of two instead of one, so a wounded agent could not be healed in the immediately following round. An attacker could not gain anything directly, but affected players had to wait an extra round, lowering their chance of a successful heal.

coffiasd Follow with lil.eth, mstpr-brainbot and 1 other

Originally disclosed on Sherlock

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

Found by

coffiasd, lil.eth, mstpr-brainbot, pontifex According to the document:

if a user dies on round 12. The first round they can heal is round 13 However incorrect current round id check led to users being unable to invoke the heal function in the next round.

Vulnerability Detail

Assume players being marked as wounded in the round 12 , players cannot invoke heal in the next round 13

Solidity
    function test_heal_in_next_round_v1() public {
        _startGameAndDrawOneRound();

        _drawXRounds(11);


        (uint256[] memory woundedAgentIds, ) = infiltration.getRoundInfo({roundId: 12});

        address agentOwner = _ownerOf(woundedAgentIds[0]);
        looks.mint(agentOwner, HEAL_BASE_COST);

        vm.startPrank(agentOwner);
        _grantLooksApprovals();
        looks.approve(TRANSFER_MANAGER, HEAL_BASE_COST);

        uint256[] memory agentIds = new uint256[](1);
        agentIds[0] = woundedAgentIds[0];

        uint256[] memory costs = new uint256[](1);
        costs[0] = HEAL_BASE_COST;

        //get gameInfo
        (,,,,,uint40 currentRoundId,,,,,) = infiltration.gameInfo();
        assert(currentRoundId == 13);

        //get agent Info
        IInfiltration.Agent memory agentInfo = infiltration.getAgent(woundedAgentIds[0]);
        assert(agentInfo.woundedAt == 12);

        //agent can't invoke heal in the next round.
        vm.expectRevert(IInfiltration.HealingMustWaitAtLeastOneRound.selector);
        infiltration.heal(agentIds);
    }

Impact

User have to wait for 1 more round which led to the odds for an Agent to heal successfully start at 99% at Round 1 reduce to 98% at Round 2.

Code Snippet

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

Solidity
    // No need to check if the heal deadline has passed as the agent would be killed
    unchecked {
        if (currentRoundId - woundedAt < 2) {
            revert HealingMustWaitAtLeastOneRound();
        }
    }

Tool used

Manual Review

Recommendation

Solidity
    // No need to check if the heal deadline has passed as the agent would be killed
    unchecked {
-       if (currentRoundId - woundedAt < 2) {
-       if (currentRoundId - woundedAt < 1) {
            revert HealingMustWaitAtLeastOneRound();
        }
    }

Discussion

nevillehuang

@0xhiroshi Any reason why you disagree with the severity? It does mentioned in the docs that the first round user can heal is right after the round his agent is wounded. The above PoC also shows how a user cannot heal a wounded agent at round 13 when his agent was wounded at round 12.

0xhiroshi

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

SergeKireev

Fix LGTM

The original report as published on Sherlock, by coffiasd. 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

Likely an off-by-one error: the check required the current round minus the wounded round to be at least two, when the documented rule only requires one round to have passed.

Impact

Players had to wait one extra round before healing, which reduced the chance of a successful heal from 99% in the first round to 98% in the second.

What the attacker needed

A wounded agent; enough game tokens to pay the heal cost

How it was found

  1. Start the game and draw one round, then draw eleven more rounds so that round 12 is reached.
  2. Read the round info for round 12 and take the id of a wounded agent.
  3. Give the agent's owner enough of the game token and approve the transfer manager.
  4. Confirm the current round is 13 and that the agent was wounded in round 12.
  5. Call the heal function for that agent and observe that it reverts with the wait error.

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.

This is a game contract where a player's agent can be wounded in one round and healed in a later round. The code that decides whether enough time has passed counted one round too many, so the heal button was refused when it should have worked. The result is a delay for the player, not a way for someone to steal funds.

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 coffiasd

View all

4 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.