-
Notifications
You must be signed in to change notification settings - Fork 2
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
Exact input functions yield less value than exact output for the same parameters #219
Comments
0xRobocop marked the issue as primary issue |
0xRobocop marked the issue as high quality report |
0xRobocop marked the issue as sufficient quality report |
Description fails to point out precisely what the root cause is. Seems that this is acknowledged in the documentation:
|
ishaansinghal (sponsor) acknowledged |
viraj124 marked the issue as disagree with severity |
probably can be low/QA since we've already encountered this and have been aware of this as the fee mechanism is intended |
JustDravee changed the severity to QA (Quality Assurance) |
To be merged with #222 |
JustDravee marked the issue as grade-b |
Lines of code
https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L272
https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L353
https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L463
Vulnerability details
Impact
swapGivenInputAmount
,depositGivenInputAmount
andwithdrawGivenInputAmount
functions yield less value than their counterpartsswapGivenOutputAmount
,depositGivenOutputAmount
, andwithdrawGivenOutputAmount
for the same parameters.This results in integrators losing money when using the exact input functions.
Proof of Concept
Alice calls
depositGivenInputAmount
with the following parameters:The
depositGivenInputAmount
function returns the minted amount of LP tokens for depositing1e18
X tokens.If you call the
depositGivenOutputAmount
and pass this minted amount of LP tokens, you need a lesser amount of X tokens to deposit.This makes it meaningless for anyone to use the exact input functions since they would be losing value.
The same flaw is present in the
swapGivenInputAmount
vsswapGivenOutputAmount
andwithdrawGivenInputAmount
vswithdrawGivenOutputAmount
functions.To find the magnitude of the discrepancy between the exact input and exact output functions, here are invariant tests that provide the maximum difference.
https://gist.github.com/josipkoncurat/4cc3cd48403d880efd766938e85aeae7
The maximum differences we were able to spot were:
depositGivenInputAmount
vsdepositGivenOutputAmount
- 0.000418%swapGivenInputAmount
vsswapGivenOutputAmount
- 0.000312679%withdrawGivenInputAmount
vswithdrawGivenOutputAmount
- 0.169%Note: Try running invariant tests several times to get the maximum difference.
Tools Used
Recommended Mitigation Steps
The discrepancy is caused by the incorrect fee accounting between the different functions. For cases where fees are omitted, there is still some discrepancy, but it is rather small.
An option that doesn't require a whole reengineering of the fees is either removing the input functions or adding a warning in the documentation(comments) that the exact input functions yield less value than the exact output functions for the same parameters.
Assessed type
Other
The text was updated successfully, but these errors were encountered: