Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Milad-Sha - Unsafe downcast #144

Closed
sherlock-admin opened this issue Nov 4, 2023 · 1 comment
Closed

Milad-Sha - Unsafe downcast #144

sherlock-admin opened this issue Nov 4, 2023 · 1 comment
Labels
Excluded Excluded by the judge without consulting the protocol or the senior Non-Reward This issue will not receive a payout

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Nov 4, 2023

Milad-Sha

medium

Unsafe downcast

Summary

When a type is downcast to a smaller type, the higher order bits are truncated

Vulnerability Detail

When a type is downcast to a smaller type, the higher order bits are truncated, effectively applying a modulo to the original value. Without any other checks, this wrapping will lead to unexpected behavior and bugs.

Solidity does not check if it is safe to cast an integer to a smaller one. Unless some business logic ensures that the downcasting is safe, a library like SafeCast should be used.

Impact

When a type is downcast to a smaller type, the higher order bits are truncated, effectively applying a modulo to the original value. Without any other checks, this wrapping will lead to unexpected behavior and bugs.

Code Snippet

https://github.com/sherlock-audit/2023-10-looksrare/blob/main/contracts-infiltration/contracts/Infiltration.sol?plain=1#L875

                healingAgentIds[currentHealingAgentIdsCount + i] = uint16(agentId);

https://github.com/sherlock-audit/2023-10-looksrare/blob/main/contracts-infiltration/contracts/Infiltration.sol?plain=1#L879

        healingAgentIds[0] = uint16(newHealingAgentIdsCount);

https://github.com/sherlock-audit/2023-10-looksrare/blob/main/contracts-infiltration/contracts/Infiltration.sol?plain=1#L512

        gameInfo.activeAgents = uint16(numberOfAgents);

Tool used

Manual Review

Recommendation

You can use the SafeCast library to prevent Unsafe downcast.

@github-actions github-actions bot closed this as completed Nov 6, 2023
@github-actions github-actions bot added the Excluded Excluded by the judge without consulting the protocol or the senior label Nov 6, 2023
@nevillehuang
Copy link
Collaborator

Near impossible for agent ids to be out of bounds/unsafely downcasted

@rcstanciu rcstanciu added the Has Duplicates A valid issue with 1+ other issues describing the same vulnerability label Nov 8, 2023
@sherlock-admin2 sherlock-admin2 changed the title Odd Berry Rabbit - Unsafe downcast Milad-Sha - Unsafe downcast Nov 9, 2023
@sherlock-admin2 sherlock-admin2 added Non-Reward This issue will not receive a payout and removed Has Duplicates A valid issue with 1+ other issues describing the same vulnerability labels Nov 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Excluded Excluded by the judge without consulting the protocol or the senior Non-Reward This issue will not receive a payout
Projects
None yet
Development

No branches or pull requests

4 participants