sherlock-audit / 2023-10-looksrare-judging

6 stars 6 forks source link

pontifex - Users have no option to heal agents with probability 99 percents #49

Closed sherlock-admin2 closed 1 year ago

sherlock-admin2 commented 1 year ago

pontifex

medium

Users have no option to heal agents with probability 99 percents

Summary

Due to check at the line L#844 of the Infiltration contract users have no option to heal agents at the first round after they are wounded. The healing probability can be decreased faster depending on the amount of rounds before the agent dies (ROUNDS_TO_BE_WOUNDED_BEFORE_DEAD). The shortest possible period before an agent dies is 3 rounds. So the probability can decrease dramatically to the second round after wounding.

Vulnerability Detail

Depends on how early the user decided to heal a wounded agent the probability of success of the agent healing is from 99% (the first round since wounding) to 80% (the last round before the agent will be killed):

1004     * Maximum_Heal_Percentage - the maximum % chance a user can heal for, this will be if they heal in Heal_Rounds_Minimum (we have set this to 99% of a successful healing) - this is y1
1005     * Minimum_Heal_Percentage - the minimum % chance a user can heal for, this will be if they heal in Heal_Rounds_Maximum (we have set this to 80% of a successful healing) - this is y2

1019    function healProbability(uint256 healingBlocksDelay) public view returns (uint256 y) {
1020        if (healingBlocksDelay == 0 || healingBlocksDelay > ROUNDS_TO_BE_WOUNDED_BEFORE_DEAD) {
1021            revert InvalidHealingBlocksDelay();
1022        }
1023
1024        y =
1025            HEAL_PROBABILITY_MINUEND -
1026            ((healingBlocksDelay * 19) * PROBABILITY_PRECISION) /
1027            ROUNDS_TO_BE_WOUNDED_BEFORE_DEAD_MINUS_ONE;
1028    }

The healingBlocksDelay parameter is the amount of rounds since the agent was wounded. So if the amount equals 1 the probability of successful healing is 99%. But due to the check at the heal function users can't heal agents at the first round after wounding:

844                if (currentRoundId - woundedAt < 2) {
845                    revert HealingMustWaitAtLeastOneRound();
846                }

Impact

Users have no option to heal agents with maximal probability but should have.

Code Snippet

https://github.com/sherlock-audit/2023-10-looksrare/blob/86e8a3a6d7880af0dc2ca03bf3eb31bc0a10a552/contracts-infiltration/contracts/Infiltration.sol#L844-L845 https://github.com/sherlock-audit/2023-10-looksrare/blob/86e8a3a6d7880af0dc2ca03bf3eb31bc0a10a552/contracts-infiltration/contracts/Infiltration.sol#L1014-L1028

Tool used

Manual Review

Recommendation

Consider using 1 instead of 2 in the check:

-               if (currentRoundId - woundedAt < 2) {
+               if (currentRoundId - woundedAt < 1) {
                    revert HealingMustWaitAtLeastOneRound();
                }

Duplicate of #44

nevillehuang commented 1 year ago

invalid recommendation, completely changes formula, no example to display impact of finding