Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Albort - When _deltaFlow is zero, deltaFlowUnits is incorrectly set to -1 #76

Open
sherlock-admin2 opened this issue Oct 31, 2024 · 0 comments

Comments

@sherlock-admin2
Copy link
Contributor

sherlock-admin2 commented Oct 31, 2024

Albort

High

When _deltaFlow is zero, deltaFlowUnits is incorrectly set to -1

Summary

https://github.com/sherlock-audit/2024-10-mento-update/blob/098b17fb32d294145a7f000d96917d13db8756cc/mento-core/contracts/libraries/TradingLimits.sol#L134
When _deltaFlow == 0:
Calculate _deltaFlowUnits:

_deltaFlowUnits = 0 / (10 ** uint256(decimals)) = 0
Convert to int48:
deltaFlowUnits = int48(0)
Enter conditional check:
if (deltaFlowUnits == 0) { ... }
Since _deltaFlow == 0, _deltaFlow > 0 is false.
Thus, deltaFlowUnits is set to -1:
deltaFlowUnits = int48(-1)
Problem:

When the net flow change _deltaFlow is zero, the system should not modify deltaFlowUnits.
Setting deltaFlowUnits to -1 causes the net flow to be erroneously reduced without an actual change.

Root Cause

No response

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

No response

Impact

Incorrect Net Flow Update: The net flow will decrease without any real transaction, which may trigger erroneous limits.
State Inconsistency: The net flow state does not match actual transaction activity, potentially causing logical errors in the system.

PoC

No response

Mitigation

Modify the conditional check to ensure deltaFlowUnits is only adjusted when _deltaFlow is non-zero.

@sherlock-admin3 sherlock-admin3 changed the title Eager Juniper Ram - When _deltaFlow is zero, deltaFlowUnits is incorrectly set to -1 Albort - When _deltaFlow is zero, deltaFlowUnits is incorrectly set to -1 Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant