Booleans are more expensive than uint256 or any type that takes up a full word because each write operation emits an extra SLOAD to first read the
slot's contents, replace the bits taken up by the boolean, and then write back. This is the compiler's defense against contract upgrades and
pointer aliasing, and it cannot be disabled.
Use uint256(1) and uint256(2) for true/false to avoid a Gwarmaccess (100 gas) for the extra SLOAD, and to avoid Asset (20000 gas) when changing from ‘false’ to ‘true’, after having been ‘true’ in the past
[G-8] FUNCTIONS GUARANTEED TO REVERT WHEN CALLED BY NORMAL USERS CAN BE MARKED PAYABLE
If a function modifier such as onlyOwner is used, the function will revert if a normal user tries to pay the function. Marking the function as payable will lower the gas cost for legitimate callers because the compiler will not include checks for whether a payment was provided.
[G-01] += costs more gas than = + for state variables
There is 4 instance of this issue:
Mitigation
for example ::
To
[G-02] >= COSTS LESS GAS THAN >
The compiler uses opcodes GT and ISZERO for solidity code that uses >, but only requires LT for >=, which saves 3 gas
There is 5 instance of this issue:
[G-03] VARIABLE DECLARED AND THEN INITIALIZED
Here "founder" variable first initialized to its default value, then after again changed to other value and checked in if condition
Mitigation
To
[G-04] USING CALLDATA INSTEAD OF MEMORY FOR READ-ONLY ARGUMENT IN EXTERNAL FUNCTIONS CAN SAVE GAS
[G-05] USING BOOLS FOR STORAGE INCURS OVERHEAD
Booleans are more expensive than uint256 or any type that takes up a full word because each write operation emits an extra SLOAD to first read the slot's contents, replace the bits taken up by the boolean, and then write back. This is the compiler's defense against contract upgrades and pointer aliasing, and it cannot be disabled.
Use uint256(1) and uint256(2) for true/false to avoid a Gwarmaccess (100 gas) for the extra SLOAD, and to avoid Asset (20000 gas) when changing from ‘false’ to ‘true’, after having been ‘true’ in the past
Use uint256 in hasVoted mapping instead bool
[G-06] REPEATING SAME CODE IN DIFFERENT CONTRACTS
hashProposal() code repeated in 2 contract files
Mitigation
shift these code of hashProposal() to a separate library, and this library in above contract files
[G-07] EMPTY BLOCKS SHOULD BE REMOVED OR EMIT SOMETHING
The code should be refactored such that they no longer exist, or the block should do something useful, such as emitting an event or reverting.
_authorizeUpgrade() function is just blank block which doing nothing, At least it should emit a events when Implemented address changes
[G-8] FUNCTIONS GUARANTEED TO REVERT WHEN CALLED BY NORMAL USERS CAN BE MARKED PAYABLE
If a function modifier such as onlyOwner is used, the function will revert if a normal user tries to pay the function. Marking the function as payable will lower the gas cost for legitimate callers because the compiler will not include checks for whether a payment was provided.