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 #318

Open
code423n4 opened this issue Jul 19, 2022 · 0 comments
Open

Gas Optimizations #318

code423n4 opened this issue Jul 19, 2022 · 0 comments
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

x = x + y is more efficient than x += y, same for x = x - y and x -= y

RRUtils.sol
BytesUtils.sol

variables that are assigned as zero should be left unitialized

RRUtils.sol
DNSSECImpl.sol
BytesUtils.sol

Potencies of 2 (and multiples of 2) i.e. 2**(number) can be converted into left-shift minus one 2<<(number - 1) for a more efficient operation

#L219
#L69

Multiplications by multiples of 2 can be turned into a left shift which uses cheaper opcodes

#L316

require() statements using && operators should be split into two different require() operations.

#L268

Use a more recent version of Solidity

NameWrapper.sol

This is an important mention because not only v0.8.15 has introduced better heuristics for yul optimization, relevant for the assembly codes in here, but also because the developers have compiled this very project and found a decrease in 4.89% in deployment costs and 0.29% in runtime gas. Source

++i iterators are more efficient than i++ iterators.

RRUtils.sol
DNSSECImpl.sol
ETHRegistrarController.sol

uint256 iterators should be left unchecked {} as there's no risk of overflow

RRUtils.sol
DNSSECImpl.sol
ETHRegistrarController.sol

<array>.length loop comparisons being iterated one by one can use the != operator instead of <

RRUtils.sol
DNSSECImpl.sol
ETHRegistrarController.sol

#L93

!= 0 comparisons are more efficient than > 0 for unsigned integers

#L245
#L93

require() statements will consume less gas if the revert string contains less than 32 characters

ETHRegistrarController.sol

Using unsigned integers other than uint256 incurs overhead costs

#L47

Remove unused error message

#L25

Functions that necessarily revert when called by normal users can be set as payable

DNSSECImpl.sol

Use calldata for read-only arguments for external functions

DNSSECImpl.sol

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jul 19, 2022
code423n4 added a commit that referenced this issue Jul 19, 2022
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

1 participant