This 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
TOOLS USED
Manual Review
Mitigation Step
Remove = 0
Title : using ++i than i++ for saving more gas
Using i++ instead ++i for all the loops, the variable i is incremented using i++. It is known that implementation by using ++i costs less gas per iteration than i++.
This implementation can be saving more gas, since if caching the array length is more gas efficient.
just because access to a local variable in solidity is more efficient.
The linked variables assigned in the constructor can be declared as immutable. Immutable state variables can be assigned during contract creation but will remain constant throughout the lifetime of a deployed contract. A big advantage of immutable variables is that reading them is significantly cheaper than reading from regular state variables since they will not be stored in storage.
= 0
This 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
TOOLS USED
Manual Review
Mitigation Step
Remove
= 0
Using i++ instead ++i for all the loops, the variable i is incremented using i++. It is known that implementation by using ++i costs less gas per iteration than i++.
Tools Used
Manual Review
Occurances
Gravity.sol#L128 Gravity.sol#L233 Gravity.sol#L263 Gravity.sol#L453 Gravity.sol#L569 Gravity.sol#L579 Gravity.sol#L660
uint256 i = 0
intouint256 i
for saving more gasusing this implementation can saving more gas for each loops.
Tool Used
Manual Review
Recommended Mitigation
Change it
Occurances
Gravity.sol#L128 Gravity.sol#L233 Gravity.sol#L263 Gravity.sol#L453 Gravity.sol#L569 Gravity.sol#L579 Gravity.sol#L660
This implementation can be saving more gas, since if caching the array length is more gas efficient. just because access to a local variable in solidity is more efficient.
Tool Used
Manual Review
Occurances
Gravity.sol#L128 Gravity.sol#L233 Gravity.sol#L263 Gravity.sol#L453 Gravity.sol#L569 Gravity.sol#L579 Gravity.sol#L660
This
cumulativePower
Implementation can be used for saving more gas, instead of doube caching, it can be changed by using+=
instead.POC
https://www.tutorialspoint.com/solidity/solidity_operators.htm
Tool Used
Manual Review, Remix
Recommended Mitigation
change to :
Another Occurances
Gravity.sol#L244
Every reason string takes at least 32 bytes. Use short reason strings that fits in 32 bytes or it will become more expensive.
Tool Used
Manual Review
Occurances
Gravity.sol#L119 Gravity.sol#L256 Gravity.sol#L386 Gravity.sol#L492 Gravity.sol#L407 Gravity.sol#L496 Gravity.sol#L655 Gravity.sol#L668
The linked variables assigned in the constructor can be declared as
immutable
.Immutable
state variables can be assigned during contract creation but will remain constant throughout the lifetime of a deployed contract. A big advantage of immutable variables is that reading them is significantly cheaper than reading from regular state variables since they will not be stored in storage.Tool Used
Manual Review