Skip to content

Commit

Permalink
fix: fixed stack underflow error.
Browse files Browse the repository at this point in the history
  • Loading branch information
blmalone committed Sep 13, 2024
1 parent 53c02b3 commit b8f36c1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
17 changes: 12 additions & 5 deletions packages/contracts-bedrock/scripts/DeployImplementations.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity 0.8.15;

import { Script } from "forge-std/Script.sol";
import "forge-std/console.sol";

import { LibString } from "@solady/utils/LibString.sol";

Expand Down Expand Up @@ -131,9 +130,14 @@ contract DeployImplementationsInput {
require(address(_protocolVersionsProxy) != address(0), "DeployImplementationsInput: not set");
return _protocolVersionsProxy;
}

function superchainProxyAdmin() public view returns (ProxyAdmin) {
assertInputSet();
return inputs.superchainProxyAdmin;
}
}

contract DeployImplementationsOutput {
contract DeployImplementationsOutput is Script {
OPStackManager internal _opsm;
DelayedWETH internal _delayedWETHImpl;
OptimismPortal2 internal _optimismPortalImpl;
Expand Down Expand Up @@ -189,7 +193,9 @@ contract DeployImplementationsOutput {

function opsm() public view returns (OPStackManager) {
DeployUtils.assertValidContractAddress(address(_opsm));
DeployUtils.assertEIP1967ImplementationSet(address(_opsm));
// We prank as the zero address due to the Proxy's `proxyCallIfNotAdmin` modifier.
vm.prank(address(0));
DeployUtils.assertEIP1967Implementation(address(_opsm));
return _opsm;
}

Expand Down Expand Up @@ -310,9 +316,10 @@ contract DeployImplementations is Script {
// To deploy a proxy contract, you need to know the proxy admin.
// However, this proxy admin is not deployed until the OPStackManager.
// Not using blueprint because we don't have access to l2ChainId.
vm.broadcast(msg.sender);

// Setting proxy admin to msg.sender because ProxyAdmin is not deployed yet.
Proxy proxy = new Proxy(msg.sender);
vm.broadcast(msg.sender);
Proxy proxy = new Proxy(address(_dii.superchainProxyAdmin()));
OPStackManager opsm = new OPStackManager({
_superchainConfig: superchainConfigProxy,
_protocolVersions: protocolVersionsProxy,
Expand Down
11 changes: 7 additions & 4 deletions packages/contracts-bedrock/scripts/libraries/DeployUtils.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;

import { Proxy } from "src/universal/Proxy.sol";
import { LibString } from "@solady/utils/LibString.sol";
import "forge-std/console.sol";

Expand All @@ -19,12 +20,14 @@ library DeployUtils {
require(_who.code.length > 0, string.concat("DeployUtils: no code at ", LibString.toHexStringChecksummed(_who)));
}

function assertEIP1967ImplementationSet(address _proxy) internal view {
function assertEIP1967ImplementationSet(address _proxy) internal {
address implementation = Proxy(payable(_proxy)).implementation();
assertValidContractAddress(implementation);
}

function assertEIP1967Implementation(address _proxy) internal view {
(bool success, bytes memory result) = _proxy.staticcall(abi.encodeWithSignature("implementation()"));
console.logBool(success);
require(success, "DeployUtils: EIP1967 implementation check failed");
console.log("success is true");
console.logBytes(result);
address implementation = abi.decode(result, (address));
assertValidContractAddress(implementation);
}
Expand Down
6 changes: 0 additions & 6 deletions packages/contracts-bedrock/src/universal/Proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity 0.8.15;

import { Constants } from "src/libraries/Constants.sol";
import "forge-std/console.sol";

/// @title Proxy
/// @notice Proxy is a transparent proxy that passes through the call if the caller is the owner or
Expand Down Expand Up @@ -97,8 +96,6 @@ contract Proxy {
/// @return Implementation address.
function implementation() public virtual proxyCallIfNotAdmin returns (address) {
address impl = _getImplementation();
console.log("inside proxy.sol implementation()");
console.log(impl);
return impl;
}

Expand Down Expand Up @@ -153,12 +150,9 @@ contract Proxy {
function _getImplementation() internal view returns (address) {
address impl;
bytes32 proxyImplementation = Constants.PROXY_IMPLEMENTATION_ADDRESS;
console.logBytes32(proxyImplementation);
assembly {
impl := sload(proxyImplementation)
}
console.log("inside proxy.sol _getImplementation()");
console.log(impl);
return impl;
}

Expand Down
1 change: 1 addition & 0 deletions packages/contracts-bedrock/test/DeployOPChain.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ contract DeployOPChain_TestBase is Test {
string release = "op-contracts/latest";
SuperchainConfig superchainConfigProxy;
ProtocolVersions protocolVersionsProxy;
ProxyAdmin superchainProxyAdmin;

// Define default inputs for DeployOPChain.
// `opsm` is set during `setUp` since it is an output of the previous step.
Expand Down

0 comments on commit b8f36c1

Please sign in to comment.