Gas optimize ERC5643 #6
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have applied some optimizations on repository-owned code whilst keeping it readable:
Changes
0.8.13->0.8.19, right beforePUSH0opcode was introduced, thus allowing the usage of this base on not fully EVM compliant chains.reverterrors with their inline-assembly equivalence:SubscriptionUpdatelogs and perform storage-related operations with inline-assembly.All forge tests passed successfully, with these before and after gas costs:
testCancelNotOwner(): from17,836to17,800testCancelValid(): from20,777to20,723testExpiresAt(): from42,743to42,056testExpiresAtInvalidToken(): from12,901to12,865testExtendSubscriptionInvalidToken(): from13,039to12,991testIsRenewableInvalidToken(): from12,831to12,795testRenewalDurationTooLong(): from47,961to47,581testRenewalDurationTooShort(): from47,664to47,583testRenewalExistingSubscription(): from145,175to144,285testRenewalInsufficientPayment(): from26,874to26,650testRenewalInvalidTokenId(): from22,316to22,304testRenewalNewSubscription(): from53,103to52,702testRenewalNotOwner(): from17,961to17,913Notes
STATICCALL) at the cost of code readability.