Back to Blog7 min read
Hack Autopsy

Truebit Integer Overflow Autopsy: How Silent Math Breaks Smart Contracts

Integer overflow doesn't throw an error — it silently wraps numbers to zero. We dissect how this classic vulnerability hit Truebit and why it still kills contracts today.

Published: October 16, 2026
7 min read
4 views
✓ Written by blockchain developers·✓ Reviewed for technical accuracy
Truebit Integer Overflow Autopsy: How Silent Math Breaks Smart Contracts

What Is Integer Overflow and Why Does It Happen in Smart Contracts?

Integer overflow is not a new vulnerability. It existed in C programs in the 1980s, crashed satellites, and corrupted financial systems long before blockchain existed. In smart contracts, it is uniquely dangerous because there is no runtime exception — no error log, no revert, no alert. The math silently produces the wrong answer, and funds move accordingly.

In Solidity versions below 0.8.0, every integer type has a hard boundary. A uint256 holds values from 0 to 2²⁵⁶−1. A uint8 holds 0 to 255. When a calculation pushes past that boundary, the value wraps around — back to zero on overflow, or up to the maximum on underflow. No exception. No warning. Just wrong math executed on an immutable ledger with real money behind it.

// Solidity <0.8.0 — DANGEROUS
uint8 x = 255;
x = x + 1;
// x is now 0, not 256

uint8 balance = 0;
balance = balance - 1;
// balance is now 255 — attacker minted value from nothing

This is the vulnerability class that hit Truebit — and it remains one of the most frequently detected issues in the Blockhertz free AI smart contract auditor. Integer overflow ranks among the top three vulnerability types found in deployed EVM contracts, alongside reentrancy and oracle manipulation.

What Happened to Truebit? The Integer Overflow Incident Explained

Truebit is an Ethereum-based computation verification protocol designed to let smart contracts outsource heavy computation off-chain while retaining on-chain verifiability. The protocol was technically ambitious, peer-reviewed, and well-funded — not the profile of a project you would expect to fall to a basic arithmetic bug.

The vulnerability lived in the token contract. Arithmetic operations on token balances were performed without overflow protection. An attacker identified a code path where a crafted transaction could push an unsigned integer past its minimum value, wrapping it to near-maximum. This corrupted internal balance accounting without triggering a revert or emitting any error signal.

The attacker used the underflow path to effectively erase their own debt — borrowing against inflated balances and exiting with funds the protocol believed were still secured as collateral. The contract had no SafeMath library and was compiled on a Solidity version with no built-in arithmetic guards.

The root cause was a misunderstanding of where responsibility for safe arithmetic sat. Before Solidity 0.8.0, overflow protection was entirely the developer's job — the compiler offered no safety net. That is an unusual contract for a programming language to make with its users, and experienced engineers regularly missed it.

For a different attack class — where an attacker manipulates external price data rather than internal math — read our Nostra Finance oracle manipulation autopsy, where $3.5M was drained from Starknet's largest lending protocol in 78 minutes.

Vulnerable vs Safe Code: Integer Overflow in Solidity

Vulnerable — Pre-0.8.0 without SafeMath:

// VULNERABLE — Solidity <0.8.0
pragma solidity ^0.6.0;

contract VulnerableToken {
    mapping(address => uint256) public balances;

    function transfer(address to, uint256 amount) public {
        // If balances[msg.sender] < amount, this wraps to a huge number
        balances[msg.sender] -= amount;
        balances[to] += amount;
    }
}

Safe — Using OpenZeppelin SafeMath (pre-0.8.0 fix):

// SAFE — with OpenZeppelin SafeMath
pragma solidity ^0.6.0;
import "@openzeppelin/contracts/math/SafeMath.sol";

contract SafeToken {
    using SafeMath for uint256;
    mapping(address => uint256) public balances;

    function transfer(address to, uint256 amount) public {
        balances[msg.sender] = balances[msg.sender].sub(amount);
        balances[to] = balances[to].add(amount);
        // .sub() reverts on underflow — no silent wrap
    }
}

Safe — Solidity 0.8.0+ built-in checks:

// SAFE — Solidity 0.8.0 and above
pragma solidity ^0.8.0;

contract SafeToken {
    mapping(address => uint256) public balances;

    function transfer(address to, uint256 amount) public {
        balances[msg.sender] -= amount; // Auto-reverts on underflow
        balances[to] += amount;         // Auto-reverts on overflow
    }
}

