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

Merged
merged 5 commits into from
Oct 14, 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: 3 additions & 1 deletion bedrock-devnet/devnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,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 @@ -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 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
Loading