Handling External Calls to IERC20Metadata.decimals() Failing Silently #136
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
🤖_primary
AI based primary recommendation
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/ronin-chain/katana-v3-contracts/blob/03c80179e04f40d96f06c451ea494bb18f2a58fc/src/periphery/NonfungibleTokenPositionDescriptor.sol#L75-L76
Vulnerability details
Proof of Concept
Explain and rationalize the potential impact. Provide:
Issue: Handling External Calls to IERC20Metadata.decimals() Failing Silently
Severity Level: Medium
Issue Type: Data Integrity and External Call Validation
Impact
The contract relies on external calls to token contracts, such as calling IERC20Metadata(token).decimals(), to retrieve token metadata. There is a risk that these external calls could fail, revert, or return unexpected data due to issues such as:
If these calls fail or return incorrect data, the contract could generate incorrect metadata for NFTs, which may mislead users or disrupt the intended functionality. For example, if decimals() fails or returns an unreasonable value, the constructed token URI could include inaccurate token details, leading to confusion or misrepresentation.
Explanation
Proof of Concept (PoC)
The following PoC demonstrates how an external call to IERC20Metadata.decimals() could fail or return unexpected results:
PoC
In this example, if IERC20Metadata(token).decimals() fails, the catch block handles the error by returning a default value of 18.
Mitigation
Implement error handling using try/catch when making external calls to ensure the contract handles cases where the call fails gracefully. This can prevent logical inconsistencies and improve the robustness of the contract.
Solidity Coded Mitigation
Mitigation
In this mitigation, the try/catch block ensures that if the call fails, the contract returns a default value of 18 decimals. Additionally, the require statement validates that the returned decimals value is within a reasonable range, mitigating risks of a malicious contract returning an unusual value.
References
Summary
Adding checks to ensure external calls do not fail silently improves the robustness of the contract by handling cases where the call may revert or return unexpected values. By using try/catch, the contract can provide a fallback mechanism and validate data integrity, enhancing the contract’s reliability and preventing potential data inconsistencies.
Recommended Mitigation Steps
Assessed type
Invalid Validation
The text was updated successfully, but these errors were encountered: