Flow

Sablier
FoundryDeFi
20,000 USDC
View results
Submission Details
Severity: low
Invalid

Flow Audit Report (by coinleft)

Overview

This report examines three functions for potential vulnerabilities, specifically focusing on overflow/underflow risks and missing validation checks. The issues found and recommendations provided aim to improve the security and reliability of the contract.


1. Function: descaleAmount

function descaleAmount(uint256 amount, uint8 decimals) internal pure returns (uint256) {
if (decimals == 18) {
return amount;
}
unchecked {
uint256 scaleFactor = 10 ** (18 - decimals);
return amount / scaleFactor;
}
}

Issue: Potential Underflow

Severity: Medium

Description: While the current implementation of this function may assume that decimals is validated at other points in code, this assumption is dangerous given that scaleAmount is written as a generalized library function, designed for flexible reuse. Without a built-in guard in the function itself, contexts where decimals is unchecked can lead to an overflow when decimals is greater than 18. This overflow occurs due to a negative exponent, resulting in an unintended large output that can break contract logic and undermine reliability in systems relying on this library.

Recommendation:
Add a validation to ensure decimals is no greater than 18, preventing the underflow scenario:

if (decimals >= 18) { return amount;}

Adding this validation will mitigate the risk of underflow and maintain function integrity.


2. Function: scaleAmount

function scaleAmount(uint256 amount, uint8 decimals) internal pure returns (uint256) {
if (decimals == 18) {
return amount;
}
unchecked {
uint256 scaleFactor = 10 ** (18 - decimals);
return amount * scaleFactor;
}
}

Issue: Potential Underflow and Overflow

Severity: Medium

Description: This function is intended to scale an amount from a given decimals precision to 18 decimals. However, if decimals > 18, the calculation 10 ** (18 - decimals) underflows, which can cause scaleFactor to wrap to a large value. This unintended value can then lead to an overflow when multiplying by amount, producing an inaccurate and extremely large output.

Recommendation:
Add a validation to ensure decimals does not exceed 18:

if (decimals >= 18) { return amount;}

This will prevent underflow and overflow scenarios by ensuring decimals stays within an appropriate range.


3. Function: transferAdmin

function transferAdmin(address newAdmin) public virtual override onlyAdmin {
// Effect: update the admin.
admin = newAdmin;
// Log the transfer of the admin.
emit IAdminable.TransferAdmin({ oldAdmin: msg.sender, newAdmin: newAdmin });
}

Issue: Missing Zero-Address Check

Severity: Medium

Description: The transferAdmin function does not check if newAdmin is the zero address (address(0)). Assigning the zero address as an admin can unintentionally lock administrative actions, making the contract unmanageable.

Recommendation:
Add a check to ensure newAdmin is not the zero address:

require(newAdmin != address(0), "New admin cannot be the zero address");

Implementing this check ensures that the admin role is always assigned to a valid address, preventing potential loss of control over the contract.


Conclusion

This audit highlights underflow and overflow vulnerabilities in the scaling functions and a missing validation in the transferAdmin function. Addressing these issues by implementing the recommended checks will enhance the contract’s security and maintainability.

Updates

Lead Judging Commences

inallhonesty Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

[Invalid] Tokens with decimals > 18

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.