sherlock-audit / 2023-12-avail-judging

4 stars 4 forks source link

0xC - Integer Overflow in `sendETH` Function #91

Closed sherlock-admin closed 8 months ago

sherlock-admin commented 8 months ago

0xC

high

Integer Overflow in sendETH Function

Summary

The sendETH function in the smart contract contains a potential integer overflow vulnerability when typecasting a uint256 value to a uint64. This vulnerability could allow an attacker to exploit the contract when the id becomes too large, resulting in unintended behavior or manipulation of the contract state.

Vulnerability Detail

The id variable is initially declared as uint256, which means it can potentially exceed the maximum value that a uint64 can hold. When an overflow occurs during this typecasting, it can lead to unexpected behavior and security risks.

Impact

If an attacker successfully triggers the integer overflow in the sendETH function, it can have several adverse consequences:

  1. Data Corruption: An overflowed id may lead to data corruption within the contract or unintended data storage in the isSent mapping.

  2. Manipulation: An attacker could potentially manipulate the contract's state or disrupt its normal operation.

  3. Financial Loss: Depending on how the contract uses id, an overflow could result in financial losses for users or unintended transfers of funds.

Code Snippet

Here is the relevant code snippet from the sendETH function:

https://github.com/sherlock-audit/2023-12-avail/blob/main/contracts/src/AvailBridge.sol#L368

Tool used

Manual Review

Recommendation

To address the integer overflow vulnerability in the sendETH function, consider the following recommendations:

  1. Validate Inputs: Implement input validation to ensure that the id does not exceed the maximum value that can be represented by a uint64. This can be done by checking if the id is within the valid range before performing the typecast.

  2. Safe Casting: Use a safe typecasting method, such as the SafeMath library, to ensure that typecasting from uint256 to uint64 does not result in an integer overflow.

  3. Comprehensive Testing: Thoroughly test the contract with various scenarios to verify that the vulnerability has been effectively mitigated.

By implementing these recommendations, you can enhance the security and reliability of the smart contract, reducing the risk of potential exploits related to integer overflows.

sherlock-admin commented 8 months ago

1 comment(s) were left on this issue during the judging contest.

takarez commented:

invalid because { invalid: no impact}