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

Gas Optimizations #274

Open
code423n4 opened this issue Oct 8, 2022 · 1 comment
Open

Gas Optimizations #274

code423n4 opened this issue Oct 8, 2022 · 1 comment
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

code423n4 commented Oct 8, 2022

1. Use require(x) instead of require(x == true)

contracts/BlurExchange.sol: L267

contracts/ExecutionDelegate.sol: L92
L108
L124

2. Strings messages in require statements should not be longer than 32 bytes of length

contracts/BlurExchange.sol: L482

contracts/ExecutionDelegate.sol: L22

3. Place i++ in an unchecked blocks in for-loops

contracts/lib/MerkleVerifier.sol: L38

contracts/lib/EIP712.sol: L77

contracts/BlurExchange.sol: L199
L476

contracts/PolicyManager.sol: L77

4. Consider marking functions as payable if there is no risk of sending value through them

This change will save gas each time a function is called

contracts/ExecutionDelegate.sol: L36
L45

contracts/PolicyManager.sol: L25
L36

contracts/BlurExchange.sol: L43
L47
L53

5. Calldata is cheaper than memory for function input

contracts/lib/EIP712.sol: L39

contracts/lib/MerkleVerifier.sol: L20
L35

6. Function that are called only once can be inlined in the calling function

This change will save around 30 gas units

contracts/lib/MerkleVerifier.sol: L45
L49

7. Cache storage variables in function call stack to save gas

contracts/PolicyManager.sol: L71-L78

8. Prefix incrementing and decrementing costs around 6 gas less than the postfix ones

e.g. ++var is cheaper than var++

contracts/lib/MerkleVerifier.sol: L38

contracts/BlurExchange.sol: L199
L476

contracts/PolicyManager.sol: L77

contracts/lib/EIP712.sol: L77

9. Use 1 and 2 for true and false

contracts/lib/ReentrancyGuarded.sol: L10

10. public storage constant(and immutable) variable should be private

saves tons of gas on deployment

contracts/lib/EIP712.sol: L23
L26
L29

contracts/BlurExchange.sol: L57
L58
L59

11. Custom error are cheaper than string messages

contracts/BlurExchange.sol: L36
L139
L142
L143
L228
L318
L407
L424
L431
L482
L534

contracts/PolicyManager.sol: L26
L37

contracts/ExecutionDelegate.sol: L22
L77
L92
L108

contracts/lib/ReentrancyGuarded.sol: L14

12. Use constant and immutable for constants

contracts/PolicyManager.sol: L16

contracts/lib/EIP712.sol: L37

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Oct 8, 2022
code423n4 added a commit that referenced this issue Oct 8, 2022
code423n4 added a commit that referenced this issue Oct 8, 2022
@GalloDaSballo
Copy link
Collaborator

5k from nonReentrant rest is negligible (immutable is incorrect)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization)
Projects
None yet
Development

No branches or pull requests

2 participants