Open
Description
The following code is expected (by a developer using any other language) to catch failures related to the call.
But instead, it reverts.
This is due to the very confusing semantics of the "try/catch" construct in solidity: the catch block will only be called if the actual external code was reverted, but it might still revert in some compiler-generated code
pragma solidity ^0.8.12;
interface Xface {
function func() external;
}
contract Test {
function run() external {
try Xface(address(0)).func() {
console.log('successfully called');
} catch {
console.log('catch everything');
}
}
}
Suggestion: solidity should not generate a "revert" code between the try and catch. Instead, it should jump into the catch block.
Currently, the following checks are done by solidity, and it reverts if any of these validation fails:
- if the called method is "void", it first performs
extcodesize
, to validate the target indeed has some code - if the called method is expected to return something, it validates that
returndatasize
is not zero - if there are returned values, it decodes them and of course validates they were encoded correctly.