Open code423n4 opened 1 year ago
141345 marked the issue as primary issue
donosonaumczuk marked the issue as sponsor confirmed
We found this issue once the contest was already in progress, so we weren't allowed to push it, but we already mitigated it by adding this function in the LensHub:
function getProfileIdByHandleHash(bytes32 handleHash) external view returns (uint256) {
return StorageLib.profileIdByHandleHash()[handleHash];
}
And then making the ProfileCreationProxy to validate against it:
function proxyCreateProfileWithHandle(
Types.CreateProfileParams memory createProfileParams,
string calldata handle
) external onlyOwner returns (uint256, uint256) {
// Check if LensHubV1 already has a profile with this handle that was not migrated yet:
bytes32 handleHash = keccak256(bytes(string.concat(handle, '.lens')));
if (LensV2Migration(LENS_HUB).getProfileIdByHandleHash(handleHash) != 0) {
revert ProfileAlreadyExists();
}
// ...
}
Note that we add the validation at ProfileCreationProxy instead of LensHub, as we don't want LensHub to "be aware" of the Handles, architecturally-wise.
Picodes marked the issue as selected for report
Picodes marked the issue as satisfactory
Lines of code
https://github.com/code-423n4/2023-07-lens/blob/main/contracts/libraries/MigrationLib.sol#L69-L85
Vulnerability details
Bug Description
Profiles that exist before the V2 upgrade are migrated using the
batchMigrateProfiles()
function, which works by minting the profile's handle and linking it to their profile:MigrationLib.sol#L69-L85
For example, a profile with the handle "alice.lens" will receive a "alice" LensHandles NFT post-migration.
However, whitelisted profile creators are able to mint any handle using
mintHandle()
in theLensHandles
contract. This makes it possible for any whitelisted profile creator to mint a handle corresponding to a V1 profile before the profile is migrated.If this occurs,
batchMigrateProfiles()
will always revert for the corresponding V1 profile as the same handle cannot be minted twice, thereby breaking migration for that profile.Impact
If a whitelisted profile creator accidentally mints a handle that already belongs to a V1 profile, that profile cannot be migrated.
Proof of Concept
The Foundry test below demonstrates how
batchMigrateProfiles()
will revert if a V1 profile's handle has already been minted. It can be run with the following command:Recommended Mitigation
Ensure that the handle of a V1 profile cannot be minted through
mintHandle()
. This validation will probably have to be done off-chain, as it is unfeasible to check all existing handles on-chain with a reasonable gas cost.Assessed type
Upgradable