Skip to content

Commit

Permalink
gianganhnguyen data for issue #28
Browse files Browse the repository at this point in the history
  • Loading branch information
code423n4 committed Sep 14, 2022
1 parent be3ac1d commit f0cd824
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions data/gianganhnguyen-G.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# 1. [G-1] ++i cost less gas compare i++ in for loops

File CollectionBuyCrowdfund.sol, function onlyHost, line 62:

for (uint256 i; i < hosts.length; i++) {
...
}

Becomes:

for (uint256 i; i < hosts.length; ++i) {
...
}

##### Instances include:

File PartyHelpers.sol, line 64, 85, 115

# 2. [G-2] Cache the length of arrays in the loops

File CollectionBuyCrowdfund.sol, function onlyHost, line 62:

for (uint256 i; i < hosts.length; i++) {
...
}

Becomes:

uint256 lengthHosts = hosts.length;
for (uint256 i; i < lengthHosts; ++i) {
...
}

##### Instances include:

File Crowdfund.sol, line 180, 300
File PartyGovernance.sol, line 306
File ArbitraryCallsProposal.sol, line 52, 61, 78
File LibProposal.sol, line 14, 32
File ListOnOpenseaProposal.sol, line 291
File PartyHelpers.sol, line 64, 85
File ERC1155.sol, line 80, 118

# 3. [G-3] Using uncheck blocks to save gas - increments in for loop can be uncheck
Solidity version 0.8+ comes with implicit overflow and underflow checks on unsigned integers. When an overflow or an underflow isn’t possible (as an example, when a comparison is made before the arithmetic operation), some gas can be saved by using an unchecked block

File CollectionBuyCrowdfund.sol, function onlyHost, line 62:

for (uint256 i; i < hosts.length; i++) {
...
}

Becomes:

uint256 lengthHosts = hosts.length;
for (uint256 i; i < lengthHosts;) {
...
unchecked { ++i; }
}

##### Instances include:

File Crowdfund.sol, line 180, 300, 348
File PartyGovernance.sol, line 306
File ArbitraryCallsProposal.sol, line 52, 61, 78
File LibProposal.sol, line 14, 32
File ListOnOpenseaProposal.sol, line 291
File PartyHelpers.sol, line 64, 85, 115
File ERC1155.sol, line 118
File Strings.sol, line 57

# 4. [G-4] Initialize uint256 i; is cheaper than uint256 i = 0

##### Instances include:

File Crowdfund.sol, line 180, 242, 300, 348
File PartyGovernance.sol, line 306
File ArbitraryCallsProposal.sol, line 52, 61, 78
File LibProposal.sol, line 14, 32
File ListOnOpenseaProposal.sol, line 291
File PartyHelpers.sol, line 64, 85, 115
File ERC1155.sol, line 80, 118, 168, 198




0 comments on commit f0cd824

Please sign in to comment.