⚠️ The unchecked{} trap — re-introducing overflow in Solidity 0.8.x:

// DANGEROUS — unchecked block disables overflow protection
pragma solidity ^0.8.0;

contract GasOptimizedButDangerous {
    mapping(address => uint256) public balances;

    function transfer(address to, uint256 amount) public {
        unchecked {
            // Overflow checks are OFF inside this block
            // Gas saved — but silent wrap is back
            balances[msg.sender] -= amount;
            balances[to] += amount;
        }
    }
}

The unchecked{} block is safe for loop counters. It is dangerous on any arithmetic that touches balances, debt, rewards, or fees. Many developers copy the pattern from gas-optimisation guides without realising the scope of what they are disabling. The Blockhertz AI auditor flags unchecked blocks wrapping financial logic as a High severity finding.

For gas savings that do not introduce security risk, see the Blockhertz Gas Optimizer — it identifies safe optimisations without compromising arithmetic safety.

What Does the Blockhertz AI Auditor Detect for Integer Overflow?

The Blockhertz AI smart contract auditor analyses your Solidity code statically and flags integer overflow patterns across all severity levels. Here is what it catches and what falls outside its scope:

Vulnerability Pattern Blockhertz AI Auditor
Arithmetic without SafeMath on Solidity <0.8.0 ✅ Detected — Critical
unchecked{} blocks wrapping balance or debt arithmetic ✅ Detected — High
Subtraction on uint that can reach zero ✅ Detected — High
Multiplication before division causing precision loss ✅ Detected — Medium
Loop counters with unchecked increment ✅ Detected — Low (context-aware)
Type casting from uint256 to smaller uint ✅ Detected — Medium
Off-chain calculation errors feeding on-chain state ❌ Outside scope — not in submitted code
Overflow in attacker-deployed contracts ❌ Outside scope — external contract not submitted

Audit your contract free — no signup, no credit card, results in under 60 seconds: blockhertz.com/tools/ai-auditor

What No Automated Smart Contract Auditor Can Catch

Every automated auditor — including Blockhertz — analyses the code submitted. It cannot reason about what it cannot see. Three categories fall outside any static analyser's reach:

  • Off-chain logic feeding on-chain state. If your backend calculates a value and passes it to a contract via a transaction, the auditor never sees that calculation. An overflow in your server-side arithmetic produces a corrupted input that the contract trusts unconditionally.
  • Attacker-deployed contracts. If exploitation requires the attacker to deploy their own contract to trigger a specific interaction path, that contract is not in scope at audit time.
  • Emergent behaviour across protocol integrations. A contract that is arithmetically safe in isolation can behave unsafely when composed with an external protocol that makes assumptions about your integer ranges or token decimal precision.

The solution is layered security: automated audit first, manual review of integration boundaries second, economic attack simulation third. The Blockhertz AI auditor is the fastest first layer — use it on every compile before any manual review begins. If you use Hardhat, the Blockhertz Hardhat Plugin runs this check automatically on every build.

Integer Overflow Security Checklist for Solidity Developers

  • ✅ Use Solidity 0.8.0 or above for all new contracts — built-in overflow protection is non-negotiable
  • ✅ Audit every unchecked{} block — restrict to loop counters only, never balance, debt, reward, or fee arithmetic
  • ✅ Use OpenZeppelin SafeMath if maintaining any legacy <0.8.0 contract still on mainnet
  • ✅ Review all explicit type casts — casting uint256 to uint128 or lower silently truncates large values
  • ✅ Always multiply before dividing — division before multiplication causes precision loss that compounds over time
  • ✅ Test arithmetic edge cases explicitly — max uint256, zero balances, back-to-back large transfers
  • ✅ Use OpenZeppelin ERC20 for token contracts — its transfer logic is battle-tested and overflow-safe
  • ✅ Run the Blockhertz AI Auditor before every deployment — free, 60 seconds, no signup

How Much Has Been Lost to Integer Overflow in DeFi History?

Integer overflow is not a theoretical risk. It has drained hundreds of millions of dollars from production contracts across every major EVM chain:

