Issue | Instances | |
---|---|---|
[GAS-1] | Cache array length outside of loop | 2 |
[GAS-2] | ++i costs less gas than i++ , especially when it's used in for -loops (--i /i-- too) |
2 |
If not cached, the solidity compiler will always read the length of the array during each iteration. That is, if it is a storage array, this is an extra sload operation (100 additional extra gas for each iteration except for the first) and if it is a memory array, this is an extra mload operation (3 additional gas for each iteration except for the first).
Instances (2):
File: SizeSealed.sol
244: for (uint256 i; i < bidIndices.length; i++) {
302: for (uint256 i; i < seenBidMap.length - 1; i++) {
Saves 5 gas per loop
Instances (2):
File: SizeSealed.sol
244: for (uint256 i; i < bidIndices.length; i++) {
302: for (uint256 i; i < seenBidMap.length - 1; i++) {
Issue | Instances | |
---|---|---|
[L-1] | abi.encodePacked() should not be used with dynamic types when passing the result to a hash function such as keccak256() |
1 |
[L-1] abi.encodePacked()
should not be used with dynamic types when passing the result to a hash function such as keccak256()
Use abi.encode()
instead which will pad items to 32 bytes, which will prevent hash collisions (e.g. abi.encodePacked(0x123,0x456)
=> 0x123456
=> abi.encodePacked(0x1,0x23456)
, but abi.encode(0x123,0x456)
=> 0x0...1230...456
). "Unless there is a compelling reason, abi.encode
should be preferred". If there is only one argument to abi.encodePacked()
it can often be cast to bytes()
or bytes32()
instead.
If all arguments are strings and or bytes, bytes.concat()
should be used instead
Instances (1):
File: SizeSealed.sol
133: bytes32 leaf = keccak256(abi.encodePacked(msg.sender));