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: Prevent casting LSP17 Data shorter than 20 bytes #778

Merged
merged 4 commits into from
Nov 2, 2023

Conversation

YamenMerhi
Copy link
Member

What does this PR introduce?

♻️ Refactor

Prevent casting LSP17 Data shorter than 20 bytes.
In this way, if some mistake happens while setting the extension, the call won't be forwarded to the faulty casted extension.

PR Checklist

  • Wrote Tests
  • Wrote & Generated Documentation (readme/natspec/dodoc)
  • Ran npm run lint && npm run lint:solidity (solhint)
  • Ran npm run format (prettier)
  • Ran npm run build
  • Ran npm run test

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.

⛽📊 Gas Benchmark Report

Deployment Costs

Deployed contracts ⛽ Deployment cost
UniversalProfile 3135098 (4,964 📈❌)
KeyManager 3656003 (0 )
LSP1DelegateUP 1630159 (0 )
LSP7Mintable 2350310 (0 )
LSP8Mintable 2443708 (0 )

Runtime Costs

UniversalProfile owned by an 🔑 EOA

🔀 execute scenarios

execute scenarios - UP owned by 🔑 EOA ⛽ Gas Usage
Transfer 1 LYX to an EOA without data 37560 (0 )
Transfer 1 LYX to a UP without data 46253 (0 )
Transfer 1 LYX to an EOA with 256 bytes of data 42233 (12 📈❌)
Transfer 1 LYX to a UP with 256 bytes of data 57186 (-148 📉✅)
Transfer 0.1 LYX to 3x EOA without data 70862 (0 )
Transfer 0.1 LYX to 3x UP without data 104453 (0 )
Transfer 0.1 LYX to 3x EOA with 256 bytes of data 84838 (0 )
Transfer 0.1 LYX to 3x UPs with 256 bytes of data 137173 (-480 📉✅)

🗄️ setData scenarios

setData scenarios - UP owned by 🔑 EOA ⛽ Gas Usage
Set a 20 bytes long value 49971 (0 )
Set a 60 bytes long value 95293 (0 )
Set a 160 bytes long value 164465 (12 📈❌)
Set a 300 bytes long value 279676 (12 📈❌)
Set a 600 bytes long value 484124 (12 📈❌)
Change the value of a data key already set 32859 (0 )
Remove the value of a data key already set 27333 (0 )
Set 2 data keys of 20 bytes long value 78454 (0 )
Set 2 data keys of 100 bytes long value 260606 (12 📈❌)
Set 3 data keys of 20 bytes long value 105171 (0 )
Change the value of three data keys already set of 20 bytes long value 45471 (0 )
Remove the value of three data keys already set 41360 (0 )

🗄️ Tokens scenarios

Tokens scenarios - UP owned by 🔑 EOA ⛽ Gas Usage
Minting a LSP7Token to a UP (No Delegate) from an EOA 92724 (0 )
Minting a LSP7Token to an EOA from an EOA 59377 (0 )
Transferring an LSP7Token from a UP to another UP (No Delegate) 101577 (0 )
Minting a LSP8Token to a UP (No Delegate) from an EOA 159593 (0 )
Minting a LSP8Token to an EOA from an EOA 126247 (0 )
Transferring an LSP8Token from a UP to another UP (No Delegate) 150271 (0 )
UniversalProfile owned by a 🔒📄 LSP6KeyManager

🔀 execute scenarios

execute scenarios 👑 main controller 🛃 restricted controller
LYX transfer --> to an EOA 64336 (0 ) 75148 (0 )
LYX transfer --> to a UP 78488 (0 ) 93210 (0 )
LSP7 token transfer --> to an EOA 116353 (0 ) 131067 (0 )
LSP7 token transfer --> to a UP 249627 (0 ) 264341 (0 )
LSP8 NFT transfer --> to an EOA 180440 (0 ) 195154 (0 )
LSP8 NFT transfer --> to a UP 296916 (0 ) 311630 (0 )

🗄️ setData scenarios

setData scenarios 👑 main controller 🛃 restricted controller
Update Profile details (LSP3Profile Metadata) 67338 (0 ) 77360 (0 )
Add a new controller with permission to SET_DATA + 3x allowed data keys:
AddressPermissions[]
+ AddressPermissions[index]
+ AddressPermissions:Permissions:<controller>
+ AddressPermissions:AllowedERC725YDataKeys:<controller)
209610 (0 ) 219767 (0 )
Update permissions of previous controller. Allow it now to SUPER_SETDATA 52366 (0 ) 55372 (0 )
Remove a controller:
1. decrease AddressPermissions[] Array length
2. remove the controller address at AddressPermissions[index]
3. set "0x" for the controller permissions under AddressPermissions:Permissions:
78842 (0 ) 90140 (0 )
Write 5x new LSP12 Issued Assets 67032 (0 ) 101659 (0 )
Update 3x data keys (first 3) 125476 (0 ) 159580 (0 )
Update 3x data keys (middle 3) 105564 (0 ) 143734 (0 )
Update 3x data keys (last 3) 125476 (0 ) 169067 (0 )
Set 2 x new data keys + add 3x new controllers 810447 (0 ) 872247 (0 )

Copy link
Contributor