Protocol Year Loss Overflow Type
Beauty Chain (BEC) 2018 ~$900M market cap wiped Multiplication overflow — unlimited token mint
SmartMesh (SMT) 2018 ~$140M market cap wiped batchTransfer overflow — same pattern as BEC
Truebit 2019 Undisclosed Underflow on token balance — debt reduced to zero
Uranium Finance 2021 $57M Balance check overflow — swap contract fully drained
Meter.io Bridge 2022 $4.4M Unchecked arithmetic in bridge deposit handler
Chainge Finance 2023 $600K Integer overflow in cross-chain swap router

The BEC and SMT incidents triggered the industry-wide adoption of SafeMath as a default. Solidity 0.8.0 in 2020 moved that protection into the compiler. Yet Meter.io and Chainge Finance — both post-0.8.0 era protocols — were still exploited via overflow paths introduced by unchecked{} blocks and unsafe type casting. The version bump closed the default door; it did not close all doors.

The Real Lesson From the Truebit Vulnerability

Truebit was not hacked because its developers were careless. It was hacked because a responsibility boundary was invisible. Before Solidity 0.8.0, overflow protection was the developer's job — not the compiler's, not the EVM's. Most developers coming from higher-level languages had never had to think about this. The language did not make the expectation clear, the tooling did not enforce it, and auditors at the time had fewer automated checks to catch it.

Today the compiler protects you by default. But unchecked{} blocks, type casts, and legacy codebases create exactly the same invisible boundary — and developers are still crossing it without realising.

Arithmetic is the foundation of every financial contract. One silent wrap on a balance subtraction and the foundation cracks. The fix costs nothing. Run your contracts through the Blockhertz AI Auditor — free, 60 seconds, catches integer overflow before it reaches mainnet.

Also in this series: Nostra Finance — How a $3.5M Oracle Manipulation Drained Starknet in 78 Minutes.

Frequently Asked Questions

What is integer overflow in Solidity?

Integer overflow in Solidity occurs when an arithmetic operation produces a result outside the range of the integer type used. In Solidity below 0.8.0, the value wraps silently — a uint8 at 255 incremented by 1 becomes 0 with no error thrown. Attackers exploit this to inflate balances, erase debts, or mint unlimited tokens. Solidity 0.8.0 added automatic revert on overflow, but the risk reappears inside unchecked{} blocks.

Does Solidity 0.8.0 fix integer overflow completely?

Solidity 0.8.0 adds built-in overflow and underflow checks that automatically revert any transaction that would wrap an integer. This eliminates the default risk. However, the unchecked{} block introduced in the same version disables those checks for gas optimisation — any arithmetic inside an unchecked block has the same overflow risk as pre-0.8.0 code. Explicit type casting from larger to smaller integer types also bypasses these protections.

Does the Blockhertz AI Auditor detect integer overflow?

Yes. The Blockhertz AI Auditor detects unsafe arithmetic in Solidity below 0.8.0, flags unchecked{} blocks wrapping financial logic, identifies subtraction on unsigned integers that can underflow, and catches precision loss from division-before-multiplication patterns. Audit your contract free in 60 seconds — no signup required.

What is the unchecked block risk in Solidity 0.8.x?

The unchecked{} block was introduced in Solidity 0.8.0 to allow developers to skip overflow checks on operations where overflow is mathematically impossible — typically loop counters — to save gas. The danger is applying it to financial arithmetic: balance subtractions, debt calculations, reward distributions, fee logic. Inside an unchecked block, these operations wrap silently, exactly as they did in pre-0.8.0 Solidity. The Blockhertz AI Auditor flags this pattern as a High severity finding.

References

Related Articles

Resource Hub

Explore all articles →

Browse every guide on the Blockhertz blog

📚

Views

4

Read Time

7 min read

Likes

0

Published

Oct 16, 2026

Integer OverflowSmart Contract SecurityHack AutopsyTruebitSolidityEVM SecurityWeb3 SecurityDeFi Vulnerabilities
Integer OverflowSmart Contract SecurityHack AutopsyTruebitSolidityEVM SecurityWeb3 SecurityDeFi Vulnerabilities

SIGNAL THREAD

00 SIGNALS

NO SIGNALS YET — BE FIRST TO TRANSMIT

Muhammad Asif

Senior Blockchain Developer & Founder, Blockhertz

Blockchain developer and security engineer with 8+ years of experience. Founded Blockhertz in 2018 to build AI-powered tools for Web3 teams — smart contract auditing, architecture generation, gas optimization, and RWA tokenization platforms. Serving clients worldwide.