Skip to content

Commit 941ee77

Browse files
author
Dev Kalra
authored
[entropy] audit - 2. lack of contract existence check (#1177)
* contract existence check * better comment
1 parent 245cc23 commit 941ee77

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

target_chains/ethereum/contracts/contracts/executor/Executor.sol

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,16 @@ contract Executor {
7676
gi.executorAddress != address(this)
7777
) revert ExecutorErrors.DeserializationError();
7878

79+
// Check if the gi.callAddress is a contract account.
80+
uint len;
81+
address callAddress = address(gi.callAddress);
82+
assembly {
83+
len := extcodesize(callAddress)
84+
}
85+
if (len == 0) revert ExecutorErrors.InvalidContractTarget();
86+
7987
bool success;
80-
(success, response) = address(gi.callAddress).call(gi.callData);
88+
(success, response) = address(callAddress).call(gi.callData);
8189

8290
// Check if the call was successful or not.
8391
if (!success) {

target_chains/ethereum/contracts/contracts/executor/ExecutorErrors.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ library ExecutorErrors {
1414
error DeserializationError();
1515
// The message is not intended for this contract.
1616
error InvalidGovernanceTarget();
17+
// The target address for the contract call is not a contract
18+
error InvalidContractTarget();
1719
}

target_chains/ethereum/contracts/forge-test/Executor.t.sol

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,30 @@ contract ExecutorTest is Test, WormholeTestUtils {
344344
vm.expectRevert("call should revert");
345345
executor.execute(vaa);
346346
}
347+
348+
function testCallToEoaReverts() public {
349+
bytes memory payload = abi.encodePacked(
350+
uint32(0x5054474d),
351+
PythGovernanceInstructions.GovernanceModule.EvmExecutor,
352+
Executor.ExecutorAction.Execute,
353+
CHAIN_ID,
354+
address(executor),
355+
address(100),
356+
abi.encodeWithSelector(ICallable.foo.selector)
357+
);
358+
359+
bytes memory vaa = generateVaa(
360+
uint32(block.timestamp),
361+
OWNER_CHAIN_ID,
362+
OWNER_EMITTER,
363+
1,
364+
payload,
365+
NUM_SIGNERS
366+
);
367+
368+
vm.expectRevert(ExecutorErrors.InvalidContractTarget.selector);
369+
executor.execute(vaa);
370+
}
347371
}
348372

349373
interface ICallable {

0 commit comments

Comments
 (0)