Memory is corrupted when remove asset from token reserve #422
Labels
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-33
edited-by-warden
grade-a
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/core/RdpxV2Core.sol#L287
Vulnerability details
Impact
Impact of memory corruption will appear in case of address update of reserve tokens RDPX/WETH/DPXETH.
I.e. when admin
removeAssetFromtokenReserves()
addAssetTotokenReserves()
After these actions protocol is completely bricked.
Proof of Concept
Corrupted memory layout is hard to illustrate in Solidity, I provide PoC for this.
Please add this function to RdpxV2Core.sol:
Add this test to tests/rdpxV2-core/Admin.t.sol. And run
forge test --match-test testCorruptedMemory -vvv
Tools Used
Manual Review
Recommended Mitigation Steps
Current implementation always pops last element of array
reserveTokens
.Swap element you want to remove with the last element before
pop()
like you do withreserveAsset
:Assessed type
Error
The text was updated successfully, but these errors were encountered: