Skip to content

Commit

Permalink
10-17% Gas reduction for checks, hash tests (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
mireynolds authored Jul 11, 2023
1 parent 4f9f5b8 commit 7b06abc
Show file tree
Hide file tree
Showing 12 changed files with 638 additions and 173 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/slither-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Check slither report
run: |
section=$(awk '/^##/{exit} {print}' slitherReport.md)
if [[ $section == *"Medium"* || $section == *"High"* ]]; then
echo "Medium or High risk found in slither report. Failing the run."
if [[ $section == *"Medium"* || $section == *"High"* || $section == *"Low"* ]]; then
echo "Low, Medium or High risk found in slither report. Failing the run."
exit 1
fi
24 changes: 12 additions & 12 deletions gasbenchmark10mil
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
| src/DelegateRegistry.sol:DelegateRegistry contract | | | | | |
|----------------------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 1840741 | 9226 | | | | |
| 2124658 | 10644 | | | | |
| Function Name | min | avg | median | max | # calls |
| checkDelegateForAll | 3293 | 3648 | 3648 | 4004 | 2 |
| checkDelegateForContract | 6120 | 6856 | 6856 | 7593 | 2 |
| checkDelegateForERC1155 | 8989 | 10164 | 10164 | 11340 | 2 |
| checkDelegateForERC20 | 8899 | 10053 | 10053 | 11207 | 2 |
| checkDelegateForERC721 | 8981 | 10114 | 10114 | 11248 | 2 |
| delegateAll | 136182 | 136182 | 136182 | 136182 | 2 |
| delegateContract | 114804 | 125754 | 125754 | 136704 | 2 |
| delegateERC1155 | 159739 | 170689 | 170689 | 181639 | 2 |
| delegateERC20 | 137269 | 148219 | 148219 | 159169 | 2 |
| delegateERC721 | 137279 | 148229 | 148229 | 159179 | 2 |
| multicall | 691368 | 691368 | 691368 | 691368 | 1 |
| checkDelegateForAll | 2980 | 3183 | 3183 | 3386 | 2 |
| checkDelegateForContract | 5473 | 5895 | 5895 | 6317 | 2 |
| checkDelegateForERC1155 | 7990 | 8685 | 8685 | 9380 | 2 |
| checkDelegateForERC20 | 7927 | 8610 | 8610 | 9293 | 2 |
| checkDelegateForERC721 | 7991 | 8644 | 8644 | 9297 | 2 |
| delegateAll | 135861 | 135861 | 135861 | 135861 | 2 |
| delegateContract | 114469 | 125419 | 125419 | 136369 | 2 |
| delegateERC1155 | 159393 | 170343 | 170343 | 181293 | 2 |
| delegateERC20 | 136942 | 147892 | 147892 | 158842 | 2 |
| delegateERC721 | 136936 | 147886 | 147886 | 158836 | 2 |
| multicall | 689696 | 689696 | 689696 | 689696 | 1 |
18 changes: 18 additions & 0 deletions hashbenchmark10mil
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
| src/tools/HashHarness.sol:HashHarness contract | | | | | |
|------------------------------------------------|-----------------|-----|--------|-----|---------|
| Deployment Cost | Deployment Size | | | | |
| 416655 | 2113 | | | | |
| Function Name | min | avg | median | max | # calls |
| allHash | 634 | 634 | 634 | 634 | 1 |
| allLocation | 746 | 746 | 746 | 746 | 1 |
| contractHash | 835 | 835 | 835 | 835 | 1 |
| contractLocation | 873 | 873 | 873 | 873 | 1 |
| decodeType | 393 | 393 | 393 | 393 | 1 |
| encodeType | 351 | 351 | 351 | 351 | 1 |
| erc1155Hash | 843 | 843 | 843 | 843 | 1 |
| erc1155Location | 876 | 876 | 876 | 876 | 1 |
| erc20Hash | 814 | 814 | 814 | 814 | 1 |
| erc20Location | 831 | 831 | 831 | 831 | 1 |
| erc721Hash | 821 | 821 | 821 | 821 | 1 |
| erc721Location | 910 | 910 | 910 | 910 | 1 |
| location | 406 | 406 | 406 | 406 | 1 |
80 changes: 43 additions & 37 deletions slitherReport.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
**THIS CHECKLIST IS NOT COMPLETE**. Use `--show-ignored-findings` to show all the results.
Summary
- [assembly](#assembly) (9 results) (Informational)
- [solc-version](#solc-version) (7 results) (Informational)
- [solc-version](#solc-version) (8 results) (Informational)
- [low-level-calls](#low-level-calls) (1 results) (Informational)
## assembly
Impact: Informational
Confidence: High
- [ ] ID-0
[DelegateRegistry.readSlot(bytes32)](src/DelegateRegistry.sol#L254-L258) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L255-L257)
[DelegateRegistry.readSlots(bytes32[])](src/DelegateRegistry.sol#L255-L261) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L258-L260)

src/DelegateRegistry.sol#L254-L258
src/DelegateRegistry.sol#L255-L261


- [ ] ID-1
[DelegateRegistry._loadDelegationAddresses(bytes32,IDelegateRegistry.StoragePositions,IDelegateRegistry.StoragePositions)](src/DelegateRegistry.sol#L383-L396) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L388-L395)
[DelegateRegistry._loadDelegationBytes32(bytes32,IDelegateRegistry.StoragePositions)](src/DelegateRegistry.sol#L357-L361) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L358-L360)

src/DelegateRegistry.sol#L383-L396
src/DelegateRegistry.sol#L357-L361


- [ ] ID-2
[DelegateRegistry._loadDelegationUint(bytes32,IDelegateRegistry.StoragePositions)](src/DelegateRegistry.sol#L369-L373) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L370-L372)
[DelegateRegistry._loadDelegationUint(bytes32,IDelegateRegistry.StoragePositions)](src/DelegateRegistry.sol#L364-L368) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L365-L367)

src/DelegateRegistry.sol#L369-L373
src/DelegateRegistry.sol#L364-L368


- [ ] ID-3
[DelegateRegistry._writeDelegation(bytes32,IDelegateRegistry.StoragePositions,uint256)](src/DelegateRegistry.sol#L297-L301) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L298-L300)
[DelegateRegistry._writeDelegation(bytes32,IDelegateRegistry.StoragePositions,uint256)](src/DelegateRegistry.sol#L292-L296) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L293-L295)

src/DelegateRegistry.sol#L297-L301
src/DelegateRegistry.sol#L292-L296


- [ ] ID-4
[DelegateRegistry._loadDelegationBytes32(bytes32,IDelegateRegistry.StoragePositions)](src/DelegateRegistry.sol#L362-L366) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L363-L365)
[DelegateRegistry._writeDelegation(bytes32,IDelegateRegistry.StoragePositions,bytes32)](src/DelegateRegistry.sol#L285-L289) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L286-L288)

src/DelegateRegistry.sol#L362-L366
src/DelegateRegistry.sol#L285-L289


- [ ] ID-5
[DelegateRegistry.readSlots(bytes32[])](src/DelegateRegistry.sol#L260-L266) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L263-L265)
[DelegateRegistry._writeDelegationAddresses(bytes32,IDelegateRegistry.StoragePositions,IDelegateRegistry.StoragePositions,address,address,address)](src/DelegateRegistry.sol#L299-L306) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L302-L305)

src/DelegateRegistry.sol#L260-L266
src/DelegateRegistry.sol#L299-L306


- [ ] ID-6
[DelegateRegistry._writeDelegation(bytes32,IDelegateRegistry.StoragePositions,bytes32)](src/DelegateRegistry.sol#L290-L294) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L291-L293)
[DelegateRegistry._loadFrom(bytes32,IDelegateRegistry.StoragePositions)](src/DelegateRegistry.sol#L371-L375) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L372-L374)

src/DelegateRegistry.sol#L290-L294
src/DelegateRegistry.sol#L371-L375


- [ ] ID-7
[DelegateRegistry._writeDelegationAddresses(bytes32,IDelegateRegistry.StoragePositions,IDelegateRegistry.StoragePositions,address,address,address)](src/DelegateRegistry.sol#L304-L311) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L307-L310)
[DelegateRegistry._loadDelegationAddresses(bytes32,IDelegateRegistry.StoragePositions,IDelegateRegistry.StoragePositions)](src/DelegateRegistry.sol#L378-L391) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L383-L390)

src/DelegateRegistry.sol#L304-L311
src/DelegateRegistry.sol#L378-L391


- [ ] ID-8
[DelegateRegistry._loadFrom(bytes32,IDelegateRegistry.StoragePositions)](src/DelegateRegistry.sol#L376-L380) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L377-L379)
[DelegateRegistry.readSlot(bytes32)](src/DelegateRegistry.sol#L249-L253) uses assembly
- [INLINE ASM](src/DelegateRegistry.sol#L250-L252)

src/DelegateRegistry.sol#L376-L380
src/DelegateRegistry.sol#L249-L253


## solc-version
Expand All @@ -79,33 +79,39 @@ src/IDelegateRegistry.sol#L2


- [ ] ID-10
Pragma version[^0.8.20](src/tools/HashHarness.sol#L2) necessitates a version too recent to be trusted. Consider deploying with 0.8.18.

src/tools/HashHarness.sol#L2


- [ ] ID-11
Pragma version[^0.8.20](src/examples/Airdrop.sol#L2) necessitates a version too recent to be trusted. Consider deploying with 0.8.18.

src/examples/Airdrop.sol#L2


- [ ] ID-11
- [ ] ID-12
solc-0.8.20 is not recommended for deployment

- [ ] ID-12
- [ ] ID-13
Pragma version[^0.8.20](src/tools/RegistryHarness.sol#L2) necessitates a version too recent to be trusted. Consider deploying with 0.8.18.

src/tools/RegistryHarness.sol#L2


- [ ] ID-13
- [ ] ID-14
Pragma version[^0.8.20](src/examples/IPLicenseCheck.sol#L2) necessitates a version too recent to be trusted. Consider deploying with 0.8.18.

src/examples/IPLicenseCheck.sol#L2


- [ ] ID-14
- [ ] ID-15
Pragma version[^0.8.20](src/DelegateRegistry.sol#L2) necessitates a version too recent to be trusted. Consider deploying with 0.8.18.

src/DelegateRegistry.sol#L2


- [ ] ID-15
- [ ] ID-16
Pragma version[^0.8.20](src/examples/DelegateClaim.sol#L2) necessitates a version too recent to be trusted. Consider deploying with 0.8.18.

src/examples/DelegateClaim.sol#L2
Expand All @@ -114,10 +120,10 @@ src/examples/DelegateClaim.sol#L2
## low-level-calls
Impact: Informational
Confidence: High
- [ ] ID-16
Low level call in [DelegateRegistry.multicall(bytes[])](src/DelegateRegistry.sol#L34-L45):
- [(success,results[i]) = address(this).delegatecall(data[i])](src/DelegateRegistry.sol#L41)
- [ ] ID-17
Low level call in [DelegateRegistry.multicall(bytes[])](src/DelegateRegistry.sol#L34-L44):
- [(success,results[i]) = address(this).delegatecall(data[i])](src/DelegateRegistry.sol#L40)

src/DelegateRegistry.sol#L34-L45
src/DelegateRegistry.sol#L34-L44


Loading

0 comments on commit 7b06abc

Please sign in to comment.