Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: prevent proxy upgrade to addresses with no code #74

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
}
}
Loading