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

feat!: add callee params to lsp20 & EXECUTE_RELAY_CALL permission & mapping reentrancyStatus #729

Merged
merged 25 commits into from
Oct 2, 2023

Conversation

skimaharvey
Copy link
Member

@skimaharvey skimaharvey commented Sep 26, 2023

What does this PR introduce?

⚠️ BREAKING CHANGES

  • Update lsp20 interface with the callee params
  • Update lsp20 constant file
  • Update lsp20 mocks contracts
  • Add EXECUTE_RELAY_CALL permission
  • Change reentrancyStatus from uint8 to mapping(address => uint8)
  • Update constant.ts file

@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 of Using UniversalProfile owned by an EOA

🔀 execute scenarios

execute scenarios - 👑 UP Owner ⛽ Gas Usage
Transfer 1 LYX to an EOA without data 37537
Transfer 1 LYX to a UP without data 36639
Transfer 1 LYX to an EOA with 256 bytes of data 42210
Transfer 1 LYX to a UP with 256 bytes of data 44867
Transfer 0.1 LYX to 3x EOA without data 70862
Transfer 0.1 LYX to 3x UP without data 75680
Transfer 0.1 LYX to 3x EOA with 256 bytes of data 84826
Transfer 0.1 LYX to 3x EOA with 256 bytes of data 100357

🗄️ setData scenarios

setData scenarios - 👑 UP Owner ⛽ Gas Usage
Set a 20 bytes long value 49971
Set a 60 bytes long value 95293
Set a 160 bytes long value 164465
Set a 300 bytes long value 279700
Set a 600 bytes long value 484136
Change the value of a data key already set 32847
Remove the value of a data key already set 27333
Set 2 data keys of 20 bytes long value 78428
Set 2 data keys of 100 bytes long value 260580
Set 3 data keys of 20 bytes long value 105145
Change the value of three data keys already set of 20 bytes long value 45445
Remove the value of three data keys already set 41339

🗄️ Tokens scenarios

Tokens scenarios - 👑 UP Owner ⛽ Gas Usage
Minting a LSP7Token to a UP (No Delegate) from an EOA 92016
Minting a LSP7Token to an EOA from an EOA 59323
Transferring an LSP7Token from a UP to another UP (No Delegate) 100102
Minting a LSP8Token to a UP (No Delegate) from an EOA 158946
Minting a LSP8Token to an EOA from an EOA 126253
Transferring an LSP8Token from a UP to another UP (No Delegate) 148671

📝 Notes

  • The execute and setData scenarios are executed on a fresh UniversalProfile smart contract, deployed as standard contracts (not as proxy behind a base contract implementation).
⛽📊 See Gas Benchmark report of Using UniversalProfile owned by an LSP6KeyManager

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 60386
transfer LYX to a UP 61988
transfer tokens (LSP7) to an EOA (no data) 107906
transfer tokens (LSP7) to a UP (no data) 244229
transfer a NFT (LSP8) to a EOA (no data) 171775
transfer a NFT (LSP8) to a UP (no data) 291345

🛃 restricted controller

execute scenarios - 🛃 restricted controller ⛽ Gas Usage
transfer some LYXes to an EOA - restricted to 1 x allowed address only (TRANSFERVALUE + 1x AllowedCalls) 71578
transfers some tokens (LSP7) to an EOA - restricted to LSP7 + 2x allowed contracts only (CALL + 2x AllowedCalls) (no data) 122597
transfers some tokens (LSP7) to an other UP - restricted to LSP7 + 2x allowed contracts only (CALL + 2x AllowedCalls) (no data) 258920
transfers a NFT (LSP8) to an EOA - restricted to LSP8 + 2x allowed contracts only (CALL + 2x AllowedCalls) (no data) 186431
transfers a NFT (LSP8) to an other UP - restricted to LSP8 + 2x allowed contracts only (CALL + 2x AllowedCalls) (no data) 306001

🗄️ setData scenarios

👑 unrestricted controller

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

🛃 restricted controller

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

📝 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).

@skimaharvey skimaharvey changed the title Feat/modify lsp20 feat!: add callee params to lsp20 Sep 26, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 26, 2023

Changes to gas cost

Generated at commit: 40ec7a78dca8bcac5e8d13f7e5537664c1991e6f, compared to commit: b8eca3c5696acf85239130ef67edec9e8c134bfa

🧾 Summary (10% most significant diffs)

