Skip to content
Business logic Audit finding Intermediate

Users can self-follow via FollowNFT::tryMigrate() on Lens V2

The FollowNFT::tryMigrate() function lacks a check to prevent a user from following their own profile, allowing a user who owns a V1 follow NFT for their own profile to self-follow on V2. This bypasses the intended restriction that users cannot self-follow.

juancito Follow with evmboi32 and Emmanuel

Originally disclosed on Code4rena

Submitted by juancito, also found by evmboi32 and Emmanuel

Users are not supposed to be able to self-follow on Lens v2, but they are able to bypass the restriction. This can also affect modules or newer functionalities that count on this behaviour.

Migration is an Area of specific concern for the devs, and this can easily be prevented with a simple check.

This can’t be undone without any upgrade.

Proof of Concept

FollowLib::follow() has a specific restriction to revert when a user tries to self-follow on Lens v2:

    if (followerProfileId == idsOfProfilesToFollow[i]) {
        revert Errors.SelfFollow();
    }

FollowLib.sol#L35-L37

However, users that own a follow NFT from V1 can execute FollowNFT::tryMigrate() to self-follow on V2, as there is no restriction to prevent it. A test proving it can be found on the next section.

FollowNFT.sol#L480-L520

Coded POC

Add this test to test/migrations/Migrations.t.sol and run TESTING_FORK=mainnet POLYGON_RPC_URL="https://polygon.llamarpc.com" forge test --mt "testSelfFollow".

Note: In case of a memory allocation error during the Forge test, please comment these lines. They are not used for the current test.

    function testSelfFollow() public onlyFork {
        uint256 selfFollowProfileId = 3659; // juancito.lens
        uint256 selfFollowTokenId = 42;     // juancito.lens follows juancito.lens on V1

        FollowNFT nft = FollowNFT(hub.getProfile(selfFollowProfileId).followNFT);
        address user = nft.ownerOf(selfFollowTokenId); // Owner of juancito.lens

        // 1. Migrate the self-follow
        uint256[] memory selfFollowProfileIdArray = new uint256[](1);
        uint256[] memory selfFollowTokenIdArray = new uint256[](1);

        selfFollowProfileIdArray[0] = selfFollowProfileId; // 3659
        selfFollowTokenIdArray[0] = selfFollowTokenId;     // 42

        hub.batchMigrateFollows(selfFollowProfileIdArray, selfFollowProfileIdArray, selfFollowTokenIdArray);

        // 2. The user is self-following on V2
        assertTrue(nft.isFollowing(selfFollowProfileId));
    }

Recommended Mitigation Steps

Add the following validation to FollowNFT::tryMigrate():

+    if (followerProfileId == _followedProfileId) {
+        return 0;
+    }

Assessed type

Invalid Validation

vicnaum (Lens) confirmed and commented:

This seems like a sub-case of issue 112. (But the mitigation is different for this case)

Picodes (judge) commented:

The impact is the same but the issue seems different, as the mitigation suggested by #112 wouldn’t prevent this from happening.


The original report as published on Code4rena, by juancito. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

The migration function FollowNFT::tryMigrate() does not validate that the follower profile ID and the followed profile ID are different, unlike the regular follow function which reverts on self-follow.

Impact

A user can self-follow on V2, which may affect modules or newer functionalities that rely on the restriction against self-following; the issue cannot be undone without an upgrade.

What the attacker needed

Own a V1 follow NFT for own profile; Access to the migration function

The fix

Add a check in FollowNFT::tryMigrate() to return 0 if the follower profile ID equals the followed profile ID.

How it was found

  1. Obtain a follow NFT from V1 that represents a self-follow (the user follows their own profile).
  2. Call batchMigrateFollows with the profile ID and token ID of the self-follow NFT.
  3. The migration succeeds and the user is now self-following on V2.

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.

On Lens, a social platform, users are not allowed to follow themselves. However, when moving (migrating) old follow records from version 1 to version 2, the migration function does not check if the follower and the followed profile are the same. So a user who had a self-follow on version 1 can bring it over to version 2.

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.

More by juancito

View all

14 more disclosed reports, best first.

More from Lens Protocol V2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.