Skip to content

Commit

Permalink
OptimismPortal2 set initial _balance through StorageSetter pattern (#…
Browse files Browse the repository at this point in the history
…254)

* OptimismPortal2 set initial `_balance` through StorageSetter pattern

Fixes #239

The custom gas-token feature adaptation for the fault-proof system using
the `OptimismPortal2` contract has been merged recently upstream.

We are using the custom-gas-token feature and additionally require a
modification of the OptimismPortal's `_balance` value to be set
to the entire allocation of Celo on the L2 - meaning that all L1 token is
initially locked in the bridge and only usable on the L2.

Those changes are now adapted also to the `OptimismPortal2`, which
was a requirement to make our custom-gas-token pre-locked balance
feature work in conjunction with fault-proofs.

* Adapt withdraw e2e-tests to work with fault-proofs

* Use prettier for formatting e2e tests

* Fix typo

Co-authored-by: Valentin Rodygin <[email protected]>

* Set L1-fee scalars to zero in devnet

---------

Co-authored-by: Valentin Rodygin <[email protected]>
  • Loading branch information
2 people authored and alecps committed Oct 15, 2024
1 parent e0b6bc2 commit 42df247
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 78 deletions.
4 changes: 3 additions & 1 deletion bedrock-devnet/devnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ 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['gasPriceOracleBlobBaseFeeScalar'] = 0
deploy_config['gasPriceOracleBaseFeeScalar'] = 0
deploy_config['deployCeloContracts'] = True
# Usage of the zero address in combination of the useCustomGasToken == True
# will deploy a new contract
Expand Down
4 changes: 4 additions & 0 deletions op-e2e/celo/.prettierrc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
trailingComma = "es5"
tabWidth = 2
semi = false
singleQuote = true
129 changes: 82 additions & 47 deletions op-e2e/celo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions op-e2e/celo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"type": "module",
"main": "dist/test.js",
"scripts": {
"test": "jest tests --detectOpenHandles"
"test": "jest tests --detectOpenHandles",
"format": "npx prettier . --write"
},
"author": "Celo Labs Inc.",
"license": "ISC",
Expand All @@ -17,6 +18,7 @@
"@babel/core": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"babel-jest": "^29.7.0",
"jest": "^29.7.0"
"jest": "^29.7.0",
"prettier": "3.3.3"
}
}
2 changes: 1 addition & 1 deletion op-e2e/celo/run_all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if [[ $spawn_devnet != false ]]; then
## Start geth
cd "$SCRIPT_DIR/../.." || exit 1
trap 'cd "$SCRIPT_DIR/../.." && make devnet-down' EXIT # kill bg job at exit
DEVNET_L2OO=true DEVNET_CELO=true make devnet-up
DEVNET_CELO=true make devnet-up
fi

cd "$SCRIPT_DIR" || exit 1
Expand Down
5 changes: 5 additions & 0 deletions op-e2e/celo/src/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export function makeChainConfigs(l1ChainID, l2ChainID, contractAddresses) {
address: contractAddresses.L2OutputOracleProxy,
},
},
disputeGameFactory: {
[l1ChainID]: {
address: contractAddresses.DisputeGameFactoryProxy,
},
},
portal: {
[l1ChainID]: {
address: contractAddresses.OptimismPortalProxy,
Expand Down
9 changes: 8 additions & 1 deletion op-e2e/celo/src/withdraw.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ export const withdraw = async function (args, config) {
const receipt = await config.client.l2.public.waitForTransactionReceipt({
hash: initiateHash,
})
console.log('receipt', receipt)

const l2GasPayment =
receipt.gasUsed * receipt.effectiveGasPrice + receipt.l1Fee
receipt.gasUsed * receipt.effectiveGasPrice + receipt.l1fee

// FIXME: this blocks longer, the longer the devnet is running, see
// https://github.com/ethereum-optimism/optimism/issues/7668
Expand Down Expand Up @@ -46,6 +47,12 @@ export const withdraw = async function (args, config) {
targetChain: config.client.l2.public.chain,
})

// HACK: the waitToFinalize does not seem to calculate the wait time
// correctly..., lets hardcode a wait time for now to see if it can work.
// In theory viem is not waiting an additional DISPUTE_GAME_FINALITY_DELAY_SECONDS.
// The current default value for this is 6, but this was not enough in manual testing.
// TODO: fix this upstream in viem...
await new Promise((res) => setTimeout(res, 16 * 1000))
const finalizeHash = await config.client.l1.wallet.finalizeWithdrawal({
targetChain: config.client.l2.public.chain,
withdrawal,
Expand Down
8 changes: 4 additions & 4 deletions op-e2e/celo/tests/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function waitForNoError(func, timeout) {
try {
await func()
return true
} catch (error) { }
} catch (error) {}
await new Promise((r) => setTimeout(r, 1000))
}
return false
Expand All @@ -27,9 +27,9 @@ async function waitReachable(client, timeout) {
return waitForNoError(f, timeout)
}

async function waitForNextL2Output(client, l2ChainConfig, timeout) {
async function waitForNextGame(client, l2ChainConfig, timeout) {
const f = async () =>
client.waitForNextL2Output({
client.waitForNextGame({
pollingInterval: 500,
l2BlockNumber: 0,
targetChain: l2ChainConfig,
Expand All @@ -55,7 +55,7 @@ export async function setup() {
const success = await Promise.all([
waitReachable(config.client.l1.public, 10_000),
waitReachable(config.client.l2.public, 10_000),
waitForNextL2Output(config.client.l1.public, chainConfig.l2, 60_000),
waitForNextGame(config.client.l1.public, chainConfig.l2, 60_000),
])
if (success.every((v) => v == true)) {
return config
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 @@ -36,6 +36,10 @@ import { IOptimismMintableERC20Factory } from "src/universal/interfaces/IOptimis
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 @@ -368,7 +372,13 @@ library ChainAssertions {
internal
view
{
IOptimismPortal portal = IOptimismPortal(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 @@ -383,6 +393,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 @@ -421,7 +432,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 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
Loading

0 comments on commit 42df247

Please sign in to comment.