Open code423n4 opened 2 years ago
https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/Gravity.sol#L301 https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/Gravity.sol#L396
before '''
require( _currentValset.validators.length == _currentValset.powers.length && _currentValset.validators.length == _v.length && _currentValset.validators.length == _r.length && _currentValset.validators.length == _s.length, "Malformed current validator set" );
'''
after '''
uint256 length = _currentValset.validators.length; require(length == _currentValset.powers.length, "Malformed current validator set"); require(length == _v.length, "Malformed current validator set"); require(length == _r.length, "Malformed current validator set"); require(length == _s.length, "Malformed current validator set");
make a local copy of multiple use of a global variable and use one require only for one logic to save gas
poc
https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/Gravity.sol#L301 https://github.com/code-423n4/2022-05-cudos/blob/main/solidity/contracts/Gravity.sol#L396
before '''
'''
after '''
'''