An open technology stack, builders can create social front-ends or integrate Lens social capabilities.
Platform: Code4rena
Start Date: 17/07/2023
End Date: 31/07/2023
Period: 14 days
Status: Completed
Pot Size: $85,500 USDC
Participants: 26
Reporter: liveactionllama
Judge: Picodes
Id: 263
League: ETH
MiloTruck | 1/26 | $29,747.31 | 9 | 0 | 0 | 8 | 1 | Grade A | 0 | 0 |
juancito | 2/26 | $12,925.99 | 6 | 0 | 0 | 5 | 0 | Grade A | 0 | 0 |
Emmanuel | 3/26 | $7,481.06 | 5 | 0 | 0 | 4 | 0 | Grade B | 0 | 0 |
evmboi32 | 4/26 | $4,288.34 | 3 | 0 | 0 | 2 | 0 | Grade B | 0 | 0 |
klau5 | 5/26 | $3,458.78 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
maanas | 6/26 | $3,192.72 | 2 | 0 | 0 | 2 | 0 | 0 | 0 | 0 |
Limbooo | 7/26 | $2,660.60 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
Prestige | 8/26 | $430.47 | 2 | 0 | 0 | 1 | 0 | Grade B | 0 | 0 |
fatherOfBlocks | 9/26 | $31.38 | 1 | 0 | 0 | 0 | 0 | Grade B | 0 | 0 |
Rolezn | 10/26 | $31.38 | 1 | 0 | 0 | 0 | 0 | Grade B | 0 | 0 |
Auditor per page
We want to proposal this structure for the prize pool (please remove this line if you are ok with it if not chat in discord)
⚠️ note that for this contest, gas optimizations AND Analysis Reports are both out of scope. The Lens Protocol team will not be awarding prize funds for gas-specific submissions.
Automated findings output for the audit can be found here.
Note for C4 wardens: Anything included in the automated findings output is considered a publicly known issue and is ineligible for awards.
Below is a list of statements we wish to clear up, these are not bugs it as design but flagging so nobody raises them:
LensHandle
to a Profile
and on transfer of that handle or profile the link will still be valid. The new owner will need to unlink for it to be removed.contracts/
directory: LensHandles (#1, #2), Types (#3, #4), LensSeaDropCollection (#5 this file is out of the audit scope). These TODOs will be resolved later.isFollowing(uint256 profileId, address follower, uint256 followNFTTokenId)
function is not part of the Follow module interface anymore.Lens V1 docs to learn more about the Lens Protocol.
Although these docs are for Lens V1, they are still useful to understand the Lens Protocol in general. To see the changes done in Lens V2 - look at the next section.
Upgrade from Lens V1 to V2 will be done in-place using a transparent proxy pattern, knowdlege about Lens V1 is required in the context of upgrade and migration success, including unexpected breaking changes.
Lens Protocol is a social graph built on-chain, designed to empower creators to own their identities, and links between themselves and their community, forming a fully composable, user-owned social graph. The protocol is built from the ground up with modularity in mind, allowing new features and fixes to be added while ensuring immutable user-owned content and social relationships.
Lens V2 is the first big upgrade of the Lens Protocol, it aims to improve the protocol design based on all the learnings after its first year, as well as introduce some new interesting features:
Many of the things mentioned above introduce breaking changes in the protocol.
The ControllableByContract pattern that we introduced to allow preparing upgrades on beforehand, automating them through contracts and testing them in forks, while also avoiding the risk of transferring ownership of Governance and ProxyAdmin.
The Follow NFT design.
Please give special attention to Upgrade and Migration procedures, and anything that can get broken after the V2 upgrade (like the breaking changes mentioned in the "Publicly Known Issues" section). For that you might need to refer to the Lens V1 code.
The ControllableByContract pattern introduced, as it will be used by Governance and ProxyAdmin contracts, the latter being the most critical piece of Lens Protocol's security.
In V2 we introduced a complex Referral System, which supports verified and non-verified referrals for any module action that is performed on a publication (Reference Modules, Action Modules). Referral system allows to reward users that helped to discover a publication, and also to reward original posters for any activity that happens below, and reward the applications and UIs that are used to interact with Lens Protocol and help the discovery of content.
Lens V2 Referral System supports:
As we upgrade from Lens V1 to Lens V2, we need to take into account that not all publications would support the new Referral system (Lens V1 publications are supported only partly):
Why there is a difference between Pure and Non-Pure trees?
In V2 we introduced a “ROOT” - which is a post, and all the comments/quotes have this root copied recursively. So all the publication tree can always refer and check if two publications belong to the same ROOT - originating from the same post.
But in V1 we didn’t have a concept of a “ROOT”, so the existing V1 trees don’t have it.
Contract | SLOC | Purpose | Libraries used |
---|---|---|---|
contracts/LensHub.sol | 263 | Main contract. Entry point for all social operations (like publishing, follow, etc) and events. Profile NFT collection. | ActionLib, LegacyCollectLib, FollowLib, MetaTxLib, ProfileLib, PublicationLib, StorageLib, ValidationLib |
contracts/FollowNFT.sol | 357 | Follow NFT collection implementation, that is pointed by a Beacon proxy pattern by all Follow NFTs of all Lens Profiles. | @openzeppelin/*, StorageLib, FollowTokenURILib |
contracts/libraries/ActionLib.sol | 52 | Library containing logic of Publication Actions. | StorageLib, ValidationLib |
contracts/libraries/FollowLib.sol | 97 | Library containing logic of Follow operations. | StorageLib, ValidationLib |
contracts/libraries/GovernanceLib.sol | 70 | Library containing logic of Governance operations. | StorageLib |
contracts/libraries/LegacyCollectLib.sol | 89 | Library containing logic of Legacy Lens V1 Collect operations. | StorageLib, ValidationLib, @openzeppelin/* |
contracts/libraries/MetaTxLib.sol | 365 | Library containing logic of everything related to Meta-Transactions. | StorageLib, Typehash |
contracts/libraries/MigrationLib.sol | 109 | Library that will be used to migrate and adjust some state after Lens V1 to Lens V2 upgrade. | StorageLib |
contracts/libraries/ProfileLib.sol | 199 | Library containing logic of Profile operations. | StorageLib, ValidationLib |
contracts/libraries/PublicationLib.sol | 385 | Library for everything related to Publication (Posts/Comments/Quotes/Mirrors). | StorageLib, ValidationLib |
contracts/libraries/StorageLib.sol | 154 | Library handling the storage operations and helpers for getting and setting storage slots. | - |
contracts/libraries/ValidationLib.sol | 150 | Library containing logic of Validation. | StorageLib, ProfileLib, PublicationLib |
contracts/libraries/constants/Errors.sol | 40 | Library containing main custom error definitions. | - |
contracts/libraries/constants/Events.sol | 136 | Library containing main Events. | - |
contracts/libraries/constants/Typehash.sol | 18 | Library containing the Typehash constants for Meta-Transactions. | - |
contracts/libraries/constants/Types.sol | 193 | Library containing custom types, enums and structs. | - |
contracts/base/ERC2981CollectionRoyalties.sol | 42 | Base contract containing a generic implementation of ERC-2981. | - |
contracts/base/HubRestricted.sol | 14 | Base contract containing logic to restrict functions to be only called by the LensHub. | - |
contracts/base/LensBaseERC721.sol | 220 | Base contract implementing ERC-721. Used by Lens Profiles (LensHub), Follow, and Collect NFTs. | MetaTxLib, @openzeppelin/* |
contracts/base/LensGovernable.sol | 51 | Base contract implementing governance operations. Part of the LensHub. | StorageLib, ValidationLib, GovernanceLib |
contracts/base/LensHubEventHooks.sol | 21 | Base contract implementing logic to hook events into the LensHub. Part of the LensHub. | StorageLib |
contracts/base/LensHubStorage.sol | 24 | Base contract containing the last part of LensHub storage layout. Part of the LensHub. | - |
contracts/base/LensImplGetters.sol | 16 | Base contract implementing getters for Follow and Legacy Collect NFT implementations. Part of the LensHub. | - |
contracts/base/LensProfiles.sol | 118 | Base contract implementing Lens Profiles collection. Part of the LensHub. | StorageLib, ValidationLib, ProfileLib, ProfileTokenURILib, @openzeppelin/* |
contracts/base/upgradeability/FollowNFTProxy.sol | 13 | Proxy implementing Beacon pattern to be used by each Follow NFT. | @openzeppelin/* |
contracts/misc/ImmutableOwnable.sol | 23 | An Ownable contract to be inherited instead of OZ Ownable if the owner shall be immutable. | - |
contracts/misc/LegacyCollectNFT.sol | 69 | Legacy Collect NFT for Lens V1 support. | @openzeppelin/* |
contracts/misc/LensV2Migration.sol | 38 | Lens V1 to V2 Migration functions. | MigrationLib |
contracts/misc/LensV2UpgradeContract.sol | 111 | Contract handling the V1 to V2 upgrade procedure. | - |
contracts/misc/ModuleGlobals.sol | 75 | Contract containing global Module-related values (fee, governance, etc). | - |
contracts/misc/ProfileCreationProxy.sol | 35 | A trusted whitelisted Proxy for Profile creation. | - |
contracts/misc/access/ControllableByContract.sol | 24 | An additional Ownable layer that has an owner and a manager. | @openzeppelin/* |
contracts/misc/access/Governance.sol | 44 | A contract helper for safer Governance during upgrades, operated by Governance MultiSig. | - |
contracts/misc/access/ProxyAdmin.sol | 34 | A contract helper for safer upgrades, operated by ProxyAdmin Multisig. | @openzeppelin/* |
contracts/namespaces/LensHandles.sol | 196 | Default namespace contract (".lens" Handles). | HandleTokenURILib, @openzeppelin/* |
contracts/namespaces/TokenHandleRegistry.sol | 120 | Registry that links Tokens (so far, Lens Profiles) with Handles. | @openzeppelin/* |
contracts/namespaces/constants/Errors.sol | 22 | Namespaces Errors. | - |
contracts/namespaces/constants/Events.sol | 15 | Namespaces Events. | - |
contracts/namespaces/constants/Types.sol | 11 | Namespaces Types. | - |
contracts/interfaces/ICollectModule.sol | 4 | ||
contracts/interfaces/ICollectNFT.sol | 3 | ||
contracts/interfaces/IERC721Burnable.sol | 3 | ||
contracts/interfaces/IERC721MetaTx.sol | 3 | ||
contracts/interfaces/IERC721Timestamped.sol | 4 | ||
contracts/interfaces/IFollowModule.sol | 3 | ||
contracts/interfaces/IFollowNFT.sol | 10 | ||
contracts/interfaces/ILegacyCollectModule.sol | 3 | ||
contracts/interfaces/ILegacyCollectNFT.sol | 3 | ||
contracts/interfaces/ILegacyFollowModule.sol | 3 | ||
contracts/interfaces/ILegacyReferenceModule.sol | 3 | ||
contracts/interfaces/ILensERC721.sol | 7 | ||
contracts/interfaces/ILensGovernable.sol | 4 | ||
contracts/interfaces/ILensHandles.sol | 4 | ||
contracts/interfaces/ILensHub.sol | 7 | ||
contracts/interfaces/ILensHubEventHooks.sol | 3 | ||
contracts/interfaces/ILensHubInitializable.sol | 3 | ||
contracts/interfaces/ILensImplGetters.sol | 3 | ||
contracts/interfaces/ILensProfiles.sol | 4 | ||
contracts/interfaces/ILensProtocol.sol | 4 | ||
contracts/interfaces/IModuleGlobals.sol | 3 | ||
contracts/interfaces/IPublicationActionModule.sol | 4 | ||
contracts/interfaces/IReferenceModule.sol | 4 | ||
contracts/interfaces/ITokenHandleRegistry.sol | 3 |
Everything inside contracts/modules
, contracts/libraries/token-uris
directories, and LensHubInitializable
, VersionedInitializable
, UIDataProvider
contracts.
N/A (optional)
- If you have a public code repo, please share it here: [TBA](#TBA) - How many contracts are in scope?: 63 - Total SLoC for these contracts?: 4108 - How many external imports are there?: 0 - How many separate interfaces and struct definitions are there for the contracts within scope?: 32 Files = Interface files (24) + Error definition files (3) + Struct definition files (2) + Event definition files (2) + Constant definition files (1) - Does most of your code generally use composition or inheritance?: Inheritance - How many external calls?: 0 - What is the overall line coverage percentage provided by your tests?: 84% - Is this an upgrade of an existing system? Yes. We do in-place upgrades using different proxy patterns depending on the contract. LensHub (most core contract) is upgraded (transparent proxy), Follow NFT (beacon proxy). - Does it use a timelock function?: Yes - Is it an NFT?: Yes - Does the token conform to the ERC20 standard?: N/A (its ERC721) - Is there a need to understand a separate part of the codebase / get context in order to audit this part of the protocol?: Yes - Please describe required context: Upgrade from Lens V1 to V2 will be done in-place using a transparent proxy pattern, knowdlege about Lens V1 is required in the context of upgrade and migration success, including unexpected breaking changes. - Does it use an oracle?: No - Are there any novel or unique curve logic or mathematical models?: No - Is it a fork of a popular project?: No - Does it use a side-chain?: Uses EVM-compatible chain (Polygon).
git clone https://github.com/code-423n4/2023-07-lens.git
curl -L https://foundry.paradigm.xyz | bash
foundryup
You can do it either with forge:
forge install
or directly with git:
git submodule update --init --recursive
You can compile the project using:
forge build
You will notice a warning about LensHubInitializable exceeding code size (anyways, this file is out of the scope for this audit). To avoid the warning, compile Via IR (it will take more time):
forge build --via-ir
During the deployment we will compile with --via-ir
and tweak the optimizer runs for optimum gas performance while still keeping the contract size under the limit.
You can run unit tests using:
forge test
You can run coverage using:
forge coverage
If you run slither .
it will output an error. As a workaround, at the time of writing this, you need to follow these steps.
foundryup
test/
and contract/modules/
directories (which are out of the scope of this audit anyways):forge build --build-info --skip '*/test/**' --skip '*/modules/**' --force && slither . --ignore-compile
You can go to our docs (still V1) to learn more about Lens Protocol.
Upgrade from Lens V1 to V2 will be done in-place using a transparent proxy pattern, knowdlege about Lens V1 is required in the context of upgrade and migration success, including unexpected breaking changes.