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

OptimismPortal2 set initial _balance through StorageSetter pattern #254

Open
wants to merge 1 commit into
base: celo9
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion bedrock-devnet/devnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def init_devnet_l1_deploy_config(paths, update_timestamp=False):
if GENERIC_ALTDA:
deploy_config['daCommitmentType'] = "GenericCommitment"
if DEVNET_CELO:
deploy_config['useFaultProofs'] = False
deploy_config['useFaultProofs'] = True
deploy_config['useCustomGasToken'] = True
deploy_config['deployCeloContracts'] = True
# Usage of the zero address in combination of the useCustomGasToken == True
Expand Down
21 changes: 19 additions & 2 deletions packages/contracts-bedrock/scripts/deploy/ChainAssertions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import { console2 as console } from "forge-std/console2.sol";
import { CeloTokenL1 } from "src/celo/CeloTokenL1.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IOptimismPortalBalance {
function balance() external view returns (uint256);
}

library ChainAssertions {
Vm internal constant vm = Vm(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);

Expand Down Expand Up @@ -359,7 +363,13 @@ library ChainAssertions {
internal
view
{
OptimismPortal portal = OptimismPortal(payable(_contracts.OptimismPortal));
address payable portalAddress;
if (_cfg.useFaultProofs()) {
portalAddress = payable(_contracts.OptimismPortal2);
} else {
portalAddress = payable(_contracts.OptimismPortal);
}
IOptimismPortalBalance portal = IOptimismPortalBalance(portalAddress);

uint256 expectedInitialBalance = 0;
if (_isProxy && _cfg.useCustomGasToken()) {
Expand All @@ -374,6 +384,7 @@ library ChainAssertions {
} else {
require(portal.balance() == 0);
}
require(vm.load(address(portal), bytes32(uint256(61))) == bytes32(portal.balance()));
}

/// @notice Asserts the OptimismPortal2 is setup correctly
Expand Down Expand Up @@ -412,7 +423,13 @@ library ChainAssertions {
}
// This slot is the custom gas token _balance and this check ensures
// that it stays unset for forwards compatibility with custom gas token.
require(vm.load(address(portal), bytes32(uint256(61))) == bytes32(0));
// if we use the pre-locked storage modification, the comprison

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// if we use the pre-locked storage modification, the comprison
// if we use the pre-locked storage modification, the comparison

// against 0 doesn't hold anymore.
// We do a check of the balance field downstream anyways, that's why we
// can disable this check
if (!_cfg.useCustomGasToken()) {
require(vm.load(address(portal), bytes32(uint256(61))) == bytes32(0));
}
}

/// @notice Asserts that the ProtocolVersions is setup correctly
Expand Down
53 changes: 32 additions & 21 deletions packages/contracts-bedrock/scripts/deploy/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -407,21 +407,47 @@ contract Deploy is Deployer {
deployMulticall3();
}

function preInitializeOptimismPortalBalance() public broadcast {
address optimismPortalProxy = mustGetAddress("OptimismPortalProxy");
address storageSetter = mustGetAddress("StorageSetter");

// NOTE: the storage slot index should stay the same across versions
// (OptimismPortal, OptimismPortal2, ...) since slot spacers are used
// for legacy storage variables.
// We also assert correctness in a downstream ChainAssertion,
// so changing slot numbers should get detected for coming versions.
uint256 balanceStorageSlot = 61; // slot of _balance variable

address customGasTokenAddress = Constants.ETHER;
uint256 initialBalance = 0;
customGasTokenAddress = cfg.customGasTokenAddress();
IERC20 token = IERC20(customGasTokenAddress);
initialBalance = token.balanceOf(optimismPortalProxy);

_upgradeAndCallViaSafe({
_proxy: payable(optimismPortalProxy),
_implementation: storageSetter,
_innerCallData: abi.encodeCall(StorageSetter.setUint, (bytes32(balanceStorageSlot), initialBalance))
});
}

/// @notice Initialize all of the implementations
function initializeImplementations() public {
console.log("Initializing implementations");

setupCustomGasToken();

address storageSetter = deployStorageSetter();
if (cfg.useCustomGasToken()) {
setupCustomGasToken();
save("StorageSetter", deployStorageSetter());
preInitializeOptimismPortalBalance();
}

// Selectively initialize either the original OptimismPortal or the new OptimismPortal2. Since this will upgrade
// the proxy, we cannot initialize both.
if (cfg.useFaultProofs()) {
console.log("Fault proofs enabled. Initializing the OptimismPortal proxy with the OptimismPortal2.");
initializeOptimismPortal2();
} else {
initializeOptimismPortal(storageSetter);
initializeOptimismPortal();
}

initializeSystemConfig();
Expand Down Expand Up @@ -1279,29 +1305,14 @@ contract Deploy is Deployer {
}

/// @notice Initialize the OptimismPortal
function initializeOptimismPortal(address strorageSetter) public broadcast {
function initializeOptimismPortal() public broadcast {
console.log("Upgrading and initializing OptimismPortal proxy");
address optimismPortalProxy = mustGetAddress("OptimismPortalProxy");
address optimismPortal = mustGetAddress("OptimismPortal");
address l2OutputOracleProxy = mustGetAddress("L2OutputOracleProxy");
address systemConfigProxy = mustGetAddress("SystemConfigProxy");
address superchainConfigProxy = mustGetAddress("SuperchainConfigProxy");

address customGasTokenAddress = Constants.ETHER;
uint256 initialBalance = 0;
if (cfg.useCustomGasToken()) {
customGasTokenAddress = cfg.customGasTokenAddress();
IERC20 token = IERC20(customGasTokenAddress);
initialBalance = token.balanceOf(optimismPortalProxy);

uint256 balanceStorageSlot = 61; // slot of _balance variable
_upgradeAndCallViaSafe({
_proxy: payable(optimismPortalProxy),
_implementation: strorageSetter,
_innerCallData: abi.encodeCall(StorageSetter.setUint, (bytes32(balanceStorageSlot), initialBalance))
});
}

_upgradeAndCallViaSafe({
_proxy: payable(optimismPortalProxy),
_implementation: optimismPortal,
Expand Down Expand Up @@ -1437,7 +1448,7 @@ contract Deploy is Deployer {
string[] memory commands = new string[](3);
commands[0] = "bash";
commands[1] = "-c";
commands[2] = string.concat("[[ -f ", filePath, " ]] && echo \"present\"");
commands[2] = string.concat("[[ -f ", filePath, ' ]] && echo "present"');
if (Process.run(commands).length == 0) {
revert("Cannon prestate dump not found, generate it with `make cannon-prestate` in the monorepo root.");
}
Expand Down
Loading