// These are set once at initialization
bytes32 public state_gravityId;
uint256 public state_powerThreshold;
CudosAccessControls public cudosAccessControls;
contracts/Gravity.sol:128: for (uint256 i = 0; i < _users.length; i++) {
contracts/Gravity.sol:233: for (uint256 i = 0; i < _currentValidators.length; i++) {
contracts/Gravity.sol:263: for (uint256 i = 0; i < _newValset.validators.length; i++) {
contracts/Gravity.sol:453: for (uint256 i = 0; i < _amounts.length; i++) {
contracts/Gravity.sol:568: for (uint256 i = 0; i < _args.transferAmounts.length; i++) {
contracts/Gravity.sol:579: for (uint256 i = 0; i < _args.feeAmounts.length; i++) {
contracts/Gravity.sol:660: for (uint256 i = 0; i < _powers.length; i++) {
For loop optimization by caching length
Cache array length to reduce MLOADs, e.g.
uint256 arrlen = _users.length;
for (uint256 i = 0; i < arrlen; i++)
contracts/Gravity.sol:128: for (uint256 i = 0; i < _users.length; i++) {
contracts/Gravity.sol:233: for (uint256 i = 0; i < _currentValidators.length; i++) {
contracts/Gravity.sol:263: for (uint256 i = 0; i < _newValset.validators.length; i++) {
contracts/Gravity.sol:453: for (uint256 i = 0; i < _amounts.length; i++) {
contracts/Gravity.sol:568: for (uint256 i = 0; i < _args.transferAmounts.length; i++) {
contracts/Gravity.sol:579: for (uint256 i = 0; i < _args.feeAmounts.length; i++) {
contracts/Gravity.sol:660: for (uint256 i = 0; i < _powers.length; i++) {
Variable can be constant
https://github.com/code-423n4/2022-05-cudos/blob/de39cf3cd1f1e1cf211819b06d4acf6a043acda0/solidity/contracts/CosmosToken.sol#L5-L6
Variables can be immutable
https://github.com/code-423n4/2022-05-cudos/blob/de39cf3cd1f1e1cf211819b06d4acf6a043acda0/solidity/contracts/Gravity.sol#L59-L63
Cache state_lastEventNonce
Here is an example but there are multiple occurrence https://github.com/code-423n4/2022-05-cudos/blob/de39cf3cd1f1e1cf211819b06d4acf6a043acda0/solidity/contracts/Gravity.sol#L583-L592
Change the code into
For loop optimization with ++i
using ++i save gas against i++
For loop optimization by caching length
Cache array length to reduce MLOADs, e.g.
Unnecessary safe math
https://github.com/code-423n4/2022-05-cudos/blob/de39cf3cd1f1e1cf211819b06d4acf6a043acda0/solidity/contracts/Gravity.sol#L465-L466
Use separate require instead of &&
https://github.com/code-423n4/2022-05-cudos/blob/de39cf3cd1f1e1cf211819b06d4acf6a043acda0/solidity/contracts/Gravity.sol#L301-L307
Upgrade to latest Solidity
Consider upgrade to latest 0.8.12 for various gas saving