Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: separate the LSP6 core contract in logic modules #461

Merged
merged 5 commits into from
Feb 14, 2023

Conversation

b00ste
Copy link
Member

@b00ste b00ste commented Jan 27, 2023

What does this PR introduce?

  • Move set data permissions verification logic in LSP6SetDataLogicModule.sol.
  • Move execute permissions verification logic in LSP6ExecuteLogicModule.sol.
  • Move ownership transfer permissions verification logic in LSP6OwnershipLogicModule.sol.
  • Move getPermissionName(...) and requirePermissions(...) to the LSP6Utils.sol for re-usability in modules and core contract.

Side notes:

  1. Unfortunately, for avoiding having requirePermissions(...) in each module, I moved it to LSP6Utils.sol. This function reverts with custom error if the required permission is not present.

Cons:

  • Library method which reverts.

Pros:

  • Useful function which can be re-used by other developers who want to create a Key Manager contract.
  1. The target is passed to the modules as a method parameter.

Cons:

  • This might confuse some developers regarding the requirement of LSP6 to have a single target contract stored in the storage of the contract.

Pros:

  • This allows for re-usability of the modules in both single-target Key Manager and multi-target Key Managers.

@github-actions
Copy link
Contributor

👋 Hello
⛽ I am the Gas Bot Reporter. I keep track of the gas costs of common interactions using Universal Profiles 🆙 !
📊 Here is a summary of the gas cost with the code introduced by this PR.

⛽📊 See Gas Benchmark report

This document contains the gas usage for common interactions and scenarios when using UniversalProfile smart contracts.

🔀 execute scenarios

👑 unrestricted controller

execute scenarios - 👑 main controller ⛽ Gas Usage
transfer LYX to an EOA 55442
transfer LYX to a UP 57044
transfer tokens (LSP7) to an EOA (no data) 101696
transfer tokens (LSP7) to a UP (no data) 261725
transfer a NFT (LSP8) to a EOA (no data) 165572
transfer a NFT (LSP8) to a UP (no data) 289469

🛃 restricted controller

execute scenarios - 🛃 restricted controller ⛽ Gas Usage
transfer some LYXes to an EOA - restricted to 1 x allowed address only (TRANSFERVALUE + 1x AllowedCalls) 62158
transfers some tokens (LSP7) to an EOA - restricted to LSP7 + 2x allowed contracts only (CALL + 2x AllowedCalls) (no data) 114071
transfers some tokens (LSP7) to an other UP - restricted to LSP7 + 2x allowed contracts only (CALL + 2x AllowedCalls) (no data) 274100
transfers a NFT (LSP8) to an EOA - restricted to LSP8 + 2x allowed contracts only (CALL + 2x AllowedCalls) (no data) 177947
transfers a NFT (LSP8) to an other UP - restricted to LSP8 + 2x allowed contracts only (CALL + 2x AllowedCalls) (no data) 301844

🗄️ setData scenarios

👑 unrestricted controller

setData scenarios - 👑 main controller ⛽ Gas Usage
updates profile details (LSP3Profile metadata) 135626
give permissions to a controller (AddressPermissions[] + AddressPermissions[index] + AddressPermissions:Permissions:) 140144
restrict a controller to some specific ERC725Y Data Keys 140077
restrict a controller to interact only with 3x specific addresses 140021
remove a controller (its permissions + its address from the AddressPermissions[] array) 75499
write 5x LSP12 Issued Assets 230434

🛃 restricted controller

setData scenarios - 🛃 restricted controller ⛽ Gas Usage
setData(bytes32,bytes) -> updates 1x data key 109016
setData(bytes32[],bytes[]) -> updates 3x data keys (first x3) 166976
setData(bytes32[],bytes[]) -> updates 3x data keys (middle x3) 150909
setData(bytes32[],bytes[]) -> updates 3x data keys (last x3) 175942
setData(bytes32[],bytes[]) -> updates 2x data keys + add 3x new controllers (including setting the array length + indexes under AddressPermissions[index]) 265774

