From f4f8751268346809dd43a1aefb5ba0a71a550b23 Mon Sep 17 00:00:00 2001 From: vicnaum Date: Wed, 8 Jan 2025 21:40:31 +0100 Subject: [PATCH 1/9] misc: add fuzzing, via_ir and zkSync compilation to foundry.toml --- foundry.toml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/foundry.toml b/foundry.toml index 1abb8d9a..56a7e71a 100644 --- a/foundry.toml +++ b/foundry.toml @@ -6,11 +6,15 @@ test = 'test' cache_path = 'cache_forge' solc_version = '0.8.28' -# [profile.default.zksync] -# # Compile contracts for zkVM -# compile = true -# # Enable zkVM at startup, needs `compile = true` to have effect -# startup = true +[profile.default.fuzz] +runs = 1024 +no_zksync_reserved_addresses = true + +[profile.default.zksync] +# Compile contracts for zkVM +compile = true +# Enable zkVM at startup, needs `compile = true` to have effect +startup = true # # By default the latest version is used # zksolc = "1.5.0" # # By default the corresponding solc patched version from matter-labs is used @@ -24,9 +28,9 @@ solc_version = '0.8.28' # # Force compilation via EVMLA instead of Yul codegen pipeline # force_evmla = false # # Enable optimizer on zksolc (defaults to true) -# optimizer = true -# # zksolc optimizer mode (0 | 1 | 2 | 3 | s | z) -# optimizer_mode = '3' +optimizer = true +# zksolc optimizer mode (0 | 1 | 2 | 3 | s | z) +optimizer_mode = '1' # # zksolc optimizer details # optimizer_details = { ... } From f435b95ca13bfb5e647d769be9a162b970f36f28 Mon Sep 17 00:00:00 2001 From: vicnaum Date: Thu, 9 Jan 2025 15:17:47 +0100 Subject: [PATCH 2/9] misc: commented out all lines that caused stack-too-deep --- contracts/core/base/RuleBasedPrimitive.sol | 18 +- contracts/core/primitives/feed/Feed.sol | 64 ++--- .../core/primitives/feed/RuleBasedFeed.sol | 40 +-- .../core/primitives/graph/RuleBasedGraph.sol | 88 +++---- .../core/primitives/group/RuleBasedGroup.sol | 20 +- .../core/primitives/namespace/Namespace.sol | 28 +- .../namespace/RuleBasedNamespace.sol | 44 ++-- .../extensions/factories/LensFactory.sol | 242 +++++++++--------- contracts/migration/MigrationFeed.sol | 40 +-- foundry.toml | 7 +- test/factories/LensFactory.t.sol | 56 ++-- test/primitives/Namespace.t.sol | 24 +- 12 files changed, 337 insertions(+), 334 deletions(-) diff --git a/contracts/core/base/RuleBasedPrimitive.sol b/contracts/core/base/RuleBasedPrimitive.sol index 0a7478ec..7f92b03c 100644 --- a/contracts/core/base/RuleBasedPrimitive.sol +++ b/contracts/core/base/RuleBasedPrimitive.sol @@ -170,15 +170,15 @@ abstract contract RuleBasedPrimitive { ruleChange.selectorChanges[j].ruleSelector, entityId == 0 ? _supportedPrimitiveRuleSelectors() : _supportedEntityRuleSelectors() ); - rulesStorage._changeRulesSelectors( - ruleChanges[i].ruleAddress, - ruleChange.configSalt, - entityId, - ruleChanges[i].selectorChanges[j].ruleSelector, - ruleChanges[i].selectorChanges[j].isRequired, - ruleChanges[i].selectorChanges[j].enabled, - fn_emitSelectorEvent - ); + // rulesStorage._changeRulesSelectors( + // ruleChanges[i].ruleAddress, + // ruleChange.configSalt, + // entityId, + // ruleChanges[i].selectorChanges[j].ruleSelector, + // ruleChanges[i].selectorChanges[j].isRequired, + // ruleChanges[i].selectorChanges[j].enabled, + // fn_emitSelectorEvent + // ); } } if (entityId == 0) { diff --git a/contracts/core/primitives/feed/Feed.sol b/contracts/core/primitives/feed/Feed.sol index 357ac54a..b067c001 100644 --- a/contracts/core/primitives/feed/Feed.sol +++ b/contracts/core/primitives/feed/Feed.sol @@ -98,36 +98,36 @@ contract Feed is // Process rules of the Quote (if quoting) if (postParams.quotedPostId != 0) { // TODO: Maybe quotes shouldn't be limited by rules... Just a brave thought. Like quotations in real life. - uint256 rootOfQuotedPost = Core.$storage().posts[postParams.quotedPostId].rootPostId; - if (rootOfQuotedPost != rootPostId) { - _processPostCreationOnRootPost(rootOfQuotedPost, postId, postParams, customParams, quotedPostRulesParams); - } + // uint256 rootOfQuotedPost = Core.$storage().posts[postParams.quotedPostId].rootPostId; + // if (rootOfQuotedPost != rootPostId) { + // _processPostCreationOnRootPost(rootOfQuotedPost, postId, postParams, customParams, quotedPostRulesParams); + // } } if (postId != rootPostId) { require(postParams.ruleChanges.length == 0, Errors.CannotHaveRules()); // This covers the Reply or Repost cases - _processPostCreationOnRootPost(rootPostId, postId, postParams, customParams, rootPostRulesParams); + // _processPostCreationOnRootPost(rootPostId, postId, postParams, customParams, rootPostRulesParams); } else { _addPostRulesAtCreation(postId, postParams, feedRulesParams); } - emit Lens_Feed_PostCreated( - postId, - postParams.author, - authorPostSequentialId, - rootPostId, - postParams, - customParams, - feedRulesParams, - rootPostRulesParams, - quotedPostRulesParams, - source - ); - for (uint256 i = 0; i < postParams.extraData.length; i++) { - _setEntityExtraData(postId, postParams.extraData[i]); - emit Lens_Feed_Post_ExtraDataAdded( - postId, postParams.extraData[i].key, postParams.extraData[i].value, postParams.extraData[i].value - ); - } + // emit Lens_Feed_PostCreated( + // postId, + // postParams.author, + // authorPostSequentialId, + // rootPostId, + // postParams, + // customParams, + // feedRulesParams, + // rootPostRulesParams, + // quotedPostRulesParams, + // source + // ); + // for (uint256 i = 0; i < postParams.extraData.length; i++) { + // _setEntityExtraData(postId, postParams.extraData[i]); + // emit Lens_Feed_Post_ExtraDataAdded( + // postId, postParams.extraData[i].key, postParams.extraData[i].value, postParams.extraData[i].value + // ); + // } return postId; } @@ -165,18 +165,18 @@ contract Feed is storeSource: true, lastUpdatedSourceType: true }); - emit Lens_Feed_PostEdited( - postId, author, postParams, customParams, feedRulesParams, rootPostRulesParams, quotedPostRulesParams, source - ); + // emit Lens_Feed_PostEdited( + // postId, author, postParams, customParams, feedRulesParams, rootPostRulesParams, quotedPostRulesParams, source + // ); for (uint256 i = 0; i < postParams.extraData.length; i++) { if (wereExtraDataValuesSet[i]) { - emit Lens_Feed_Post_ExtraDataUpdated( - postId, postParams.extraData[i].key, postParams.extraData[i].value, postParams.extraData[i].value - ); + // emit Lens_Feed_Post_ExtraDataUpdated( + // postId, postParams.extraData[i].key, postParams.extraData[i].value, postParams.extraData[i].value + // ); } else { - emit Lens_Feed_Post_ExtraDataAdded( - postId, postParams.extraData[i].key, postParams.extraData[i].value, postParams.extraData[i].value - ); + // emit Lens_Feed_Post_ExtraDataAdded( + // postId, postParams.extraData[i].key, postParams.extraData[i].value, postParams.extraData[i].value + // ); } } } diff --git a/contracts/core/primitives/feed/RuleBasedFeed.sol b/contracts/core/primitives/feed/RuleBasedFeed.sol index d6967577..8d2ab2da 100644 --- a/contracts/core/primitives/feed/RuleBasedFeed.sol +++ b/contracts/core/primitives/feed/RuleBasedFeed.sol @@ -190,10 +190,10 @@ abstract contract RuleBasedFeed is IFeed, RuleBasedPrimitive { ) { ruleCustomParams = rulesProcessingParams[j].ruleParams; } - (bool callNotReverted,) = encodeAndCall( - rule.ruleAddress, rule.configSalt, rootPostId, postId, postParams, customParams, ruleCustomParams - ); - require(callNotReverted, Errors.RequiredRuleReverted()); + // (bool callNotReverted,) = encodeAndCall( + // rule.ruleAddress, rule.configSalt, rootPostId, postId, postParams, customParams, ruleCustomParams + // ); + // require(callNotReverted, Errors.RequiredRuleReverted()); } } // Check any-of rules (OR-combined rules) @@ -207,12 +207,12 @@ abstract contract RuleBasedFeed is IFeed, RuleBasedPrimitive { ) { ruleCustomParams = rulesProcessingParams[j].ruleParams; } - (bool callNotReverted,) = encodeAndCall( - rule.ruleAddress, rule.configSalt, rootPostId, postId, postParams, customParams, ruleCustomParams - ); - if (callNotReverted) { - return; // If any of the OR-combined rules passed, it means they succeed and we can return - } + // (bool callNotReverted,) = encodeAndCall( + // rule.ruleAddress, rule.configSalt, rootPostId, postId, postParams, customParams, ruleCustomParams + // ); + // if (callNotReverted) { + // return; // If any of the OR-combined rules passed, it means they succeed and we can return + // } } } // If there are any-of rules and it reached this point, it means all of them failed. @@ -344,10 +344,10 @@ abstract contract RuleBasedFeed is IFeed, RuleBasedPrimitive { ) { ruleCustomParams = rulesProcessingParams[j].ruleParams; } - (bool callNotReverted,) = encodeAndCall( - rule.ruleAddress, rule.configSalt, rootPostId, postId, postParams, customParams, ruleCustomParams - ); - require(callNotReverted, Errors.RequiredRuleReverted()); + // (bool callNotReverted,) = encodeAndCall( + // rule.ruleAddress, rule.configSalt, rootPostId, postId, postParams, customParams, ruleCustomParams + // ); + // require(callNotReverted, Errors.RequiredRuleReverted()); } } // Check any-of rules (OR-combined rules) @@ -361,12 +361,12 @@ abstract contract RuleBasedFeed is IFeed, RuleBasedPrimitive { ) { ruleCustomParams = rulesProcessingParams[j].ruleParams; } - (bool callNotReverted,) = encodeAndCall( - rule.ruleAddress, rule.configSalt, rootPostId, postId, postParams, customParams, ruleCustomParams - ); - if (callNotReverted) { - return; // If any of the OR-combined rules passed, it means they succeed and we can return - } + // (bool callNotReverted,) = encodeAndCall( + // rule.ruleAddress, rule.configSalt, rootPostId, postId, postParams, customParams, ruleCustomParams + // ); + // if (callNotReverted) { + // return; // If any of the OR-combined rules passed, it means they succeed and we can return + // } } } // If there are any-of rules and it reached this point, it means all of them failed. diff --git a/contracts/core/primitives/graph/RuleBasedGraph.sol b/contracts/core/primitives/graph/RuleBasedGraph.sol index 36a94ba3..7158d81f 100644 --- a/contracts/core/primitives/graph/RuleBasedGraph.sol +++ b/contracts/core/primitives/graph/RuleBasedGraph.sol @@ -331,16 +331,16 @@ abstract contract RuleBasedGraph is IGraph, RuleBasedPrimitive { ) { ruleCustomParams = rulesProcessingParams[j].ruleParams; } - (bool callNotReverted,) = encodeAndCall( - rule.ruleAddress, - rule.configSalt, - originalMsgSender, - followerAccount, - accountToUnfollow, - primitiveCustomParams, - ruleCustomParams - ); - require(callNotReverted, Errors.RequiredRuleReverted()); + // (bool callNotReverted,) = encodeAndCall( + // rule.ruleAddress, + // rule.configSalt, + // originalMsgSender, + // followerAccount, + // accountToUnfollow, + // primitiveCustomParams, + // ruleCustomParams + // ); + // require(callNotReverted, Errors.RequiredRuleReverted()); } } for (uint256 i = 0; i < rulesStorage.anyOfRules[ruleSelector].length; i++) { @@ -353,18 +353,18 @@ abstract contract RuleBasedGraph is IGraph, RuleBasedPrimitive { ) { ruleCustomParams = rulesProcessingParams[j].ruleParams; } - (bool callNotReverted,) = encodeAndCall( - rule.ruleAddress, - rule.configSalt, - originalMsgSender, - followerAccount, - accountToUnfollow, - primitiveCustomParams, - ruleCustomParams - ); - if (callNotReverted) { - return; // If any of the OR-combined rules passed, it means they succeed and we can return - } + // (bool callNotReverted,) = encodeAndCall( + // rule.ruleAddress, + // rule.configSalt, + // originalMsgSender, + // followerAccount, + // accountToUnfollow, + // primitiveCustomParams, + // ruleCustomParams + // ); + // if (callNotReverted) { + // return; // If any of the OR-combined rules passed, it means they succeed and we can return + // } } } // If there are any-of rules and it reached this point, it means all of them failed. @@ -394,16 +394,16 @@ abstract contract RuleBasedGraph is IGraph, RuleBasedPrimitive { ) { ruleCustomParams = rulesProcessingParams[j].ruleParams; } - (bool callNotReverted,) = encodeAndCall( - rule.ruleAddress, - rule.configSalt, - originalMsgSender, - followerAccount, - accountToFollow, - primitiveCustomParams, - ruleCustomParams - ); - require(callNotReverted, Errors.RequiredRuleReverted()); + // (bool callNotReverted,) = encodeAndCall( + // rule.ruleAddress, + // rule.configSalt, + // originalMsgSender, + // followerAccount, + // accountToFollow, + // primitiveCustomParams, + // ruleCustomParams + // ); + // require(callNotReverted, Errors.RequiredRuleReverted()); } } for (uint256 i = 0; i < rulesStorage.anyOfRules[ruleSelector].length; i++) { @@ -416,18 +416,18 @@ abstract contract RuleBasedGraph is IGraph, RuleBasedPrimitive { ) { ruleCustomParams = rulesProcessingParams[j].ruleParams; } - (bool callNotReverted,) = encodeAndCall( - rule.ruleAddress, - rule.configSalt, - originalMsgSender, - followerAccount, - accountToFollow, - primitiveCustomParams, - ruleCustomParams - ); - if (callNotReverted) { - return; // If any of the OR-combined rules passed, it means they succeed and we can return - } + // (bool callNotReverted,) = encodeAndCall( + // rule.ruleAddress, + // rule.configSalt, + // originalMsgSender, + // followerAccount, + // accountToFollow, + // primitiveCustomParams, + // ruleCustomParams + // ); + // if (callNotReverted) { + // return; // If any of the OR-combined rules passed, it means they succeed and we can return + // } } } // If there are any-of rules and it reached this point, it means all of them failed. diff --git a/contracts/core/primitives/group/RuleBasedGroup.sol b/contracts/core/primitives/group/RuleBasedGroup.sol index 05e25622..480aee7d 100644 --- a/contracts/core/primitives/group/RuleBasedGroup.sol +++ b/contracts/core/primitives/group/RuleBasedGroup.sol @@ -241,10 +241,10 @@ abstract contract RuleBasedGroup is IGroup, RuleBasedPrimitive { ) { ruleParams = rulesProcessingParams[j].ruleParams; } - (bool callNotReverted,) = encodeAndCall( - rule.ruleAddress, rule.configSalt, originalMsgSender, account, primitiveCustomParams, ruleParams - ); - require(callNotReverted, Errors.RequiredRuleReverted()); + // (bool callNotReverted,) = encodeAndCall( + // rule.ruleAddress, rule.configSalt, originalMsgSender, account, primitiveCustomParams, ruleParams + // ); + // require(callNotReverted, Errors.RequiredRuleReverted()); } } // Check any-of rules (OR-combined rules) @@ -258,12 +258,12 @@ abstract contract RuleBasedGroup is IGroup, RuleBasedPrimitive { ) { ruleParams = rulesProcessingParams[j].ruleParams; } - (bool callNotReverted,) = encodeAndCall( - rule.ruleAddress, rule.configSalt, originalMsgSender, account, primitiveCustomParams, ruleParams - ); - if (callNotReverted) { - return; // If any of the OR-combined rules passed, it means they succeed and we can return - } + // (bool callNotReverted,) = encodeAndCall( + // rule.ruleAddress, rule.configSalt, originalMsgSender, account, primitiveCustomParams, ruleParams + // ); + // if (callNotReverted) { + // return; // If any of the OR-combined rules passed, it means they succeed and we can return + // } } } // If there are any-of rules and it reached this point, it means all of them failed. diff --git a/contracts/core/primitives/namespace/Namespace.sol b/contracts/core/primitives/namespace/Namespace.sol index 67ce98df..03a72144 100644 --- a/contracts/core/primitives/namespace/Namespace.sol +++ b/contracts/core/primitives/namespace/Namespace.sol @@ -100,22 +100,22 @@ contract Namespace is KeyValue[] calldata customParams, RuleProcessingParams[] calldata unassigningProcessingParams, RuleProcessingParams[] calldata creationProcessingParams, - RuleProcessingParams[] calldata assigningProcessingParams, + RuleProcessingParams[] memory assigningProcessingParams, KeyValue[] memory extraData ) external { - require(msg.sender == account, Errors.InvalidMsgSender()); - uint256 id = _computeId(username); - _safeMint(account, id); - _idToUsername[id] = username; - Core._createUsername(username); - address source = _processSourceStamp(id, customParams); - _decodeAndSetUsernameExtraData(id, extraData); - emit Lens_Username_Created(username, account, customParams, creationProcessingParams, source, extraData); - _unassignIfAssigned(account, customParams, unassigningProcessingParams, source); - Core._assignUsername(account, username); - emit Lens_Username_Assigned(username, account, customParams, assigningProcessingParams, source); - _processCreation(msg.sender, account, username, customParams, creationProcessingParams); - _processAssigning(msg.sender, account, username, customParams, assigningProcessingParams); + // require(msg.sender == account, Errors.InvalidMsgSender()); + // uint256 id = _computeId(username); + // _safeMint(account, id); + // _idToUsername[id] = username; + // Core._createUsername(username); + // address source = _processSourceStamp(id, customParams); + // _decodeAndSetUsernameExtraData(id, extraData); + // emit Lens_Username_Created(username, account, customParams, creationProcessingParams, source, extraData); + // _unassignIfAssigned(account, customParams, unassigningProcessingParams, source); + // Core._assignUsername(account, username); + // emit Lens_Username_Assigned(username, account, customParams, assigningProcessingParams, source); + // _processCreation(msg.sender, account, username, customParams, creationProcessingParams); + // _processAssigning(msg.sender, account, username, customParams, assigningProcessingParams); } function createUsername( diff --git a/contracts/core/primitives/namespace/RuleBasedNamespace.sol b/contracts/core/primitives/namespace/RuleBasedNamespace.sol index 6aaa08ba..0ed78dcf 100644 --- a/contracts/core/primitives/namespace/RuleBasedNamespace.sol +++ b/contracts/core/primitives/namespace/RuleBasedNamespace.sol @@ -259,16 +259,16 @@ abstract contract RuleBasedNamespace is INamespace, RuleBasedPrimitive { ) { ruleParams = rulesProcessingParams[j].ruleParams; } - (bool callNotReverted,) = encodeAndCall( - rule.ruleAddress, - rule.configSalt, - originalMsgSender, - account, - username, - primitiveCustomParams, - ruleParams - ); - require(callNotReverted, Errors.RequiredRuleReverted()); + // (bool callNotReverted,) = encodeAndCall( + // rule.ruleAddress, + // rule.configSalt, + // originalMsgSender, + // account, + // username, + // primitiveCustomParams, + // ruleParams + // ); + // require(callNotReverted, Errors.RequiredRuleReverted()); } } // Check any-of rules (OR-combined rules) @@ -282,18 +282,18 @@ abstract contract RuleBasedNamespace is INamespace, RuleBasedPrimitive { ) { ruleParams = rulesProcessingParams[j].ruleParams; } - (bool callNotReverted,) = encodeAndCall( - rule.ruleAddress, - rule.configSalt, - originalMsgSender, - account, - username, - primitiveCustomParams, - ruleParams - ); - if (callNotReverted) { - return; // If any of the OR-combined rules passed, it means they succeed and we can return - } + // (bool callNotReverted,) = encodeAndCall( + // rule.ruleAddress, + // rule.configSalt, + // originalMsgSender, + // account, + // username, + // primitiveCustomParams, + // ruleParams + // ); + // if (callNotReverted) { + // return; // If any of the OR-combined rules passed, it means they succeed and we can return + // } } } // If there are any-of rules and it reached this point, it means all of them failed. diff --git a/contracts/extensions/factories/LensFactory.sol b/contracts/extensions/factories/LensFactory.sol index 33ed6e71..bece1ccb 100644 --- a/contracts/extensions/factories/LensFactory.sol +++ b/contracts/extensions/factories/LensFactory.sol @@ -87,114 +87,114 @@ contract LensFactory { GROUP_GATED_FEED_RULE = groupGatedFeedRule; } - // TODO: This function belongs to an App probably. - function createAccountWithUsernameFree( - string calldata metadataURI, - address owner, - address[] calldata accountManagers, - AccountManagerPermissions[] calldata accountManagersPermissions, - address namespacePrimitiveAddress, - string calldata username, - SourceStamp calldata accountCreationSourceStamp, - KeyValue[] calldata createUsernameCustomParams, - RuleProcessingParams[] calldata createUsernameRuleProcessingParams, - KeyValue[] calldata assignUsernameCustomParams, - RuleProcessingParams[] calldata unassignAccountRuleProcessingParams, - RuleProcessingParams[] calldata assignRuleProcessingParams, - KeyValue[] calldata accountExtraData, - KeyValue[] calldata usernameExtraData - ) external returns (address) { - address account = ACCOUNT_FACTORY.deployAccount( - address(this), - metadataURI, - accountManagers, - accountManagersPermissions, - accountCreationSourceStamp, - accountExtraData - ); - INamespace namespacePrimitive = INamespace(namespacePrimitiveAddress); - bytes memory txData = abi.encodeCall( - namespacePrimitive.createUsername, - (account, username, createUsernameCustomParams, createUsernameRuleProcessingParams, usernameExtraData) - ); - IAccount(payable(account)).executeTransaction(namespacePrimitiveAddress, uint256(0), txData); - txData = abi.encodeCall( - namespacePrimitive.assignUsername, - ( - account, - username, - assignUsernameCustomParams, - unassignAccountRuleProcessingParams, - new RuleProcessingParams[](0), - assignRuleProcessingParams - ) - ); - IAccount(payable(account)).executeTransaction(namespacePrimitiveAddress, uint256(0), txData); - IOwnable(account).transferOwnership(owner); - return account; - } + // // TODO: This function belongs to an App probably. + // function createAccountWithUsernameFree( + // string calldata metadataURI, + // address owner, + // address[] calldata accountManagers, + // AccountManagerPermissions[] calldata accountManagersPermissions, + // address namespacePrimitiveAddress, + // string calldata username, + // SourceStamp calldata accountCreationSourceStamp, + // KeyValue[] calldata createUsernameCustomParams, + // RuleProcessingParams[] calldata createUsernameRuleProcessingParams, + // KeyValue[] calldata assignUsernameCustomParams, + // RuleProcessingParams[] calldata unassignAccountRuleProcessingParams, + // RuleProcessingParams[] calldata assignRuleProcessingParams, + // KeyValue[] calldata accountExtraData, + // KeyValue[] calldata usernameExtraData + // ) external returns (address) { + // address account = ACCOUNT_FACTORY.deployAccount( + // address(this), + // metadataURI, + // accountManagers, + // accountManagersPermissions, + // accountCreationSourceStamp, + // accountExtraData + // ); + // INamespace namespacePrimitive = INamespace(namespacePrimitiveAddress); + // bytes memory txData = abi.encodeCall( + // namespacePrimitive.createUsername, + // (account, username, createUsernameCustomParams, createUsernameRuleProcessingParams, usernameExtraData) + // ); + // IAccount(payable(account)).executeTransaction(namespacePrimitiveAddress, uint256(0), txData); + // txData = abi.encodeCall( + // namespacePrimitive.assignUsername, + // ( + // account, + // username, + // assignUsernameCustomParams, + // unassignAccountRuleProcessingParams, + // new RuleProcessingParams[](0), + // assignRuleProcessingParams + // ) + // ); + // IAccount(payable(account)).executeTransaction(namespacePrimitiveAddress, uint256(0), txData); + // IOwnable(account).transferOwnership(owner); + // return account; + // } - function createGroupWithFeed( - address owner, - address[] calldata admins, - string calldata groupMetadataURI, - RuleChange[] calldata groupRules, - KeyValue[] calldata groupExtraData, - string calldata feedMetadataURI, - RuleChange[] calldata feedRules, - KeyValue[] calldata feedExtraData - ) external returns (address, address) { - IRoleBasedAccessControl groupAccessControl = _deployAccessControl(owner, admins); + // function createGroupWithFeed( + // address owner, + // address[] calldata admins, + // string calldata groupMetadataURI, + // RuleChange[] calldata groupRules, + // KeyValue[] calldata groupExtraData, + // string calldata feedMetadataURI, + // RuleChange[] calldata feedRules, + // KeyValue[] calldata feedExtraData + // ) external returns (address, address) { + // IRoleBasedAccessControl groupAccessControl = _deployAccessControl(owner, admins); - address group = GROUP_FACTORY.deployGroup( - groupMetadataURI, - TEMPORARY_ACCESS_CONTROL, - owner, - _injectRuleAccessControl(groupRules, address(groupAccessControl)), - groupExtraData - ); + // address group = GROUP_FACTORY.deployGroup( + // groupMetadataURI, + // TEMPORARY_ACCESS_CONTROL, + // owner, + // _injectRuleAccessControl(groupRules, address(groupAccessControl)), + // groupExtraData + // ); - RuleChange[] memory modifiedFeedRules = new RuleChange[](feedRules.length + 2); + // RuleChange[] memory modifiedFeedRules = new RuleChange[](feedRules.length + 2); - RuleSelectorChange[] memory selectorChanges = new RuleSelectorChange[](1); - // Both rules only operate on IFeedRule.processCreatePost.selector (at least at the moment of writing this) - selectorChanges[0] = - RuleSelectorChange({ruleSelector: IFeedRule.processCreatePost.selector, isRequired: true, enabled: true}); + // RuleSelectorChange[] memory selectorChanges = new RuleSelectorChange[](1); + // // Both rules only operate on IFeedRule.processCreatePost.selector (at least at the moment of writing this) + // selectorChanges[0] = + // RuleSelectorChange({ruleSelector: IFeedRule.processCreatePost.selector, isRequired: true, enabled: true}); - modifiedFeedRules[0] = RuleChange({ - ruleAddress: ACCOUNT_BLOCKING_RULE, - configSalt: bytes32(0), - configurationChanges: RuleConfigurationChange({configure: true, ruleParams: new KeyValue[](0)}), - selectorChanges: selectorChanges - }); + // modifiedFeedRules[0] = RuleChange({ + // ruleAddress: ACCOUNT_BLOCKING_RULE, + // configSalt: bytes32(0), + // configurationChanges: RuleConfigurationChange({configure: true, ruleParams: new KeyValue[](0)}), + // selectorChanges: selectorChanges + // }); - KeyValue[] memory groupGatedRuleParams = new KeyValue[](1); - groupGatedRuleParams[0] = KeyValue({key: PARAM__GROUP, value: abi.encode(group)}); + // KeyValue[] memory groupGatedRuleParams = new KeyValue[](1); + // groupGatedRuleParams[0] = KeyValue({key: PARAM__GROUP, value: abi.encode(group)}); - modifiedFeedRules[1] = RuleChange({ - ruleAddress: GROUP_GATED_FEED_RULE, - configSalt: bytes32(0), - configurationChanges: RuleConfigurationChange({configure: true, ruleParams: groupGatedRuleParams}), - selectorChanges: selectorChanges - }); + // modifiedFeedRules[1] = RuleChange({ + // ruleAddress: GROUP_GATED_FEED_RULE, + // configSalt: bytes32(0), + // configurationChanges: RuleConfigurationChange({configure: true, ruleParams: groupGatedRuleParams}), + // selectorChanges: selectorChanges + // }); - IRoleBasedAccessControl feedAccessControl = _deployAccessControl(owner, admins); + // IRoleBasedAccessControl feedAccessControl = _deployAccessControl(owner, admins); - for (uint256 i = 0; i < feedRules.length; i++) { - require(feedRules[i].ruleAddress != ACCOUNT_BLOCKING_RULE, Errors.DuplicatedValue()); - require(feedRules[i].ruleAddress != GROUP_GATED_FEED_RULE, Errors.DuplicatedValue()); - modifiedFeedRules[i + 2] = _injectRuleAccessControl(feedRules[i], address(feedAccessControl)); - } + // for (uint256 i = 0; i < feedRules.length; i++) { + // require(feedRules[i].ruleAddress != ACCOUNT_BLOCKING_RULE, Errors.DuplicatedValue()); + // require(feedRules[i].ruleAddress != GROUP_GATED_FEED_RULE, Errors.DuplicatedValue()); + // modifiedFeedRules[i + 2] = _injectRuleAccessControl(feedRules[i], address(feedAccessControl)); + // } - address feed = - FEED_FACTORY.deployFeed(feedMetadataURI, feedAccessControl, owner, modifiedFeedRules, feedExtraData); + // address feed = + // FEED_FACTORY.deployFeed(feedMetadataURI, feedAccessControl, owner, modifiedFeedRules, feedExtraData); - KeyValue[] memory groupExtraDataWithFeed = new KeyValue[](1); - groupExtraDataWithFeed[0] = KeyValue({key: DATA__GROUP_LINKED_FEED, value: abi.encode(feed)}); - IGroup(group).setExtraData(groupExtraDataWithFeed); - AccessControlled(group).setAccessControl(groupAccessControl); - return (group, feed); - } + // KeyValue[] memory groupExtraDataWithFeed = new KeyValue[](1); + // groupExtraDataWithFeed[0] = KeyValue({key: DATA__GROUP_LINKED_FEED, value: abi.encode(feed)}); + // IGroup(group).setExtraData(groupExtraDataWithFeed); + // AccessControlled(group).setAccessControl(groupAccessControl); + // return (group, feed); + // } function deployAccount( string calldata metadataURI, @@ -274,30 +274,30 @@ contract LensFactory { ); } - function deployNamespace( - string calldata namespace, - string calldata metadataURI, - address owner, - address[] calldata admins, - RuleChange[] calldata rules, - KeyValue[] calldata extraData, - string calldata nftName, - string calldata nftSymbol - ) external returns (address) { - ITokenURIProvider tokenURIProvider = new LensUsernameTokenURIProvider(); - IRoleBasedAccessControl accessControl = _deployAccessControl(owner, admins); - return NAMESPACE_FACTORY.deployNamespace( - namespace, - metadataURI, - accessControl, - owner, - _injectRuleAccessControl(rules, address(accessControl)), - extraData, - nftName, - nftSymbol, - tokenURIProvider - ); - } + // function deployNamespace( + // string calldata namespace, + // string calldata metadataURI, + // address owner, + // address[] calldata admins, + // RuleChange[] calldata rules, + // KeyValue[] calldata extraData, + // string calldata nftName, + // string calldata nftSymbol + // ) external returns (address) { + // ITokenURIProvider tokenURIProvider = new LensUsernameTokenURIProvider(); + // IRoleBasedAccessControl accessControl = _deployAccessControl(owner, admins); + // return NAMESPACE_FACTORY.deployNamespace( + // namespace, + // metadataURI, + // accessControl, + // owner, + // _injectRuleAccessControl(rules, address(accessControl)), + // extraData, + // nftName, + // nftSymbol, + // tokenURIProvider + // ); + // } function _deployAccessControl(address owner, address[] calldata admins) internal returns (IRoleBasedAccessControl) { return ACCESS_CONTROL_FACTORY.deployOwnerAdminOnlyAccessControl(owner, admins); diff --git a/contracts/migration/MigrationFeed.sol b/contracts/migration/MigrationFeed.sol index f469e4f3..82e51cea 100644 --- a/contracts/migration/MigrationFeed.sol +++ b/contracts/migration/MigrationFeed.sol @@ -24,11 +24,11 @@ contract MigrationFeed is Feed { uint80 creationTimestamp, address source ) = abi.decode(customParams[0].value, (uint256, uint256, uint256, uint256, uint80, address)); - _createPost(postParams, postId, rootPostId, postSequentialId, authorPostSequentialId, creationTimestamp); + // _createPost(postParams, postId, rootPostId, postSequentialId, authorPostSequentialId, creationTimestamp); if (customParams.length > 1 && abi.decode(customParams[1].value, (bool))) { // If customParams[1] is present, it must be an ABI-encoded bool representing `forceChecks` - _forceChecks(postId, rootPostId, postParams); + // _forceChecks(postId, rootPostId, postParams); } if (source != address(0)) { @@ -37,25 +37,25 @@ contract MigrationFeed is Feed { _setPrimitiveInternalExtraDataForEntity(postId, KeyValue(DATA__LAST_UPDATED_SOURCE, abi.encode(source))); } - emit Lens_Feed_PostCreated( - postId, - postParams.author, - authorPostSequentialId, - rootPostId, - postParams, - customParams, - feedRulesParams, - rootPostRulesParams, - quotedPostRulesParams, - source - ); + // emit Lens_Feed_PostCreated( + // source, + // postId, + // authorPostSequentialId, + // rootPostId, + // quotedPostRulesParams, + // rootPostRulesParams, + // feedRulesParams, + // customParams, + // postParams, + // postParams.author + // ); - for (uint256 i = 0; i < postParams.extraData.length; i++) { - _setEntityExtraData(postId, postParams.extraData[i]); - emit Lens_Feed_Post_ExtraDataAdded( - postId, postParams.extraData[i].key, postParams.extraData[i].value, postParams.extraData[i].value - ); - } + // for (uint256 i = 0; i < postParams.extraData.length; i++) { + // _setEntityExtraData(postId, postParams.extraData[i]); + // emit Lens_Feed_Post_ExtraDataAdded( + // postId, postParams.extraData[i].key, postParams.extraData[i].value, postParams.extraData[i].value + // ); + // } return postId; } diff --git a/foundry.toml b/foundry.toml index 56a7e71a..9c6d9180 100644 --- a/foundry.toml +++ b/foundry.toml @@ -5,6 +5,9 @@ libs = ['node_modules', 'lib'] test = 'test' cache_path = 'cache_forge' solc_version = '0.8.28' +# via_ir = true +optimizer = false +# optimizer_runs = 10 [profile.default.fuzz] runs = 1024 @@ -12,9 +15,9 @@ no_zksync_reserved_addresses = true [profile.default.zksync] # Compile contracts for zkVM -compile = true +# compile = true # Enable zkVM at startup, needs `compile = true` to have effect -startup = true +# startup = true # # By default the latest version is used # zksolc = "1.5.0" # # By default the corresponding solc patched version from matter-labs is used diff --git a/test/factories/LensFactory.t.sol b/test/factories/LensFactory.t.sol index d079b561..3d6fdba6 100644 --- a/test/factories/LensFactory.t.sol +++ b/test/factories/LensFactory.t.sol @@ -25,18 +25,18 @@ contract LensFactoryTest is Test, BaseDeployments { function setUp() public override { super.setUp(); - namespace = Namespace( - lensFactory.deployNamespace({ - namespace: "bitcoin", - metadataURI: "satoshi://nakamoto", - owner: address(this), - admins: new address[](0), - rules: new RuleChange[](0), - extraData: new KeyValue[](0), - nftName: "Bitcoin", - nftSymbol: "BTC" - }) - ); + // namespace = Namespace( + // lensFactory.deployNamespace({ + // namespace: "bitcoin", + // metadataURI: "satoshi://nakamoto", + // owner: address(this), + // admins: new address[](0), + // rules: new RuleChange[](0), + // extraData: new KeyValue[](0), + // nftName: "Bitcoin", + // nftSymbol: "BTC" + // }) + // ); } function testCanDeployFeed() public { @@ -50,22 +50,22 @@ contract LensFactoryTest is Test, BaseDeployments { } function testCreateAccountWithUsernameFree() public { - lensFactory.createAccountWithUsernameFree({ - metadataURI: "someMetadataURI", - owner: address(this), - accountManagers: _emptyAddressArray(), - accountManagersPermissions: new AccountManagerPermissions[](0), - namespacePrimitiveAddress: address(namespace), - username: "myTestUsername", - accountCreationSourceStamp: _emptySourceStamp(), - createUsernameCustomParams: _emptyKeyValueArray(), - createUsernameRuleProcessingParams: _emptyRuleProcessingParamsArray(), - assignUsernameCustomParams: _emptyKeyValueArray(), - unassignAccountRuleProcessingParams: _emptyRuleProcessingParamsArray(), - assignRuleProcessingParams: _emptyRuleProcessingParamsArray(), - accountExtraData: _emptyKeyValueArray(), - usernameExtraData: _emptyKeyValueArray() - }); + // lensFactory.createAccountWithUsernameFree({ + // metadataURI: "someMetadataURI", + // owner: address(this), + // accountManagers: _emptyAddressArray(), + // accountManagersPermissions: new AccountManagerPermissions[](0), + // namespacePrimitiveAddress: address(namespace), + // username: "myTestUsername", + // accountCreationSourceStamp: _emptySourceStamp(), + // createUsernameCustomParams: _emptyKeyValueArray(), + // createUsernameRuleProcessingParams: _emptyRuleProcessingParamsArray(), + // assignUsernameCustomParams: _emptyKeyValueArray(), + // unassignAccountRuleProcessingParams: _emptyRuleProcessingParamsArray(), + // assignRuleProcessingParams: _emptyRuleProcessingParamsArray(), + // accountExtraData: _emptyKeyValueArray(), + // usernameExtraData: _emptyKeyValueArray() + // }); } function testGraphFollowWithFactorySetup() public { diff --git a/test/primitives/Namespace.t.sol b/test/primitives/Namespace.t.sol index 9e097c7e..32b4f1a2 100644 --- a/test/primitives/Namespace.t.sol +++ b/test/primitives/Namespace.t.sol @@ -20,18 +20,18 @@ contract NamespaceTest is Test, BaseDeployments { function setUp() public override { super.setUp(); - namespace = INamespace( - lensFactory.deployNamespace({ - namespace: "bitcoin", - metadataURI: "satoshi://nakamoto", - owner: namespaceOwner, - admins: _emptyAddressArray(), - rules: _emptyRuleChangeArray(), - extraData: _emptyKeyValueArray(), - nftName: "Bitcoin", - nftSymbol: "BTC" - }) - ); + // namespace = INamespace( + // lensFactory.deployNamespace({ + // namespace: "bitcoin", + // metadataURI: "satoshi://nakamoto", + // owner: namespaceOwner, + // admins: _emptyAddressArray(), + // rules: _emptyRuleChangeArray(), + // extraData: _emptyKeyValueArray(), + // nftName: "Bitcoin", + // nftSymbol: "BTC" + // }) + // ); } function testCreateAssignUnassignDelete() public { From 5873156f7ac14d8f0a645d79ec4a3bd5079b7316 Mon Sep 17 00:00:00 2001 From: vicnaum Date: Thu, 9 Jan 2025 20:54:26 +0100 Subject: [PATCH 3/9] misc: Namespaces and Graph compile without IR --- .../core/primitives/graph/RuleBasedGraph.sol | 220 +++++++----------- .../core/primitives/namespace/Namespace.sol | 28 +-- .../namespace/RuleBasedNamespace.sol | 206 ++++++++-------- .../extensions/factories/LensFactory.sol | 50 ++-- test/factories/LensFactory.t.sol | 24 +- test/primitives/Namespace.t.sol | 24 +- 6 files changed, 260 insertions(+), 292 deletions(-) diff --git a/contracts/core/primitives/graph/RuleBasedGraph.sol b/contracts/core/primitives/graph/RuleBasedGraph.sol index 7158d81f..ea02f760 100644 --- a/contracts/core/primitives/graph/RuleBasedGraph.sol +++ b/contracts/core/primitives/graph/RuleBasedGraph.sol @@ -180,24 +180,28 @@ abstract contract RuleBasedGraph is IGraph, RuleBasedPrimitive { require($graphRulesStorage().anyOfRules[ruleSelector].length == 0, Errors.AllAnyOfRulesReverted()); } + struct ProcessParams { + address originalMsgSender; + address sourceAccount; + address targetAccount; + KeyValue[] primitiveCustomParams; + RuleProcessingParams[] rulesProcessingParams; + } + function _encodeAndCallGraphProcessFollow( - address rule, - bytes32 configSalt, - address originalMsgSender, - address followerAccount, - address accountToFollow, - KeyValue[] calldata primitiveCustomParams, + Rule memory rule, + ProcessParams memory processParams, KeyValue[] memory ruleCustomParams ) internal returns (bool, bytes memory) { - return rule.safecall( + return rule.ruleAddress.safecall( abi.encodeCall( IGraphRule.processFollow, ( - configSalt, - originalMsgSender, - followerAccount, - accountToFollow, - primitiveCustomParams, + rule.configSalt, + processParams.originalMsgSender, + processParams.sourceAccount, + processParams.targetAccount, + processParams.primitiveCustomParams, ruleCustomParams ) ) @@ -209,38 +213,36 @@ abstract contract RuleBasedGraph is IGraph, RuleBasedPrimitive { address followerAccount, address accountToFollow, KeyValue[] calldata primitiveCustomParams, - RuleProcessingParams[] calldata ruleProcessingParams + RuleProcessingParams[] calldata rulesProcessingParams ) internal { _processFollow( $graphRulesStorage(), _encodeAndCallGraphProcessFollow, IGraphRule.processFollow.selector, - originalMsgSender, - followerAccount, - accountToFollow, - primitiveCustomParams, - ruleProcessingParams + ProcessParams({ + originalMsgSender: originalMsgSender, + sourceAccount: followerAccount, + targetAccount: accountToFollow, + primitiveCustomParams: primitiveCustomParams, + rulesProcessingParams: rulesProcessingParams + }) ); } function _encodeAndCallGraphProcessUnfollow( - address rule, - bytes32 configSalt, - address originalMsgSender, - address followerAccount, - address accountToUnfollow, - KeyValue[] calldata primitiveCustomParams, + Rule memory rule, + ProcessParams memory processParams, KeyValue[] memory ruleCustomParams ) internal returns (bool, bytes memory) { - return rule.safecall( + return rule.ruleAddress.safecall( abi.encodeCall( IGraphRule.processUnfollow, ( - configSalt, - originalMsgSender, - followerAccount, - accountToUnfollow, - primitiveCustomParams, + rule.configSalt, + processParams.originalMsgSender, + processParams.sourceAccount, + processParams.targetAccount, + processParams.primitiveCustomParams, ruleCustomParams ) ) @@ -252,37 +254,35 @@ abstract contract RuleBasedGraph is IGraph, RuleBasedPrimitive { address followerAccount, address accountToUnfollow, KeyValue[] calldata primitiveCustomParams, - RuleProcessingParams[] calldata ruleProcessingParams + RuleProcessingParams[] calldata rulesProcessingParams ) internal { _processUnfollow( $graphRulesStorage(), _encodeAndCallGraphProcessUnfollow, - originalMsgSender, - followerAccount, - accountToUnfollow, - primitiveCustomParams, - ruleProcessingParams + ProcessParams({ + originalMsgSender: originalMsgSender, + sourceAccount: followerAccount, + targetAccount: accountToUnfollow, + primitiveCustomParams: primitiveCustomParams, + rulesProcessingParams: rulesProcessingParams + }) ); } function _encodeAndCallAccountProcessFollow( - address rule, - bytes32 configSalt, - address originalMsgSender, - address followerAccount, - address accountToFollow, - KeyValue[] calldata primitiveCustomParams, + Rule memory rule, + ProcessParams memory processParams, KeyValue[] memory ruleCustomParams ) internal returns (bool, bytes memory) { - return rule.safecall( + return rule.ruleAddress.safecall( abi.encodeCall( IFollowRule.processFollow, ( - configSalt, - originalMsgSender, - followerAccount, - accountToFollow, - primitiveCustomParams, + rule.configSalt, + processParams.originalMsgSender, + processParams.sourceAccount, + processParams.targetAccount, + processParams.primitiveCustomParams, ruleCustomParams ) ) @@ -294,143 +294,103 @@ abstract contract RuleBasedGraph is IGraph, RuleBasedPrimitive { address followerAccount, address accountToFollow, KeyValue[] calldata primitiveCustomParams, - RuleProcessingParams[] calldata ruleProcessingParams + RuleProcessingParams[] calldata rulesProcessingParams ) internal { _processFollow( $followRulesStorage(accountToFollow), _encodeAndCallAccountProcessFollow, IFollowRule.processFollow.selector, - originalMsgSender, - followerAccount, - accountToFollow, - primitiveCustomParams, - ruleProcessingParams + ProcessParams({ + originalMsgSender: originalMsgSender, + sourceAccount: followerAccount, + targetAccount: accountToFollow, + primitiveCustomParams: primitiveCustomParams, + rulesProcessingParams: rulesProcessingParams + }) ); } function _processUnfollow( RulesStorage storage rulesStorage, - function(address,bytes32,address,address,address,KeyValue[] calldata,KeyValue[] memory) internal returns (bool,bytes memory) - encodeAndCall, - address originalMsgSender, - address followerAccount, - address accountToUnfollow, - KeyValue[] calldata primitiveCustomParams, - RuleProcessingParams[] calldata rulesProcessingParams + function(Rule memory,ProcessParams memory,KeyValue[] memory) internal returns (bool,bytes memory) encodeAndCall, + ProcessParams memory processParams ) internal { bytes4 ruleSelector = IGraphRule.processUnfollow.selector; // Check required rules (AND-combined rules) for (uint256 i = 0; i < rulesStorage.requiredRules[ruleSelector].length; i++) { Rule memory rule = rulesStorage.requiredRules[ruleSelector][i]; // TODO: Think how to put this loop into a library (all the rules use it) - for (uint256 j = 0; j < rulesProcessingParams.length; j++) { + for (uint256 j = 0; j < processParams.rulesProcessingParams.length; j++) { KeyValue[] memory ruleCustomParams = new KeyValue[](0); if ( - rulesProcessingParams[j].ruleAddress == rule.ruleAddress - && rulesProcessingParams[j].configSalt == rule.configSalt + processParams.rulesProcessingParams[j].ruleAddress == rule.ruleAddress + && processParams.rulesProcessingParams[j].configSalt == rule.configSalt ) { - ruleCustomParams = rulesProcessingParams[j].ruleParams; + ruleCustomParams = processParams.rulesProcessingParams[j].ruleParams; } - // (bool callNotReverted,) = encodeAndCall( - // rule.ruleAddress, - // rule.configSalt, - // originalMsgSender, - // followerAccount, - // accountToUnfollow, - // primitiveCustomParams, - // ruleCustomParams - // ); - // require(callNotReverted, Errors.RequiredRuleReverted()); + (bool callNotReverted,) = encodeAndCall(rule, processParams, ruleCustomParams); + require(callNotReverted, Errors.RequiredRuleReverted()); } } for (uint256 i = 0; i < rulesStorage.anyOfRules[ruleSelector].length; i++) { Rule memory rule = rulesStorage.anyOfRules[ruleSelector][i]; - for (uint256 j = 0; j < rulesProcessingParams.length; j++) { + for (uint256 j = 0; j < processParams.rulesProcessingParams.length; j++) { KeyValue[] memory ruleCustomParams = new KeyValue[](0); if ( - rulesProcessingParams[j].ruleAddress == rule.ruleAddress - && rulesProcessingParams[j].configSalt == rule.configSalt + processParams.rulesProcessingParams[j].ruleAddress == rule.ruleAddress + && processParams.rulesProcessingParams[j].configSalt == rule.configSalt ) { - ruleCustomParams = rulesProcessingParams[j].ruleParams; + ruleCustomParams = processParams.rulesProcessingParams[j].ruleParams; + } + (bool callNotReverted,) = encodeAndCall(rule, processParams, ruleCustomParams); + if (callNotReverted) { + return; // If any of the OR-combined rules passed, it means they succeed and we can return } - // (bool callNotReverted,) = encodeAndCall( - // rule.ruleAddress, - // rule.configSalt, - // originalMsgSender, - // followerAccount, - // accountToUnfollow, - // primitiveCustomParams, - // ruleCustomParams - // ); - // if (callNotReverted) { - // return; // If any of the OR-combined rules passed, it means they succeed and we can return - // } } } // If there are any-of rules and it reached this point, it means all of them failed. - require($graphRulesStorage().anyOfRules[ruleSelector].length == 0, Errors.AllAnyOfRulesReverted()); + require(rulesStorage.anyOfRules[ruleSelector].length == 0, Errors.AllAnyOfRulesReverted()); } function _processFollow( RulesStorage storage rulesStorage, - function(address,bytes32,address,address,address,KeyValue[] calldata,KeyValue[] memory) internal returns (bool,bytes memory) - encodeAndCall, + function(Rule memory,ProcessParams memory,KeyValue[] memory) internal returns (bool,bytes memory) encodeAndCall, bytes4 ruleSelector, - address originalMsgSender, - address followerAccount, - address accountToFollow, - KeyValue[] calldata primitiveCustomParams, - RuleProcessingParams[] calldata rulesProcessingParams + ProcessParams memory processParams ) internal { // Check required rules (AND-combined rules) for (uint256 i = 0; i < rulesStorage.requiredRules[ruleSelector].length; i++) { Rule memory rule = rulesStorage.requiredRules[ruleSelector][i]; // TODO: Think how to put this loop into a library (all the rules use it) - for (uint256 j = 0; j < rulesProcessingParams.length; j++) { + for (uint256 j = 0; j < processParams.rulesProcessingParams.length; j++) { KeyValue[] memory ruleCustomParams = new KeyValue[](0); if ( - rulesProcessingParams[j].ruleAddress == rule.ruleAddress - && rulesProcessingParams[j].configSalt == rule.configSalt + processParams.rulesProcessingParams[j].ruleAddress == rule.ruleAddress + && processParams.rulesProcessingParams[j].configSalt == rule.configSalt ) { - ruleCustomParams = rulesProcessingParams[j].ruleParams; + ruleCustomParams = processParams.rulesProcessingParams[j].ruleParams; } - // (bool callNotReverted,) = encodeAndCall( - // rule.ruleAddress, - // rule.configSalt, - // originalMsgSender, - // followerAccount, - // accountToFollow, - // primitiveCustomParams, - // ruleCustomParams - // ); - // require(callNotReverted, Errors.RequiredRuleReverted()); + (bool callNotReverted,) = encodeAndCall(rule, processParams, ruleCustomParams); + require(callNotReverted, Errors.RequiredRuleReverted()); } } for (uint256 i = 0; i < rulesStorage.anyOfRules[ruleSelector].length; i++) { Rule memory rule = rulesStorage.anyOfRules[ruleSelector][i]; - for (uint256 j = 0; j < rulesProcessingParams.length; j++) { + for (uint256 j = 0; j < processParams.rulesProcessingParams.length; j++) { KeyValue[] memory ruleCustomParams = new KeyValue[](0); if ( - rulesProcessingParams[j].ruleAddress == rule.ruleAddress - && rulesProcessingParams[j].configSalt == rule.configSalt + processParams.rulesProcessingParams[j].ruleAddress == rule.ruleAddress + && processParams.rulesProcessingParams[j].configSalt == rule.configSalt ) { - ruleCustomParams = rulesProcessingParams[j].ruleParams; + ruleCustomParams = processParams.rulesProcessingParams[j].ruleParams; + } + (bool callNotReverted,) = encodeAndCall(rule, processParams, ruleCustomParams); + if (callNotReverted) { + return; // If any of the OR-combined rules passed, it means they succeed and we can return } - // (bool callNotReverted,) = encodeAndCall( - // rule.ruleAddress, - // rule.configSalt, - // originalMsgSender, - // followerAccount, - // accountToFollow, - // primitiveCustomParams, - // ruleCustomParams - // ); - // if (callNotReverted) { - // return; // If any of the OR-combined rules passed, it means they succeed and we can return - // } } } // If there are any-of rules and it reached this point, it means all of them failed. - require($graphRulesStorage().anyOfRules[ruleSelector].length == 0, Errors.AllAnyOfRulesReverted()); + require(rulesStorage.anyOfRules[ruleSelector].length == 0, Errors.AllAnyOfRulesReverted()); } } diff --git a/contracts/core/primitives/namespace/Namespace.sol b/contracts/core/primitives/namespace/Namespace.sol index 03a72144..67ce98df 100644 --- a/contracts/core/primitives/namespace/Namespace.sol +++ b/contracts/core/primitives/namespace/Namespace.sol @@ -100,22 +100,22 @@ contract Namespace is KeyValue[] calldata customParams, RuleProcessingParams[] calldata unassigningProcessingParams, RuleProcessingParams[] calldata creationProcessingParams, - RuleProcessingParams[] memory assigningProcessingParams, + RuleProcessingParams[] calldata assigningProcessingParams, KeyValue[] memory extraData ) external { - // require(msg.sender == account, Errors.InvalidMsgSender()); - // uint256 id = _computeId(username); - // _safeMint(account, id); - // _idToUsername[id] = username; - // Core._createUsername(username); - // address source = _processSourceStamp(id, customParams); - // _decodeAndSetUsernameExtraData(id, extraData); - // emit Lens_Username_Created(username, account, customParams, creationProcessingParams, source, extraData); - // _unassignIfAssigned(account, customParams, unassigningProcessingParams, source); - // Core._assignUsername(account, username); - // emit Lens_Username_Assigned(username, account, customParams, assigningProcessingParams, source); - // _processCreation(msg.sender, account, username, customParams, creationProcessingParams); - // _processAssigning(msg.sender, account, username, customParams, assigningProcessingParams); + require(msg.sender == account, Errors.InvalidMsgSender()); + uint256 id = _computeId(username); + _safeMint(account, id); + _idToUsername[id] = username; + Core._createUsername(username); + address source = _processSourceStamp(id, customParams); + _decodeAndSetUsernameExtraData(id, extraData); + emit Lens_Username_Created(username, account, customParams, creationProcessingParams, source, extraData); + _unassignIfAssigned(account, customParams, unassigningProcessingParams, source); + Core._assignUsername(account, username); + emit Lens_Username_Assigned(username, account, customParams, assigningProcessingParams, source); + _processCreation(msg.sender, account, username, customParams, creationProcessingParams); + _processAssigning(msg.sender, account, username, customParams, assigningProcessingParams); } function createUsername( diff --git a/contracts/core/primitives/namespace/RuleBasedNamespace.sol b/contracts/core/primitives/namespace/RuleBasedNamespace.sol index 0ed78dcf..9501a261 100644 --- a/contracts/core/primitives/namespace/RuleBasedNamespace.sol +++ b/contracts/core/primitives/namespace/RuleBasedNamespace.sol @@ -100,18 +100,21 @@ abstract contract RuleBasedNamespace is INamespace, RuleBasedPrimitive { //////////////////////////// PROCESSING FUNCTIONS //////////////////////////// function _encodeAndCallProcessCreation( - address rule, - bytes32 configSalt, - address originalMsgSender, - address account, - string memory username, - KeyValue[] calldata primitiveCustomParams, + Rule memory rule, + ProcessParams memory processParams, KeyValue[] memory ruleCustomParams ) internal returns (bool, bytes memory) { - return rule.safecall( + return rule.ruleAddress.safecall( abi.encodeCall( INamespaceRule.processCreation, - (configSalt, originalMsgSender, account, username, primitiveCustomParams, ruleCustomParams) + ( + rule.configSalt, + processParams.originalMsgSender, + processParams.account, + processParams.username, + processParams.primitiveCustomParams, + ruleCustomParams + ) ) ); } @@ -125,28 +128,32 @@ abstract contract RuleBasedNamespace is INamespace, RuleBasedPrimitive { ) internal { _processNamespaceRule( _encodeAndCallProcessCreation, - INamespaceRule.processCreation.selector, - originalMsgSender, - account, - username, - primitiveCustomParams, - rulesProcessingParams + ProcessParams({ + ruleSelector: INamespaceRule.processCreation.selector, + originalMsgSender: originalMsgSender, + account: account, + username: username, + primitiveCustomParams: primitiveCustomParams, + rulesProcessingParams: rulesProcessingParams + }) ); } function _encodeAndCallProcessRemoval( - address rule, - bytes32 configSalt, - address originalMsgSender, - address, /* account */ - string memory username, - KeyValue[] calldata primitiveCustomParams, + Rule memory rule, + ProcessParams memory processParams, KeyValue[] memory ruleCustomParams ) internal returns (bool, bytes memory) { - return rule.safecall( + return rule.ruleAddress.safecall( abi.encodeCall( INamespaceRule.processRemoval, - (configSalt, originalMsgSender, username, primitiveCustomParams, ruleCustomParams) + ( + rule.configSalt, + processParams.originalMsgSender, + processParams.username, + processParams.primitiveCustomParams, + ruleCustomParams + ) ) ); } @@ -159,28 +166,33 @@ abstract contract RuleBasedNamespace is INamespace, RuleBasedPrimitive { ) internal { _processNamespaceRule( _encodeAndCallProcessRemoval, - INamespaceRule.processRemoval.selector, - originalMsgSender, - address(0), - username, - primitiveCustomParams, - rulesProcessingParams + ProcessParams({ + ruleSelector: INamespaceRule.processRemoval.selector, + originalMsgSender: originalMsgSender, + account: address(0), + username: username, + primitiveCustomParams: primitiveCustomParams, + rulesProcessingParams: rulesProcessingParams + }) ); } function _encodeAndCallProcessAssigning( - address rule, - bytes32 configSalt, - address originalMsgSender, - address account, - string memory username, - KeyValue[] calldata primitiveCustomParams, + Rule memory rule, + ProcessParams memory processParams, KeyValue[] memory ruleCustomParams ) internal returns (bool, bytes memory) { - return rule.safecall( + return rule.ruleAddress.safecall( abi.encodeCall( INamespaceRule.processAssigning, - (configSalt, originalMsgSender, account, username, primitiveCustomParams, ruleCustomParams) + ( + rule.configSalt, + processParams.originalMsgSender, + processParams.account, + processParams.username, + processParams.primitiveCustomParams, + ruleCustomParams + ) ) ); } @@ -194,28 +206,33 @@ abstract contract RuleBasedNamespace is INamespace, RuleBasedPrimitive { ) internal { _processNamespaceRule( _encodeAndCallProcessAssigning, - INamespaceRule.processAssigning.selector, - originalMsgSender, - account, - username, - primitiveCustomParams, - rulesProcessingParams + ProcessParams({ + ruleSelector: INamespaceRule.processAssigning.selector, + originalMsgSender: originalMsgSender, + account: account, + username: username, + primitiveCustomParams: primitiveCustomParams, + rulesProcessingParams: rulesProcessingParams + }) ); } function _encodeAndCallProcessUnassigning( - address rule, - bytes32 configSalt, - address originalMsgSender, - address account, - string memory username, - KeyValue[] calldata primitiveCustomParams, + Rule memory rule, + ProcessParams memory processParams, KeyValue[] memory ruleCustomParams ) internal returns (bool, bytes memory) { - return rule.safecall( + return rule.ruleAddress.safecall( abi.encodeCall( INamespaceRule.processUnassigning, - (configSalt, originalMsgSender, account, username, primitiveCustomParams, ruleCustomParams) + ( + rule.configSalt, + processParams.originalMsgSender, + processParams.account, + processParams.username, + processParams.primitiveCustomParams, + ruleCustomParams + ) ) ); } @@ -229,74 +246,65 @@ abstract contract RuleBasedNamespace is INamespace, RuleBasedPrimitive { ) internal { _processNamespaceRule( _encodeAndCallProcessUnassigning, - INamespaceRule.processUnassigning.selector, - originalMsgSender, - account, - username, - primitiveCustomParams, - rulesProcessingParams + ProcessParams({ + ruleSelector: INamespaceRule.processUnassigning.selector, + originalMsgSender: originalMsgSender, + account: account, + username: username, + primitiveCustomParams: primitiveCustomParams, + rulesProcessingParams: rulesProcessingParams + }) ); } + struct ProcessParams { + bytes4 ruleSelector; + address originalMsgSender; + address account; + string username; + KeyValue[] primitiveCustomParams; + RuleProcessingParams[] rulesProcessingParams; + } + function _processNamespaceRule( - function(address,bytes32,address,address,string memory,KeyValue[] calldata,KeyValue[] memory) internal returns (bool,bytes memory) - encodeAndCall, - bytes4 ruleSelector, - address originalMsgSender, - address account, - string memory username, - KeyValue[] calldata primitiveCustomParams, - RuleProcessingParams[] calldata rulesProcessingParams + function(Rule memory,ProcessParams memory,KeyValue[] memory) internal returns (bool,bytes memory) encodeAndCall, + ProcessParams memory processParams ) private { // Check required rules (AND-combined rules) - for (uint256 i = 0; i < $namespaceRulesStorage().requiredRules[ruleSelector].length; i++) { - Rule memory rule = $namespaceRulesStorage().requiredRules[ruleSelector][i]; - for (uint256 j = 0; j < rulesProcessingParams.length; j++) { + for (uint256 i = 0; i < $namespaceRulesStorage().requiredRules[processParams.ruleSelector].length; i++) { + Rule memory rule = $namespaceRulesStorage().requiredRules[processParams.ruleSelector][i]; + for (uint256 j = 0; j < processParams.rulesProcessingParams.length; j++) { KeyValue[] memory ruleParams = new KeyValue[](0); if ( - rulesProcessingParams[j].ruleAddress == rule.ruleAddress - && rulesProcessingParams[j].configSalt == rule.configSalt + processParams.rulesProcessingParams[j].ruleAddress == rule.ruleAddress + && processParams.rulesProcessingParams[j].configSalt == rule.configSalt ) { - ruleParams = rulesProcessingParams[j].ruleParams; + ruleParams = processParams.rulesProcessingParams[j].ruleParams; } - // (bool callNotReverted,) = encodeAndCall( - // rule.ruleAddress, - // rule.configSalt, - // originalMsgSender, - // account, - // username, - // primitiveCustomParams, - // ruleParams - // ); - // require(callNotReverted, Errors.RequiredRuleReverted()); + (bool callNotReverted,) = encodeAndCall(rule, processParams, ruleParams); + require(callNotReverted, Errors.RequiredRuleReverted()); } } // Check any-of rules (OR-combined rules) - for (uint256 i = 0; i < $namespaceRulesStorage().anyOfRules[ruleSelector].length; i++) { - Rule memory rule = $namespaceRulesStorage().anyOfRules[ruleSelector][i]; - for (uint256 j = 0; j < rulesProcessingParams.length; j++) { + for (uint256 i = 0; i < $namespaceRulesStorage().anyOfRules[processParams.ruleSelector].length; i++) { + Rule memory rule = $namespaceRulesStorage().anyOfRules[processParams.ruleSelector][i]; + for (uint256 j = 0; j < processParams.rulesProcessingParams.length; j++) { KeyValue[] memory ruleParams = new KeyValue[](0); if ( - rulesProcessingParams[j].ruleAddress == rule.ruleAddress - && rulesProcessingParams[j].configSalt == rule.configSalt + processParams.rulesProcessingParams[j].ruleAddress == rule.ruleAddress + && processParams.rulesProcessingParams[j].configSalt == rule.configSalt ) { - ruleParams = rulesProcessingParams[j].ruleParams; + ruleParams = processParams.rulesProcessingParams[j].ruleParams; + } + (bool callNotReverted,) = encodeAndCall(rule, processParams, ruleParams); + if (callNotReverted) { + return; // If any of the OR-combined rules passed, it means they succeed and we can return } - // (bool callNotReverted,) = encodeAndCall( - // rule.ruleAddress, - // rule.configSalt, - // originalMsgSender, - // account, - // username, - // primitiveCustomParams, - // ruleParams - // ); - // if (callNotReverted) { - // return; // If any of the OR-combined rules passed, it means they succeed and we can return - // } } } // If there are any-of rules and it reached this point, it means all of them failed. - require($namespaceRulesStorage().anyOfRules[ruleSelector].length == 0, Errors.AllAnyOfRulesReverted()); + require( + $namespaceRulesStorage().anyOfRules[processParams.ruleSelector].length == 0, Errors.AllAnyOfRulesReverted() + ); } } diff --git a/contracts/extensions/factories/LensFactory.sol b/contracts/extensions/factories/LensFactory.sol index bece1ccb..eab6ef0b 100644 --- a/contracts/extensions/factories/LensFactory.sol +++ b/contracts/extensions/factories/LensFactory.sol @@ -274,32 +274,32 @@ contract LensFactory { ); } - // function deployNamespace( - // string calldata namespace, - // string calldata metadataURI, - // address owner, - // address[] calldata admins, - // RuleChange[] calldata rules, - // KeyValue[] calldata extraData, - // string calldata nftName, - // string calldata nftSymbol - // ) external returns (address) { - // ITokenURIProvider tokenURIProvider = new LensUsernameTokenURIProvider(); - // IRoleBasedAccessControl accessControl = _deployAccessControl(owner, admins); - // return NAMESPACE_FACTORY.deployNamespace( - // namespace, - // metadataURI, - // accessControl, - // owner, - // _injectRuleAccessControl(rules, address(accessControl)), - // extraData, - // nftName, - // nftSymbol, - // tokenURIProvider - // ); - // } + function deployNamespace( + string memory namespace, + string memory metadataURI, + address owner, + address[] memory admins, + RuleChange[] calldata rules, + KeyValue[] calldata extraData, + string memory nftName, + string memory nftSymbol + ) external returns (address) { + ITokenURIProvider tokenURIProvider = new LensUsernameTokenURIProvider(); + IRoleBasedAccessControl accessControl = _deployAccessControl(owner, admins); + return NAMESPACE_FACTORY.deployNamespace( + namespace, + metadataURI, + accessControl, + owner, + _injectRuleAccessControl(rules, address(accessControl)), + extraData, + nftName, + nftSymbol, + tokenURIProvider + ); + } - function _deployAccessControl(address owner, address[] calldata admins) internal returns (IRoleBasedAccessControl) { + function _deployAccessControl(address owner, address[] memory admins) internal returns (IRoleBasedAccessControl) { return ACCESS_CONTROL_FACTORY.deployOwnerAdminOnlyAccessControl(owner, admins); } diff --git a/test/factories/LensFactory.t.sol b/test/factories/LensFactory.t.sol index 3d6fdba6..50cd0b3d 100644 --- a/test/factories/LensFactory.t.sol +++ b/test/factories/LensFactory.t.sol @@ -25,18 +25,18 @@ contract LensFactoryTest is Test, BaseDeployments { function setUp() public override { super.setUp(); - // namespace = Namespace( - // lensFactory.deployNamespace({ - // namespace: "bitcoin", - // metadataURI: "satoshi://nakamoto", - // owner: address(this), - // admins: new address[](0), - // rules: new RuleChange[](0), - // extraData: new KeyValue[](0), - // nftName: "Bitcoin", - // nftSymbol: "BTC" - // }) - // ); + namespace = Namespace( + lensFactory.deployNamespace({ + namespace: "bitcoin", + metadataURI: "satoshi://nakamoto", + owner: address(this), + admins: new address[](0), + rules: new RuleChange[](0), + extraData: new KeyValue[](0), + nftName: "Bitcoin", + nftSymbol: "BTC" + }) + ); } function testCanDeployFeed() public { diff --git a/test/primitives/Namespace.t.sol b/test/primitives/Namespace.t.sol index 32b4f1a2..9e097c7e 100644 --- a/test/primitives/Namespace.t.sol +++ b/test/primitives/Namespace.t.sol @@ -20,18 +20,18 @@ contract NamespaceTest is Test, BaseDeployments { function setUp() public override { super.setUp(); - // namespace = INamespace( - // lensFactory.deployNamespace({ - // namespace: "bitcoin", - // metadataURI: "satoshi://nakamoto", - // owner: namespaceOwner, - // admins: _emptyAddressArray(), - // rules: _emptyRuleChangeArray(), - // extraData: _emptyKeyValueArray(), - // nftName: "Bitcoin", - // nftSymbol: "BTC" - // }) - // ); + namespace = INamespace( + lensFactory.deployNamespace({ + namespace: "bitcoin", + metadataURI: "satoshi://nakamoto", + owner: namespaceOwner, + admins: _emptyAddressArray(), + rules: _emptyRuleChangeArray(), + extraData: _emptyKeyValueArray(), + nftName: "Bitcoin", + nftSymbol: "BTC" + }) + ); } function testCreateAssignUnassignDelete() public { From 706a0aa57d61c625656dcd711934df85e95abad3 Mon Sep 17 00:00:00 2001 From: vicnaum Date: Fri, 10 Jan 2025 11:24:46 +0100 Subject: [PATCH 4/9] misc: Rule Based Feed and Group made to compile without IR --- .../core/primitives/feed/RuleBasedFeed.sol | 266 ++++++++++-------- .../core/primitives/group/RuleBasedGroup.sol | 169 ++++++----- 2 files changed, 235 insertions(+), 200 deletions(-) diff --git a/contracts/core/primitives/feed/RuleBasedFeed.sol b/contracts/core/primitives/feed/RuleBasedFeed.sol index 8d2ab2da..41ff7587 100644 --- a/contracts/core/primitives/feed/RuleBasedFeed.sol +++ b/contracts/core/primitives/feed/RuleBasedFeed.sol @@ -136,121 +136,132 @@ abstract contract RuleBasedFeed is IFeed, RuleBasedPrimitive { // Internal function _encodeAndCallProcessCreatePostOnFeed( - address rule, - bytes32 configSalt, - uint256, /* rootPostId */ - uint256 postId, - CreatePostParams calldata postParams, - KeyValue[] calldata primitiveCustomParams, + Rule memory rule, + ProcessPostCreationParams memory processParams, KeyValue[] memory ruleCustomParams ) internal returns (bool, bytes memory) { - return rule.safecall( + return rule.ruleAddress.safecall( abi.encodeCall( - IFeedRule.processCreatePost, (configSalt, postId, postParams, primitiveCustomParams, ruleCustomParams) + IFeedRule.processCreatePost, + ( + rule.configSalt, + processParams.postId, + processParams.postParams, + processParams.primitiveCustomParams, + ruleCustomParams + ) ) ); } function _encodeAndCallProcessCreatePostOnRootPost( - address rule, - bytes32 configSalt, - uint256 rootPostId, - uint256 postId, - CreatePostParams calldata postParams, - KeyValue[] calldata primitiveCustomParams, + Rule memory rule, + ProcessPostCreationParams memory processParams, KeyValue[] memory ruleCustomParams ) internal returns (bool, bytes memory) { - return rule.safecall( + return rule.ruleAddress.safecall( abi.encodeCall( IPostRule.processCreatePost, - (configSalt, rootPostId, postId, postParams, primitiveCustomParams, ruleCustomParams) + ( + rule.configSalt, + processParams.rootPostId, + processParams.postId, + processParams.postParams, + processParams.primitiveCustomParams, + ruleCustomParams + ) ) ); } + struct ProcessPostCreationParams { + bytes4 ruleSelector; + uint256 rootPostId; + uint256 postId; + CreatePostParams postParams; + KeyValue[] primitiveCustomParams; + RuleProcessingParams[] rulesProcessingParams; + } + function _processPostCreation( - function(address,bytes32,uint256,uint256,CreatePostParams calldata,KeyValue[] calldata,KeyValue[] memory) internal returns (bool, bytes memory) + function(Rule memory,ProcessPostCreationParams memory,KeyValue[] memory) internal returns (bool, bytes memory) encodeAndCall, - bytes4 ruleSelector, - uint256 rootPostId, - uint256 postId, - CreatePostParams calldata postParams, - KeyValue[] calldata customParams, - RuleProcessingParams[] calldata rulesProcessingParams + ProcessPostCreationParams memory processParams ) internal { - RulesStorage storage _rulesStorage = rootPostId == 0 ? $feedRulesStorage() : $postRulesStorage(rootPostId); + RulesStorage storage _rulesStorage = + processParams.rootPostId == 0 ? $feedRulesStorage() : $postRulesStorage(processParams.rootPostId); // Check required rules (AND-combined rules) - for (uint256 i = 0; i < _rulesStorage.requiredRules[ruleSelector].length; i++) { - Rule memory rule = _rulesStorage.requiredRules[ruleSelector][i]; - for (uint256 j = 0; j < rulesProcessingParams.length; j++) { + for (uint256 i = 0; i < _rulesStorage.requiredRules[processParams.ruleSelector].length; i++) { + Rule memory rule = _rulesStorage.requiredRules[processParams.ruleSelector][i]; + for (uint256 j = 0; j < processParams.rulesProcessingParams.length; j++) { KeyValue[] memory ruleCustomParams = new KeyValue[](0); if ( - rulesProcessingParams[j].ruleAddress == rule.ruleAddress - && rulesProcessingParams[j].configSalt == rule.configSalt + processParams.rulesProcessingParams[j].ruleAddress == rule.ruleAddress + && processParams.rulesProcessingParams[j].configSalt == rule.configSalt ) { - ruleCustomParams = rulesProcessingParams[j].ruleParams; + ruleCustomParams = processParams.rulesProcessingParams[j].ruleParams; } - // (bool callNotReverted,) = encodeAndCall( - // rule.ruleAddress, rule.configSalt, rootPostId, postId, postParams, customParams, ruleCustomParams - // ); - // require(callNotReverted, Errors.RequiredRuleReverted()); + (bool callNotReverted,) = encodeAndCall(rule, processParams, ruleCustomParams); + require(callNotReverted, Errors.RequiredRuleReverted()); } } // Check any-of rules (OR-combined rules) - for (uint256 i = 0; i < _rulesStorage.anyOfRules[ruleSelector].length; i++) { - Rule memory rule = _rulesStorage.anyOfRules[ruleSelector][i]; - for (uint256 j = 0; j < rulesProcessingParams.length; j++) { + for (uint256 i = 0; i < _rulesStorage.anyOfRules[processParams.ruleSelector].length; i++) { + Rule memory rule = _rulesStorage.anyOfRules[processParams.ruleSelector][i]; + for (uint256 j = 0; j < processParams.rulesProcessingParams.length; j++) { KeyValue[] memory ruleCustomParams = new KeyValue[](0); if ( - rulesProcessingParams[j].ruleAddress == rule.ruleAddress - && rulesProcessingParams[j].configSalt == rule.configSalt + processParams.rulesProcessingParams[j].ruleAddress == rule.ruleAddress + && processParams.rulesProcessingParams[j].configSalt == rule.configSalt ) { - ruleCustomParams = rulesProcessingParams[j].ruleParams; + ruleCustomParams = processParams.rulesProcessingParams[j].ruleParams; + } + (bool callNotReverted,) = encodeAndCall(rule, processParams, ruleCustomParams); + if (callNotReverted) { + return; // If any of the OR-combined rules passed, it means they succeed and we can return } - // (bool callNotReverted,) = encodeAndCall( - // rule.ruleAddress, rule.configSalt, rootPostId, postId, postParams, customParams, ruleCustomParams - // ); - // if (callNotReverted) { - // return; // If any of the OR-combined rules passed, it means they succeed and we can return - // } } } // If there are any-of rules and it reached this point, it means all of them failed. - require(_rulesStorage.anyOfRules[ruleSelector].length == 0, Errors.AllAnyOfRulesReverted()); + require(_rulesStorage.anyOfRules[processParams.ruleSelector].length == 0, Errors.AllAnyOfRulesReverted()); } function _processPostCreationOnRootPost( uint256 rootPostId, uint256 postId, CreatePostParams calldata postParams, - KeyValue[] calldata customParams, + KeyValue[] calldata primitiveCustomParams, RuleProcessingParams[] calldata postRulesParams ) internal { _processPostCreation( _encodeAndCallProcessCreatePostOnRootPost, - IPostRule.processCreatePost.selector, - rootPostId, - postId, - postParams, - customParams, - postRulesParams + ProcessPostCreationParams({ + ruleSelector: IPostRule.processCreatePost.selector, + rootPostId: rootPostId, + postId: postId, + postParams: postParams, + primitiveCustomParams: primitiveCustomParams, + rulesProcessingParams: postRulesParams + }) ); } function _processPostCreationOnFeed( uint256 postId, CreatePostParams calldata postParams, - KeyValue[] calldata customParams, + KeyValue[] calldata primitiveCustomParams, RuleProcessingParams[] calldata feedRulesParams ) internal { _processPostCreation( _encodeAndCallProcessCreatePostOnFeed, - IFeedRule.processCreatePost.selector, - 0, - postId, - postParams, - customParams, - feedRulesParams + ProcessPostCreationParams({ + ruleSelector: IFeedRule.processCreatePost.selector, + rootPostId: 0, + postId: postId, + postParams: postParams, + primitiveCustomParams: primitiveCustomParams, + rulesProcessingParams: feedRulesParams + }) ); } @@ -258,119 +269,130 @@ abstract contract RuleBasedFeed is IFeed, RuleBasedPrimitive { uint256 rootPostId, uint256 postId, EditPostParams calldata postParams, - KeyValue[] calldata customParams, + KeyValue[] calldata primitiveCustomParams, RuleProcessingParams[] calldata postRulesParams ) internal { _processPostEditing( _encodeAndCallProcessEditPostOnRootPost, - IPostRule.processEditPost.selector, - rootPostId, - postId, - postParams, - customParams, - postRulesParams + ProcessPostEditingParams({ + ruleSelector: IPostRule.processEditPost.selector, + rootPostId: rootPostId, + postId: postId, + postParams: postParams, + primitiveCustomParams: primitiveCustomParams, + rulesProcessingParams: postRulesParams + }) ); } function _processPostEditingOnFeed( uint256 postId, EditPostParams calldata postParams, - KeyValue[] calldata customParams, + KeyValue[] calldata primitiveCustomParams, RuleProcessingParams[] calldata feedRulesParams ) internal { _processPostEditing( _encodeAndCallProcessEditPostOnFeed, - IFeedRule.processEditPost.selector, - 0, - postId, - postParams, - customParams, - feedRulesParams + ProcessPostEditingParams({ + ruleSelector: IFeedRule.processEditPost.selector, + rootPostId: 0, + postId: postId, + postParams: postParams, + primitiveCustomParams: primitiveCustomParams, + rulesProcessingParams: feedRulesParams + }) ); } function _encodeAndCallProcessEditPostOnFeed( - address rule, - bytes32 configSalt, - uint256, /* rootPostId */ - uint256 postId, - EditPostParams calldata postParams, - KeyValue[] calldata primitiveCustomParams, + Rule memory rule, + ProcessPostEditingParams memory processParams, KeyValue[] memory ruleCustomParams ) internal returns (bool, bytes memory) { - return rule.safecall( + return rule.ruleAddress.safecall( abi.encodeCall( - IFeedRule.processEditPost, (configSalt, postId, postParams, primitiveCustomParams, ruleCustomParams) + IFeedRule.processEditPost, + ( + rule.configSalt, + processParams.postId, + processParams.postParams, + processParams.primitiveCustomParams, + ruleCustomParams + ) ) ); } function _encodeAndCallProcessEditPostOnRootPost( - address rule, - bytes32 configSalt, - uint256 rootPostId, - uint256 postId, - EditPostParams calldata postParams, - KeyValue[] calldata primitiveCustomParams, + Rule memory rule, + ProcessPostEditingParams memory processParams, KeyValue[] memory ruleCustomParams ) internal returns (bool, bytes memory) { - return rule.safecall( + return rule.ruleAddress.safecall( abi.encodeCall( IPostRule.processEditPost, - (configSalt, rootPostId, postId, postParams, primitiveCustomParams, ruleCustomParams) + ( + rule.configSalt, + processParams.rootPostId, + processParams.postId, + processParams.postParams, + processParams.primitiveCustomParams, + ruleCustomParams + ) ) ); } + struct ProcessPostEditingParams { + bytes4 ruleSelector; + uint256 rootPostId; + uint256 postId; + EditPostParams postParams; + KeyValue[] primitiveCustomParams; + RuleProcessingParams[] rulesProcessingParams; + } + function _processPostEditing( - function(address,bytes32,uint256,uint256,EditPostParams calldata,KeyValue[] calldata,KeyValue[] memory) internal returns (bool, bytes memory) + function(Rule memory,ProcessPostEditingParams memory,KeyValue[] memory) internal returns (bool,bytes memory) encodeAndCall, - bytes4 ruleSelector, - uint256 rootPostId, - uint256 postId, - EditPostParams calldata postParams, - KeyValue[] calldata customParams, - RuleProcessingParams[] calldata rulesProcessingParams + ProcessPostEditingParams memory processParams ) internal { - RulesStorage storage _rulesStorage = rootPostId == 0 ? $feedRulesStorage() : $postRulesStorage(rootPostId); + RulesStorage storage _rulesStorage = + processParams.rootPostId == 0 ? $feedRulesStorage() : $postRulesStorage(processParams.rootPostId); // Check required rules (AND-combined rules) - for (uint256 i = 0; i < _rulesStorage.requiredRules[ruleSelector].length; i++) { - Rule memory rule = _rulesStorage.requiredRules[ruleSelector][i]; - for (uint256 j = 0; j < rulesProcessingParams.length; j++) { + for (uint256 i = 0; i < _rulesStorage.requiredRules[processParams.ruleSelector].length; i++) { + Rule memory rule = _rulesStorage.requiredRules[processParams.ruleSelector][i]; + for (uint256 j = 0; j < processParams.rulesProcessingParams.length; j++) { KeyValue[] memory ruleCustomParams = new KeyValue[](0); if ( - rulesProcessingParams[j].ruleAddress == rule.ruleAddress - && rulesProcessingParams[j].configSalt == rule.configSalt + processParams.rulesProcessingParams[j].ruleAddress == rule.ruleAddress + && processParams.rulesProcessingParams[j].configSalt == rule.configSalt ) { - ruleCustomParams = rulesProcessingParams[j].ruleParams; + ruleCustomParams = processParams.rulesProcessingParams[j].ruleParams; } - // (bool callNotReverted,) = encodeAndCall( - // rule.ruleAddress, rule.configSalt, rootPostId, postId, postParams, customParams, ruleCustomParams - // ); - // require(callNotReverted, Errors.RequiredRuleReverted()); + (bool callNotReverted,) = encodeAndCall(rule, processParams, ruleCustomParams); + require(callNotReverted, Errors.RequiredRuleReverted()); } } // Check any-of rules (OR-combined rules) - for (uint256 i = 0; i < _rulesStorage.anyOfRules[ruleSelector].length; i++) { - Rule memory rule = _rulesStorage.anyOfRules[ruleSelector][i]; - for (uint256 j = 0; j < rulesProcessingParams.length; j++) { + for (uint256 i = 0; i < _rulesStorage.anyOfRules[processParams.ruleSelector].length; i++) { + Rule memory rule = _rulesStorage.anyOfRules[processParams.ruleSelector][i]; + for (uint256 j = 0; j < processParams.rulesProcessingParams.length; j++) { KeyValue[] memory ruleCustomParams = new KeyValue[](0); if ( - rulesProcessingParams[j].ruleAddress == rule.ruleAddress - && rulesProcessingParams[j].configSalt == rule.configSalt + processParams.rulesProcessingParams[j].ruleAddress == rule.ruleAddress + && processParams.rulesProcessingParams[j].configSalt == rule.configSalt ) { - ruleCustomParams = rulesProcessingParams[j].ruleParams; + ruleCustomParams = processParams.rulesProcessingParams[j].ruleParams; + } + (bool callNotReverted,) = encodeAndCall(rule, processParams, ruleCustomParams); + if (callNotReverted) { + return; // If any of the OR-combined rules passed, it means they succeed and we can return } - // (bool callNotReverted,) = encodeAndCall( - // rule.ruleAddress, rule.configSalt, rootPostId, postId, postParams, customParams, ruleCustomParams - // ); - // if (callNotReverted) { - // return; // If any of the OR-combined rules passed, it means they succeed and we can return - // } } } // If there are any-of rules and it reached this point, it means all of them failed. - require(_rulesStorage.anyOfRules[ruleSelector].length == 0, Errors.AllAnyOfRulesReverted()); + require(_rulesStorage.anyOfRules[processParams.ruleSelector].length == 0, Errors.AllAnyOfRulesReverted()); } function _processPostRemoval( diff --git a/contracts/core/primitives/group/RuleBasedGroup.sol b/contracts/core/primitives/group/RuleBasedGroup.sol index 480aee7d..95cb3e6b 100644 --- a/contracts/core/primitives/group/RuleBasedGroup.sol +++ b/contracts/core/primitives/group/RuleBasedGroup.sol @@ -100,17 +100,20 @@ abstract contract RuleBasedGroup is IGroup, RuleBasedPrimitive { //////////////////////////// PROCESSING FUNCTIONS //////////////////////////// function _encodeAndCallProcessMemberRemoval( - address rule, - bytes32 configSalt, - address originalMsgSender, - address account, - KeyValue[] calldata primitiveCustomParams, + Rule memory rule, + ProcessParams memory processParams, KeyValue[] memory ruleCustomParams ) internal returns (bool, bytes memory) { - return rule.safecall( + return rule.ruleAddress.safecall( abi.encodeCall( IGroupRule.processRemoval, - (configSalt, originalMsgSender, account, primitiveCustomParams, ruleCustomParams) + ( + rule.configSalt, + processParams.originalMsgSender, + processParams.account, + processParams.primitiveCustomParams, + ruleCustomParams + ) ) ); } @@ -123,26 +126,31 @@ abstract contract RuleBasedGroup is IGroup, RuleBasedPrimitive { ) internal { _processGroupRule( _encodeAndCallProcessMemberRemoval, - IGroupRule.processRemoval.selector, - originalMsgSender, - account, - primitiveCustomParams, - ruleProcessingParams + ProcessParams({ + ruleSelector: IGroupRule.processRemoval.selector, + originalMsgSender: originalMsgSender, + account: account, + primitiveCustomParams: primitiveCustomParams, + rulesProcessingParams: ruleProcessingParams + }) ); } function _encodeAndCallProcessMemberAddition( - address rule, - bytes32 configSalt, - address originalMsgSender, - address account, - KeyValue[] calldata primitiveCustomParams, + Rule memory rule, + ProcessParams memory processParams, KeyValue[] memory ruleCustomParams ) internal returns (bool, bytes memory) { - return rule.safecall( + return rule.ruleAddress.safecall( abi.encodeCall( IGroupRule.processAddition, - (configSalt, originalMsgSender, account, primitiveCustomParams, ruleCustomParams) + ( + rule.configSalt, + processParams.originalMsgSender, + processParams.account, + processParams.primitiveCustomParams, + ruleCustomParams + ) ) ); } @@ -155,24 +163,26 @@ abstract contract RuleBasedGroup is IGroup, RuleBasedPrimitive { ) internal { _processGroupRule( _encodeAndCallProcessMemberAddition, - IGroupRule.processAddition.selector, - originalMsgSender, - account, - primitiveCustomParams, - ruleProcessingParams + ProcessParams({ + ruleSelector: IGroupRule.processAddition.selector, + originalMsgSender: originalMsgSender, + account: account, + primitiveCustomParams: primitiveCustomParams, + rulesProcessingParams: ruleProcessingParams + }) ); } function _encodeAndCallProcessMemberJoining( - address rule, - bytes32 configSalt, - address, /* originalMsgSender */ - address account, - KeyValue[] calldata primitiveCustomParams, + Rule memory rule, + ProcessParams memory processParams, KeyValue[] memory ruleCustomParams ) internal returns (bool, bytes memory) { - return rule.safecall( - abi.encodeCall(IGroupRule.processJoining, (configSalt, account, primitiveCustomParams, ruleCustomParams)) + return rule.ruleAddress.safecall( + abi.encodeCall( + IGroupRule.processJoining, + (rule.configSalt, processParams.account, processParams.primitiveCustomParams, ruleCustomParams) + ) ); } @@ -184,24 +194,26 @@ abstract contract RuleBasedGroup is IGroup, RuleBasedPrimitive { ) internal { _processGroupRule( _encodeAndCallProcessMemberJoining, - IGroupRule.processJoining.selector, - originalMsgSender, - account, - primitiveCustomParams, - ruleProcessingParams + ProcessParams({ + ruleSelector: IGroupRule.processJoining.selector, + originalMsgSender: originalMsgSender, + account: account, + primitiveCustomParams: primitiveCustomParams, + rulesProcessingParams: ruleProcessingParams + }) ); } function _encodeAndCallProcessMemberLeaving( - address rule, - bytes32 configSalt, - address, /* originalMsgSender */ - address account, - KeyValue[] calldata primitiveCustomParams, + Rule memory rule, + ProcessParams memory processParams, KeyValue[] memory ruleCustomParams ) internal returns (bool, bytes memory) { - return rule.safecall( - abi.encodeCall(IGroupRule.processLeaving, (configSalt, account, primitiveCustomParams, ruleCustomParams)) + return rule.ruleAddress.safecall( + abi.encodeCall( + IGroupRule.processLeaving, + (rule.configSalt, processParams.account, processParams.primitiveCustomParams, ruleCustomParams) + ) ); } @@ -213,60 +225,61 @@ abstract contract RuleBasedGroup is IGroup, RuleBasedPrimitive { ) internal { _processGroupRule( _encodeAndCallProcessMemberLeaving, - IGroupRule.processLeaving.selector, - originalMsgSender, - account, - primitiveCustomParams, - ruleProcessingParams + ProcessParams({ + ruleSelector: IGroupRule.processLeaving.selector, + originalMsgSender: originalMsgSender, + account: account, + primitiveCustomParams: primitiveCustomParams, + rulesProcessingParams: ruleProcessingParams + }) ); } + struct ProcessParams { + bytes4 ruleSelector; + address originalMsgSender; + address account; + KeyValue[] primitiveCustomParams; + RuleProcessingParams[] rulesProcessingParams; + } + function _processGroupRule( - function(address,bytes32,address,address,KeyValue[] calldata,KeyValue[] memory) internal returns (bool,bytes memory) - encodeAndCall, - bytes4 ruleSelector, - address originalMsgSender, - address account, - KeyValue[] calldata primitiveCustomParams, - RuleProcessingParams[] calldata rulesProcessingParams + function(Rule memory,ProcessParams memory,KeyValue[] memory) internal returns (bool,bytes memory) encodeAndCall, + ProcessParams memory processParams ) private { // Check required rules (AND-combined rules) - for (uint256 i = 0; i < $groupRulesStorage().requiredRules[ruleSelector].length; i++) { - Rule memory rule = $groupRulesStorage().requiredRules[ruleSelector][i]; - for (uint256 j = 0; j < rulesProcessingParams.length; j++) { + for (uint256 i = 0; i < $groupRulesStorage().requiredRules[processParams.ruleSelector].length; i++) { + Rule memory rule = $groupRulesStorage().requiredRules[processParams.ruleSelector][i]; + for (uint256 j = 0; j < processParams.rulesProcessingParams.length; j++) { KeyValue[] memory ruleParams = new KeyValue[](0); if ( - rulesProcessingParams[j].ruleAddress == rule.ruleAddress - && rulesProcessingParams[j].configSalt == rule.configSalt + processParams.rulesProcessingParams[j].ruleAddress == rule.ruleAddress + && processParams.rulesProcessingParams[j].configSalt == rule.configSalt ) { - ruleParams = rulesProcessingParams[j].ruleParams; + ruleParams = processParams.rulesProcessingParams[j].ruleParams; } - // (bool callNotReverted,) = encodeAndCall( - // rule.ruleAddress, rule.configSalt, originalMsgSender, account, primitiveCustomParams, ruleParams - // ); - // require(callNotReverted, Errors.RequiredRuleReverted()); + (bool callNotReverted,) = encodeAndCall(rule, processParams, ruleParams); + require(callNotReverted, Errors.RequiredRuleReverted()); } } // Check any-of rules (OR-combined rules) - for (uint256 i = 0; i < $groupRulesStorage().anyOfRules[ruleSelector].length; i++) { - Rule memory rule = $groupRulesStorage().anyOfRules[ruleSelector][i]; - for (uint256 j = 0; j < rulesProcessingParams.length; j++) { + for (uint256 i = 0; i < $groupRulesStorage().anyOfRules[processParams.ruleSelector].length; i++) { + Rule memory rule = $groupRulesStorage().anyOfRules[processParams.ruleSelector][i]; + for (uint256 j = 0; j < processParams.rulesProcessingParams.length; j++) { KeyValue[] memory ruleParams = new KeyValue[](0); if ( - rulesProcessingParams[j].ruleAddress == rule.ruleAddress - && rulesProcessingParams[j].configSalt == rule.configSalt + processParams.rulesProcessingParams[j].ruleAddress == rule.ruleAddress + && processParams.rulesProcessingParams[j].configSalt == rule.configSalt ) { - ruleParams = rulesProcessingParams[j].ruleParams; + ruleParams = processParams.rulesProcessingParams[j].ruleParams; + } + (bool callNotReverted,) = encodeAndCall(rule, processParams, ruleParams); + if (callNotReverted) { + return; // If any of the OR-combined rules passed, it means they succeed and we can return } - // (bool callNotReverted,) = encodeAndCall( - // rule.ruleAddress, rule.configSalt, originalMsgSender, account, primitiveCustomParams, ruleParams - // ); - // if (callNotReverted) { - // return; // If any of the OR-combined rules passed, it means they succeed and we can return - // } } } // If there are any-of rules and it reached this point, it means all of them failed. - require($groupRulesStorage().anyOfRules[ruleSelector].length == 0, Errors.AllAnyOfRulesReverted()); + require($groupRulesStorage().anyOfRules[processParams.ruleSelector].length == 0, Errors.AllAnyOfRulesReverted()); } } From 0ba5dd181c2ef0e595e7e7f89cbaba4fe8c146bb Mon Sep 17 00:00:00 2001 From: vicnaum Date: Fri, 10 Jan 2025 11:36:02 +0100 Subject: [PATCH 5/9] misc: RuleBasePrimitive made to compile without IR --- contracts/core/base/RuleBasedPrimitive.sol | 80 +++++++++---------- contracts/core/libraries/RulesLib.sol | 28 ++++--- contracts/core/primitives/feed/Feed.sol | 4 +- .../core/primitives/feed/RuleBasedFeed.sol | 4 +- contracts/core/primitives/graph/Graph.sol | 4 +- .../core/primitives/graph/RuleBasedGraph.sol | 4 +- contracts/core/primitives/group/Group.sol | 2 +- .../core/primitives/group/RuleBasedGroup.sol | 4 +- .../core/primitives/namespace/Namespace.sol | 2 +- .../namespace/RuleBasedNamespace.sol | 4 +- 10 files changed, 70 insertions(+), 66 deletions(-) diff --git a/contracts/core/base/RuleBasedPrimitive.sol b/contracts/core/base/RuleBasedPrimitive.sol index 7f92b03c..e1acb778 100644 --- a/contracts/core/base/RuleBasedPrimitive.sol +++ b/contracts/core/base/RuleBasedPrimitive.sol @@ -18,7 +18,7 @@ abstract contract RuleBasedPrimitive { using RulesLib for RulesStorage; using CallLib for address; - function _changePrimitiveRules(RulesStorage storage rulesStorage, RuleChange[] calldata ruleChanges) + function _changePrimitiveRules(RulesStorage storage rulesStorage, RuleChange[] memory ruleChanges) internal virtual { @@ -36,8 +36,8 @@ abstract contract RuleBasedPrimitive { function _changeEntityRules( RulesStorage storage rulesStorage, uint256 entityId, - RuleChange[] calldata ruleChanges, - RuleProcessingParams[] calldata ruleChangesProcessingParams + RuleChange[] memory ruleChanges, + RuleProcessingParams[] memory ruleChangesProcessingParams ) internal virtual { _changeRules( rulesStorage, @@ -50,7 +50,7 @@ abstract contract RuleBasedPrimitive { ); } - function _encodeConfigureCall(uint256 entityId, bytes32 configSalt, KeyValue[] calldata ruleParams) + function _encodeConfigureCall(uint256 entityId, bytes32 configSalt, KeyValue[] memory ruleParams) internal pure returns (bytes memory) @@ -67,7 +67,7 @@ abstract contract RuleBasedPrimitive { uint256 entityId, address ruleAddress, bytes32 configSalt, - KeyValue[] calldata ruleParams + KeyValue[] memory ruleParams ) internal { if (entityId == 0) { _emitPrimitiveRuleConfiguredEvent(wasAlreadyConfigured, ruleAddress, configSalt, ruleParams); @@ -93,7 +93,7 @@ abstract contract RuleBasedPrimitive { // Primitive functions: - function _encodePrimitiveConfigureCall(bytes32 configSalt, KeyValue[] calldata ruleParams) + function _encodePrimitiveConfigureCall(bytes32 configSalt, KeyValue[] memory ruleParams) internal pure virtual @@ -103,7 +103,7 @@ abstract contract RuleBasedPrimitive { bool wasAlreadyConfigured, address ruleAddress, bytes32 configSalt, - KeyValue[] calldata ruleParams + KeyValue[] memory ruleParams ) internal virtual; function _emitPrimitiveRuleSelectorEvent( @@ -116,7 +116,7 @@ abstract contract RuleBasedPrimitive { // Entity functions: - function _encodeEntityConfigureCall(uint256 entityId, bytes32 configSalt, KeyValue[] calldata ruleParams) + function _encodeEntityConfigureCall(uint256 entityId, bytes32 configSalt, KeyValue[] memory ruleParams) internal pure virtual @@ -128,7 +128,7 @@ abstract contract RuleBasedPrimitive { uint256 entityId, address ruleAddress, bytes32 configSalt, - KeyValue[] calldata ruleParams + KeyValue[] memory ruleParams ) internal virtual {} function _emitEntityRuleSelectorEvent( @@ -145,40 +145,27 @@ abstract contract RuleBasedPrimitive { function _changeRules( RulesStorage storage rulesStorage, uint256 entityId, - RuleChange[] calldata ruleChanges, + RuleChange[] memory ruleChanges, RuleProcessingParams[] memory ruleChangesProcessingParams, - function(uint256,bytes32,KeyValue[] calldata) internal returns (bytes memory) fn_encodeConfigureCall, - function(bool,uint256,address,bytes32,KeyValue[] calldata) internal fn_emitConfiguredEvent, + function(uint256,bytes32,KeyValue[] memory) internal returns (bytes memory) fn_encodeConfigureCall, + function(bool,uint256,address,bytes32,KeyValue[] memory) internal fn_emitConfiguredEvent, function(bool,uint256,address,bytes32,bool,bytes4) internal fn_emitSelectorEvent ) private { _beforeChangeRules(entityId, ruleChanges); for (uint256 i = 0; i < ruleChanges.length; i++) { RuleChange memory ruleChange = ruleChanges[i]; if (ruleChange.configurationChanges.configure) { - ruleChange.configSalt = _configureRule( - rulesStorage, - ruleChanges[i].ruleAddress, - ruleChanges[i].configSalt, - entityId, - ruleChanges[i].configurationChanges.ruleParams, - fn_encodeConfigureCall, - fn_emitConfiguredEvent - ); + ruleChange.configSalt = + _configureRule(rulesStorage, ruleChange, entityId, fn_encodeConfigureCall, fn_emitConfiguredEvent); } for (uint256 j = 0; j < ruleChange.selectorChanges.length; j++) { _validateIsSupportedRuleSelector( ruleChange.selectorChanges[j].ruleSelector, entityId == 0 ? _supportedPrimitiveRuleSelectors() : _supportedEntityRuleSelectors() ); - // rulesStorage._changeRulesSelectors( - // ruleChanges[i].ruleAddress, - // ruleChange.configSalt, - // entityId, - // ruleChanges[i].selectorChanges[j].ruleSelector, - // ruleChanges[i].selectorChanges[j].isRequired, - // ruleChanges[i].selectorChanges[j].enabled, - // fn_emitSelectorEvent - // ); + rulesStorage._changeRulesSelectors( + ruleChange, entityId, ruleChange.selectorChanges[j], fn_emitSelectorEvent + ); } } if (entityId == 0) { @@ -207,7 +194,7 @@ abstract contract RuleBasedPrimitive { revert Errors.UnsupportedSelector(); } - function _beforeChangeRules(uint256 entityId, RuleChange[] calldata ruleChanges) internal virtual { + function _beforeChangeRules(uint256 entityId, RuleChange[] memory ruleChanges) internal virtual { if (entityId == 0) { _beforeChangePrimitiveRules(ruleChanges); } else { @@ -217,7 +204,7 @@ abstract contract RuleBasedPrimitive { function _processEntityRulesChanges( uint256 entityId, - RuleChange[] calldata ruleChanges, + RuleChange[] memory ruleChanges, RuleProcessingParams[] memory ruleChangesProcessingParams ) internal virtual {} @@ -234,23 +221,30 @@ abstract contract RuleBasedPrimitive { } } - function _beforeChangePrimitiveRules(RuleChange[] calldata ruleChanges) internal virtual {} + function _beforeChangePrimitiveRules(RuleChange[] memory ruleChanges) internal virtual {} - function _beforeChangeEntityRules(uint256 entityId, RuleChange[] calldata ruleChanges) internal virtual {} + function _beforeChangeEntityRules(uint256 entityId, RuleChange[] memory ruleChanges) internal virtual {} function _configureRule( RulesStorage storage rulesStorage, - address ruleAddress, - bytes32 providedConfigSalt, + RuleChange memory ruleChange, uint256 entityId, - KeyValue[] calldata ruleParams, - function(uint256,bytes32,KeyValue[] calldata) internal returns (bytes memory) fn_encodeConfigureCall, - function(bool,uint256,address,bytes32,KeyValue[] calldata) internal fn_emitEvent + function(uint256,bytes32,KeyValue[] memory) internal returns (bytes memory) fn_encodeConfigureCall, + function(bool,uint256,address,bytes32,KeyValue[] memory) internal fn_emitEvent ) internal returns (bytes32) { - bytes32 configSalt = rulesStorage.generateOrValidateConfigSalt(ruleAddress, providedConfigSalt); - bool wasAlreadyConfigured = - rulesStorage.configureRule(ruleAddress, configSalt, fn_encodeConfigureCall(entityId, configSalt, ruleParams)); - fn_emitEvent(wasAlreadyConfigured, entityId, ruleAddress, configSalt, ruleParams); + bytes32 configSalt = rulesStorage.generateOrValidateConfigSalt(ruleChange.ruleAddress, ruleChange.configSalt); + bool wasAlreadyConfigured = rulesStorage.configureRule( + ruleChange.ruleAddress, + configSalt, + fn_encodeConfigureCall(entityId, configSalt, ruleChange.configurationChanges.ruleParams) + ); + fn_emitEvent( + wasAlreadyConfigured, + entityId, + ruleChange.ruleAddress, + configSalt, + ruleChange.configurationChanges.ruleParams + ); return configSalt; } } diff --git a/contracts/core/libraries/RulesLib.sol b/contracts/core/libraries/RulesLib.sol index 82d16d94..15547514 100644 --- a/contracts/core/libraries/RulesLib.sol +++ b/contracts/core/libraries/RulesLib.sol @@ -2,7 +2,7 @@ // Copyright (C) 2024 Lens Labs. All Rights Reserved. pragma solidity ^0.8.26; -import {Rule} from "contracts/core/types/Types.sol"; +import {Rule, RuleChange, RuleSelectorChange} from "contracts/core/types/Types.sol"; import {CallLib} from "contracts/core/libraries/CallLib.sol"; import {Errors} from "contracts/core/types/Errors.sol"; @@ -89,18 +89,28 @@ library RulesLib { function _changeRulesSelectors( RulesStorage storage rulesStorage, - address ruleAddress, - bytes32 configSalt, + RuleChange memory ruleChange, uint256 entityId, - bytes4 ruleSelector, - bool isRequired, - bool enabled, + RuleSelectorChange memory ruleSelectorChange, function(bool,uint256,address,bytes32,bool,bytes4) internal fn_emitEvent ) internal { function(RulesStorage storage, bool, address, bytes32, bytes4) internal fn_changeRuleSelector = - enabled ? RulesLib.enableRuleSelector : RulesLib.disableRuleSelector; - fn_changeRuleSelector(rulesStorage, isRequired, ruleAddress, configSalt, ruleSelector); - fn_emitEvent(enabled, entityId, ruleAddress, configSalt, isRequired, ruleSelector); + ruleSelectorChange.enabled ? RulesLib.enableRuleSelector : RulesLib.disableRuleSelector; + fn_changeRuleSelector( + rulesStorage, + ruleSelectorChange.isRequired, + ruleChange.ruleAddress, + ruleChange.configSalt, + ruleSelectorChange.ruleSelector + ); + fn_emitEvent( + ruleSelectorChange.enabled, + entityId, + ruleChange.ruleAddress, + ruleChange.configSalt, + ruleSelectorChange.isRequired, + ruleSelectorChange.ruleSelector + ); } // Private diff --git a/contracts/core/primitives/feed/Feed.sol b/contracts/core/primitives/feed/Feed.sol index b067c001..e7f5b5b8 100644 --- a/contracts/core/primitives/feed/Feed.sol +++ b/contracts/core/primitives/feed/Feed.sol @@ -69,11 +69,11 @@ contract Feed is _requireAccess(msg.sender, PID__SET_METADATA); } - function _beforeChangePrimitiveRules(RuleChange[] calldata /* ruleChanges */ ) internal virtual override { + function _beforeChangePrimitiveRules(RuleChange[] memory /* ruleChanges */ ) internal virtual override { _requireAccess(msg.sender, PID__CHANGE_RULES); } - function _beforeChangeEntityRules(uint256 entityId, RuleChange[] calldata /* ruleChanges */ ) + function _beforeChangeEntityRules(uint256 entityId, RuleChange[] memory /* ruleChanges */ ) internal virtual override diff --git a/contracts/core/primitives/feed/RuleBasedFeed.sol b/contracts/core/primitives/feed/RuleBasedFeed.sol index 41ff7587..547b9b5c 100644 --- a/contracts/core/primitives/feed/RuleBasedFeed.sol +++ b/contracts/core/primitives/feed/RuleBasedFeed.sol @@ -68,7 +68,7 @@ abstract contract RuleBasedFeed is IFeed, RuleBasedPrimitive { return selectors; } - function _encodePrimitiveConfigureCall(bytes32 configSalt, KeyValue[] calldata ruleParams) + function _encodePrimitiveConfigureCall(bytes32 configSalt, KeyValue[] memory ruleParams) internal pure override @@ -81,7 +81,7 @@ abstract contract RuleBasedFeed is IFeed, RuleBasedPrimitive { bool wasAlreadyConfigured, address ruleAddress, bytes32 configSalt, - KeyValue[] calldata ruleParams + KeyValue[] memory ruleParams ) internal override { if (wasAlreadyConfigured) { emit IFeed.Lens_Feed_RuleReconfigured(ruleAddress, configSalt, ruleParams); diff --git a/contracts/core/primitives/graph/Graph.sol b/contracts/core/primitives/graph/Graph.sol index ab16d57f..4ed4b3b2 100644 --- a/contracts/core/primitives/graph/Graph.sol +++ b/contracts/core/primitives/graph/Graph.sol @@ -65,11 +65,11 @@ contract Graph is _requireAccess(msg.sender, PID__SET_METADATA); } - function _beforeChangePrimitiveRules(RuleChange[] calldata /* ruleChanges */ ) internal virtual override { + function _beforeChangePrimitiveRules(RuleChange[] memory /* ruleChanges */ ) internal virtual override { _requireAccess(msg.sender, PID__CHANGE_RULES); } - function _beforeChangeEntityRules(uint256 entityId, RuleChange[] calldata /* ruleChanges */ ) + function _beforeChangeEntityRules(uint256 entityId, RuleChange[] memory /* ruleChanges */ ) internal virtual override diff --git a/contracts/core/primitives/graph/RuleBasedGraph.sol b/contracts/core/primitives/graph/RuleBasedGraph.sol index ea02f760..418877d1 100644 --- a/contracts/core/primitives/graph/RuleBasedGraph.sol +++ b/contracts/core/primitives/graph/RuleBasedGraph.sol @@ -67,7 +67,7 @@ abstract contract RuleBasedGraph is IGraph, RuleBasedPrimitive { return selectors; } - function _encodePrimitiveConfigureCall(bytes32 configSalt, KeyValue[] calldata ruleParams) + function _encodePrimitiveConfigureCall(bytes32 configSalt, KeyValue[] memory ruleParams) internal pure override @@ -80,7 +80,7 @@ abstract contract RuleBasedGraph is IGraph, RuleBasedPrimitive { bool wasAlreadyConfigured, address ruleAddress, bytes32 configSalt, - KeyValue[] calldata ruleParams + KeyValue[] memory ruleParams ) internal override { if (wasAlreadyConfigured) { emit IGraph.Lens_Graph_RuleReconfigured(ruleAddress, configSalt, ruleParams); diff --git a/contracts/core/primitives/group/Group.sol b/contracts/core/primitives/group/Group.sol index c9f79dd5..77d55c7c 100644 --- a/contracts/core/primitives/group/Group.sol +++ b/contracts/core/primitives/group/Group.sol @@ -71,7 +71,7 @@ contract Group is _requireAccess(msg.sender, PID__SET_METADATA); } - function _beforeChangePrimitiveRules(RuleChange[] calldata /* ruleChanges */ ) internal virtual override { + function _beforeChangePrimitiveRules(RuleChange[] memory /* ruleChanges */ ) internal virtual override { _requireAccess(msg.sender, PID__CHANGE_RULES); } diff --git a/contracts/core/primitives/group/RuleBasedGroup.sol b/contracts/core/primitives/group/RuleBasedGroup.sol index 95cb3e6b..ce7edf0c 100644 --- a/contracts/core/primitives/group/RuleBasedGroup.sol +++ b/contracts/core/primitives/group/RuleBasedGroup.sol @@ -46,7 +46,7 @@ abstract contract RuleBasedGroup is IGroup, RuleBasedPrimitive { return selectors; } - function _encodePrimitiveConfigureCall(bytes32 configSalt, KeyValue[] calldata ruleParams) + function _encodePrimitiveConfigureCall(bytes32 configSalt, KeyValue[] memory ruleParams) internal pure override @@ -59,7 +59,7 @@ abstract contract RuleBasedGroup is IGroup, RuleBasedPrimitive { bool wasAlreadyConfigured, address ruleAddress, bytes32 configSalt, - KeyValue[] calldata ruleParams + KeyValue[] memory ruleParams ) internal override { if (wasAlreadyConfigured) { emit IGroup.Lens_Group_RuleReconfigured(ruleAddress, configSalt, ruleParams); diff --git a/contracts/core/primitives/namespace/Namespace.sol b/contracts/core/primitives/namespace/Namespace.sol index 67ce98df..865e0e88 100644 --- a/contracts/core/primitives/namespace/Namespace.sol +++ b/contracts/core/primitives/namespace/Namespace.sol @@ -89,7 +89,7 @@ contract Namespace is _requireAccess(msg.sender, PID__SET_TOKEN_URI_PROVIDER); } - function _beforeChangePrimitiveRules(RuleChange[] calldata /* ruleChanges */ ) internal virtual override { + function _beforeChangePrimitiveRules(RuleChange[] memory /* ruleChanges */ ) internal virtual override { _requireAccess(msg.sender, PID__CHANGE_RULES); } // Permissionless functions diff --git a/contracts/core/primitives/namespace/RuleBasedNamespace.sol b/contracts/core/primitives/namespace/RuleBasedNamespace.sol index 9501a261..b1356b89 100644 --- a/contracts/core/primitives/namespace/RuleBasedNamespace.sol +++ b/contracts/core/primitives/namespace/RuleBasedNamespace.sol @@ -46,7 +46,7 @@ abstract contract RuleBasedNamespace is INamespace, RuleBasedPrimitive { return selectors; } - function _encodePrimitiveConfigureCall(bytes32 configSalt, KeyValue[] calldata ruleParams) + function _encodePrimitiveConfigureCall(bytes32 configSalt, KeyValue[] memory ruleParams) internal pure override @@ -59,7 +59,7 @@ abstract contract RuleBasedNamespace is INamespace, RuleBasedPrimitive { bool wasAlreadyConfigured, address ruleAddress, bytes32 configSalt, - KeyValue[] calldata ruleParams + KeyValue[] memory ruleParams ) internal override { if (wasAlreadyConfigured) { emit INamespace.Lens_Namespace_RuleReconfigured(ruleAddress, configSalt, ruleParams); From c5a740a8f000a032e2d7d660640b86d691a64b12 Mon Sep 17 00:00:00 2001 From: vicnaum Date: Fri, 10 Jan 2025 11:53:23 +0100 Subject: [PATCH 6/9] misc: Feed made to compile without IR --- contracts/core/base/SourceStampBased.sol | 6 +- contracts/core/primitives/feed/Feed.sol | 84 +++++++++---------- contracts/core/primitives/feed/FeedCore.sol | 2 +- .../core/primitives/feed/RuleBasedFeed.sol | 28 +++---- 4 files changed, 60 insertions(+), 60 deletions(-) diff --git a/contracts/core/base/SourceStampBased.sol b/contracts/core/base/SourceStampBased.sol index bd1b3069..72d5a2d4 100644 --- a/contracts/core/base/SourceStampBased.sol +++ b/contracts/core/base/SourceStampBased.sol @@ -16,7 +16,7 @@ abstract contract SourceStampBased is ExtraStorageBased { // TODO: We might consider moving source storing out of this contract (see Post created VS lastUpdated source) function _processSourceStamp( uint256 entityId, - KeyValue[] calldata customParams, + KeyValue[] memory customParams, bool storeSource, bool lastUpdatedSourceType ) internal returns (address) { @@ -40,14 +40,14 @@ abstract contract SourceStampBased is ExtraStorageBased { return address(0); } - function _processSourceStamp(uint256 entityId, KeyValue[] calldata customParams, bool storeSource) + function _processSourceStamp(uint256 entityId, KeyValue[] memory customParams, bool storeSource) internal returns (address) { return _processSourceStamp(entityId, customParams, storeSource, false); } - function _processSourceStamp(uint256 entityId, KeyValue[] calldata customParams) internal returns (address) { + function _processSourceStamp(uint256 entityId, KeyValue[] memory customParams) internal returns (address) { return _processSourceStamp(entityId, customParams, true, false); } diff --git a/contracts/core/primitives/feed/Feed.sol b/contracts/core/primitives/feed/Feed.sol index e7f5b5b8..8df76e91 100644 --- a/contracts/core/primitives/feed/Feed.sol +++ b/contracts/core/primitives/feed/Feed.sol @@ -84,11 +84,11 @@ contract Feed is // Public user functions function createPost( - CreatePostParams calldata postParams, - KeyValue[] calldata customParams, - RuleProcessingParams[] calldata feedRulesParams, - RuleProcessingParams[] calldata rootPostRulesParams, - RuleProcessingParams[] calldata quotedPostRulesParams + CreatePostParams memory postParams, + KeyValue[] memory customParams, + RuleProcessingParams[] memory feedRulesParams, + RuleProcessingParams[] memory rootPostRulesParams, + RuleProcessingParams[] memory quotedPostRulesParams ) external virtual override returns (uint256) { require(msg.sender == postParams.author, Errors.InvalidMsgSender()); (uint256 postId, uint256 authorPostSequentialId, uint256 rootPostId) = Core._createPost(postParams); @@ -98,46 +98,46 @@ contract Feed is // Process rules of the Quote (if quoting) if (postParams.quotedPostId != 0) { // TODO: Maybe quotes shouldn't be limited by rules... Just a brave thought. Like quotations in real life. - // uint256 rootOfQuotedPost = Core.$storage().posts[postParams.quotedPostId].rootPostId; - // if (rootOfQuotedPost != rootPostId) { - // _processPostCreationOnRootPost(rootOfQuotedPost, postId, postParams, customParams, quotedPostRulesParams); - // } + uint256 rootOfQuotedPost = Core.$storage().posts[postParams.quotedPostId].rootPostId; + if (rootOfQuotedPost != rootPostId) { + _processPostCreationOnRootPost(rootOfQuotedPost, postId, postParams, customParams, quotedPostRulesParams); + } } if (postId != rootPostId) { require(postParams.ruleChanges.length == 0, Errors.CannotHaveRules()); // This covers the Reply or Repost cases - // _processPostCreationOnRootPost(rootPostId, postId, postParams, customParams, rootPostRulesParams); + _processPostCreationOnRootPost(rootPostId, postId, postParams, customParams, rootPostRulesParams); } else { _addPostRulesAtCreation(postId, postParams, feedRulesParams); } - // emit Lens_Feed_PostCreated( - // postId, - // postParams.author, - // authorPostSequentialId, - // rootPostId, - // postParams, - // customParams, - // feedRulesParams, - // rootPostRulesParams, - // quotedPostRulesParams, - // source - // ); - // for (uint256 i = 0; i < postParams.extraData.length; i++) { - // _setEntityExtraData(postId, postParams.extraData[i]); - // emit Lens_Feed_Post_ExtraDataAdded( - // postId, postParams.extraData[i].key, postParams.extraData[i].value, postParams.extraData[i].value - // ); - // } + emit Lens_Feed_PostCreated( + postId, + postParams.author, + authorPostSequentialId, + rootPostId, + postParams, + customParams, + feedRulesParams, + rootPostRulesParams, + quotedPostRulesParams, + source + ); + for (uint256 i = 0; i < postParams.extraData.length; i++) { + _setEntityExtraData(postId, postParams.extraData[i]); + emit Lens_Feed_Post_ExtraDataAdded( + postId, postParams.extraData[i].key, postParams.extraData[i].value, postParams.extraData[i].value + ); + } return postId; } function editPost( uint256 postId, - EditPostParams calldata postParams, - KeyValue[] calldata customParams, - RuleProcessingParams[] calldata feedRulesParams, - RuleProcessingParams[] calldata rootPostRulesParams, - RuleProcessingParams[] calldata quotedPostRulesParams + EditPostParams memory postParams, + KeyValue[] memory customParams, + RuleProcessingParams[] memory feedRulesParams, + RuleProcessingParams[] memory rootPostRulesParams, + RuleProcessingParams[] memory quotedPostRulesParams ) external virtual override { address author = Core.$storage().posts[postId].author; // TODO: We can have this for moderators: @@ -165,18 +165,18 @@ contract Feed is storeSource: true, lastUpdatedSourceType: true }); - // emit Lens_Feed_PostEdited( - // postId, author, postParams, customParams, feedRulesParams, rootPostRulesParams, quotedPostRulesParams, source - // ); + emit Lens_Feed_PostEdited( + postId, author, postParams, customParams, feedRulesParams, rootPostRulesParams, quotedPostRulesParams, source + ); for (uint256 i = 0; i < postParams.extraData.length; i++) { if (wereExtraDataValuesSet[i]) { - // emit Lens_Feed_Post_ExtraDataUpdated( - // postId, postParams.extraData[i].key, postParams.extraData[i].value, postParams.extraData[i].value - // ); + emit Lens_Feed_Post_ExtraDataUpdated( + postId, postParams.extraData[i].key, postParams.extraData[i].value, postParams.extraData[i].value + ); } else { - // emit Lens_Feed_Post_ExtraDataAdded( - // postId, postParams.extraData[i].key, postParams.extraData[i].value, postParams.extraData[i].value - // ); + emit Lens_Feed_Post_ExtraDataAdded( + postId, postParams.extraData[i].key, postParams.extraData[i].value, postParams.extraData[i].value + ); } } } diff --git a/contracts/core/primitives/feed/FeedCore.sol b/contracts/core/primitives/feed/FeedCore.sol index 2eee2cc6..ac627b01 100644 --- a/contracts/core/primitives/feed/FeedCore.sol +++ b/contracts/core/primitives/feed/FeedCore.sol @@ -42,7 +42,7 @@ library FeedCore { return uint256(keccak256(abi.encode("evm:", block.chainid, address(this), author, authorPostSequentialId))); } - function _createPost(CreatePostParams calldata postParams) internal returns (uint256, uint256, uint256) { + function _createPost(CreatePostParams memory postParams) internal returns (uint256, uint256, uint256) { uint256 postSequentialId = ++$storage().postCount; uint256 authorPostSequentialId = ++$storage().authorPostCount[postParams.author]; uint256 postId = _generatePostId(postParams.author, authorPostSequentialId); diff --git a/contracts/core/primitives/feed/RuleBasedFeed.sol b/contracts/core/primitives/feed/RuleBasedFeed.sol index 547b9b5c..5b8ffa2a 100644 --- a/contracts/core/primitives/feed/RuleBasedFeed.sol +++ b/contracts/core/primitives/feed/RuleBasedFeed.sol @@ -127,8 +127,8 @@ abstract contract RuleBasedFeed is IFeed, RuleBasedPrimitive { function _addPostRulesAtCreation( uint256 postId, - CreatePostParams calldata postParams, - RuleProcessingParams[] calldata feedRulesParams + CreatePostParams memory postParams, + RuleProcessingParams[] memory feedRulesParams ) internal { _changeEntityRules($postRulesStorage(postId), postId, postParams.ruleChanges, feedRulesParams); } @@ -229,9 +229,9 @@ abstract contract RuleBasedFeed is IFeed, RuleBasedPrimitive { function _processPostCreationOnRootPost( uint256 rootPostId, uint256 postId, - CreatePostParams calldata postParams, - KeyValue[] calldata primitiveCustomParams, - RuleProcessingParams[] calldata postRulesParams + CreatePostParams memory postParams, + KeyValue[] memory primitiveCustomParams, + RuleProcessingParams[] memory postRulesParams ) internal { _processPostCreation( _encodeAndCallProcessCreatePostOnRootPost, @@ -248,9 +248,9 @@ abstract contract RuleBasedFeed is IFeed, RuleBasedPrimitive { function _processPostCreationOnFeed( uint256 postId, - CreatePostParams calldata postParams, - KeyValue[] calldata primitiveCustomParams, - RuleProcessingParams[] calldata feedRulesParams + CreatePostParams memory postParams, + KeyValue[] memory primitiveCustomParams, + RuleProcessingParams[] memory feedRulesParams ) internal { _processPostCreation( _encodeAndCallProcessCreatePostOnFeed, @@ -268,9 +268,9 @@ abstract contract RuleBasedFeed is IFeed, RuleBasedPrimitive { function _processPostEditingOnRootPost( uint256 rootPostId, uint256 postId, - EditPostParams calldata postParams, - KeyValue[] calldata primitiveCustomParams, - RuleProcessingParams[] calldata postRulesParams + EditPostParams memory postParams, + KeyValue[] memory primitiveCustomParams, + RuleProcessingParams[] memory postRulesParams ) internal { _processPostEditing( _encodeAndCallProcessEditPostOnRootPost, @@ -287,9 +287,9 @@ abstract contract RuleBasedFeed is IFeed, RuleBasedPrimitive { function _processPostEditingOnFeed( uint256 postId, - EditPostParams calldata postParams, - KeyValue[] calldata primitiveCustomParams, - RuleProcessingParams[] calldata feedRulesParams + EditPostParams memory postParams, + KeyValue[] memory primitiveCustomParams, + RuleProcessingParams[] memory feedRulesParams ) internal { _processPostEditing( _encodeAndCallProcessEditPostOnFeed, From af083d7eea36d847f7b2866c6cd6506d377e4b7f Mon Sep 17 00:00:00 2001 From: vicnaum Date: Fri, 10 Jan 2025 11:58:43 +0100 Subject: [PATCH 7/9] misc: MigrationFeed made to compile without IR --- contracts/migration/MigrationFeed.sol | 94 ++++++++++++++++----------- 1 file changed, 55 insertions(+), 39 deletions(-) diff --git a/contracts/migration/MigrationFeed.sol b/contracts/migration/MigrationFeed.sol index 82e51cea..8579bcce 100644 --- a/contracts/migration/MigrationFeed.sol +++ b/contracts/migration/MigrationFeed.sol @@ -8,60 +8,76 @@ import {FeedCore as Core, PostStorage} from "contracts/core/primitives/feed/Feed import {Feed} from "contracts/core/primitives/feed/Feed.sol"; import {Errors} from "contracts/core/types/Errors.sol"; +struct PostCreationParams { + uint256 postId; + uint256 rootPostId; + uint256 postSequentialId; + uint256 authorPostSequentialId; + uint80 creationTimestamp; + address source; +} + contract MigrationFeed is Feed { function createPost( - CreatePostParams calldata postParams, - KeyValue[] calldata customParams, - RuleProcessingParams[] calldata feedRulesParams, - RuleProcessingParams[] calldata rootPostRulesParams, - RuleProcessingParams[] calldata quotedPostRulesParams + CreatePostParams memory postParams, + KeyValue[] memory customParams, + RuleProcessingParams[] memory feedRulesParams, + RuleProcessingParams[] memory rootPostRulesParams, + RuleProcessingParams[] memory quotedPostRulesParams ) external override returns (uint256) { - ( - uint256 postId, - uint256 rootPostId, - uint256 postSequentialId, - uint256 authorPostSequentialId, - uint80 creationTimestamp, - address source - ) = abi.decode(customParams[0].value, (uint256, uint256, uint256, uint256, uint80, address)); - // _createPost(postParams, postId, rootPostId, postSequentialId, authorPostSequentialId, creationTimestamp); + PostCreationParams memory postCreationParams = abi.decode(customParams[0].value, (PostCreationParams)); + _createPost( + postParams, + postCreationParams.postId, + postCreationParams.rootPostId, + postCreationParams.postSequentialId, + postCreationParams.authorPostSequentialId, + postCreationParams.creationTimestamp + ); if (customParams.length > 1 && abi.decode(customParams[1].value, (bool))) { // If customParams[1] is present, it must be an ABI-encoded bool representing `forceChecks` - // _forceChecks(postId, rootPostId, postParams); + _forceChecks(postCreationParams.postId, postCreationParams.rootPostId, postParams); } - if (source != address(0)) { + if (postCreationParams.source != address(0)) { // Trust the migrator, no source verification - _setPrimitiveInternalExtraDataForEntity(postId, KeyValue(DATA__SOURCE, abi.encode(source))); - _setPrimitiveInternalExtraDataForEntity(postId, KeyValue(DATA__LAST_UPDATED_SOURCE, abi.encode(source))); + _setPrimitiveInternalExtraDataForEntity( + postCreationParams.postId, KeyValue(DATA__SOURCE, abi.encode(postCreationParams.source)) + ); + _setPrimitiveInternalExtraDataForEntity( + postCreationParams.postId, KeyValue(DATA__LAST_UPDATED_SOURCE, abi.encode(postCreationParams.source)) + ); } - // emit Lens_Feed_PostCreated( - // source, - // postId, - // authorPostSequentialId, - // rootPostId, - // quotedPostRulesParams, - // rootPostRulesParams, - // feedRulesParams, - // customParams, - // postParams, - // postParams.author - // ); + emit Lens_Feed_PostCreated( + postCreationParams.postId, + postParams.author, + postCreationParams.authorPostSequentialId, + postCreationParams.rootPostId, + postParams, + customParams, + feedRulesParams, + rootPostRulesParams, + quotedPostRulesParams, + postCreationParams.source + ); - // for (uint256 i = 0; i < postParams.extraData.length; i++) { - // _setEntityExtraData(postId, postParams.extraData[i]); - // emit Lens_Feed_Post_ExtraDataAdded( - // postId, postParams.extraData[i].key, postParams.extraData[i].value, postParams.extraData[i].value - // ); - // } - return postId; + for (uint256 i = 0; i < postParams.extraData.length; i++) { + _setEntityExtraData(postCreationParams.postId, postParams.extraData[i]); + emit Lens_Feed_Post_ExtraDataAdded( + postCreationParams.postId, + postParams.extraData[i].key, + postParams.extraData[i].value, + postParams.extraData[i].value + ); + } + return postCreationParams.postId; } // Overriding the FeedCore function _createPost( - CreatePostParams calldata postParams, + CreatePostParams memory postParams, uint256 postId, uint256 rootPostId, uint256 postSequentialId, @@ -83,7 +99,7 @@ contract MigrationFeed is Feed { _newPost.lastUpdatedTimestamp = creationTimestamp; } - function _forceChecks(uint256 postId, uint256 rootPostId, CreatePostParams calldata postParams) internal view { + function _forceChecks(uint256 postId, uint256 rootPostId, CreatePostParams memory postParams) internal view { // TODO: Check if the rootPostId == postId case (not a reply, not a repost) if (rootPostId != postId) { require(Core._postExists(rootPostId), Errors.DoesNotExist()); From 0aad9f25c6fbb0f51f31301919c1debb361281c8 Mon Sep 17 00:00:00 2001 From: vicnaum Date: Fri, 10 Jan 2025 12:21:17 +0100 Subject: [PATCH 8/9] misc: LensFactory made to compile without IR --- .../extensions/factories/LensFactory.sol | 250 ++++++++++-------- 1 file changed, 140 insertions(+), 110 deletions(-) diff --git a/contracts/extensions/factories/LensFactory.sol b/contracts/extensions/factories/LensFactory.sol index eab6ef0b..83ddf8f2 100644 --- a/contracts/extensions/factories/LensFactory.sol +++ b/contracts/extensions/factories/LensFactory.sol @@ -87,114 +87,144 @@ contract LensFactory { GROUP_GATED_FEED_RULE = groupGatedFeedRule; } - // // TODO: This function belongs to an App probably. - // function createAccountWithUsernameFree( - // string calldata metadataURI, - // address owner, - // address[] calldata accountManagers, - // AccountManagerPermissions[] calldata accountManagersPermissions, - // address namespacePrimitiveAddress, - // string calldata username, - // SourceStamp calldata accountCreationSourceStamp, - // KeyValue[] calldata createUsernameCustomParams, - // RuleProcessingParams[] calldata createUsernameRuleProcessingParams, - // KeyValue[] calldata assignUsernameCustomParams, - // RuleProcessingParams[] calldata unassignAccountRuleProcessingParams, - // RuleProcessingParams[] calldata assignRuleProcessingParams, - // KeyValue[] calldata accountExtraData, - // KeyValue[] calldata usernameExtraData - // ) external returns (address) { - // address account = ACCOUNT_FACTORY.deployAccount( - // address(this), - // metadataURI, - // accountManagers, - // accountManagersPermissions, - // accountCreationSourceStamp, - // accountExtraData - // ); - // INamespace namespacePrimitive = INamespace(namespacePrimitiveAddress); - // bytes memory txData = abi.encodeCall( - // namespacePrimitive.createUsername, - // (account, username, createUsernameCustomParams, createUsernameRuleProcessingParams, usernameExtraData) - // ); - // IAccount(payable(account)).executeTransaction(namespacePrimitiveAddress, uint256(0), txData); - // txData = abi.encodeCall( - // namespacePrimitive.assignUsername, - // ( - // account, - // username, - // assignUsernameCustomParams, - // unassignAccountRuleProcessingParams, - // new RuleProcessingParams[](0), - // assignRuleProcessingParams - // ) - // ); - // IAccount(payable(account)).executeTransaction(namespacePrimitiveAddress, uint256(0), txData); - // IOwnable(account).transferOwnership(owner); - // return account; - // } - - // function createGroupWithFeed( - // address owner, - // address[] calldata admins, - // string calldata groupMetadataURI, - // RuleChange[] calldata groupRules, - // KeyValue[] calldata groupExtraData, - // string calldata feedMetadataURI, - // RuleChange[] calldata feedRules, - // KeyValue[] calldata feedExtraData - // ) external returns (address, address) { - // IRoleBasedAccessControl groupAccessControl = _deployAccessControl(owner, admins); - - // address group = GROUP_FACTORY.deployGroup( - // groupMetadataURI, - // TEMPORARY_ACCESS_CONTROL, - // owner, - // _injectRuleAccessControl(groupRules, address(groupAccessControl)), - // groupExtraData - // ); - - // RuleChange[] memory modifiedFeedRules = new RuleChange[](feedRules.length + 2); - - // RuleSelectorChange[] memory selectorChanges = new RuleSelectorChange[](1); - // // Both rules only operate on IFeedRule.processCreatePost.selector (at least at the moment of writing this) - // selectorChanges[0] = - // RuleSelectorChange({ruleSelector: IFeedRule.processCreatePost.selector, isRequired: true, enabled: true}); - - // modifiedFeedRules[0] = RuleChange({ - // ruleAddress: ACCOUNT_BLOCKING_RULE, - // configSalt: bytes32(0), - // configurationChanges: RuleConfigurationChange({configure: true, ruleParams: new KeyValue[](0)}), - // selectorChanges: selectorChanges - // }); - - // KeyValue[] memory groupGatedRuleParams = new KeyValue[](1); - // groupGatedRuleParams[0] = KeyValue({key: PARAM__GROUP, value: abi.encode(group)}); - - // modifiedFeedRules[1] = RuleChange({ - // ruleAddress: GROUP_GATED_FEED_RULE, - // configSalt: bytes32(0), - // configurationChanges: RuleConfigurationChange({configure: true, ruleParams: groupGatedRuleParams}), - // selectorChanges: selectorChanges - // }); - - // IRoleBasedAccessControl feedAccessControl = _deployAccessControl(owner, admins); - - // for (uint256 i = 0; i < feedRules.length; i++) { - // require(feedRules[i].ruleAddress != ACCOUNT_BLOCKING_RULE, Errors.DuplicatedValue()); - // require(feedRules[i].ruleAddress != GROUP_GATED_FEED_RULE, Errors.DuplicatedValue()); - // modifiedFeedRules[i + 2] = _injectRuleAccessControl(feedRules[i], address(feedAccessControl)); - // } - - // address feed = - // FEED_FACTORY.deployFeed(feedMetadataURI, feedAccessControl, owner, modifiedFeedRules, feedExtraData); - - // KeyValue[] memory groupExtraDataWithFeed = new KeyValue[](1); - // groupExtraDataWithFeed[0] = KeyValue({key: DATA__GROUP_LINKED_FEED, value: abi.encode(feed)}); - // IGroup(group).setExtraData(groupExtraDataWithFeed); - // AccessControlled(group).setAccessControl(groupAccessControl); - // return (group, feed); - // } + struct CreateAccountParams { + string metadataURI; + address owner; + address[] accountManagers; + AccountManagerPermissions[] accountManagersPermissions; + SourceStamp accountCreationSourceStamp; + KeyValue[] accountExtraData; + } + + struct CreateUsernameParams { + string username; + KeyValue[] createUsernameCustomParams; + RuleProcessingParams[] createUsernameRuleProcessingParams; + KeyValue[] assignUsernameCustomParams; + RuleProcessingParams[] unassignAccountRuleProcessingParams; + RuleProcessingParams[] assignRuleProcessingParams; + KeyValue[] usernameExtraData; + } + + // TODO: This function belongs to an App probably. + function createAccountWithUsernameFree( + address namespacePrimitiveAddress, + CreateAccountParams calldata accountParams, + CreateUsernameParams calldata usernameParams + ) external returns (address) { + address account = ACCOUNT_FACTORY.deployAccount( + address(this), + accountParams.metadataURI, + accountParams.accountManagers, + accountParams.accountManagersPermissions, + accountParams.accountCreationSourceStamp, + accountParams.accountExtraData + ); + INamespace namespacePrimitive = INamespace(namespacePrimitiveAddress); + bytes memory txData = abi.encodeCall( + namespacePrimitive.createUsername, + ( + account, + usernameParams.username, + usernameParams.createUsernameCustomParams, + usernameParams.createUsernameRuleProcessingParams, + usernameParams.usernameExtraData + ) + ); + IAccount(payable(account)).executeTransaction(namespacePrimitiveAddress, uint256(0), txData); + txData = abi.encodeCall( + namespacePrimitive.assignUsername, + ( + account, + usernameParams.username, + usernameParams.assignUsernameCustomParams, + usernameParams.unassignAccountRuleProcessingParams, + new RuleProcessingParams[](0), + usernameParams.assignRuleProcessingParams + ) + ); + IAccount(payable(account)).executeTransaction(namespacePrimitiveAddress, uint256(0), txData); + IOwnable(account).transferOwnership(accountParams.owner); + return account; + } + + struct CreateGroupWithFeedParams { + address group; + IRoleBasedAccessControl groupAccessControl; + IRoleBasedAccessControl feedAccessControl; + RuleChange[] modifiedFeedRules; + KeyValue[] feedExtraData; + } + + function createGroupWithFeed( + address owner, + address[] memory admins, + string memory groupMetadataURI, + RuleChange[] memory groupRules, + KeyValue[] memory groupExtraData, + string memory feedMetadataURI, + RuleChange[] memory feedRules, + KeyValue[] memory feedExtraData + ) external returns (address, address) { + CreateGroupWithFeedParams memory s; + s.feedExtraData = feedExtraData; + s.feedAccessControl = _deployAccessControl(owner, admins); + + { + s.groupAccessControl = _deployAccessControl(owner, admins); + + s.group = GROUP_FACTORY.deployGroup( + groupMetadataURI, + TEMPORARY_ACCESS_CONTROL, + owner, + _injectRuleAccessControl(groupRules, address(s.groupAccessControl)), + groupExtraData + ); + } + + s.modifiedFeedRules = new RuleChange[](feedRules.length + 2); + + { + RuleSelectorChange[] memory selectorChanges = new RuleSelectorChange[](1); + // Both rules only operate on IFeedRule.processCreatePost.selector (at least at the moment of writing this) + selectorChanges[0] = + RuleSelectorChange({ruleSelector: IFeedRule.processCreatePost.selector, isRequired: true, enabled: true}); + + s.modifiedFeedRules[0] = RuleChange({ + ruleAddress: ACCOUNT_BLOCKING_RULE, + configSalt: bytes32(0), + configurationChanges: RuleConfigurationChange({configure: true, ruleParams: new KeyValue[](0)}), + selectorChanges: selectorChanges + }); + + KeyValue[] memory groupGatedRuleParams = new KeyValue[](1); + groupGatedRuleParams[0] = KeyValue({key: PARAM__GROUP, value: abi.encode(s.group)}); + + s.modifiedFeedRules[1] = RuleChange({ + ruleAddress: GROUP_GATED_FEED_RULE, + configSalt: bytes32(0), + configurationChanges: RuleConfigurationChange({configure: true, ruleParams: groupGatedRuleParams}), + selectorChanges: selectorChanges + }); + } + + { + for (uint256 i = 0; i < feedRules.length; i++) { + require(feedRules[i].ruleAddress != ACCOUNT_BLOCKING_RULE, Errors.DuplicatedValue()); + require(feedRules[i].ruleAddress != GROUP_GATED_FEED_RULE, Errors.DuplicatedValue()); + s.modifiedFeedRules[i + 2] = _injectRuleAccessControl(feedRules[i], address(s.feedAccessControl)); + } + } + + address feed = + FEED_FACTORY.deployFeed(feedMetadataURI, s.feedAccessControl, owner, s.modifiedFeedRules, s.feedExtraData); + + KeyValue[] memory groupExtraDataWithFeed = new KeyValue[](1); + groupExtraDataWithFeed[0] = KeyValue({key: DATA__GROUP_LINKED_FEED, value: abi.encode(feed)}); + IGroup(s.group).setExtraData(groupExtraDataWithFeed); + AccessControlled(s.group).setAccessControl(s.groupAccessControl); + return (s.group, feed); + } function deployAccount( string calldata metadataURI, @@ -322,7 +352,7 @@ contract LensFactory { return rule; } - function _injectRuleAccessControl(RuleChange[] calldata rules, address accessControl) + function _injectRuleAccessControl(RuleChange[] memory rules, address accessControl) internal pure returns (RuleChange[] memory) @@ -334,7 +364,7 @@ contract LensFactory { return modifiedRules; } - function _prepareRules(RuleChange[] calldata rules, bytes4 ruleSelector, address accessControl) + function _prepareRules(RuleChange[] memory rules, bytes4 ruleSelector, address accessControl) internal view returns (RuleChange[] memory) From cc4fe7eb1fb29e3ac417fb47223a3064e6793ae4 Mon Sep 17 00:00:00 2001 From: vicnaum Date: Fri, 10 Jan 2025 12:23:05 +0100 Subject: [PATCH 9/9] misc: LensFactory tests made to compile without IR --- .../extensions/factories/LensFactory.sol | 38 +++++++++--------- test/factories/LensFactory.t.sol | 40 +++++++++++-------- 2 files changed, 42 insertions(+), 36 deletions(-) diff --git a/contracts/extensions/factories/LensFactory.sol b/contracts/extensions/factories/LensFactory.sol index 83ddf8f2..50db4d41 100644 --- a/contracts/extensions/factories/LensFactory.sol +++ b/contracts/extensions/factories/LensFactory.sol @@ -52,6 +52,25 @@ bytes32 constant DATA__GROUP_LINKED_FEED = 0xfec1c12508813d27a0104e0d1f0ad007b92 /// @custom:keccak lens.param.accessControl bytes32 constant PARAM__ACCESS_CONTROL = 0xcf3b0fab90208e4185bf857e0f943f6672abffb7d0898e0750beeeb991ae35fa; +struct CreateAccountParams { + string metadataURI; + address owner; + address[] accountManagers; + AccountManagerPermissions[] accountManagersPermissions; + SourceStamp accountCreationSourceStamp; + KeyValue[] accountExtraData; +} + +struct CreateUsernameParams { + string username; + KeyValue[] createUsernameCustomParams; + RuleProcessingParams[] createUsernameRuleProcessingParams; + KeyValue[] assignUsernameCustomParams; + RuleProcessingParams[] unassignAccountRuleProcessingParams; + RuleProcessingParams[] assignRuleProcessingParams; + KeyValue[] usernameExtraData; +} + contract LensFactory { AccessControlFactory internal immutable ACCESS_CONTROL_FACTORY; AccountFactory internal immutable ACCOUNT_FACTORY; @@ -87,25 +106,6 @@ contract LensFactory { GROUP_GATED_FEED_RULE = groupGatedFeedRule; } - struct CreateAccountParams { - string metadataURI; - address owner; - address[] accountManagers; - AccountManagerPermissions[] accountManagersPermissions; - SourceStamp accountCreationSourceStamp; - KeyValue[] accountExtraData; - } - - struct CreateUsernameParams { - string username; - KeyValue[] createUsernameCustomParams; - RuleProcessingParams[] createUsernameRuleProcessingParams; - KeyValue[] assignUsernameCustomParams; - RuleProcessingParams[] unassignAccountRuleProcessingParams; - RuleProcessingParams[] assignRuleProcessingParams; - KeyValue[] usernameExtraData; - } - // TODO: This function belongs to an App probably. function createAccountWithUsernameFree( address namespacePrimitiveAddress, diff --git a/test/factories/LensFactory.t.sol b/test/factories/LensFactory.t.sol index 50cd0b3d..dd3cebbc 100644 --- a/test/factories/LensFactory.t.sol +++ b/test/factories/LensFactory.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.26; import "forge-std/Test.sol"; -import {LensFactory} from "@extensions/factories/LensFactory.sol"; +import {LensFactory, CreateAccountParams, CreateUsernameParams} from "@extensions/factories/LensFactory.sol"; import {AccountFactory} from "@extensions/factories/AccountFactory.sol"; import {AppFactory} from "@extensions/factories/AppFactory.sol"; import {GroupFactory} from "@extensions/factories/GroupFactory.sol"; @@ -50,22 +50,28 @@ contract LensFactoryTest is Test, BaseDeployments { } function testCreateAccountWithUsernameFree() public { - // lensFactory.createAccountWithUsernameFree({ - // metadataURI: "someMetadataURI", - // owner: address(this), - // accountManagers: _emptyAddressArray(), - // accountManagersPermissions: new AccountManagerPermissions[](0), - // namespacePrimitiveAddress: address(namespace), - // username: "myTestUsername", - // accountCreationSourceStamp: _emptySourceStamp(), - // createUsernameCustomParams: _emptyKeyValueArray(), - // createUsernameRuleProcessingParams: _emptyRuleProcessingParamsArray(), - // assignUsernameCustomParams: _emptyKeyValueArray(), - // unassignAccountRuleProcessingParams: _emptyRuleProcessingParamsArray(), - // assignRuleProcessingParams: _emptyRuleProcessingParamsArray(), - // accountExtraData: _emptyKeyValueArray(), - // usernameExtraData: _emptyKeyValueArray() - // }); + CreateAccountParams memory accountParams = CreateAccountParams({ + metadataURI: "someMetadataURI", + owner: address(this), + accountManagers: _emptyAddressArray(), + accountManagersPermissions: new AccountManagerPermissions[](0), + accountCreationSourceStamp: _emptySourceStamp(), + accountExtraData: _emptyKeyValueArray() + }); + CreateUsernameParams memory usernameParams = CreateUsernameParams({ + username: "myTestUsername", + createUsernameCustomParams: _emptyKeyValueArray(), + createUsernameRuleProcessingParams: _emptyRuleProcessingParamsArray(), + assignUsernameCustomParams: _emptyKeyValueArray(), + unassignAccountRuleProcessingParams: _emptyRuleProcessingParamsArray(), + assignRuleProcessingParams: _emptyRuleProcessingParamsArray(), + usernameExtraData: _emptyKeyValueArray() + }); + lensFactory.createAccountWithUsernameFree({ + accountParams: accountParams, + namespacePrimitiveAddress: address(namespace), + usernameParams: usernameParams + }); } function testGraphFollowWithFactorySetup() public {