The DelegateFactory::revokeExpiredDelegators function will iterate through the delegators in the system and attempt to withdraw the delegated token for each if they have expired.
The problem lies in the fact that the Delegator::withdrawDelegatedToken function will transfer the EIP-721 asset using the IERC721::safeTransferFrom function which will in turn inform the recipient.
The recipient can then:
Transfer the EIP-721 asset they received back to the Delegator
The above will result in the delegators array being reduced by one on each re-entry incorrectly for the same entry. To avoid out-of-bound access errors, the user can also re-enter the DelegateFactory::deployDelegator function resulting in their newly deposited token overwriting the previously-last entry in the delegators array and thus causing the NFT to be lost.
Impact:
It is presently possible to cause the last entry in the delegators array to be erased incorrectly via a re-entrancy attack, thereby causing it to be lost. The exhibit requires the malicious user to be able to re-enter the DelegateFactory::deployDelegator function thereby reducing the finding's severity to medium.
DFY-02M: Delegator Removal Re-Entrancy Flaw
Description:
The
DelegateFactory::revokeExpiredDelegators
function will iterate through thedelegators
in the system and attempt to withdraw the delegated token for each if they have expired.The problem lies in the fact that the
Delegator::withdrawDelegatedToken
function will transfer the EIP-721 asset using theIERC721::safeTransferFrom
function which will in turn inform the recipient.The recipient can then:
Delegator
DelegateFactory::revokeExpiredDelegators
function againThe above will result in the
delegators
array being reduced by one on each re-entry incorrectly for the same entry. To avoid out-of-bound access errors, the user can also re-enter theDelegateFactory::deployDelegator
function resulting in their newly deposited token overwriting the previously-last entry in thedelegators
array and thus causing the NFT to be lost.Impact:
It is presently possible to cause the last entry in the
delegators
array to be erased incorrectly via a re-entrancy attack, thereby causing it to be lost. The exhibit requires the malicious user to be able to re-enter theDelegateFactory::deployDelegator
function thereby reducing the finding's severity to medium.Example:
Recommendation:
We advise the
Delegator::withdrawDelegatedToken
function to utilize a normalIERC721::transferFrom
operation, and theDelegateFactory::deployDelegator
andDelegateFactory::revokeExpiredDelegators
functions to be non-reentrant preventing the misbehaviour described.