📝 Notes

  • The execute and setData scenarios are executed on a fresh UniversalProfile and LSP6KeyManager smart contracts, deployed as standard contracts (not as proxy behind a base contract implementation).

@github-actions
Copy link
Contributor

github-actions bot commented Jan 27, 2023

Changes to gas cost

Generated at commit: 7ada03c91bf66ba5149668fcd1c58294ed8dc5c6, compared to commit: a51883eabe22109c17cc9740af46cd8c7495a467

🧾 Summary (10% most significant diffs)

Contract Method Avg (+/-) %
LSP6ExecuteRestrictedController transferLYXToUP +126 ❌ +0.42%
LSP6ExecuteUnrestrictedController transferLYXToUP +126 ❌ +0.39%
LSP6SetDataRestrictedController execute +94 ❌ +0.34%
LSP6SetDataUnrestrictedController execute +94 ❌ +0.34%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
LSP6ExecuteRestrictedController 2,426,359 (+20,223) execute
transferLYXToEOA
transferLYXToUP
transferNFTToRandomEOA
transferNFTToRandomUP
transferTokensToRandomEOA
transferTokensToRandomUP
21,976 (+147)
54,627 (+79)
30,375 (+126)
130,956 (+210)
260,264 (+324)
76,945 (+79)
235,626 (+223)
+0.67%
+0.14%
+0.42%
+0.16%
+0.12%
+0.10%
+0.09%
90,088 (+145)
54,627 (+79)
30,375 (+126)
130,956 (+210)
260,264 (+324)
76,945 (+79)
235,626 (+223)
+0.16%
+0.14%
+0.42%
+0.16%
+0.12%
+0.10%
+0.09%
112,792 (+144)
54,627 (+79)
30,375 (+126)
130,956 (+210)
260,264 (+324)
76,945 (+79)
235,626 (+223)
+0.13%
+0.14%
+0.42%
+0.16%
+0.12%
+0.10%
+0.09%
112,792 (+144)
54,627 (+79)
30,375 (+126)
130,956 (+210)
260,264 (+324)
76,945 (+79)
235,626 (+223)
+0.13%
+0.14%
+0.42%
+0.16%
+0.12%
+0.10%
+0.09%
8 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
LSP6ExecuteUnrestrictedController 2,426,359 (+20,223) execute
transferLYXToEOA
transferLYXToUP
transferNFTToRandomEOA
transferNFTToRandomUP
transferTokensToRandomEOA
transferTokensToRandomUP
21,976 (+147)
55,718 (+126)
32,375 (+126)
129,941 (+247)
259,250 (+362)
75,677 (+126)
234,358 (+270)
+0.67%
+0.23%
+0.39%
+0.19%
+0.14%
+0.17%
+0.12%
90,088 (+145)
55,718 (+126)
32,375 (+126)
129,941 (+247)
259,250 (+362)
75,677 (+126)
234,358 (+270)
+0.16%
+0.23%
+0.39%
+0.19%
+0.14%
+0.17%
+0.12%
112,792 (+144)
55,718 (+126)
32,375 (+126)
129,941 (+247)
259,250 (+362)
75,677 (+126)
234,358 (+270)
+0.13%
+0.23%
+0.39%
+0.19%
+0.14%
+0.17%
+0.12%
112,792 (+144)
55,718 (+126)
32,375 (+126)
129,941 (+247)
259,250 (+362)
75,677 (+126)
234,358 (+270)
+0.13%
+0.23%
+0.39%
+0.19%
+0.14%
+0.17%
+0.12%
8 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
LSP6SetDataRestrictedController 2,411,136 (+20,222) execute
givePermissionsToController
restrictControllerToERC725YKeys
17,288 (+126)
142,147 (-15)
138,502 (+24)
+0.73%
-0.01%
+0.02%
27,881 (+94)
142,147 (-15)
138,502 (+24)
+0.34%
-0.01%
+0.02%
27,881 (+94)
142,147 (-15)
138,502 (+24)
+0.34%
-0.01%
+0.02%
38,474 (+61)
142,147 (-15)
138,502 (+24)
+0.16%
-0.01%
+0.02%
2 (0)
1 (0)
1 (0)
LSP6SetDataUnrestrictedController 2,411,136 (+20,222) execute
givePermissionsToController
restrictControllerToERC725YKeys
17,288 (+126)
148,147 (-15)
147,002 (+24)
+0.73%
-0.01%
+0.02%
27,881 (+94)
148,147 (-15)
147,002 (+24)
+0.34%
-0.01%
+0.02%
27,881 (+94)
148,147 (-15)
147,002 (+24)
+0.34%
-0.01%
+0.02%
38,474 (+61)
148,147 (-15)
147,002 (+24)
+0.16%
-0.01%
+0.02%
2 (0)
1 (0)
1 (0)