Contract Method Avg (+/-) %
LSP6ExecuteRestrictedController transferLYXToUP +11,283 ❌ +35.82%
LSP6ExecuteUnrestrictedController transferLYXToUP +10,883 ❌ +32.49%
LSP6SetDataRestrictedController execute +6,096 ❌ +21.36%
LSP6SetDataUnrestrictedController execute +6,096 ❌ +21.36%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
LSP6ExecuteRestrictedController 2,901,935 (+26,244) lsp20VerifyCall
transferLYXToEOA
transferLYXToUP
transferNFTToRandomEOA
transferNFTToRandomUP
transferTokensToRandomEOA
transferTokensToRandomUP
14,682 (-214)
62,532 (+6,367)
42,779 (+11,283)
146,341 (+15,572)
254,966 (+15,652)
76,501 (+2,809)
211,403 (+2,244)
-1.44%
+11.34%
+35.82%
+11.91%
+6.54%
+3.81%
+1.07%
16,881 (-151)
62,532 (+6,367)
42,779 (+11,283)
146,341 (+15,572)
254,966 (+15,652)
76,501 (+2,809)
211,403 (+2,244)
-0.89%
+11.34%
+35.82%
+11.91%
+6.54%
+3.81%
+1.07%
17,614 (-131)
62,532 (+6,367)
42,779 (+11,283)
146,341 (+15,572)
254,966 (+15,652)
76,501 (+2,809)
211,403 (+2,244)
-0.74%
+11.34%
+35.82%
+11.91%
+6.54%
+3.81%
+1.07%
17,614 (-131)
62,532 (+6,367)
42,779 (+11,283)
146,341 (+15,572)
254,966 (+15,652)
76,501 (+2,809)
211,403 (+2,244)
-0.74%
+11.34%
+35.82%
+11.91%
+6.54%
+3.81%
+1.07%
8 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
LSP6ExecuteUnrestrictedController 2,901,935 (+26,244) lsp20VerifyCall
transferLYXToEOA
transferLYXToUP
transferNFTToRandomEOA
transferNFTToRandomUP
transferTokensToRandomEOA
transferTokensToRandomUP
14,682 (-214)
63,036 (+6,241)
44,379 (+10,883)
145,090 (+15,572)
253,715 (+15,652)
75,250 (+3,122)
209,839 (+2,244)
-1.44%
+10.99%
+32.49%
+12.02%
+6.57%
+4.33%
+1.08%
16,881 (-151)
63,036 (+6,241)
44,379 (+10,883)
145,090 (+15,572)
253,715 (+15,652)
75,250 (+3,122)
209,839 (+2,244)
-0.89%
+10.99%
+32.49%
+12.02%
+6.57%
+4.33%
+1.08%
17,614 (-131)
63,036 (+6,241)
44,379 (+10,883)
145,090 (+15,572)
253,715 (+15,652)
75,250 (+3,122)
209,839 (+2,244)
-0.74%
+10.99%
+32.49%
+12.02%
+6.57%
+4.33%
+1.08%
17,614 (-131)
63,036 (+6,241)
44,379 (+10,883)
145,090 (+15,572)
253,715 (+15,652)
75,250 (+3,122)
209,839 (+2,244)
-0.74%
+10.99%
+32.49%
+12.02%
+6.57%
+4.33%
+1.08%
8 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
LSP6SetDataRestrictedController 2,886,720 (+26,252) execute
givePermissionsToController
restrictControllerToERC725YKeys
30,774 (+12,284)
122,906 (+2,272)
141,156 (+2,272)
+66.44%
+1.88%
+1.64%
34,631 (+6,096)
122,906 (+2,272)
141,156 (+2,272)
+21.36%
+1.88%
+1.64%
34,631 (+6,096)
122,906 (+2,272)
141,156 (+2,272)
+21.36%
+1.88%
+1.64%
38,488 (-93)
122,906 (+2,272)
141,156 (+2,272)
-0.24%
+1.88%
+1.64%
2 (0)
1 (0)
1 (0)
LSP6SetDataUnrestrictedController 2,886,720 (+26,252) execute
givePermissionsToController
restrictControllerToERC725YKeys
30,774 (+12,284)
128,906 (+2,272)
149,656 (+2,272)
+66.44%
+1.79%
+1.54%
34,631 (+6,096)
128,906 (+2,272)
149,656 (+2,272)
+21.36%
+1.79%
+1.54%
34,631 (+6,096)
128,906 (+2,272)
149,656 (+2,272)
+21.36%
+1.79%
+1.54%
38,488 (-93)
128,906 (+2,272)
149,656 (+2,272)
-0.24%
+1.79%
+1.54%
2 (0)
1 (0)
1 (0)

@skimaharvey skimaharvey changed the title feat!: add callee params to lsp20 feat!: add callee params to lsp20 & EXECUTE_RELAY_CALL permission Oct 1, 2023
@skimaharvey skimaharvey changed the title feat!: add callee params to lsp20 & EXECUTE_RELAY_CALL permission feat!: add callee params to lsp20 & EXECUTE_RELAY_CALL permission & mapping reentrancyStatus Oct 1, 2023
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 first round of review.

I suggest to check the difference in gas cost moving back from uint8 to uint256 inside the reentrancy mapping.

constants.ts Outdated Show resolved Hide resolved
constants.ts Outdated Show resolved Hide resolved
constants.ts Show resolved Hide resolved
contracts/LSP20CallVerification/ILSP20CallVerifier.sol Outdated Show resolved Hide resolved
contracts/LSP6KeyManager/LSP6KeyManagerCore.sol Outdated Show resolved Hide resolved
contracts/LSP6KeyManager/LSP6KeyManagerCore.sol Outdated Show resolved Hide resolved
@skimaharvey skimaharvey force-pushed the feat/modify-lsp20 branch 2 times, most recently from 24848b6 to d646d67 Compare October 2, 2023 12:08
@@ -33,6 +33,7 @@ abstract contract LSP20CallVerification {
(bool success, bytes memory returnedData) = logicVerifier.call(
abi.encodeWithSelector(
ILSP20.lsp20VerifyCall.selector,
address(this),
Copy link
Member

Choose a reason for hiding this comment

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

In order to make the LSP20 modules reusable, I would suggest to parameterize in _verifyCall all the lsp20 functions parameter, because not in all scenarios the address(this) will be the target or msg.sender is the one to verify permissions for.

But probably can be done in later PRs, just a note

@CJ42 CJ42 merged commit 0ae4c83 into develop Oct 2, 2023
26 checks passed
@CJ42 CJ42 deleted the feat/modify-lsp20 branch October 2, 2023 15:33
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