How I Found a Critical Precision Loss in Kuru Labs Using Foundry Fuzzin
The smart contract performed integer division before multiplication, causing the result to round down to zero when the intermediate product was less than 1e18. An attacker could exploit this to cause a 100% loss of user funds in specific edge cases.
blog.blockmagnates.com
Published on blog.blockmagnates.com
In the world of DeFi, a single decimal point is the difference between a secure protocol and a total loss of funds. During my deep dive into Kuru Labs, I identified a classic but devastating vulnerability: Premature Division.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the order of operations in the calculation: division was performed before multiplication, causing truncation to zero when the intermediate product was small.
Impact
A user could lose all their funds in specific edge cases, as the calculated amount becomes zero.
What the attacker needed
Specific values where p*s < 1e18
The fix
The fix is to multiply all values before dividing, as shown in the corrected formula.
How it was found
- Set p and s to values greater than 0 but less than 1e18.
- Run the fuzz test with these values.
- Observe that the correct result is non-zero while the bugged result is zero.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Smart contracts use whole numbers only, so division always rounds down. If you divide too early, a small number can become zero, and multiplying by a large number later still gives zero. This means a user's funds could be calculated as zero and lost.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.