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: remove operator logic from internal _burn function in LSP7 #726

Merged
merged 3 commits into from
Sep 27, 2023

Conversation

CJ42
Copy link
Member

@CJ42 CJ42 commented Sep 21, 2023

What does this PR introduce?

♻️ Refactor

  • Remove the logic to check for the operator allowance inside the internal _burn function in LSP7 + move this function in the public burn(...) function in the extension LSP7Burnable.

  • Create internal function _spendAllowance.

🧪 Tests

  • Add tests to ensure operators is removed from list when burning all its allowance.
  • Add tests to check for event emitted AuthorizedOperator and RevokedOperator when burning as an operator.
  • Update the custom error when operator try to burn using address(0) as from (matches with OpenZeppelin logic on ERC20 implementation)

📄 Documentation

  • Add Natspec comments + update auto-generated docs.

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

@Hugoo
Copy link
Contributor

Hugoo commented Sep 21, 2023

@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 42186
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 84850
Transfer 0.1 LYX to 3x EOA with 256 bytes of data 100285

🗄️ setData scenarios

setData scenarios - 👑 UP Owner ⛽ Gas Usage
Set a 20 bytes long value 49971
Set a 60 bytes long value 95281
Set a 160 bytes long value 164453
Set a 300 bytes long value 279676
Set a 600 bytes long value 484148
Change the value of a data key already set 32859
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 260592
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) 100097
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 60475
transfer LYX to a UP 62077
transfer tokens (LSP7) to an EOA (no data) 107990
transfer tokens (LSP7) to a UP (no data) 244446
transfer a NFT (LSP8) to a EOA (no data) 171864
transfer a NFT (LSP8) to a UP (no data) 291567

🛃 restricted controller

execute scenarios - 🛃 restricted controller ⛽ Gas Usage
transfer some LYXes to an EOA - restricted to 1 x allowed address only (TRANSFERVALUE + 1x AllowedCalls) 71667
transfers some tokens (LSP7) to an EOA - restricted to LSP7 + 2x allowed contracts only (CALL + 2x AllowedCalls) (no data) 122681
transfers some tokens (LSP7) to an other UP - restricted to LSP7 + 2x allowed contracts only (CALL + 2x AllowedCalls) (no data) 259137
transfers a NFT (LSP8) to an EOA - restricted to LSP8 + 2x allowed contracts only (CALL + 2x AllowedCalls) (no data) 186520
transfers a NFT (LSP8) to an other UP - restricted to LSP8 + 2x allowed contracts only (CALL + 2x AllowedCalls) (no data) 306223

🗄️ setData scenarios

👑 unrestricted controller

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

🛃 restricted controller

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

📝 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 Sep 21, 2023

Changes to gas cost

Generated at commit: 77c5f559086ee6b7165399259a886e0520f9304e, compared to commit: b8eca3c5696acf85239130ef67edec9e8c134bfa

🧾 Summary (10% most significant diffs)

Contract Method Avg (+/-) %
LSP6ExecuteRestrictedController lsp20VerifyCall
transferLYXToEOA
transferLYXToUP
transferTokensToRandomEOA
-214 ✅
-147 ✅
-147 ✅
-124 ✅
-1.26%
-0.26%
-0.47%
-0.17%
LSP6ExecuteUnrestrictedController lsp20VerifyCall
transferLYXToEOA
transferLYXToUP
transferTokensToRandomEOA
-214 ✅
-147 ✅
-147 ✅
-124 ✅
-1.26%
-0.26%
-0.44%
-0.17%
LSP6SetDataRestrictedController execute
givePermissionsToController
restrictControllerToERC725YKeys
-160 ✅
+192 ❌
+192 ❌
-0.56%
+0.16%
+0.14%
LSP6SetDataUnrestrictedController execute
givePermissionsToController
-160 ✅
+192 ❌
-0.56%
+0.15%

