Trycatch will not function with internal type
The report claims that try/catch in Solidity only works for external calls and contract creation, so the internal functions in PriceFeed.sol that fetch Chainlink responses cannot be caught if they revert. The author suggests this could leave Chainlink variables unupdated, but provides no working test against the target.
Originally disclosed on Immunefi
- Disclosed after under an hour
28853 - [SC - Insight] Trycatch will not function with internal type
Submitted on Feb 28th 2024 at 22:08:47 UTC by @thomastech for Boost | eBTC
Report ID: #28853
Report type: Smart Contract
Report severity: Insight
Target: https://github.com/ebtc-protocol/ebtc/blob/release-0.7/packages/contracts/contracts/PriceFeed.sol
Impacts:
- Direct theft of 2 stETH worth of any user funds, whether at-rest or in-motion, other than unclaimed yield
Description
Brief/Intro
Solidity v0.8.24 "Solidity also supports exception handling in the form of try/catch-statements, but only for external function calls and contract creation calls. Errors can be created using the revert statement." PriceFeed.sol uses internal with three function calls that are used to update ChainLink Oracle values.
Vulnerability Details
Impact Details
An issue with Solidity Control Structure try/catch using internal function type in:
- PriceFeed.sol function _getPrevChainlinkResponse lines 688 - 770
- PriceFeed.sol function _getCurrentChainlinkResponse lines 607 - 682
- PriceFeed.sol function _getCurrentFallbackResponse lines 583 - 603
These functions will not update multiple ChainLink variables.
References
Add any relevant links to documentation or code:
https://github.com/ebtc-protocol/ebtc/blob/main/packages/contracts/contracts/PriceFeed.sol
Proof of concept
Given my limited skills with Solidity/Foundry I have been unable to successfully test these functions in the time allowed but have deployed the code below on Remix and changed the function from public, external, and internal to confirm try/catch fails when internal is used.
//SPDX-License-Identifier: MIT pragma solidity 0.8.24;
contract WillThrow { function aFunction() public pure { require(true, "Try succeed message require is false");
}
}
contract ErrorHandling { event ErrorLogging(string reason); event TryError(string message); function catchError() public { WillThrow will = new WillThrow(); try will.aFunction() { //here we could do something if it works emit TryError('Try Works require is true'); } catch Error(string memory reason) { emit ErrorLogging(reason); } } }
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the code uses try/catch around internal function calls, which Solidity does not support for exception handling.
Impact
The author claims the affected functions will not update multiple Chainlink variables, but no exploit or concrete fund loss is demonstrated.
What the attacker needed
Access to the deployed contract code
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Solidity is the language smart contracts are written in. A try/catch block lets code handle an error instead of crashing, but Solidity only allows it around calls to other contracts, not around the contract's own internal functions. The author says the price feed code wraps internal functions in try/catch, so the error handling would never actually run.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.