This repository has been archived by the owner on Jun 30, 2024. It is now read-only.
alexzoid - Inability to Re-add oldToken
After Execution of D3MakerFreeSlot.setNewTokenAndReplace()
#41
Labels
Has Duplicates
A valid issue with 1+ other issues describing the same vulnerability
Medium
A valid Medium severity issue
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
alexzoid
medium
Inability to Re-add
oldToken
After Execution ofD3MakerFreeSlot.setNewTokenAndReplace()
Summary
The
D3MakerFreeSlot
contract'ssetNewTokenAndReplace()
function, when executed, permanently removes theoldToken
information without clearing its index fromstate.priceListInfo.tokenIndexMap
. This oversight prevents the re-addition of theoldToken
using eithersetNewTokenAndReplace()
orsetNewToken()
methods.Vulnerability Detail
The
setNewTokenAndReplace()
function is designed to replace an existing token with a new token in a slot, thereby saving gas. However, this function only removes theoldToken
's information fromstate.tokenMMInfoMap
and does not clear its index fromstate.priceListInfo.tokenIndexMap
. Consequently, the system behaves as if theoldToken
is still present, preventing its re-addition.Impact
Once an
oldToken
is replaced, it cannot be re-introduced into the system using standard methods, potentially leading to operational inefficiencies or the need for workaround solutions.Code Snippet
https://github.com/sherlock-audit/2023-12-dodo/blob/main/dodo-v3/contracts/DODOV3MM/D3PoolNoBorrow/D3MakerFreeSlot.sol#L30
Proof Of Concept
The test validates that after executing
setNewTokenAndReplace()
, theoldToken
cannot be re-added due to its retained index instate.priceListInfo.tokenIndexMap
.Add the function below into
new-dodo-v3/test/DODOV3MM/D3MM/D3MMNoBorrow.t.sol
.Run test with
forge test --match-test testAuditReSetToken
. Output example:Tool used
VSCode, Foundry
Recommendation
The suggested fix involves modifying the
setNewTokenAndReplace()
function to remove theoldToken
fromstate.priceListInfo.tokenIndexMap
:The text was updated successfully, but these errors were encountered: