OperateProxy.callFunction() should check if the callee is a contract
The OperateProxy contract's callFunction() does not verify that the callee address is a contract, so a call to a non-contract address returns success. This could break business logic that assumes a successful call means a real contract interaction, potentially causing fund loss.
Submitted by WatchPug
/// @notice Allows a sender/signer to make external calls to any other contract.
/// @dev A separate OperateProxy contract is used to make the external calls so
/// that the Controller, which holds funds and has special privileges in the Quant
/// Protocol, is never the `msg.sender` in any of those external calls.
/// @param _callee The address of the contract to be called.
/// @param _data The calldata to be sent to the contract.
function _call(address _callee, bytes memory _data) internal {
IOperateProxy(operateProxy).callFunction(_callee, _data);
}
function callFunction(address callee, bytes memory data) external override {
require(
callee != address(0),
"OperateProxy: cannot make function calls to the zero address"
);
(bool success, bytes memory returnData) = address(callee).call(data);
require(success, "OperateProxy: low-level call failed");
emit FunctionCallExecuted(tx.origin, returnData);
}
As the OperateProxy.sol#callFunction() function not payable, we believe it’s not the desired behavior to call a non-contract address and consider it a successful call.
For example, if a certain business logic requires a successful token.transferFrom() call to be made with the OperateProxy, if the token is not a existing contract, the call will return success: true instead of success: false and break the caller’s assumption and potentially malfunction features or even cause fund loss to users.
The qBridge exploit (January 2022) was caused by a similar issue.
As a reference, OpenZeppelin’s Address.functionCall() will check and require(isContract(target), "Address: call to non-contract");
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.5.0/contracts/utils/Address.sol#L135
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
Recommended Mitigation Steps
Consider adding a check and throw when the callee is not a contract.
0xca11 (Rolla) confirmed, resolved, and commented:
Resolved in RollaProject/quant-protocol#85.
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 callFunction() function lacks a check that the callee address has code (is a contract), so low-level calls to non-contracts return success.
Impact
If a business logic relies on a successful call to a token contract, a call to a non-contract address would return success and could malfunction features or even cause fund loss to users.
What the attacker needed
None
The fix
The issue was fixed by adding a check to revert when the callee is not a contract.
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.
In Ethereum, calling a non-contract address (like a regular wallet) doesn't fail; it just returns success with no data. The OperateProxy contract didn't check if the address it was calling actually had code, so it could report success even when nothing happened. This could trick other parts of the system into thinking a token transfer worked when it didn't.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.