code-423n4 / 2023-07-lens-findings

0 stars 0 forks source link

The user who is about to be followed will frontrun a follower with a `LensHub#setFollowModule` call to steal from them. #116

Closed code423n4 closed 1 year ago

code423n4 commented 1 year ago

Lines of code

https://github.com/code-423n4/2023-07-lens/blob/main/contracts/LensHub.sol#L129

Vulnerability details

Impact

The power granted to users to freely set followModule at anytime allows for potential exploitation by frontrunning and manipulating fees, resulting in users unintentionally paying high fees when they intended to follow others for free or at a minimal cost

Proof of Concept

User that wanted to pay 0 or little fee to follow a particular user can end up paying very high fees. Here are some attack screnarios Example 1

Example 2

Tools Used

Manual Review

Recommended Mitigation Steps

There could be other better ways of fixing this, but here is my suggestion:

//code block to add start @> if ((_profileToFollow.cachedBlockNumber!=0) && (block.number>cachedBlockNumber)){ @> // perform ProfileLib#_initFollowModule logic here with cached followModule and followModuleInitData as parameters @> } //code block to add end

    bytes memory processFollowModuleReturnData;
    ...

}



However, the drawback of this approach is that the next follower after setFollowModule is called will have to pay extra gas. Additionally, the owner of the profile being followed can potentially use setFollowModule frequently to inconvenience users (although this scenario is unlikely to happen in reality, as there will be no gain from inconveniencing one's own followers).

## Assessed type

Timing
141345 commented 1 year ago

timelock issue

QA might be more appropriate.

donosonaumczuk commented 1 year ago

We are aware of this, and that's why the modules require whitelisting to be applied, so they cannot hold malicious behaviour. All modules involving fees expect custom data which contains currency and amount, so these kind of attacks cannot be performed successfully. In conclusion, this does not apply for current state of the protocol.

The solution proposed it's really interesting in case of Lens Protocol removing the whitelist at some point. Props for that!

donosonaumczuk commented 1 year ago

We misunderstood the solution proposed, and actually we think it's not a good idea. What we think can work for a context where Lens does not have whitelist for modules anymore is:

donosonaumczuk commented 1 year ago

We keep current logic as it is. This issue does not apply for current state of Lens Protocol, so we dispute its vaildity.

c4-sponsor commented 1 year ago

donosonaumczuk marked the issue as sponsor disputed

c4-judge commented 1 year ago

Picodes changed the severity to QA (Quality Assurance)

Picodes commented 1 year ago

Downgrading to QA as the report is valuable, although not of high severity as long as there is a whitelisting system

c4-judge commented 1 year ago

Picodes marked the issue as grade-b