Skip to content

Commit

Permalink
bugfix: prevent proxy upgrade to addresses with no code
Browse files Browse the repository at this point in the history
  • Loading branch information
nonergodic committed Dec 19, 2024
1 parent a126d90 commit fa686b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/proxy/ProxyBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ error InvalidSender();
error IdempotentUpgrade();
error InvalidMsgValue();
error InvalidData();
error InvalidImplementation();
error UpgradeFailed(bytes revertData);

event Upgraded(address indexed implementation);
Expand Down Expand Up @@ -40,6 +41,9 @@ abstract contract ProxyBase {
if (newImplementation == implementationState().implementation)
revert IdempotentUpgrade();

if (newImplementation.code.length == 0)
revert InvalidImplementation();

implementationState().implementation = newImplementation;

(bool success, bytes memory revertData) =
Expand Down
17 changes: 15 additions & 2 deletions test/Proxy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ pragma solidity ^0.8.24;
import "forge-std/Test.sol";

import { adminState } from "wormhole-sdk/proxy/Eip1967Admin.sol";
import { ProxyBase, UpgradeFailed, InvalidData } from "wormhole-sdk/proxy/ProxyBase.sol";
import {
ProxyBase,
UpgradeFailed,
InvalidData,
InvalidImplementation
} from "wormhole-sdk/proxy/ProxyBase.sol";
import { Proxy, ProxyConstructionFailed } from "wormhole-sdk/proxy/Proxy.sol";

error NotAuthorized();
Expand Down Expand Up @@ -104,4 +109,12 @@ contract TestProxy is Test {
assertEq(contrct.immutableNum(), 1);
assertEq(contrct.message(), "v2");
}
}

function testProxyInvalidUpgradeFails() public {
address logic1 = address(new LogicContractV1(1));
LogicContractV1 contrct = LogicContractV1(address(new Proxy(logic1, abi.encode("v1"))));

vm.expectRevert(InvalidImplementation.selector);
contrct.customUpgradeFun(makeAddr("wrongAddress"), abi.encode("oops"));
}
}

0 comments on commit fa686b5

Please sign in to comment.