Users can profit by calling Vault functions on the same block #271
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-435
edited-by-warden
🤖_271_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-03-revert-lend/blob/main/src/V3Vault.sol#L1155
Vulnerability details
Impact
Proof of Concept
In contract
Vault
, Debt exchange rate and lend exchange rate is only calculated once per block:This will create issues for transactions happens in the same block, the users could either profit or suffer loss because the exchange rate is not re-calculated.
For example a user could borrow and then deposit at the same block, the user will enjoy a lower exchange rate in deposit transaction and receive more shares.
Below is a PoC for the above issue, save these 2 test cases to file
test/integration/V3Vault.t.sol
and run it using command:forge test --match-path test/integration/V3Vault.t.sol --match-test testSameBlockActions -vvvv
In test case
testSameBlockActions1
, borrow and deposit happens in the same block, user receive 20000000 shares while in test casetestSameBlockActions2
, they happen on different blocks and user only receive 19999999 shares.Tools Used
Manual Review
Recommended Mitigation Steps
I recommend calling
_calculateGlobalInterest
every time_updateGlobalInterest
is called.Assessed type
Timing
The text was updated successfully, but these errors were encountered: