Omniscia Swisscoast Audit
HCHFToken Code Style Findings
HCHFToken Code Style Findings
HCH-01C: Deprecated Revert Pattern
Type | Severity | Location |
---|---|---|
Code Style | HCHFToken.sol:L171 |
Description:
The referenced revert
statement is issued with a string
argument which has been deprecated.
Example:
168if (169 !((_balanceOf(address(this)) - balance) ==170 amount)171) revert('The smart contract is not the treasury account');
Recommendation:
We advise a require
check with an accompanying message to be introduced, increasing the legibility of the check.
Alleviation (04618e407bddce5b22e9cadd787fd3334bd3afe6):
The referenced if-revert
statement has been replaced by a require
statement per our recommendation, optimizing its legibility.
HCH-02C: Inefficient Function Implementation
Type | Severity | Location |
---|---|---|
Gas Optimization | HCHFToken.sol:L68, L166, L198, L242, L261, L282-L286 |
Description:
The HCHFToken::_checkResponse
function will either successfully execute and yield true
, or revert
.
Example:
282function _checkResponse(int responseCode) internal pure returns (bool) {283 // Using require to check the condition, and provide a custom error message if it fails.284 require(responseCode == HederaResponseCodes.SUCCESS, "ResponseCodeInvalid: provided code is not success");285 return true;286}
Recommendation:
We advise its return variable to be removed, ensuring that it is invoked as a validation function without requiring use of its return argument.
Alleviation (04618e407bddce5b22e9cadd787fd3334bd3afe6):
The HCHFToken::_checkResponse
function has been updated to no longer return a variable, addressing this exhibit.
HCH-03C: Inefficient Negation of Conditional
Type | Severity | Location |
---|---|---|
Gas Optimization | HCHFToken.sol:L168-L171 |
Description:
The referenced conditional is negated after being evaluated.
Example:
168if (169 !((_balanceOf(address(this)) - balance) ==170 amount)171) revert('The smart contract is not the treasury account');
Recommendation:
We advise the negation to be incorporated to the comparison itself, adjusting the equality check to an inequality check.
Alleviation (04618e407bddce5b22e9cadd787fd3334bd3afe6):
The negation of the conditional is no longer preformed in its require
form, optimizing its gas cost.
HCH-04C: Redundant Function Implementation
Type | Severity | Location |
---|---|---|
Gas Optimization | HCHFToken.sol:L98, L107, L160, L192, L206-L208, L220, L238 |
Description:
The HCHFToken::_getTokenAddress
function is redundant as the tokenAddress
member is readily available throughout the contract.
Example:
181function _burn(182 address account,183 uint256 amount184)185internal186returns (bool)187{188 require(amount <= uint256(type(int64).max), "Amount exceeds int64 limits");189
190 int64 safeAmount = int64(amount);191
192 address currentTokenAddress = _getTokenAddress();193
194 _transfer(account, address(this), amount);195
196 (int responseCode,) = HederaTokenService.burnToken(currentTokenAddress, safeAmount, new int64[](0));197
198 bool success = _checkResponse(responseCode);199
200 emit TokensBurned(msg.sender, currentTokenAddress, safeAmount);201 emit Transfer(currentTokenAddress, account, address(0), safeAmount);202
203 return success;204}205
206function _getTokenAddress() internal view returns (address) {207 return tokenAddress;208}
Recommendation:
We advise the tokenAddress
to be utilized directly, optimizing the gas cost of the contract.
Alleviation (04618e407bddce5b22e9cadd787fd3334bd3afe6):
The HCHFToken::_getTokenAddress
function has been safely removed, optimizing the bytecode size and gas cost of the contract.
HCH-05C: Variable Mutability Specifier (Immutable)
Type | Severity | Location |
---|---|---|
Gas Optimization | HCHFToken.sol:L17 |
Description:
The linked variable is assigned to only once during the contract's constructor
.
Example:
35constructor(36 address _troveManagerAddress,37 address _stabilityPoolAddress,38 address _borrowerOperationsAddress39) payable public {40 checkContract(_troveManagerAddress);41 checkContract(_stabilityPoolAddress);42 checkContract(_borrowerOperationsAddress);43
44 troveManagerAddress = _troveManagerAddress;45 emit TroveManagerAddressChanged(_troveManagerAddress);46
47 stabilityPoolAddress = _stabilityPoolAddress;48 emit StabilityPoolAddressChanged(_stabilityPoolAddress);49
50 borrowerOperationsAddress = _borrowerOperationsAddress;51 emit BorrowerOperationsAddressChanged(_borrowerOperationsAddress);52
53 IHederaTokenService.HederaToken memory token;54 token.name = _NAME;55 token.symbol = _SYMBOL;56 token.treasury = address(this);57
58 token.expiry = createAutoRenewExpiry(address(this), 8000000);59
60 IHederaTokenService.TokenKey[] memory keys = new IHederaTokenService.TokenKey[](1);61 keys[0] = getSingleKey(KeyType.SUPPLY, KeyValueType.INHERIT_ACCOUNT_KEY, bytes(""));62
63 token.tokenKeys = keys;64
65 (int responseCode, address createdTokenAddress) =66 HederaTokenService.createFungibleToken(token, 0, _DECIMALS);67
68 _checkResponse(responseCode);69 tokenAddress = createdTokenAddress;70}
Recommendation:
We advise it to be set as immutable
greatly optimizing its read-access gas cost.
Alleviation (04618e407bddce5b22e9cadd787fd3334bd3afe6):
The tokenAddress
contract-level variable of the contract has been set as immutable
, optimizing its read-access gas cost significantly.