Full diff report 👇
Contract Deployment Cost (+/-) Method Min (+/-) % Avg (+/-) % Median (+/-) % Max (+/-) % # Calls (+/-)
LSP6ExecuteRestrictedController 2,862,894 (-12,797) lsp20VerifyCall
transferLYXToEOA
transferLYXToUP
transferNFTToRandomEOA
transferNFTToRandomUP
transferTokensToRandomEOA
transferTokensToRandomUP
14,619 (-277)
56,018 (-147)
31,349 (-147)
130,724 (-45)
239,224 (-90)
73,568 (-124)
208,980 (-179)
-1.86%
-0.26%
-0.47%
-0.03%
-0.04%
-0.17%
-0.09%
16,818 (-214)
56,018 (-147)
31,349 (-147)
130,724 (-45)
239,224 (-90)
73,568 (-124)
208,980 (-179)
-1.26%
-0.26%
-0.47%
-0.03%
-0.04%
-0.17%
-0.09%
17,551 (-194)
56,018 (-147)
31,349 (-147)
130,724 (-45)
239,224 (-90)
73,568 (-124)
208,980 (-179)
-1.09%
-0.26%
-0.47%
-0.03%
-0.04%
-0.17%
-0.09%
17,551 (-194)
56,018 (-147)
31,349 (-147)
130,724 (-45)
239,224 (-90)
73,568 (-124)
208,980 (-179)
-1.09%
-0.26%
-0.47%
-0.03%
-0.04%
-0.17%
-0.09%
8 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
LSP6ExecuteUnrestrictedController 2,862,894 (-12,797) lsp20VerifyCall
transferLYXToEOA
transferLYXToUP
transferNFTToRandomEOA
transferNFTToRandomUP
transferTokensToRandomEOA
transferTokensToRandomUP
14,619 (-277)
56,648 (-147)
33,349 (-147)
129,472 (-46)
237,973 (-90)
72,004 (-124)
207,416 (-179)
-1.86%
-0.26%
-0.44%
-0.04%
-0.04%
-0.17%
-0.09%
16,818 (-214)
56,648 (-147)
33,349 (-147)
129,472 (-46)
237,973 (-90)
72,004 (-124)
207,416 (-179)
-1.26%
-0.26%
-0.44%
-0.04%
-0.04%
-0.17%
-0.09%
17,551 (-194)
56,648 (-147)
33,349 (-147)
129,472 (-46)
237,973 (-90)
72,004 (-124)
207,416 (-179)
-1.09%
-0.26%
-0.44%
-0.04%
-0.04%
-0.17%
-0.09%
17,551 (-194)
56,648 (-147)
33,349 (-147)
129,472 (-46)
237,973 (-90)
72,004 (-124)
207,416 (-179)
-1.09%
-0.26%
-0.44%
-0.04%
-0.04%
-0.17%
-0.09%
8 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
1 (0)
LSP6SetDataRestrictedController 2,847,670 (-12,798) execute
givePermissionsToController
restrictControllerToERC725YKeys
18,343 (-147)
120,826 (+192)
139,076 (+192)
-0.80%
+0.16%
+0.14%
28,375 (-160)
120,826 (+192)
139,076 (+192)
-0.56%
+0.16%
+0.14%
28,375 (-160)
120,826 (+192)
139,076 (+192)
-0.56%
+0.16%
+0.14%
38,408 (-173)
120,826 (+192)
139,076 (+192)
-0.45%
+0.16%
+0.14%
2 (0)
1 (0)
1 (0)
LSP6SetDataUnrestrictedController 2,847,670 (-12,798) execute
givePermissionsToController
restrictControllerToERC725YKeys
18,343 (-147)
126,826 (+192)
147,576 (+192)
-0.80%
+0.15%
+0.13%
28,375 (-160)
126,826 (+192)
147,576 (+192)
-0.56%
+0.15%
+0.13%
28,375 (-160)
126,826 (+192)
147,576 (+192)
-0.56%
+0.15%
+0.13%
38,408 (-173)
126,826 (+192)
147,576 (+192)
-0.45%
+0.15%
+0.13%
2 (0)
1 (0)
1 (0)

Copy link
Member

@skimaharvey skimaharvey left a comment

Choose a reason for hiding this comment

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

LGTM but might give another shot later as these are quite important changes

contracts/LSP7DigitalAsset/LSP7DigitalAssetCore.sol Outdated Show resolved Hide resolved
@CJ42 CJ42 force-pushed the DEV-7958 branch 2 times, most recently from 2355e7e to c8f64a1 Compare September 27, 2023 13:02
@CJ42 CJ42 merged commit 1b50a5c into develop Sep 27, 2023
26 checks passed
@CJ42 CJ42 deleted the DEV-7958 branch September 27, 2023 18:13
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