π― The plan
- Focus: Web3 audit of a small tranche-based yield product β static pass β local Foundry harness β fork validation
- Time Spent: ~2 days across 6 sessions (the last one killed everything I had)
- Tools Used: Slither (static triage), Foundry (mock harness + mainnet-fork tests), manual review
NDA / ethics disclaimer: This finding was never filed β it died in my own validation gate. Even so, this log is fully generic: no protocol names, no addresses, no repo paths, no live PoCs. Everything technical is reproducible in abstract form.
π§ The finding that looked like money
Two stacked conversions, each one rounding down:
// strategy adapter: how many pool tokens do I need for this amount?
uint256 poolTokens = (amount * 1e18) / price(); // floors
// lending pool: how much underlying do those tokens pay?
uint256 underlying = tokens * rate / 1e30; // floors β again
Compounded truncation on the redemption path β the path every withdrawal touches. And the protocol's own tranche contract keeps a hardcoded 100 wei "as margin for rounding errors" in its rebalance routine. My harness said a single redeem was losing 100 billion wei β a billion times the developer's budget:
function test_rounding_loss_single() public {
deposit(alice, senior, 500_000e6);
deposit(bob, junior, 500_000e6);
accrueInterest(); // rate -> 1.1e18
uint256 got = rebalance(100_000e6); // redeem 100,000 units
assertGt(100_000e6 - got, 100); // PASSED: loss > 100 wei margin
}
The test passed. Unbounded accumulation, no preconditions, normal protocol operation. I had a High. I wrote the report draft: severity, impact, remediation (ceiling division in at least one layer β three fix options, no less).
There was a number in that test that should have scared me in the right way. It didn't.
βοΈ What the mainnet fork said
My pre-submission gate has one rule for precision findings: reproduce on the live deployment before believing any number. So I forked mainnet and probed the real thing.
Probe 1 β the token itself:
console.log(pool.decimals()); // 6 β the mock assumed 18
The real pool token has 6 decimals, and the live pool does its rate math at 1e18 scale β not 1e30. One real redeem:
requested: 1,000,000 units of pool token (6 decimals)
received: 999,999 units of the stablecoin
truncation: 1 wei
There was my rounding loss. One wei.
Probe 2 β the deployed strategy: it doesn't even run the repo code. It's a multi-currency variant that redeems the 6-decimal stablecoin and converts it through an upstream venue β which was saturated at the time, so the live path reverted for reasons that have nothing to do with rounding.
The real double rounding: ~2β3 wei per redeem. Comfortably inside the 100-wei margin. By design.
π¬ Why the mock lied: a 1e12 scale error
The harness's mock pool modeled the token at 18 decimals with tokens * rate / 1e30. The real token has 6 decimals with tokens * rate / 1e18. That mismatch is a factor of 1e12, and on 6-decimal amounts the mock's extra twelve zeros truncate everything to dust:
| Mock assumed | Reality | |
|---|---|---|
| Pool token decimals | 18 | 6 |
| Rate divisor | 1e30 | 1e18 |
| redeem(small amount) | ~0 | 999,999 out of 1,000,000 |
| "Loss" per redeem | the full requested amount | 1 wei |
So my "100 billion wei loss per redeem" was just requested - 0. The mock's redeem() returned zero, and loss == requested was the harness screaming I am broken, while I heard it saying the protocol is broken.
Why this bug class is dangerous to hunt: uint256 has no units. A 12-digit scale error compiles clean, passes every analyzer, and produces plausible-looking economics β until you measure one unit of the real thing. A test suite can work perfectly and prove the wrong thing.
π§Ύ The margin comment is a spec
Somewhere in the tranche contract there's a line equivalent to:
// keep 100 wei as margin for rounding errors
I treated it as a bug enabler ("the margin is insufficient β evidence of impact!"). It's the opposite: it's the developer's rounding-loss budget. They anticipated the truncation, measured it, and reserved 100 wei for it.
- Loss fits inside the budget β anticipated by design β not a finding.
- Loss exceeds the budget β now you have something β bring live evidence.
Read the epsilon and margin comments before you draft severity, not after a fork kills it.
π‘ What worked, what didn't
- What paid off: the validation gate. "No submission without live reproduction" turned a guaranteed-rejected High into one afternoon of honest work. Two fork tests, ~$0 in RPC costs, zero reputation spent.
- What tripped me up:
- I trusted my own mock as ground truth. A mock is a hypothesis about the protocol, encoded β its formula, scale and decimals are claims that need verification.
- I ignored the loudest signal: loss == full amount. Real rounding leaks single digits, not paychecks.
- I drafted severity before checking materiality: the tranche held ~$10 in TVL (product de facto discontinued), and the program's minimum payout is 500 tokens. Even a true High here was unpayable β plus two policy exclusions ("cannot be reproduced on live deployments", "no security impact") would have bounced it anyway.
- Repo β production: the deployed strategy ran different code than the audited source.
π By the numbers
- Candidate findings in the session: 4 β submitted: 0 (all four died in validation: one false positive, three documented-design exclusions)
- Foundry tests built: 38 passing (before the verdict)
- Claimed loss: 100,000,000,000 wei per redeem β measured: ~2β3 wei, inside a 100-wei budget
- Mock-vs-reality scale error: 1e12 (18-dec assumption vs 6-dec token)
- Tranche TVL at stake: ~$10 Β· minimum payout: 500 tokens
- Cost of the truth: 2 fork tests, one afternoon
β Final takeaways
- A precision finding validated only against a mock is a hypothesis, not a finding. Before believing any number: call
decimals()on the real token and push one real redeem through a mainnet fork. - Loss == requested amount isn't a rounding bug β it's a broken harness. Real rounding leaks single digits. Full-amount "losses" mean your test is measuring your own scale error.
- Margin and epsilon comments are the developer's loss budget. Inside the budget = anticipated by design. Outside it = impact worth proving.
Your move: before you file your next "unbounded rounding loss", run one unit through the real contract on a fork. If your claimed loss fits inside the developer's own epsilon, you don't have a finding β you have a mock problem. And if you write hunting logs, redact everything β even for findings you never file: no names, no addresses, no repo paths.
Next Target: turning this kill into a reusable validation checklist (mock-vs-live parity gates for precision findings) β and the next protocol on the hunt list.
**Note:** For this post, I used AI tools to format the text, add emoticons and make corrections.



