Skip to content
Business logic Audit finding Intermediate

Buoy3Pool.safetyCheck is not precise and has some assumptions

The safetyCheck function in Buoy3Pool only compares the a/b and a/c ratios, which does not guarantee that the b/c ratio is within the allowed range. This imprecision could cause the contract to incorrectly halt deposits or withdrawals.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel, also found by shw

The safetyCheck function has several issues that impact how precise the checks are:

  1. Only checks if the a/b and a/c ratios are within BASIS_POINTS. By transitivity, b/c is only within 2 * BASIS_POINTS if a/b and a/c are in range. For a more precise check whether both USDC and USDT are within range, b/c must be checked as well.
  2. If a/b is within range, this does not imply that b/a is within range.
  3. “inverted ratios, a/b bs b/a, while producing different results should both reflect the same change in any one of the two underlying assets, but in opposite directions”

  4. Example: lastRatio = 1.0 ratio: a = 1.0, b = 0.8 => a/b = 1.25, b/a = 0.8 If a/b was used with a 20% range, it’d be out of range, but b/a is in range.
  5. The NatSpec for the function states that it checks Curve and an external oracle, but no external oracle calls are checked, both _ratio and lastRatio are only from Curve. Only _updateRatios checks the oracle.

To address this issue, it is recommended to check if b/c is within BASIS_POINTS .

kristian-gro (Gro) confirmed but disagreed with severity:

Makes strong assumption about the range of possible values - small differences between a and b will result in small differences between a/b and b/a - Extreme cases are handled by emergency. Agree on b/c check

kristian-gro (Gro) commented:

medium severity - will only cause stop of deposits/withdrawals against curve, work around to put in emergency mode

kristian-gro (Gro) commented:

Acknowledged, but the differences between variables are in basis points, we’ve simulated flash loan manipulations of curve and come to the conclusion that this approximation has a sufficiently small error margin to not cause issues. The B/C check (usdc/usdt) has been added in release version.

ghoul-sol (Judge) commented:

A possibility of stopping deposits or withdrawals deserves high risk.

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

The check only verifies two of the three possible pairwise ratios, so the third ratio can be out of range without being detected.

Impact

This could cause deposits or withdrawals to be stopped, but the team argues the error margin is small and extreme cases are handled by emergency mode.

What the attacker needed

None

The fix

The b/c check was added in the release version.

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.

This is a smart contract that checks if the prices of three stablecoins are close enough to each other. It only compares two pairs of prices, but not the third pair, so it might think everything is fine when one pair is actually too far apart. That could make the contract stop working for deposits and withdrawals.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by cmichel

View all

196 more disclosed reports, best first.

More from Gro Protocol

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.