github-actions bot commented Nov 2, 2023

Changes to gas cost

Generated at commit: 9ff744a093cbfacfce5728f9b6c6f1c948eff4d0, compared to commit: 1f92ca530fb56cf2b626b0feae311d6c4737b8a0

🧾 Summary (10% most significant diffs)

Contract Method Avg (+/-) %
LSP6ExecuteRestrictedController transferLYXToEOA
transferLYXToUP
transferNFTToRandomEOA
transferNFTToRandomUP
transferTokensToRandomEOA
transferTokensToRandomUP
-350 ✅
-350 ✅
-352 ✅
-352 ✅
-352 ✅
-440 ✅
-0.56%
-0.63%
-0.25%
-0.14%
-0.47%
-0.21%
LSP6ExecuteUnrestrictedController transferLYXToEOA
transferLYXToUP
transferNFTToRandomEOA
transferNFTToRandomUP
transferTokensToRandomEOA
transferTokensToRandomUP
-350 ✅
-350 ✅
-352 ✅
-352 ✅
-352 ✅
-440 ✅
-0.56%
-0.61%
-0.25%
-0.14%
-0.48%
-0.21%
LSP6SetDataRestrictedController execute
givePermissionsToController
-198 ✅
-45 ✅
-0.57%
-0.04%
LSP6SetDataUnrestrictedController execute
givePermissionsToController
-198 ✅
-45 ✅
-0.57%
-0.03%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
LSP6ExecuteRestrictedController 3,039,699 (-4,608) transferLYXToEOA
transferLYXToUP
transferNFTToRandomEOA
transferNFTToRandomUP
transferTokensToRandomEOA
transferTokensToRandomUP
62,058 (-350)
55,389 (-350)
143,016 (-352)
248,636 (-352)
74,965 (-352)
205,750 (-440)
-0.56%
-0.63%
-0.25%
-0.14%
-0.47%
-0.21%
62,058 (-350)
55,389 (-350)
143,016 (-352)
248,636 (-352)
74,965 (-352)
205,750 (-440)
-0.56%
-0.63%
-0.25%
-0.14%
-0.47%
-0.21%
62,058 (-350)
55,389 (-350)
143,016 (-352)
248,636 (-352)
74,965 (-352)
205,750 (-440)
-0.56%
-0.63%
-0.25%
-0.14%
-0.47%
-0.21%
62,058 (-350)
55,389 (-350)
143,016 (-352)
248,636 (-352)
74,965 (-352)
205,750 (-440)
-0.56%
-0.63%
-0.25%
-0.14%
-0.47%
-0.21%
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
LSP6ExecuteUnrestrictedController 3,039,699 (-4,608) transferLYXToEOA
transferLYXToUP
transferNFTToRandomEOA
transferNFTToRandomUP
transferTokensToRandomEOA
transferTokensToRandomUP
62,585 (-350)
56,989 (-350)
141,788 (-352)
247,409 (-352)
73,738 (-352)
204,216 (-440)
-0.56%
-0.61%
-0.25%
-0.14%
-0.48%
-0.21%
62,585 (-350)
56,989 (-350)
141,788 (-352)
247,409 (-352)
73,738 (-352)
204,216 (-440)
-0.56%
-0.61%
-0.25%
-0.14%
-0.48%
-0.21%
62,585 (-350)
56,989 (-350)
141,788 (-352)
247,409 (-352)
73,738 (-352)
204,216 (-440)
-0.56%
-0.61%
-0.25%
-0.14%
-0.48%
-0.21%
62,585 (-350)
56,989 (-350)
141,788 (-352)
247,409 (-352)
73,738 (-352)
204,216 (-440)
-0.56%
-0.61%
-0.25%
-0.14%
-0.48%
-0.21%
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
LSP6SetDataRestrictedController 3,027,691 (-4,600) execute
givePermissionsToController
restrictControllerToERC725YKeys
30,328 (-352)
122,641 (-45)
141,428 (-45)
-1.15%
-0.04%
-0.03%
34,316 (-198)
122,641 (-45)
141,428 (-45)
-0.57%
-0.04%
-0.03%
34,316 (-198)
122,641 (-45)
141,428 (-45)
-0.57%
-0.04%
-0.03%
38,304 (-45)
122,641 (-45)
141,428 (-45)
-0.12%
-0.04%
-0.03%
2 (0)
1 (0)
1 (0)
LSP6SetDataUnrestrictedController 3,027,691 (-4,600) execute
givePermissionsToController
restrictControllerToERC725YKeys
30,328 (-352)
128,641 (-45)
149,928 (-45)
-1.15%
-0.03%
-0.03%
34,316 (-198)
128,641 (-45)
149,928 (-45)
-0.57%
-0.03%
-0.03%
34,316 (-198)
128,641 (-45)
149,928 (-45)
-0.57%
-0.03%
-0.03%
38,304 (-45)
128,641 (-45)
149,928 (-45)
-0.12%
-0.03%
-0.03%
2 (0)
1 (0)
1 (0)

@CJ42 CJ42 merged commit d6356a7 into develop Nov 2, 2023
25 checks passed
@CJ42 CJ42 deleted the refactor/NoCastinglsp17 branch November 2, 2023 15:37
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