_safeMint
Will Fail Due To An Edge Case In Calculating tokenId
Using The _generateNewTokenId
Function
#17
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
resolved
Finding has been patched by sponsor (sponsor pls link to PR containing fix)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Handle
leastwood
Vulnerability details
Impact
NFTs are used to represent unique positions referenced by the generated
tokenId
. ThetokenId
value contains the position's score in the upper 128 bits and the index wrt. the token supply in the lower 128 bits.When positions are unlocked after expiring, the relevant position stored in the
positionOf
mapping is deleted, however, the NFT is not. Themerge()
function is used to combine points in unlocked NFTs, burning the underlying NFTs upon merging. As a result,_generateNewTokenId()
may end up using the sametotalSupply()
value, causing_safeMint()
to fail if the sameamount_
andduration_
values are used.This edge case only occurs if there is an overlap in the
points_
andtotalSupply() + 1
values used to generatetokenId
. As a result, this may impact a user's overall experience while interacting with theXDEFI
protocol, as some transactions may fail unexpectedly.Proof of Concept
Tools Used
Manual code review.
Discussions with Michael.
Recommended Mitigation Steps
Consider replacing
totalSupply()
in_generateNewTokenId()
with an internal counter. This should ensure that_generateNewTokenId()
always returns a uniquetokenId
that is monotomically increasing .The text was updated successfully, but these errors were encountered: