Omniscia Kinza Finance Audit

ProtectedERC20 Code Style Findings

ProtectedERC20 Code Style Findings

PER-01C: Inefficient Override of Decimals

TypeSeverityLocation
Gas OptimizationProtectedERC20.sol:L18-L22

Description:

The ProtectedERC20::decimals function will override the ERC20Wrapper implementation as the Kinza Finance team wishes to revert if the underlying token has no IERC20Metadata::decimals member exposed, however, this is done inefficiently.

Example:

src/periphery/pToken/ProtectedERC20.sol
18function decimals() public view virtual override(ERC20, ERC20Wrapper) returns (uint8) {
19 // ERC20Wrapper would use try catch to return decimal 18 if the external read fails
20 // this would rather fail and revert if the underlying decimal read does not return
21 return IERC20Metadata(address(underlying())).decimals();
22}

Recommendation:

We advise an immutable variable to be introduced to the ProtectedERC20 of the uint8 type that is assigned to during the ProtectedERC20::constructor with the value of IERC20Metadata::decimals on the underlying argument.

The same variable can then be utilized by ProtectedERC20::decimals, greatly decreasing its gas cost. Additionally, the deployment of ProtectedERC20 would fail if the underlying address does not support the IERC20Metadata::decimals value which is the desire of the Kinza Finance team.

Alleviation:

An immutable variable was introduced to the ProtectedERC20 token that is assigned to during the contract's ProtectedERC20::constructor to the value of the IERC20Metadata::decimals function of the underlying token.

As such, the optimization we proposed has been applied properly.