agents/skills/soroban/overflow-safety/SKILL.md
Trigger Pattern Always required for Soroban audits - Inject Into Breadth agents, depth-edge-case
npx skillsauth add plamentsv/plamen overflow-safetyInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Trigger Pattern: Always required for Soroban audits Inject Into: Breadth agents, depth-edge-case Finding prefix:
[OF-N]Rules referenced: R10, R14
Soroban contracts are compiled Rust. Rust's overflow behavior depends on the build profile: in debug builds, overflows panic; in release builds (used for deployment), overflows silently wrap by default unless overflow-checks = true is set. Silent wrapping in financial arithmetic is a critical vulnerability.
Before tracing any arithmetic, inspect Cargo.toml for the release profile overflow setting:
| File | [profile.release] Present? | overflow-checks Setting | Safe? |
|------|------------------------------|--------------------------|-------|
| Cargo.toml | YES/NO | true / false / MISSING | Only if true |
Interpretation:
overflow-checks = true → all integer arithmetic panics on overflow in release builds. The codebase is safe from silent wrapping.overflow-checks = false or missing → overflows silently wrap in release. Proceed to Section 2.[profile.release]: treat as false (Rust default for release).Finding threshold: If overflow-checks is not true, the entire overflow safety of the contract depends on manual use of checked/saturating arithmetic. This is a configuration-level finding regardless of whether Section 2 finds specific overflow sites.
overflow-checks is false/missing)If the profile check from Section 1 found that overflow protection is NOT enabled, trace ALL arithmetic operations in financial paths:
| Location | Expression | Operand Types | Max Realistic Value | Overflow Possible? | Impact if Wrapped |
|----------|-----------|--------------|--------------------|--------------------|------------------|
| {file:line} | {a + b} | u64 / i128 / u32 | {estimate} | YES/NO | {balance wraps to 0, share inflates, etc.} |
Financial paths to prioritize:
balance + amount, total_supply + mint_amount)shares * price / precision)amount * fee_bps / 10000)principal * rate * time)rewards_per_token * user_balance)Wrapping arithmetic consequences:
u128 overflows near 2^128 ≈ 3.4 × 10^38 — practically unreachable for balancesi128 overflows near 2^127 ≈ 1.7 × 10^38 — practically unreachable for balancesu64 overflows near 1.8 × 10^19 — reachable with large token amounts in 6-decimal tokensu32 overflows near 4.3 × 10^9 — reachable in ledger numbers, timestamps, countsIdentify all financial arithmetic and classify whether safe arithmetic methods are used:
| Location | Operation | Method Used | Safe? |
|----------|-----------|-------------|-------|
| {file:line} | {description} | + / checked_add / saturating_add / wrapping_add | Only checked_* or saturating_* |
Safe methods:
checked_add(b) → returns Option<T>, panics or propagates None on overflowchecked_mul(b) → returns Option<T>saturating_add(b) → clamps at MAX (safe for balances where MAX means "very rich")checked_div(b) → also catches division by zeroUnsafe methods:
+, -, * without overflow-checks = true → silent wrapping in releasewrapping_add, wrapping_sub, wrapping_mul → explicitly wraps (intentionally unsafe for most contexts)/ → panics on divide-by-zero regardless of overflow-checks (covered in Section 5)Flag any unchecked arithmetic where:
Soroban's native token and SEP-41 tokens frequently use i128 for amounts. Check operations near the boundaries:
| Location | Operation | Uses i128? | Near-Boundary Risk | Checked? |
|----------|-----------|-------------|-------------------|---------|
| {file:line} | {expression} | YES/NO | YES/NO | YES/NO |
Specific checks:
shares = (amount * total_shares) / total_assets — if total_shares is near i128::MAX, multiplication overflows before divisionreward_per_token_stored += rewards * PRECISION / total_supply — accumulation can overflow over timei128 allows negative values; verify contracts reject negative amount parameters via explicit require!(amount > 0)u128 as i128 silently truncates if the u128 value exceeds i128::MAXSoroban has no floating-point arithmetic. All division truncates toward zero (integer division). Incorrect division ordering causes precision loss or incorrect results:
| Location | Expression | Division-Before-Multiplication? | Precision Loss Estimate | Impact |
|----------|-----------|--------------------------------|------------------------|--------|
| {file:line} | {a / b * c} | YES → FLAG | {up to b-1 units lost} | {financial impact} |
Anti-pattern (division before multiplication):
// BAD: (amount / total_supply) loses precision before multiplying by rewards
let user_share = (user_balance / total_supply) * total_rewards;
Correct pattern (multiplication before division):
// GOOD: multiply first to preserve precision
let user_share = (user_balance * total_rewards) / total_supply;
Additional checks:
require!(total_supply > 0) before x / total_supplyPRECISION / SCALAR constants match the token decimals being used**ID**: [OF-N]
**Severity**: [Critical if balance wrapping, High if unchecked overflow in financial path, Medium if precision loss, Low if config-only]
**Step Execution**: ✓1,2,3,4,5 | ✗(reasons) | ?(uncertain)
**Rules Applied**: [R10:✓/✗, R14:✓/✗]
**Location**: src/{contract}.rs:LineN (or Cargo.toml for Section 1)
**Title**: {Overflow / Precision loss} in {fn_name} — {impact}
**Description**: [Specific arithmetic expression, operand types, worst-case values, and wrapping consequence]
**Impact**: [Balance wraps to near-zero / share inflation / reward theft / incorrect accounting]
| Section | Required | Completed? | Notes |
|---------|----------|------------|-------|
| 1. Profile Check | YES | ✓/✗/? | Read Cargo.toml [profile.release] |
| 2. Arithmetic Trace | IF overflow-checks not true | ✓/✗(N/A)/? | All financial paths |
| 3. Checked Arithmetic Patterns | YES | ✓/✗/? | All arithmetic in financial paths |
| 4. i128 Boundary Analysis | YES | ✓/✗/? | Wherever i128 used for amounts/shares |
| 5. Division Precision | YES | ✓/✗/? | All division operations in financial paths |
development
Prepare Solidity projects for a security audit — test coverage, test quality, NatSpec docs, code hygiene, dependency health, best-practice enforcement, deployment readiness, and project documentation checks. Generates a scored Audit Readiness Report and optionally runs static analysis. Trigger on: "prepare for audit", "audit readiness", "pre-audit check", "audit prep", "NatSpec check", or any request to review a Solidity codebase before a security review.
development
Launch the Plamen deterministic Web3 security audit pipeline
development
Run the Plamen smart-contract audit wizard in Codex
testing
Launch the Plamen deterministic L1 infrastructure audit pipeline