Skip to content
Smart contracts Audit finding Intermediate

Unsafe Downcast vulnerability this can lead to

The queueRewardTransaction function in RewardTimelock.sol narrows a uint256 dollar amount to uint40, which can silently truncate values above the uint40 maximum. The author claims this could queue transactions with incorrect amounts and lead to loss of funds, though no working exploit is shown.

Enc3yptedDegenExt Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

29341 - [SC - Insight] Unsafe Downcast vulnerability this can lead to ...

Submitted on Mar 14th 2024 at 12:29:16 UTC by @Enc3yptedDegenExt for Boost | Immunefi Arbitration

Report ID: #29341

Report type: Smart Contract

Report severity: Insight

Target: https://github.com/immunefi-team/vaults/blob/main/src/RewardTimelock.sol

Impacts:

  • Unsafe Downcast vulnerability

Description

Brief/Intro

In Solidity, as in many other typed programming languages, a developer may (attempt to) cast between types in their code. Solidity offers many variants of certain built-in types at different bit widths (for example, uint8 vs. uint256), and it is possible to cast between these. However, a narrowing type cast (from a higher to a lower bit width) may inadvertently truncate bits and cause the value after the cast to not be equivalent to that before the cast. This can lead to inadvertent logical errors in smart contract execution.

Vulnerability Details

The vulnerability exists in the queueRewardTransaction function of the src/RewardTimelock.sol contract, where a uint256 variable dollarAmount is narrowed downcast to uint40. This downcast can lead to a silent overflow if dollarAmount exceeds the maximum value that uint40 can hold (2^40 - 1). The overflow can result in unexpected behavior, potentially leading to incorrect storage or processing of the dollarAmount

Impact Details

The silent overflow can lead to incorrect handling of dollarAmount within the RewardTimelock.sol contract. This could result in transactions being queued with incorrect amounts, potentially leading to loss of funds or other unintended consequences. The vulnerability could also be exploited to manipulate the contract's state in ways not intended by the developers.

References

Solidity Documentation: Type casting (https://docs.soliditylang.org/en/v0.8.18/types.html#type-casting)

Proof of Concept

Add this below code after line no 69

require(dollarAmount <= type(uint40).max, "dollarAmount exceeds uint40 max value");

The original report as published on Immunefi, by Enc3yptedDegenExt. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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 a narrowing cast from uint256 to uint40 without a bounds check, so values above the uint40 maximum are silently truncated.

Impact

The text claims queued transactions could carry incorrect amounts, potentially causing loss of funds, but it gives no demonstration and the suggested check is only a code snippet, not a reproduction.

What the attacker needed

Ability to call queueRewardTransaction; dollar amount above uint40 maximum

The fix

The author suggests adding a require statement that rejects any dollar amount above the uint40 maximum before the cast.

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.

Solidity numbers come in fixed sizes, and a uint40 can only hold values up to about one trillion. If you force a bigger number into a smaller slot, the extra bits are quietly dropped, so the stored value is not the one you started with. The report says the contract does this with a dollar amount without checking the size first.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More from Immunefi Arbitration

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.