You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Constants that are private instead of public save gas.
8
[G-2]
Variables set only while constructing should be immutable
3
[G-3]
Multiple mappings could be combined
8
[G-4]
Users can manipulate string chain size
1
[G-5]
Comparing a uint with != is cheaper than using >
1
Total: 21 appearances over 5 issues.
Gas Optimizations
[G-1] Constants that are private instead of public save gas.
Because constant variables should be declared an initialized as a one-liner, their value could be easily retrieved by reading directly the source code. Removing the public modifier and using private instead, does not create a function getter for the public constant saving around 3500 gas on deployment.
If there are used mappings with repeated types of keys, it is a sign that they could be refactored into a single mapping that points to a struct when appropriate. Depending on the data types and their sizes, this could avoid triggering a Gsset operation (consumes 20,000 gas while changing from zero to a non zero value). Because memory slots are calculated via keccak256, reducing the amount of slots also reduce for the compiler the need to compute the keys' hash.
Found 8 times
Governance.sol L96: mapping(uint256=> ProposalMetadata) public getProposalMetadata;
Governance.sol L99: mapping(uint256=>uint256) public totalEndorsementsForProposal;
Governance.sol L102: mapping(uint256=>mapping(address=>uint256)) public userEndorsementsForProposal;
Governance.sol L105: mapping(uint256=>bool) public proposalHasBeenActivated;
Governance.sol L108: mapping(uint256=>uint256) public yesVotesForProposal;
Governance.sol L111: mapping(uint256=>uint256) public noVotesForProposal;
Governance.sol L114: mapping(uint256=>mapping(address=>uint256)) public userVotesForProposal;
Governance.sol L117: mapping(uint256=>mapping(address=>bool)) public tokenClaimsForProposal;
[G-4] Users can manipulate string chain size
Users can freely use string chains with uncapped size. When the 32 bytes slot size is exceeded, a new slow will be used to render and store that string. In order to provide a better user experience, it is advisable to constraint the user-input string size.
Found 1 time
Governance.sol L162: stringmemoryproposalURI_
[G-5] Comparing a uint with != is cheaper than using >
For unsigned integers, it is cheaper to check that they are non zero values with the unequal operator rather than checking their greatness. While compiling with the optimizer enabled this change saves around 6 gas.
Found 1 time
Governance.sol L247: if (userVotesForProposal[activeProposal.proposalId][msg.sender] >0) {
The text was updated successfully, but these errors were encountered:
Gas Optimizations
private
instead ofpublic
save gas.immutable
uint
with!=
is cheaper than using>
Total: 21 appearances over 5 issues.
Gas Optimizations
[G-1] Constants that are
Because constant variables should be declared an initialized as a one-liner, their value could be easily retrieved by reading directly the source code. Removing theprivate
instead ofpublic
save gas.public
modifier and usingprivate
instead, does not create a function getter for the public constant saving around3500 gas
on deployment.Found 8 times
[G-2] Variables set only while constructing should be
immutable
This operation reduces the gas cost each time a variable is consulted and also avoids a Gsset (20,000 gas) while constructing.
Found 3 times
Heart.sol L48: IOperator internal _operator;
[G-3] Multiple mappings could be combined
If there are used mappings with repeated types of keys, it is a sign that they could be refactored into a single mapping that points to a struct when appropriate. Depending on the data types and their sizes, this could avoid triggering a Gsset operation (consumes 20,000 gas while changing from zero to a non zero value). Because memory slots are calculated via
keccak256
, reducing the amount of slots also reduce for the compiler the need to compute the keys' hash.Found 8 times
[G-4] Users can manipulate string chain size
Users can freely use string chains with uncapped size. When the
32 bytes
slot size is exceeded, a new slow will be used to render and store that string. In order to provide a better user experience, it is advisable to constraint the user-input string size.Found 1 time
[G-5] Comparing a
uint
with!=
is cheaper than using>
For unsigned integers, it is cheaper to check that they are non zero values with the unequal operator rather than checking their greatness. While compiling with the optimizer enabled this change saves around
6 gas
.Found 1 time
The text was updated successfully, but these errors were encountered: