code-423n4 / 2022-02-jpyc-findings

1 stars 0 forks source link

Gas Optimizations #57

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

GAS :

  1. Title : use constant value.

Impact : In the checkWhitelist modifier instead of doing calculation every time this modifier is executed, its cheaper to make it a constant variable in the storage, and the checkWhitelist only need to call the constant variable.

POC : https://github.com/code-423n4/2022-02-jpyc/blob/main/contracts/v2/FiatTokenV2.sol#L624

2. Title : use unchecked is way cheaper

Impact : In the solidity version 0.8 above there already default check on underflow and overflow, and since https://github.com/code-423n4/2022-02-jpyc/blob/main/contracts/v2/FiatTokenV2.sol#L326 there is already check on amount and balance[from], and check by default on solidity 0.8 above, its cheaper to use unchecked blok for the balance calculation the subtraction and add.

POC : https://github.com/code-423n4/2022-02-jpyc/blob/main/contracts/v2/FiatTokenV2.sol#L326-L327

3. Title : its cheaper to use constant variable

Impact : its cheaper to call decimals, name, and symbol as a constant value, since these variable shouldn't change after deployement. You can do this by hardcoded this value directly in the storage.

POC : https://github.com/code-423n4/2022-02-jpyc/blob/main/contracts/v2/FiatTokenV2.sol#L51

thurendous commented 2 years ago

1,2,3 can be valid. duplicate of #60, #27 and #49