Omniscia Tangible Audit
CurrencyFeedV2 Code Style Findings
CurrencyFeedV2 Code Style Findings
CFV-01C: Optimization of Currency & Country Alpha Codes
Type | Severity | Location |
---|---|---|
Gas Optimization | CurrencyFeedV2.sol:L19, L22, L32, L36, L40, L44 |
Description:
The referenced data structures utilize string
types as keys / values for the relevant mapping
entries when dealing with ISO 3166 and ISO 4217 alpha codes which is inefficient.
Example:
contracts/helpers/CurrencyFeedV2.sol
18/// @notice This mapping is used to store a price feed oracle for a specific currency ISO alpha code.19mapping(string => AggregatorV3Interface) public currencyPriceFeeds;20
21/// @notice A premium taken by Tangible. It's tacked on top of the existing exchange rate of 2 currencies. This one is stored using the ISO alpha code for the key.22mapping(string => uint256) public conversionPremiums;23
24/// @notice This mapping is used to store a price feed oracle for a specific currency ISO numeric code.25mapping(uint16 => AggregatorV3Interface) public currencyPriceFeedsISONum;26
27/// @notice A premium taken by Tangible. It's tacked on top of the existing exchange rate of 2 currencies. This one is stored using the ISO numeric code for the key.28mapping(uint16 => uint256) public conversionPremiumsISONum;29
30/// @notice Used to store ISO curency numeric code using it's alpha code as reference.31/// @dev i.e. ISOCurrencyCodeToNum["AUD"] = 03632mapping(string => uint16) public ISOcurrencyCodeToNum;33
34/// @notice Used to store ISO curency alpha code using it's numeric code as reference.35/// @dev i.e. ISOcurrencyNumToCode[036] = "AUD"36mapping(uint16 => string) public ISOcurrencyNumToCode;37
38/// @notice Used to store ISO country numeric code using it's alpha code as reference.39/// @dev i.e. ISOcountryCodeToNum["AUS"] = 03640mapping(string => uint16) public ISOcountryCodeToNum;41
42/// @notice Used to store ISO curency alpha code using it's numeric code as reference.43/// @dev i.e. ISOcountryNumToCode[036] = "AUS"44mapping(uint16 => string) public ISOcountryNumToCode;
Recommendation:
We advise the code to instead utilize bytes32
arguments for the same purpose, significantly optimizing the gas costs associated with interacting with the relevant structures.
Alleviation (2ad448279d9e8e4b6edd94bcd2eb22129b6f7357):
The Tangible team evaluated this exhibit and opted not to apply it as they do not consider the gas savings essential.
We concur with this statement and thus accept this exhibit as safely acknowledged.