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

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

Gas Optimizations #235

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

Comments

@code423n4
Copy link
Contributor

  1. Short reason string can be used for saving more gas

Every reason string takes at least 32 bytes. Use short reason strings that fits in 32 bytes or it will become more expensive.

main/contracts/dnssec-oracle/RRUtils.sol#L307  "Long keys not permitted"
main/contracts/wrapper/Controllable.sol#L17 "Controllable: Caller is not a controller"
main/contracts/wrapper/BytesUtil.sol#L28  "namehash: Junk at end of name"
main/contracts/wrapper/BytesUtil.sol#L42 "readLabel: Index out of bounds"
main/contracts/wrapper/ERC1155Fuse.sol#L62 "ERC1155: balance query for the zero address"
main/contracts/wrapper/ERC1155Fuse.sol#L87 "ERC1155: accounts and ids length mismatch"
main/contracts/wrapper/ERC1155Fuse.sol#L109 "ERC1155: setting approval status for self"
main/contracts/wrapper/ERC1155Fuse.sol#L176 "ERC1155: transfer to the zero address"
main/contracts/wrapper/ERC1155Fuse.sol#L179 "ERC1155: caller is not owner nor approved"
main/contracts/wrapper/ERC1155Fuse.sol#L197"ERC1155: ids and amounts length mismatch"
main/contracts/wrapper/ERC1155Fuse.sol#L199 "ERC1155: transfer to the zero address"
main/contracts/wrapper/ERC1155Fuse.sol#L202 "ERC1155: transfer caller is not owner nor approved"
main/contracts/wrapper/ERC1155Fuse.sol#L217 "ERC1155: insufficient balance for transfer"
main/contracts/wrapper/ERC1155Fuse.sol#L322 "ERC1155: ERC1155Receiver rejected tokens"
main/contracts/wrapper/ERC1155Fuse.sol#L327 "ERC1155: transfer to non ERC1155Receiver implementer"
main/contracts/wrapper/ERC1155Fuse.sol#L354 "ERC1155: ERC1155Receiver rejected tokens"
main/contracts/wrapper/ERC1155Fuse.sol#L359 "ERC1155: transfer to non ERC1155Receiver implementer"
  1. Using count++ can saving more gas

https://github.com/code-423n4/2022-07-ens/blob/ff6e59b9415d0ead7daf31c2ed06e86d9061ae22/contracts/dnssec-oracle/RRUtils.sol#L58

  1. Saving gas by removing = 0

This implementation code can be saving more gas by removing = 0, it because If a variable was not set/initialized, it is assumed to have default value to 0

https://github.com/code-423n4/2022-07-ens/blob/ff6e59b9415d0ead7daf31c2ed06e86d9061ae22/contracts/wrapper/ERC1155Fuse.sol#L145
https://github.com/code-423n4/2022-07-ens/blob/ff6e59b9415d0ead7daf31c2ed06e86d9061ae22/contracts/dnssec-oracle/BytesUtils.sol#L264

  1. change uint256 i = 0 into uint i for saving more gas

using this implementation can saving more gas for each loops.

/main/contracts/wrapper/ERC1155Fuse.sol#L92         for (uint256 i = 0; i < accounts.length; ++i) {
/main/contracts/wrapper/ERC1155Fuse.sol#L205         for (uint256 i = 0; i < ids.length; ++i) {
 /main/contracts/dnssec-oracle/BytesUtils.sol#L266        for(uint i = 0; i < len; i++) {

@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