integer-overflow

Identify and explain integer overflow and underflow risks in Solidity 0.8+ code.

120|12|Updated Apr 10, 2026
One-click install
npx skills add https://github.com/ccashwell/evm-cortex --skill integer-overflow
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: integer-overflow
Source: https://github.com/ccashwell/evm-cortex/tree/main/skills/integer-overflow
Command: npx skills add https://github.com/ccashwell/evm-cortex --skill integer-overflow

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill provides integer safety patterns for Solidity 0.8+ to prevent overflow and underflow by default, including guidance on unchecked blocks, safe casting, and handling phantom overflow.

Core Features & Use Cases

  • Automatic checks in Solidity 0.8+ prevent common overflow errors.
  • Unchecked blocks for performance where overflow is mathematically impossible.
  • Phantom overflow patterns and safe casting using libraries like SafeCast or FixedPointMathLib.
  • Practical examples and best practices for avoiding truncation and integer edge cases.

Quick Start

Review a Solidity snippet and implement safe arithmetic patterns to eliminate overflow risks.

Frequently Asked Questions about integer-overflow

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How does Solidity 0.8+ handle integer overflow and underflow automatically?

Solidity 0.8+ handles integer overflow and underflow automatically by reverting transactions when arithmetic bounds are exceeded. This built-in checking prevents common overflow errors without external libraries, ensuring safe math operations by default across contracts.

When should I use unchecked blocks in Solidity arithmetic operations?

You should use unchecked blocks in Solidity when overflow is mathematically impossible, such as bounded loop increments. Unchecked blocks bypass automatic overflow checks to optimize gas performance where safe math outcomes are guaranteed by logic.

What is phantom overflow in Solidity and how do I mitigate it?

Phantom overflow in Solidity occurs when intermediate calculations exceed maximum limits despite the final result being valid. Mitigate phantom overflow by reordering arithmetic operations or applying safe casting patterns using libraries like SafeCast or FixedPointMathLib.

How do I perform safe casting to prevent integer truncation in Solidity?

Perform safe casting in Solidity using libraries like SafeCast to prevent integer truncation and underflow during type conversions. Safe casting ensures downcasts revert on failure rather than silently truncating values, maintaining arithmetic integrity.

Do I still need SafeMath libraries for overflow protection in Solidity 0.8+?

You do not need SafeMath libraries for standard overflow protection in Solidity 0.8+ because built-in automatic checks revert overflowing operations. SafeMath patterns are replaced by default checks, though libraries remain useful for phantom overflow and safe casting.

What are the best practices for handling integer edge cases in Solidity contracts?

Best practices for handling integer edge cases in Solidity include relying on automatic 0.8+ checks, using unchecked blocks only when mathematically safe, and applying safe casting via libraries to prevent truncation and phantom overflow vulnerabilities.