Open code423n4 opened 1 year ago
0xRobocop marked the issue as primary issue
0xRobocop marked the issue as sufficient quality report
viraj124 marked the issue as disagree with severity
should be low at best IMO
viraj124 (sponsor) acknowledged
JustDravee changed the severity to QA (Quality Assurance)
To be merged with https://github.com/code-423n4/2023-08-shell-findings/issues/247 which is grade A
JustDravee marked the issue as grade-a
Lines of code
https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L586-L594 https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L658 https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L441-L448
Vulnerability details
Impact
The
EvolvingProteus._reserveTokenSpecified
function is called to calculate thechanged amount
of theLP token supply
based on theproportional change of the utility
of the pool.Firstly the initial utility and final utility are calculated as shown below:
Then the proportional change of the utility is used to calculate the final LP token supply amount as shown below:
The issue here is the computed
sf
(final LP token supply amount) is not checked against theMIN_BALANCE
value. Since_reserveTokenSpecified
is called by bothEvolvingProteus.depositGivenInputAmount
andEvolvingProteus.withdrawGivenOutputAmount
functions, thesf
amount can decrease from the initial LP token supply amount ofsi
during reserve token withdrawals.This could prompt the
sf < MIN_BALANCE
condition to occur. If this condition occurs the transaction should revert as it is done in theEvolvingProteus._getUtilityFinalLp
function. But the transaction will not revert in the_reserveTokenSpecified
function execution since there is no conditional check to verifysf >= MIN_BALANCE
.Hence the
withdrawGivenOutputAmount
transaction will execute successfully without revert even if the key invariantsf >= MIN_BALANCE
is broken. Hence this breaks the expected behaviour of the protocol.Proof of Concept
https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L586-L594
https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L658
https://github.com/code-423n4/2023-08-shell/blob/main/src/proteus/EvolvingProteus.sol#L441-L448
Tools Used
VSCode and Manual Review
Recommended Mitigation Steps
Hence it is recommended to add the conditional check to verify
sf >= MIN_BALANCE
in the_reserveTokenSpecified
function after thesf
value is calculated as shown below. If the invariant forMIN_BALANCE
is broken then the transaction should revert.Assessed type
Other