---
id: 12
title: "Arithmetic Rounding Exploit"
severity: 7
category: crypto
---

### 12 — Arithmetic Rounding Exploit
**Severity: 7** | **Real: Multiple DeFi rounding exploits, share price manipulation**

Division-before-multiplication loses precision — attacker extracts dust per share across millions of operations.

#### Verification Procedure

**Step 1: Find all division operations**
```
grep -rn --include="*.rs" "checked_div\|/ " programs/*/src/instructions/
```
- Record: Every division with context

**Step 2: Verify multiplication-before-division order**
```
# For each share/price/fee calculation, verify: (a * b) / c, NOT a * (b / c)
# Read the actual code for each financial formula
```
- ✅ PASS: Every formula multiplies first, divides last
- ❌ FAIL: Any formula where division happens before final multiplication (precision loss)

**Step 3: Check for rounding direction consistency**
```
# Deposits: round DOWN (fewer shares — favors vault)
# Withdrawals: round DOWN (less assets — favors vault)  
# Fee calculations: round UP (more fees — favors protocol)
```
- ✅ PASS: All rounding consistently favors the protocol/vault
- ❌ FAIL: Any calculation where rounding favors the user (extractable value)

**Step 4: Check for u128 intermediate calculations**
```
grep -rn --include="*.rs" "as u128\|u128::from" programs/*/src/instructions/
```
- ✅ PASS: Multiplications that could overflow u64 use u128 intermediates
- ❌ FAIL: Two u64 values multiplied without widening first

**Overall verdict:**
- ✅: Mul-before-div, consistent rounding direction favoring vault, u128 intermediates
- ⚠️: Correct order but missing u128 on some calculations
- ❌: Division before multiplication in financial formulas
