Closed code423n4 closed 2 years ago
function test_1()external pure{
for (uint256 i = 0; i < 100; i++) {
uint256 a;
a+=1;
}
}
function test_2()external pure{
for (uint128 i = 0; i < 100; i++) {
uint256 a;
a+=1;
}
}
function test_3()external pure{
for (uint8 i = 0; i < 100; i++) {
uint256 a;
a+=1;
}
}
test_1 = 59818 gas test_2 = 61046 gas test_3 = 61068 gas
closing as invalid.
Handle
defsec
Vulnerability details
Impact
In the vault contract, there is only loop is forwarded only for two times. Therefore, uint8 can be used for the loop.
Proof of Concept
https://github.com/code-423n4/2022-01-insure/blob/19d1a7819fe7ce795e6d4814e7ddf8b8e1323df3/contracts/Vault.sol#L109
Tools Used
None
Recommended Mitigation Steps
Replace the uint128 with uint8 for the gas optimization.