Missing revert keyword
A helper function intended to ensure that a delegatecall target is a contract was missing the revert keyword, so the check did nothing. An attacker could pass a non-contract address, causing the delegatecall to silently succeed without executing any code.
Source: https://github.com/sherlock-audit/2022-08-sentiment-judging/tree/main/097-M
Found by
PwnPatrol
Summary
Missing revert keyword in functionDelegateCall bypasses an intended safety check, allowing the function to fail silently.
Vulnerability Detail
In the helper function functionDelegateCall, there is a check to confirm that the target being called is a contract.
if (!isContract(target)) Errors.AddressNotContract;
However, there is a typo in the check that is missing the revert keyword.
As a result, non-contracts can be submitted as targets, which will cause the delegatecall below to return success (because EVM treats no code as STOP opcode), even though it doesn't do anything.
(bool success, ) = target.delegatecall(data);
require(success, "CALL_FAILED");
Impact
The code doesn't accomplish its intended goal of checking to confirm that only contracts are passed as targets, so delegatecalls can silently fail.
Code Snippet
https://github.com/sherlock-audit/2022-08-sentiment/blob/main/protocol/src/utils/Helpers.sol#L66-L73
function functionDelegateCall(
address target,
bytes calldata data
) internal {
if (!isContract(target)) Errors.AddressNotContract;
(bool success, ) = target.delegatecall(data);
require(success, "CALL_FAILED");
}
Tool used
Manual Review
Recommendation
Add missing revert keyword to L70 of Helpers.sol.
if (!isContract(target)) revert Errors.AddressNotContract;
Sentiment Team
Fixed as recommended. PR here.
Lead Senior Watson
Confirmed fix.
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
The safety check lacked the revert keyword, so it evaluated an error value but did not halt execution.
Impact
The intended safety check was ineffective, allowing delegatecalls to non-contracts to silently succeed without executing code.
What the attacker needed
Ability to supply a target address
The fix
The missing revert keyword was added to the check, and the fix was confirmed.
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.
A smart contract can call another contract's code using a low-level operation called delegatecall. The code tried to check that the target is a real contract, but forgot to actually stop execution when the check failed. So the call went ahead and appeared to succeed even though nothing happened.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.