Skip to content
DoS Audit finding Beginner

sharesToTokenAmount : Division by zero

The public sharesToTokenAmount function divides by the total shares minted for a token without checking whether that total is zero, and its callers do not guard against this either. When the total is zero the function reverts, so other contracts calling it or getFeeAccumulatedOnNft would fail unexpectedly.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel, also found by cccz and CertoraInc

LiquidityProviders.sol#L192

The public sharesToTokenAmount function does not check if the denominator totalSharesMinted[_tokenAddress] is zero. Neither do the callers of this function. The function will revert. Calling functions like getFeeAccumulatedOnNft and sharesToTokenAmount from another contract should never revert.

Recommended Mitigation Steps

Return 0 in case totalSharesMinted[_tokenAddress] is zero.

ankurdubey521 (Biconomy) confirmed

pauliax (judge) commented:

A valid concern of runtime error.


The original report as published on Code4rena, by cmichel. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely a missing zero check on the total shares denominator before performing the division.

Impact

Calls to sharesToTokenAmount and functions such as getFeeAccumulatedOnNft could revert when no shares have been minted for a token, breaking integrations that expect a value.

What the attacker needed

No shares minted for the token

The fix

The function should return 0 when the total shares minted for the token 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 report has not been written yet. The Original tab links to the source.

A smart contract is a program that runs on a blockchain. This one has a function that converts a share of a pool into an amount of tokens by dividing by the total number of shares. Dividing by zero is not allowed, so the program stops with an error (a revert) instead of returning a number, and anything that called it also fails.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by cmichel

View all

196 more disclosed reports, best first.

More from Biconomy - Smart Contract Wallet contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.