Skip to content

Unsafe Type Casting / Downcast Truncation

SAFE-0030 Arithmetic Checked automatically by the scanner
1

What goes wrong

Casting a larger integer to a smaller type (uint256->uint128/uint64) silently truncates high-order bits, corrupting amounts, timestamps, or IDs.

2

How to fix it

the pattern that is safe
using SafeCast for uint256;
uint128 amt = amount256.toUint128();  // reverts on overflow
Use OpenZeppelin SafeCast.
Check your own contract for this

The SaferICO scanner runs 201 detectors over your Solidity source, SAFE-0030 among them. Paste an address or the source itself — a small per-scan fee, shown before you sign, or unlimited on any plan.

Run the scanner See how it is attacked Read the docs