@YamenMerhi
Copy link
Member

Could you try to merge develop, then clone RV internal repo, and run the foundry tests again the new splitted contracts ?

contracts/LSP6KeyManager/LSP6KeyManagerCore.sol Outdated Show resolved Hide resolved
contracts/LSP6KeyManager/LSP6KeyManagerCore.sol Outdated Show resolved Hide resolved
contracts/LSP6KeyManager/LSP6KeyManagerCore.sol Outdated Show resolved Hide resolved
contracts/LSP6KeyManager/LSP6KeyManagerCore.sol Outdated Show resolved Hide resolved
Copy link
Member

@CJ42 CJ42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added requested changes

contracts/LSP6KeyManager/LSP6Utils.sol Show resolved Hide resolved
contracts/LSP6KeyManager/LSP6Utils.sol Outdated Show resolved Hide resolved
@b00ste
Copy link
Member Author

b00ste commented Feb 14, 2023

Screenshot 2023-02-14 at 13 51 54

@CJ42 CJ42 merged commit 9af7f4d into develop Feb 14, 2023
@CJ42 CJ42 deleted the refactor/split-lsp6-in-modules branch February 14, 2023 16:47
@CJ42 CJ42 mentioned this pull request Feb 21, 2023
JeneaVranceanu added a commit to JeneaVranceanu/lsp-universalprofile-smart-contracts that referenced this pull request Mar 1, 2023
* develop:
  refactor!: change LSP5/6/10 Array length from `uint256` to `uint128` (lukso-network#482)
  ci: temporarily disable downloading Android artifacts on github release (lukso-network#483)
  perf: reduce LSP1Delegate deployment cost by 8,678 gas (lukso-network#485)
  feat!: Add batchCalls function in LSP0 and LSP9 (lukso-network#476)
  test: add tests for edge cases with LSP1 returned values (e.g: `LSP1: asset sent is not registered`, ...) (lukso-network#479)
  refactor!: change `CHANGEPERMISSIONS` to `EDITPERMISSIONS` (lukso-network#481)
  ci: check deployer balance before deploy + verify contracts (lukso-network#480)
  ci: move ci scripts in a `ci/` subfolder (lukso-network#478)
  docs: add extra note about Address lib in CHANGELOG 0.8.1 (lukso-network#477)
  chore: prepare release 0.8.1 (lukso-network#474)
  refactor: replace param with literal LSP9 interfaceId (lukso-network#472)
  refactor: Support Extension for `bytes4(0)` sig in LSP0-LSP9 (lukso-network#473)
  refactor: separate the LSP6 core contract in logic modules (lukso-network#461)
  feat: create `LSP0Utils` library with functions to retrieve LSP1 addresses (lukso-network#466)
  ci: update CI to publish android artifacts + disable temporarily android artifacts build (web3 not working) (lukso-network#469)
  chore: remove Address library (lukso-network#471)
  fix: Add typescript transpilation and hook in package.json exports (lukso-network#470)

# Conflicts:
#	.gitignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants