Key transfer will destroy key if from==to
The transferFrom function in Unlock Protocol's smart contract destroys a key when the sender and recipient are the same address, because it expires and resets the key after incorrectly extending its expiration. An approved key manager could accidentally destroy a user's token, causing the user to lose the key without a refund.
Submitted by kenzo, also found by GiveMeTestEther and cmichel
If calling transferFrom with _from == _recipient, the key will get destroyed (meaning the key will be set as expired and set the owner’s key to be 0).
Impact
A key manager or approved might accidentally destroy user’s token.
Note: this requires user error and so I’m not sure if this is a valid finding. However, few things make me think that it is valid:
- Unlock protocol checks for transfer to 0-address, so some input validation is there
- Since other entities other than the owner can be allowed to transfer owner’s token, it might be best to make sure such accidental mistake could not happen.
- This scenario manifests a unique and probably unintended behavior
Proof of Concept
By following transferFrom’s execution: https://github.com/code-423n4/2021-11-unlock/blob/main/smart-contracts/contracts/mixins/MixinTransfer.sol#L109:#L166 One can see that in the case where _from == _recipient with a valid key:
- The function will deduct transfer fee from the key
- The function will incorrectly add more time to the key’s expiration (L151)
- The function will expire and reset the key (L155)
Therefore, the user will lose his key without getting a refund.
Recommended Mitigation Steps
Add a require statement in the beginning of transferFrom: require(_from != _recipient, 'TRANSFER_TO_SELF');
julien51 (Unlock Protocol) confirmed
julien51 (Unlock Protocol) commented:
Fixed since then :)
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the transferFrom function does not check whether the sender and recipient are the same address, so it proceeds to expire and reset the key after adding time to it.
Impact
An approved key manager could accidentally destroy a user's token, causing the user to lose the key without a refund.
What the attacker needed
A valid key; caller is owner or approved; user error (sending to self)
The fix
The issue was fixed by adding a require statement at the beginning of transferFrom to prevent transfers to self.
How it was found
- Call transferFrom with _from equal to _recipient and a valid key.
- The function deducts a transfer fee from the key.
- The function incorrectly adds more time to the key's expiration.
- The function expires and resets the key, destroying it.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A key is a digital token that proves you own something, like a membership. The transfer function is supposed to move a key from one person to another, but if you try to send it to yourself, the code mistakenly deletes the key instead of just leaving it alone. This means you could lose your token by accident.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.