diff --git a/contracts/hardhat.config.ts b/contracts/hardhat.config.ts index 02e5d030d..b855bc0ae 100644 --- a/contracts/hardhat.config.ts +++ b/contracts/hardhat.config.ts @@ -21,6 +21,7 @@ import "./tasks/token_deploy" import "./tasks/mainnet_upgrade" import "./src/plugin" import * as process from "process"; +import { Wallet } from "ethers"; function getRemappings() { return fs @@ -41,6 +42,18 @@ const QA_URL = process.env.QA_RPC_URL || 'http://127.0.0.1:8545' const SEPOLIA_URL = process.env.SEPOLIA_RPC_URL || 'http://127.0.0.1:8545' const HOLESKY_URL = process.env.HOLESKY_RPC_URL || 'http://127.0.0.1:8545' const HOODI_URL = process.env.HOODI_RPC_URL || 'http://127.0.0.1:8545' +// hoodidev: a private Morph L2 whose L1 is the public Ethereum Hoodi testnet. Unlike the networks above it does NOT +// fall back to the publicly known Anvil key: without DEPLOYER_PRIVATE_KEY (or with that public key) there is no +// signer, so a deployment fails instead of putting admin rights behind a key that anyone can use. +const PUBLIC_ANVIL_ADDRESS = '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' +// a key is usable for hoodidev when it parses and is not the public Anvil account #0 (the key behind the fallback above) +const usableHoodidevKey = (pk?: string): boolean => { + if (!pk) return false + try { return new Wallet(pk).address.toLowerCase() !== PUBLIC_ANVIL_ADDRESS } catch (e) { return false } +} +const HOODIDEV_URL = process.env.HOODIDEV_RPC_URL || 'http://127.0.0.1:8545' +const HOODIDEV_PK = process.env.DEPLOYER_PRIVATE_KEY +const HOODIDEV_ACCOUNTS = usableHoodidevKey(HOODIDEV_PK) ? [HOODIDEV_PK as string] : [] module.exports = { defaultNetwork: 'hardhat', @@ -107,6 +120,13 @@ module.exports = { gas: 'auto', gasPrice: 'auto', accounts: [DEPLOYER_PK] + }, + hoodidev: { + url: HOODIDEV_URL, + chainId: 560048, + gas: 'auto', + gasPrice: 'auto', + accounts: HOODIDEV_ACCOUNTS } }, foundry: { diff --git a/contracts/src/deploy-config/hoodidev.ts b/contracts/src/deploy-config/hoodidev.ts new file mode 100644 index 000000000..9a153bac2 --- /dev/null +++ b/contracts/src/deploy-config/hoodidev.ts @@ -0,0 +1,71 @@ +// hoodidev: a private Morph L2 (chain 53077) whose L1 is the public Ethereum Hoodi testnet (chain 560048). +// Derived from l1.ts (the local devnet). Do NOT reuse hoodi.ts: that is Morph's official Hoodi deployment. +// Addresses that follow whoever runs the deploy come from the environment, not from this file: deploy-l1.sh derives them +// from the keys in env/secrets.env and exports them. An empty value is rejected by the deploy tasks (isAddress checks, or the +// contract constructor), so a missing variable stops the run instead of silently using someone else's address. +const addr = (name: string): string => process.env[name] || '' + +const config = { + // Global configuration + contractAdmin: addr('MORPH_DEPLOYER_ADDRESS'), + l1FeeVaultRecipient: addr('MORPH_DEPLOYER_ADDRESS'), + + l1WETHAddress: "", + l1USDCAddress: "", + + // chainID config + l1ChainID: 560048, + l2ChainID: 53077, + + // L1MessageQueue config + l1MessageQueueMaxGasLimit: 30000000, + + // gasPriceOracle config + l2BaseFee: 0.1, // Gwei + + // verify contract config + programVkey: '0x0084f08a14f8199f87e7ae6011336724ec187b3656859184f04c7e8f382a2902', + // rollup contract config + // initialize config + finalizationPeriodSeconds: 10, + rollupProofWindow: 86400, + proofRewardPercent: 70, + rollupDelayPeriod: 86400, + + // challenge config + // `register` uses the keys in $batchSubmitterPks when they are set (deploy-l1.sh does); this list is only the fallback. + batchSubmitterAddresses: process.env.MORPH_BATCH_SUBMITTER_ADDRESS ? [process.env.MORPH_BATCH_SUBMITTER_ADDRESS] : [], + rollupChallenger: addr('MORPH_CHALLENGER_ADDRESS'), + // genesis config + // The genesis batch header comes out of the L2 genesis tool, so it is passed in through MORPH_BATCH_HEADER instead of + // being rewritten into this file (l1.ts is rewritten in place by the devnet's main.py). Empty means "not generated yet": + // the deploy driver refuses to run `initialize` without it. + batchHeader: process.env.MORPH_BATCH_HEADER || '', + + // submitter initialize config + submitterOwner: addr('MORPH_DEPLOYER_ADDRESS'), + submitterChallengeDeposit: 0.01, // 0.01 ether (devnet: l1.ts uses 1) + submitterMinimumStake: 0.01, // 0.01 ether (devnet: l1.ts uses 1); `register` stakes this from the owner + submitterRewardPercentage: 100, + // register sequencers + l2SequencerAddresses: [ + "0x783698dCDEBdc96785c5c60ED96113612bA09c2b", + "0x310824AA27a29D269d2F9C0a8563C0e3C98dD226", + "0x343C5154FFe47c8a07DF5ea6846404e68E9809A2", + "0xaaC606d51De6A5aBF0d1B9dbd5ed5Ff2Ac2e521B" + ], + l2SequencerTmKeys: [ + "0x5280d0eee2a64d3ad29480d15ffd1b048ce5908f180b5ccd65cc3dcf00941abb", + "0xb798eb74c06721d54c659e9ea2bc232a7f95e96d234cc87186b2ab8f43db6935", + "0xecffad01129786ba9c6293aa664f952894dc4019762804799dfa1ffb6e4ed040", + "0x8d29695bb4157c6960adb486be1d9a0c9f728524d09bffcc4f8932ed15221c4a" + ], + l2SequencerBlsKeys: [ + "0x00000000000000000000000000000000095ad465c2895ee825c7d4f1b60a18734db57d4108369e47c6e3a94ee15846f825c06dad5d98f503bd31ece1d9f94b11000000000000000000000000000000000c5d6ba04bc9b9674dd2acbfc5caed3976c1b8be2ec90a03d78dffe924648b4fba82225aff43c744310c6a60185b75ac000000000000000000000000000000000fce6be001c871a11b9db1c6c15f0a6999de5646941a74486206dc784f0b3ffe11799212f3f44ef754b4a0f1ecf85639000000000000000000000000000000000b2f06634e5ea719682c30911c94dfb560f0b7656b5c34a871ea035e3fe7b041885420f8fe1e251f1cce5cdb7514869e", + "0x0000000000000000000000000000000010173aeac4ff317e8e60493f962b91dbd27614e1f6594e17d18a02968bd1fd698b6703092ab8622cd22d6948d9421156000000000000000000000000000000000801aea15697ab4d7a808be45377e4f0d2f54857fdc04031e476402ff16c66a6cbcc5f09a84bf85400c8afbabed006600000000000000000000000000000000015fc71b2c4e81148274e6169c9c9aace8c34fa6030547650242b6c32527dd23a996416e32640bce4f495a0afabc7dbb900000000000000000000000000000000088c4a0dffccc96bce47aef0e176b129457a5f3ae1651b132ddb418e9f7b5850a38c6fec1be6d169eb88dc1619648bf4", + "0x0000000000000000000000000000000003fd9468a8ceffc1b696874517777ef8bfdc9a1bade95c480ee2624903e648c1caf01c65de5b4fda8876a3a0e8d9f0890000000000000000000000000000000004c02f3609a0f61d12fe737dcbb047d5253bd3ff905b55c0e0f932b476fd77d172a58b72ef0f506407870988dd6038220000000000000000000000000000000017fa5765899f60f7a58f8ccdaaa295cde55992231710672692ba6a71a4faa9572f728f438ded65576a570d57e19fd304000000000000000000000000000000001226138813bde98af3464ed03649d8c731bc4e5cb3d26b53bf7483f4105d18bbb3f19e23905119e156e7d003d2fd125c", + "0x00000000000000000000000000000000109bf02a2636c0dc1968b0a50db77251eb090c3e9f51e2a2bc60c4ac72213f41f01f0a34e92c2e0625bd62e28e27edb500000000000000000000000000000000139969bd92522113c0615659874d1fae311ad8152d0584c7b57ffc14927067486dcf86413c5684fccc1163ee2d45c1c1000000000000000000000000000000000f172603f70a0730d100ad6d28bde477195987062e8ade83b82d093935d956ff20ca768c26263577b094f1cb756adc400000000000000000000000000000000010dde3acca00b4ff1b4976500a8f97e92246f43f78cadc95c4993dfc4f4c501c33d42a4bf52587f4931287b59623149c" + ], +} + +export default config diff --git a/contracts/src/deploy-utils.ts b/contracts/src/deploy-utils.ts index ddb59efe5..61bca5395 100644 --- a/contracts/src/deploy-utils.ts +++ b/contracts/src/deploy-utils.ts @@ -5,6 +5,45 @@ import { ethers } from 'ethers' const fs = require("fs") +// Public RPC endpoints sit behind several nodes: a read issued right after a mined write can reach a node that has not +// seen the block yet and fail (empty return data) or return stale state. Retrying the read is opt-in: with +// MORPH_READ_RETRIES unset (the default) behaviour is exactly as before, so local devnets are unaffected. +// Unset or empty keeps the default; anything else has to be a non-negative integer. (Number("15s") is NaN, and then +// `attempt >= READ_RETRIES` is never true: a persistent error would be retried forever.) +const nonNegativeInt = (name: string, fallback: number): number => { + const raw = process.env[name] + if (raw === undefined || raw.trim() === '') return fallback + const n = Number(raw) + if (!Number.isInteger(n) || n < 0) throw new Error(`${name} must be a non-negative integer, got "${raw}"`) + return n +} +const READ_RETRIES = nonNegativeInt('MORPH_READ_RETRIES', 0) +const READ_RETRY_DELAY_MS = nonNegativeInt('MORPH_READ_RETRY_DELAY_MS', 2000) + +const matchesExpected = (actual: any, expected: any): boolean => { + if (ethers.utils.isAddress(expected)) { + return typeof actual === 'string' && actual.toLowerCase() === expected.toLowerCase() + } + return actual === expected || !!(actual && actual.eq && actual.eq(expected)) +} + +// Calls `read` until it succeeds and (if `expected` is given) matches, at most READ_RETRIES extra times. +// The final attempt is returned/thrown as-is so the caller's own assertion reports the real problem. +const readWithRetry = async (read: () => Promise, expected?: any): Promise => { + for (let attempt = 0; ; attempt++) { + const last = attempt >= READ_RETRIES + try { + const actual = await read() + if (last || expected === undefined || matchesExpected(actual, expected)) { + return actual + } + } catch (e) { + if (last) throw e + } + await sleep(READ_RETRY_DELAY_MS) + } +} + /** * Helper function for asserting that a contract variable is set to the expected value. * @@ -28,9 +67,9 @@ export const assertContractVariable = async ( if (caller === null || !ethers.utils.isAddress(caller)) { caller = ethers.constants.AddressZero } - const actual = await temp.callStatic[variable]({ + const actual = await readWithRetry(() => temp.callStatic[variable]({ from: caller, - }) + }), expected) if (ethers.utils.isAddress(expected)) { assert( @@ -60,7 +99,7 @@ export const assertContractVariableWithSigner = async ( contract.signer, ) - const actual = await temp.callStatic[variable]() + const actual = await readWithRetry(() => temp.callStatic[variable](), expected) if (ethers.utils.isAddress(expected)) { assert( diff --git a/ops/l2-genesis/deploy-config/hoodidev-deploy-config.json b/ops/l2-genesis/deploy-config/hoodidev-deploy-config.json new file mode 100644 index 000000000..6eb7b8e1d --- /dev/null +++ b/ops/l2-genesis/deploy-config/hoodidev-deploy-config.json @@ -0,0 +1,54 @@ +{ + "l1ChainID": 560048, + "l2ChainID": 53077, + "finalSystemOwner": "REPLACE_WITH_DEPLOYER_ADDRESS", + "proxyAdminOwner": "REPLACE_WITH_DEPLOYER_ADDRESS", + "BLOCK_SIGNER_ADDRESS": "0xaEcFF2a7E677cEFa56643Ff0aD06e233a3FdC402", + "l1FeeVaultRecipient": "REPLACE_WITH_DEPLOYER_ADDRESS", + "sequencerFeeVaultRecipient": "REPLACE_WITH_DEPLOYER_ADDRESS", + "l2BridgeFeeVaultRecipient": "REPLACE_WITH_DEPLOYER_ADDRESS", + "fundDevAccounts": true, + "l1StartingBlockTag": "REPLACE_WITH_HOODI_START_BLOCK_HEX", + "maxTxPerBlock": 1000, + "maxTxPayloadBytesPerBlock": 737280, + "gasPriceOracleOverhead": 2500, + "gasPriceOracleScalar": 1000000000, + "gasPriceOracleOwner": "REPLACE_WITH_DEPLOYER_ADDRESS", + "govVotingDuration": 1000, + "govBatchBlockInterval": 200, + "govBatchTimeout": 600, + "govRollupEpoch": 100, + "recordOracleAddress": "REPLACE_WITH_DEPLOYER_ADDRESS", + "recordNextBatchSubmissionIndex": 1, + "morphTokenName": "Morph Token", + "morphTokenSymbol": "Morph", + "morphTokenOwner": "REPLACE_WITH_DEPLOYER_ADDRESS", + "morphTokenInitialSupply": 1000000000, + "morphTokenDailyInflationRate": 1, + "morph203Time": 0, + "viridianTime": 0, + "emeraldTime": 0, + "celadonTime": 0, + "l2StakingSequencerMaxSize": 4, + "l2StakingUnDelegatedLockEpochs": 2, + "l2StakingRewardStartTime": 1728000000, + "l2StakingAddresses": [ + "0x783698dCDEBdc96785c5c60ED96113612bA09c2b", + "0x310824AA27a29D269d2F9C0a8563C0e3C98dD226", + "0x343C5154FFe47c8a07DF5ea6846404e68E9809A2", + "0xaaC606d51De6A5aBF0d1B9dbd5ed5Ff2Ac2e521B" + ], + "l2StakingTmKeys": [ + "0x5280d0eee2a64d3ad29480d15ffd1b048ce5908f180b5ccd65cc3dcf00941abb", + "0xb798eb74c06721d54c659e9ea2bc232a7f95e96d234cc87186b2ab8f43db6935", + "0xecffad01129786ba9c6293aa664f952894dc4019762804799dfa1ffb6e4ed040", + "0x8d29695bb4157c6960adb486be1d9a0c9f728524d09bffcc4f8932ed15221c4a" + ], + "l2StakingBlsKeys": [ + "0x00000000000000000000000000000000095ad465c2895ee825c7d4f1b60a18734db57d4108369e47c6e3a94ee15846f825c06dad5d98f503bd31ece1d9f94b11000000000000000000000000000000000c5d6ba04bc9b9674dd2acbfc5caed3976c1b8be2ec90a03d78dffe924648b4fba82225aff43c744310c6a60185b75ac000000000000000000000000000000000fce6be001c871a11b9db1c6c15f0a6999de5646941a74486206dc784f0b3ffe11799212f3f44ef754b4a0f1ecf85639000000000000000000000000000000000b2f06634e5ea719682c30911c94dfb560f0b7656b5c34a871ea035e3fe7b041885420f8fe1e251f1cce5cdb7514869e", + "0x0000000000000000000000000000000010173aeac4ff317e8e60493f962b91dbd27614e1f6594e17d18a02968bd1fd698b6703092ab8622cd22d6948d9421156000000000000000000000000000000000801aea15697ab4d7a808be45377e4f0d2f54857fdc04031e476402ff16c66a6cbcc5f09a84bf85400c8afbabed006600000000000000000000000000000000015fc71b2c4e81148274e6169c9c9aace8c34fa6030547650242b6c32527dd23a996416e32640bce4f495a0afabc7dbb900000000000000000000000000000000088c4a0dffccc96bce47aef0e176b129457a5f3ae1651b132ddb418e9f7b5850a38c6fec1be6d169eb88dc1619648bf4", + "0x0000000000000000000000000000000003fd9468a8ceffc1b696874517777ef8bfdc9a1bade95c480ee2624903e648c1caf01c65de5b4fda8876a3a0e8d9f0890000000000000000000000000000000004c02f3609a0f61d12fe737dcbb047d5253bd3ff905b55c0e0f932b476fd77d172a58b72ef0f506407870988dd6038220000000000000000000000000000000017fa5765899f60f7a58f8ccdaaa295cde55992231710672692ba6a71a4faa9572f728f438ded65576a570d57e19fd304000000000000000000000000000000001226138813bde98af3464ed03649d8c731bc4e5cb3d26b53bf7483f4105d18bbb3f19e23905119e156e7d003d2fd125c", + "0x00000000000000000000000000000000109bf02a2636c0dc1968b0a50db77251eb090c3e9f51e2a2bc60c4ac72213f41f01f0a34e92c2e0625bd62e28e27edb500000000000000000000000000000000139969bd92522113c0615659874d1fae311ad8152d0584c7b57ffc14927067486dcf86413c5684fccc1163ee2d45c1c1000000000000000000000000000000000f172603f70a0730d100ad6d28bde477195987062e8ade83b82d093935d956ff20ca768c26263577b094f1cb756adc400000000000000000000000000000000010dde3acca00b4ff1b4976500a8f97e92246f43f78cadc95c4993dfc4f4c501c33d42a4bf52587f4931287b59623149c" + ], + "l1StakingProxy": "0x000000000000000000000000000000000000dEaD" +} diff --git a/ops/native-hoodi/.gitignore b/ops/native-hoodi/.gitignore new file mode 100644 index 000000000..372357b5e --- /dev/null +++ b/ops/native-hoodi/.gitignore @@ -0,0 +1,11 @@ +# runtime data, binaries, secrets: never commit +/bin/ +/run/ +/deployments/ +/env/secrets.env +/env/archive/ +*.out +journal.rlp +submitter-leveldb/ +__pycache__/ +*.pyc diff --git a/ops/native-hoodi/README.md b/ops/native-hoodi/README.md new file mode 100644 index 000000000..b25abdb2c --- /dev/null +++ b/ops/native-hoodi/README.md @@ -0,0 +1,163 @@ +# Morph L2 on native processes, with public Ethereum Hoodi as L1 + +Run a private Morph L2 (chain id 53077) **without Docker**: every component is a native process, and the L1 is the +public Ethereum **Hoodi** testnet (chain id 560048), so you do not run an L1 yourself. The Rollup contracts are +deployed on Hoodi, and L2 batches are submitted there as EIP-4844 blob transactions. + +``` + public Hoodi: execution RPC (ethpandaops, fallbacks 0xrpc.io / publicnode) + beacon RPC + ▲ + l1-proxy (127.0.0.1:18546, scripts/rpc-consistency-proxy.js): every process reaches L1 through it + ▲ + ┌──────┴───────────────────────────────────────────────────────────────────────┐ + │ morph-el-0 ◀▶ node-0 block producer (tendermint, single validator, sequencer key) + │ morph-el-1 ◀▶ node-1 "layer1" verify mode: re-derives the chain from L1 blobs, no tendermint + │ morph-el-2 ◀▶ node-2 full node with tendermint, no sequencer key; required so node-0 can restart + │ tx-submitter submits batches to the Rollup on Hoodi and finalizes them + │ gas-price-oracle writes L1 fees into the L2 GasPriceOracle + │ challenger (optional) HTTP service: compares batch roots with el-0 and sends Rollup.challengeState on a mismatch + └──────────────────────────────────────────────────────────────────────────────┘ +``` + +Why it is shaped like this, and every problem met on the way: `notes/issues.md`. How to operate it: `RUNBOOK.md`. + +## 1. What this changes in the Morph repo + +Four small, already-committed changes on this branch (everything else is in this directory): + +- `contracts/hardhat.config.ts`: a `hoodidev` network (chain 560048, RPC from `HOODIDEV_RPC_URL`, key from `DEPLOYER_PRIVATE_KEY`) +- `contracts/src/deploy-config/hoodidev.ts`: deploy config for it +- `ops/l2-genesis/deploy-config/hoodidev-deploy-config.json`: L2 genesis config for it + +No owner, admin, fee-recipient or challenger address is fixed in these two files. `deploy-l1.sh` derives them from the keys in +`env/secrets.env` and passes them in (`MORPH_DEPLOYER_ADDRESS`, `MORPH_CHALLENGER_ADDRESS`, `MORPH_BATCH_SUBMITTER_ADDRESS` for `hoodidev.ts`; +a `REPLACE_WITH_DEPLOYER_ADDRESS` placeholder in the genesis config, filled into `run/l1/hoodidev-deploy-config.generated.json`). +Owner, admin and fee recipient are **the deployer**, so whoever runs the deployment holds them; the challenger, sequencer, batch +submitter and gas oracle are separate generated keys. The sequencer set, Tendermint and BLS keys in the configs are fixed. +- `contracts/src/deploy-utils.ts`: optional read retries (`MORPH_READ_RETRIES`), used because public RPCs are read-after-write inconsistent + +## 2. What you need + +| | | +|---|---| +| OS / CPU / disk | Linux x86_64; ~10 GB free for builds (Rust target dir ~1.3 GB, node_modules ~0.7 GB) and chain data | +| Build tools | Go ≥ 1.24 (tested 1.25.7), Rust (tested 1.95; needs OpenSSL headers + pkg-config), Node + yarn 1.x (tested Node 24, yarn 1.22), make, gcc | +| Runtime tools | Node ≥ 18, Python ≥ 3.9, curl, Foundry `cast` and `anvil` (tested 1.9.0) | +| Network | outbound HTTPS to the Hoodi RPC and beacon endpoints (no inbound ports) | +| **Hoodi ETH** | **about 1.5 ETH in your deployer account**: ~0.07 for gas, 1 ETH is passed on to the batch submitter (which then spends ~0.09 ETH/day), 0.2 ETH to the challenger (`CHALLENGER_FUND_ETH`). Faucet: https://hoodi.ethpandaops.io | +| A deployer key | one private key you control and fund. Other keys are generated for you | + +If your tools are not on `PATH` by default, put the `PATH`/build settings in a file and `export MORPH_ENV_FILE=/path/to/that/file`; +every script sources it first (`scripts/lib/env.sh`) and prints exactly what is missing if a tool is absent. + +Ports used on 127.0.0.1 (stop other local devnets first): 18546, 8545/8546/8551, 8645/8646/8651, 8745/8746/8751, +30303-30305, 26656/26657/26660, 26666/26667/26670, 27660, 6160-6162, 6070, 8060, and 8090 / 6065 if you run the challenger +(`CHALLENGER_HTTP_PORT` / `CHALLENGER_METRICS_PORT`; not its defaults 8080 / 6060, which are commonly taken). + +## 3. From zero to a running chain + +All commands from this directory (`ops/native-hoodi/`); the submodule command in step 1 is the exception: it names the repository root with `-C ../..`. + +```bash +# 1. fetch the go-ethereum submodule (empty after a plain clone), then build all binaries into ./bin (about 5-10 minutes the first time) +git -C ../.. submodule update --init go-ethereum +scripts/build-all.sh + +# 2. keys: your funded deployer key (it becomes the owner of everything; the public Anvil key is refused) + four generated ones (sequencer, batch submitter, gas oracle, challenger). Prints +# addresses only. Then fund the DEPLOYER address. +DEPLOYER_PRIVATE_KEY=0x... scripts/init-secrets.sh + +# 3. (optional, free) rehearse the whole L1 deployment on a local anvil fork of Hoodi (~5 minutes when the RPC behaves). +# It reads state from the public RPC, so a hiccup there can make it hang or fail to start: stop it (Ctrl-C) and run it +# again, or point it at another node with FORK_URL=https://... +scripts/dryrun-fork.sh + +# 4. deploy the L1 contracts to Hoodi and generate the L2 genesis. IRREVERSIBLE, spends testnet ETH. About 20-45 minutes +# (public RPCs are slow; it is resumable: re-running skips finished steps) +source env/secrets.env +RPC_URL="$L1_ETH_RPC" RUN_DIR="$PWD/run/l1" WAIT_FINALIZED=1 SUBMITTER_FUND_ETH=1 scripts/deploy-l1.sh +RPC_URL="$L1_ETH_RPC" scripts/verify-l1.sh # reads the chain: expect "53 passed, 0 failed" +# deploy-l1.sh also runs step s34: it adds the challenger to Rollup.isChallenger and tops it up to 0.2 ETH. The step is +# skipped when env/secrets.env has no CHALLENGER_PRIVATE_KEY; for an older deployment run scripts/register-challenger.sh. + +# 5. create the node directories, start everything, bootstrap L2 balances and the gas-oracle permission +scripts/morph-native.sh setup +scripts/morph-native.sh up +scripts/l2-bootstrap.sh +scripts/morph-native.sh status + +# 6. (optional) the challenger, see section 4a. It is not started by a plain `up` unless CHALLENGER_ENABLE=1 is set in env/secrets.env +scripts/morph-native.sh up challenger +``` + +Do not trust a hardhat task's exit code: they often print an error and exit 0. `verify-l1.sh` reads the actual on-chain state. + +## 4. Check that it works + +```bash +scripts/morph-native.sh status # 9 processes running; el-0 and el-2 heights equal and rising +cast block-number --rpc-url http://127.0.0.1:8545 # run twice a few seconds apart: it grows +H=$(( $(cast block-number --rpc-url http://127.0.0.1:8645) - 1 )) # node-1 lags up to one batch; compare below its tip +for p in 8545 8645 8745; do cast block $H --field hash --rpc-url http://127.0.0.1:$p; done # three equal hashes +# batches on L1 (ROLLUP = Proxy__Rollup address in run/l1/deployment/hoodidev.json); both numbers keep rising +cast call $ROLLUP 'lastCommittedBatchIndex()(uint256)' --rpc-url "$L1_ETH_RPC" +cast call $ROLLUP 'lastFinalizedBatchIndex()(uint256)' --rpc-url "$L1_ETH_RPC" +``` + +### 4a. The challenger (optional) + +The challenger is the `challenger/` service of this repo (built into `bin/challenger/challenger` by `scripts/build-all.sh`). +It is an HTTP service, not a watcher: it acts only when it is asked. + +- `GET /batch/{index}` reads the batch's commit transaction on L1 and the same block on el-0 and compares the state root and + the withdraw root. `"verdict":"match"` while the chain is honest; `mismatch` or `inconclusive` otherwise. It sends nothing. +- `POST /challenge` with `{"batchIndex":N,"batchHash":"0x..."}` sends `Rollup.challengeState` **only** when that exact batch + hash is the one committed on L1 and the roots differ. Everything else is refused with a 4xx and no transaction. +- It listens on `127.0.0.1:8090` (metrics `127.0.0.1:6065`) with auth off, reads the L1 through the l1-proxy and the L2 from + el-0. el-0 is an archive node (`--gcmode=archive`), which the withdraw-root read needs. +- The account is `CHALLENGER_PRIVATE_KEY` from `env/secrets.env`, a new key per `init-secrets.sh` run (it is not the deployer). + `deploy-l1.sh` (step s34) or `scripts/register-challenger.sh` adds it to `Rollup.isChallenger` and funds it. + +```bash +scripts/morph-native.sh up challenger # needs bin/challenger/challenger and the key above +scripts/morph-native.sh status # lists challenger as [optional] +curl -s http://127.0.0.1:8090/health # {"status":"ok"} +FIN=$(cast call $ROLLUP 'lastFinalizedBatchIndex()(uint256)' --rpc-url "$L1_ETH_RPC") +curl -s http://127.0.0.1:8090/batch/$FIN # 409 "batch already finalized": finalized batches are refused +curl -s http://127.0.0.1:8090/batch/$((FIN + 1)) # "verdict":"match" for a committed, not yet finalized batch (404 if there is none yet) +``` + +A successful challenge is a real transaction that locks the challenge deposit and stops finalization until the Rollup owner +calls `revertBatch`; once `proofWindow` has passed, the submitter that committed the batch can be slashed. Run it only on +purpose. All options are in `challenger/env.example`. + +End-to-end tests (each uses a few mETH; read the header of each script): + +| script | what it proves | time | +|---|---|---| +| `scripts/deposit-test.sh` | L1 → L2 deposit arrives on both L2 nodes | ~8 min | +| `scripts/withdraw-test.sh` | L2 → L1 withdrawal: Merkle proof built locally, relayed on L1 | ~10 min | +| `scripts/restart-test.sh` (then `restart-test.sh T7`) | crash/restart recovery of every component | ~35 min | +| `scripts/rpc-consistency-proxy.selftest.js`, `scripts/withdraw-proof.selftest.js` | offline unit checks | seconds | + +## 5. Daily use, reset, export + +| | | +|---|---| +| `scripts/morph-native.sh status\|up\|down\|logs NAME\|kill NAME\|start NAME` | operate the stack; `down` keeps chain data | +| `scripts/reset-env.sh plan\|run\|restore\|list` | move run data (and with `--with-build` the binaries, with `--new-keys` the keys) into `run/archive/`; nothing is deleted. A new L2 genesis needs a new L1 deployment | +| `scripts/register-challenger.sh` | add `CHALLENGER_PRIVATE_KEY`'s address to `Rollup.isChallenger` and top it up (idempotent; `deploy-l1.sh` runs it as step s34) | +| `scripts/sweep-submitter.sh` | send the submitter's remaining Hoodi ETH back to the deployer (stack must be down) | +| `scripts/export-deployment.sh NAME` | save contract addresses, genesis files and test outputs (no private keys) to `deployments/NAME/` | +| `scripts/check-no-secrets.sh` | run before committing: fails if anything looks like a private key | + +`bin/`, `run/`, `env/secrets.env`, `env/archive/` and `deployments/` are git-ignored. **Never commit or paste private keys.** + +## 6. Limits worth knowing + +- Do not remove node-2: after a restart node-0 only resumes block production if it has a tendermint peer (`notes/issues.md` I-028). +- Resetting the L2 means redeploying L1: the Rollup on Hoodi is bound to this chain's batches. Old deployments stay on Hoodi as orphan contracts. +- Deposit gas limits must be generous (use ≥ 400000), see `RUNBOOK.md` section 7. +- The challenger does not poll: nothing challenges automatically. Something has to `POST /challenge`. +- Not covered: HA sequencer cluster, reth, multi-day soak, several withdrawals in one batch, the challenger with an external signer. +- L2 chain id 53077 is shared with other Morph-style devnets; do not join them. diff --git a/ops/native-hoodi/RUNBOOK.md b/ops/native-hoodi/RUNBOOK.md new file mode 100644 index 000000000..624a0ed23 --- /dev/null +++ b/ops/native-hoodi/RUNBOOK.md @@ -0,0 +1,152 @@ +# Runbook: Morph L2 (native processes) with public Hoodi as L1 + +This runbook is about **how to use** this setup. For **why it is built this way and the problems met on the way**, see `notes/issues.md`. + +## 1. What it is + +A private Morph L2 (chain id 53077) runs on this machine as native processes (no Docker). Its L1 is the **public Ethereum Hoodi testnet** (chain id 560048). The contracts are deployed on Hoodi, and batches are submitted to Hoodi as EIP-4844 blob transactions. + +``` + public Hoodi: execution RPC (main ethpandaops, fallbacks 0xrpc.io / publicnode) + beacon RPC (ethpandaops / publicnode) + ▲ + l1-proxy (local 127.0.0.1:18546, rpc-consistency-proxy.js) - every process reaches L1 through it + ▲ + ┌──────┴─────────────────────────────────────────────────────────────────────────────┐ + │ morph-el-0 ◀▶ node-0 block producer (Tendermint, single validator, sequencer key) │ + │ morph-el-1 ◀▶ node-1 layer1 verify mode: no Tendermint, re-derives from L1 blobs │ + │ morph-el-2 ◀▶ node-2 full node with Tendermint, no sequencer key. **Only so node-0 can restart** │ + │ tx-submitter submits the L2 batches to the Rollup on Hoodi and finalizes them │ + │ gas-price-oracle writes the L1 fees into the L2 GasPriceOracle │ + │ challenger (optional) compares batch roots, sends Rollup.challengeState on a mismatch │ + └──────────────────────────────────────────────────────────────────────────────────────┘ +``` + +## 2. Prerequisites + +- The build environment is in section 2 of the README. Every script checks the toolchain through `scripts/lib/env.sh`; when a tool is not on PATH, point the environment variable `MORPH_ENV_FILE` at a file that sets PATH. When you call `cast` by hand, make sure it is on PATH yourself. +- `go-ethereum` is a git submodule and is empty after a plain clone: run `git -C ../.. submodule update --init go-ethereum` (from `ops/native-hoodi/`; the submodule lives at the repository root) once before `scripts/build-all.sh`. +- The binaries are in `bin/`: `morph-geth/geth`, `morphnode/morphnode`, `morphnode/tendermint`, `tx-submitter/tx-submitter`, `gas-oracle/app`, `challenger/challenger` (`build-all.sh` builds them all; versions in `notes/versions.md`). +- The keys are in `env/secrets.env` (mode 600, **never commit it or paste it anywhere**); the template is `env/hoodi.env.example`. Five roles: deployer, sequencer, batch submitter, gas oracle, challenger (optional). You supply the deployer key; `scripts/init-secrets.sh` generates the other four, new ones every run. + +## 3. Daily operation + +Everything goes through `scripts/morph-native.sh`: + +| Command | What it does | +|---|---| +| `status` | the 9 processes (plus the optional challenger), the heights of the three L2 nodes, the Hoodi height, proxy statistics, the batches committed on the Rollup | +| `up [NAME...]` | start all or the named processes (in dependency order). `challenger` is not in the default list: start it with `up challenger`, or set `CHALLENGER_ENABLE=1` in `env/secrets.env` | +| `down` | stop all processes (including the challenger), **chain data is kept** | +| `kill NAME` / `start NAME` | stop / start one process (after `kill` it is not restarted automatically) | +| `logs NAME` | follow the log of a process (files are in `run/l2/logs/`) | +| `setup` | create the run directories (including node-2) from the genesis that `deploy-l1.sh` produced | +| `clean logs` / `clean l2` | **nothing is deleted**, the data is only moved to `run/archive/`. `clean l2` has an important consequence, see section 7 | + +Process names: `l1-proxy morph-el-0 node-0 morph-el-1 node-1 morph-el-2 node-2 tx-submitter gas-price-oracle`, and the optional `challenger`. Every process runs inside a self-restarting supervisor shell, so a crashed process is started again within 2 seconds. + +## 4. Ports (all on 127.0.0.1) + +| Process | HTTP | WS | Engine | p2p | metrics | +|---|---|---|---|---|---| +| morph-el-0 | 8545 | 8546 | 8551 | 30303 | 6160 | +| morph-el-1 | 8645 | 8646 | 8651 | 30304 | 6161 | +| morph-el-2 | 8745 | 8746 | 8751 | 30305 | 6162 | +| node-0 (Tendermint) | | | | 26656 | 26660; Tendermint rpc 26657 | +| node-1 | | | | no Tendermint | 27660 | +| node-2 (Tendermint) | | | | 26666 | 26670; Tendermint rpc 26667 | +| tx-submitter | | | | | 8060 | +| gas-price-oracle | | | | | 6070 | +| l1-proxy | 18546 (`/stats` shows statistics) | | | | | +| challenger (optional) | 8090 | | | | 6065 | + +The geth metrics ports start at 6160 because 6060 is already taken in some environments; the challenger likewise avoids its defaults 8080 / 6060 (change them with `CHALLENGER_HTTP_PORT` / `CHALLENGER_METRICS_PORT`). **These ports (8545, 8551, 30303 and so on) are the same ones other local Ethereum devnets commonly use**, so two of them cannot run at the same time: `down` one first, or change the ports. + +## 5. From zero + +1. `git -C ../.. submodule update --init go-ethereum`, then `scripts/build-all.sh`: build every binary and install the contracts' dependencies. +2. `DEPLOYER_PRIVATE_KEY=0x... scripts/init-secrets.sh`: write `env/secrets.env` with your deployer key and four generated keys, and print the addresses. Get Hoodi test coins for the **deployer** address (it pays for the deployment and sends funds on to the batch submitter and the challenger). +3. Deploy the L1 contracts and generate the L2 genesis: + ```bash + source env/secrets.env + RPC_URL=https://rpc.hoodi.ethpandaops.io RUN_DIR=$PWD/run/l1 WAIT_FINALIZED=1 SUBMITTER_FUND_ETH=1 scripts/deploy-l1.sh + RPC_URL=https://rpc.hoodi.ethpandaops.io scripts/verify-l1.sh # checks the on-chain state, does not trust exit codes + ``` + About 20 to 45 minutes (about 13 of them waiting for Hoodi to finalize). **It spends testnet coins on a public chain and cannot be undone.** + At the end `deploy-l1.sh` also runs s34: it adds the challenger to `Rollup.isChallenger` and tops it up to 0.2 ETH (`CHALLENGER_FUND_ETH`). The step is skipped when `env/secrets.env` has no `CHALLENGER_PRIVATE_KEY`; for an existing deployment run `scripts/register-challenger.sh`. +4. `scripts/morph-native.sh setup`, then `up`. +5. `scripts/l2-bootstrap.sh`: give the deployer and the oracle a balance on the L2 and put the oracle key on the GasPriceOracle allow list (without it gas-price-oracle has no permission to update). +6. Verify with the scripts of section 6. +7. (Optional) `scripts/morph-native.sh up challenger`, and verify as in "The challenger" of section 6. + +## 6. Verification scripts + +| Script | What it verifies | Time | +|---|---|---| +| `scripts/verify-l1.sh` | reads the contract state on Hoodi: owners, cross references, the genesis batch, the submitter's stake, implementation and admin of every proxy, the first sequencer (53 checks) | 1 minute | +| `scripts/deposit-test.sh` | L1 to L2 deposit to a fresh address, waits until both nodes have it | about 7 minutes | +| `scripts/withdraw-test.sh` | L2 to L1 withdrawal: builds the Merkle proof locally and claims on L1 | about 10 minutes | +| `scripts/restart-test.sh` | crash and restart recovery (T1 to T8, T7 has to be named separately) | about 35 minutes | +| `scripts/rpc-consistency-proxy.selftest.js` | 6 behaviours of the proxy (no network) | 10 seconds | +| `scripts/withdraw-proof.selftest.js` | the Merkle proof algorithm matches the contract line by line (210 cases) | 5 seconds | +| `scripts/probe-hoodi.sh` | rate-limit probe of the public RPCs | 1 minute | +| `scripts/register-challenger.sh` | adds the challenger to `Rollup.isChallenger` and funds it (idempotent, reads each result back from the chain; it is what s34 of `deploy-l1.sh` runs) | 1 minute | + +To check that node-1 agrees with node-0, compare block by block with `cast block N --field hash --rpc-url http://127.0.0.1:8545 / 8645 / 8745` (blocks 0 to 7562, 7563 in total, were compared across the three nodes with 0 differences). + +**The challenger (optional).** The challenger is an HTTP service that **does not poll**; it only acts when it is asked: + +- `GET /batch/{index}`: reads the commit transaction of that batch on L1 and the same block on el-0, and compares the state root and the withdraw root. While the chain is honest it returns `"verdict":"match"`, otherwise `mismatch` / `inconclusive`. It sends no transaction. +- `POST /challenge` with body `{"batchIndex":N,"batchHash":"0x..."}`: it sends `Rollup.challengeState` **only** when that hash is exactly the one currently committed on L1 and the roots differ; every other case returns 4xx and sends nothing. +- It listens on `127.0.0.1:8090` (no authentication, so it only binds to localhost) with metrics on `127.0.0.1:6065`; it reaches L1 through the l1-proxy and reads the L2 from el-0 (an archive node, `--gcmode=archive`, which reading the withdraw root needs). Its account is `CHALLENGER_PRIVATE_KEY` from `env/secrets.env` (not the deployer). + +```bash +scripts/morph-native.sh up challenger +curl -s http://127.0.0.1:8090/health # {"status":"ok"} +FIN=$(cast call $ROLLUP 'lastFinalizedBatchIndex()(uint256)' --rpc-url "$L1_ETH_RPC") +curl -s http://127.0.0.1:8090/batch/$FIN # 409 "batch already finalized" +curl -s http://127.0.0.1:8090/batch/$((FIN + 1)) # a committed, not yet finalized batch: "verdict":"match" (404 when there is none yet) +``` + +A successful challenge is a real transaction: it locks the deposit (`challengeDeposit`) and stops finalization until the Rollup owner calls `revertBatch`; once `proofWindow` has passed, the submitter that committed the batch is slashed. Do not send one casually. All options are in `challenger/env.example`. + +## 7. Limits and pitfalls you must know + +1. **node-2 cannot be removed.** After a restart the block producer node-0 only resumes block production when it has at least one Tendermint peer; without one it stalls silently (the process is up, the RPC is up, the log shows no error, the height is frozen). node-1 runs in layer1 verify mode and does not count as a Tendermint peer. See `notes/issues.md` I-028. node-2 must be built from the genesis of the deployment it belongs to (`L1_RUN`); a different genesis makes it reject every block with `wrong parent hash`. +2. **The L2 and the Rollup on L1 are bound one to one.** The batches already committed on L1 are bound to this L2 chain. If you empty the L2 and produce blocks from genesis again, the new blocks do not match the old batches and tx-submitter cannot continue. **Resetting the L2 means deploying the L1 contracts again** (with a new `RUN_DIR`), which is why `clean l2` only moves the data away. +3. **Give deposits enough gas.** The `110000` in the repository's examples makes the execution fail on the L2 in this deployment (the money stays locked in the L1 gateway). `deposit-test.sh` defaults to 400000. +4. **Public RPCs are unreliable.** Several nodes sit behind them: a block that was just mined may not be readable, and there is occasional rate limiting. `l1-proxy` solves both; every process should go through it, do not connect to Hoodi directly. +5. **node-1 is not real time.** It advances per batch, only after the batch is committed to L1, so it always lags by a few hundred blocks (about one batch). +6. **Do not treat the exit code of a `hardhat` task as success.** On errors they often print one line and still exit with 0. After deploying, read the on-chain state with `verify-l1.sh`. +7. **Owner, admin and fee recipient are the deployer; no such address is fixed in the repository.** `deploy-l1.sh` derives the addresses from the keys in `env/secrets.env`, passes them to `hoodidev.ts` through the environment and fills them into the generated genesis config (`run/l1/hoodidev-deploy-config.generated.json`). Whoever deploys is the owner. The sequencer set and the Tendermint and BLS public keys are fixed. +8. **The changes outside this directory are in git.** Only 4 files of the upstream repository are changed: `contracts/hardhat.config.ts` (adds the network `hoodidev`), `contracts/src/deploy-config/hoodidev.ts`, `ops/l2-genesis/deploy-config/hoodidev-deploy-config.json`, `contracts/src/deploy-utils.ts` (optional read retries). +9. **The challenger does not challenge by itself.** It does not poll L1; someone has to `POST /challenge`. After a successful challenge finalization stops and the owner has to close it with `revertBatch`; after `proofWindow`, `proveState` rules for the challenger, slashes the submitter that committed the batch, and puts the contract into `pending revert request`. + +## 8. Cost (measured) + +| Item | Value | +|---|---| +| L1 contract deployment | 77 transactions, 51.3 million gas; about 0.06 ETH at 1 gwei (including the 0.01 ETH submitter stake) | +| tx-submitter running | about 0.0004 ETH per batch; one batch about every 7 minutes, about 0.09 ETH per day | +| Challenger funding | 0.2 ETH sent at deployment (`CHALLENGER_FUND_ETH`); one challenge locks a 0.01 ETH deposit plus about 0.0002 ETH of gas | +| Losses while deploying | orphan contracts left by the first failed attempts, less than 0.2 ETH in total | + +## 9. Troubleshooting + +| Symptom | Likely cause and what to do | +|---|---| +| L2 height does not move, all processes are up | First check whether the node-0 log stops at `derivation skipped: sequencer mode`: node-2 is not running or not connected. Look at node-2 in `status`; its log should contain `Added peer`. If node-2 logs `wrong parent hash`, its genesis differs from node-0's: compare `cast block 0 --field hash` on 8545 and 8745 | +| node-1 height does not grow | Normal: it waits for the next batch to be committed. As long as `lastCommittedBatchIndex` in `status` grows, it is fine | +| `failed to fetch L1 messages ... beyond current head` | A lagging L1 backend; the proxy retries. Occasional, no action needed | +| gas-price-oracle reports `ErrCallerNotAllowed` | `l2-bootstrap.sh` was not run, so the oracle is not on the allow list | +| After a deposit the L2 shows nothing, but the L1 message is queued | Find the transaction of type `0x7e` on the L2 and look at its receipt: status 0 usually means `_gasLimit` was too small | +| Cannot start, port in use | First `scripts/morph-native.sh down`; another devnet or node on this machine using the same ports also conflicts (check with `ss -ltn`) | +| `up challenger` complains about a missing `CHALLENGER_PRIVATE_KEY` / `bin/challenger/challenger` | An old `env/secrets.env` has no such key (add one made with `cast wallet new`, then run `register-challenger.sh`); the binary needs `build-all.sh` first | +| `POST /challenge` returns `only challenger allowed` | The challenger account is not on `Rollup.isChallenger`: run `scripts/register-challenger.sh` | +| The challenger process keeps restarting | Look at `logs challenger`: it refuses to start when the chain behind the L2 RPC does not match the Rollup; make sure el-0 is running and `L1_RUN` points at the current deployment | + +## 10. Reset and deployment records (added 2026-11-19, the whole flow has been redone once) + +- `scripts/reset-env.sh plan|run|restore|list`: archives the run data (and optionally the build products with `--with-build`, and the keys with `--new-keys`) with `mv` into `run/archive//`; `restore` moves the archived run data (and build products) back as it was, but it does not overwrite the current `env/secrets.env`: after a reset with `--new-keys`, copy the matching `env/archive/secrets-.env` back yourself before starting the old deployment (restore prints where it is). Nothing is deleted. It refuses to run when the submitter holds more than 0.02 ETH on L1; first move the money back to the deployer with `scripts/sweep-submitter.sh` (run `down` first). +- `scripts/export-deployment.sh NAME`: stores the contract addresses, the genesis files, the account addresses (no private keys), the versions and the test output of a deployment in `deployments/NAME/`. Export before resetting. +- Existing records: `deployments/devnet-1/` (old), `deployments/devnet-2/` (current). +- Order of a redo: sweep, export the old deployment, `reset-env run --with-build --new-keys`, `build-all`, `deploy-l1` (about 43 minutes, of which `s30_initialize` takes about 20), `verify-l1`, `setup`, `up`, `l2-bootstrap`, then the deposit / withdrawal / restart tests. diff --git a/ops/native-hoodi/env/hoodi.env.example b/ops/native-hoodi/env/hoodi.env.example new file mode 100644 index 000000000..8119ed3a9 --- /dev/null +++ b/ops/native-hoodi/env/hoodi.env.example @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Template for env/secrets.env (the real file is git-ignored; never commit it). Easiest way to create it: +# DEPLOYER_PRIVATE_KEY=0x... scripts/init-secrets.sh # generates the three other keys for you +# The scripts derive everything else (contract addresses, start block) from the deployment output. + +# ---- L1 = public Ethereum Hoodi (chain id 560048) ---- +export L1_ETH_RPC="https://rpc.hoodi.ethpandaops.io" +# fallbacks the local l1-proxy switches to on rate limits (comma separated; override with RPC_FALLBACK_URLS) +# export RPC_FALLBACK_URLS="https://0xrpc.io/hoodi,https://ethereum-hoodi-rpc.publicnode.com" +# beacon endpoints: morphnode accepts a comma separated list; gas-price-oracle uses the first one only +export L1_BEACON_RPC="https://beacon.hoodi.ethpandaops.io,https://ethereum-hoodi-beacon-api.publicnode.com" + +# ---- private keys (cast wallet new). Never use the public Anvil key. ---- +export DEPLOYER_PRIVATE_KEY="" +export SEQUENCER_PRIVATE_KEY="" +export BATCH_SUBMITTER_PRIVATE_KEY="" +export L2_GAS_ORACLE_PRIVATE_KEY="" +export CHALLENGER_PRIVATE_KEY="" +# Set to 1 to start the challenger with a plain `morph-native.sh up` (it can always be started with `up challenger`). +# export CHALLENGER_ENABLE=1 diff --git a/ops/native-hoodi/notes/budget.md b/ops/native-hoodi/notes/budget.md new file mode 100644 index 000000000..4db45a924 --- /dev/null +++ b/ops/native-hoodi/notes/budget.md @@ -0,0 +1,40 @@ +# Funds budget (result of P2-5) + +Basis: the whole of `scripts/deploy-l1.sh` was rehearsed on an anvil fork of Hoodi (`run/dryrun-1/`), and **every step succeeded**. Transactions in the fork do not spend any coin of public Hoodi. + +## Measured + +| Item | Value | +|---|---| +| Transactions sent by the deployer | **77** | +| Total gas | **51,304,680** (the largest one 4,780,806, far below the 60 million block gas limit) | +| Submitter stake (paid by the deployer) | 0.01 ETH (lowered in the configuration; the default is 1 ETH) | +| What the deployer actually spent in the dry run | 0.0179 ETH (about 0.0079 ETH gas + 0.01 ETH stake), at a gas price of about 0.15 gwei in the fork | +| Duration | about 2 minutes to deploy, about 2 minutes to initialise, about 4 minutes in total (no confirmations to wait for in the fork) | + +## The deployer's need at different gas prices + +(51,304,680 gas x price + 0.01 ETH stake) + +| Hoodi gas price | The deployer needs | +|---|---| +| 0.15 gwei | about 0.018 ETH | +| 0.5 gwei | about 0.036 ETH | +| 1 gwei (I measured 1.08 gwei at 09:19) | about 0.061 ETH | +| 2 gwei | about 0.113 ETH | +| 5 gwei | about 0.267 ETH | + +**Keep 0.2 ETH on the deployer** (it covers gas rising to about 3 gwei and leaves a margin). Check the gas price again right before the real deployment. + +This covers the contract deployment only. A full run of `deploy-l1.sh` also sends `SUBMITTER_FUND_ETH` (1 ETH in the README flow) to the batch submitter and, when a challenger key is configured, tops the challenger up to `CHALLENGER_FUND_ETH` (0.2 ETH; nothing is sent for an account that already holds it). The preflight of `deploy-l1.sh` adds all of that to the 0.1 ETH deployment allowance and refuses to start when the deployer's balance is lower. So with a challenger key and an empty challenger account the deployer needs at least 0.3 ETH even with `SUBMITTER_FUND_ETH=0`, not 0.2. + +## Submitter + +- It was **not measured** this time: the submitter sent no transaction in the dry run (batches are only submitted once the L2 is running). +- It sends one blob transaction per batch. The blob fee itself is very low (the Hoodi blob base fee was about 0.05 gwei at the time); the main cost is execution gas. +- The batch interval is set by the configuration (`govBatchBlockInterval=200` blocks / `govBatchTimeout=600` seconds), roughly one batch every 10 minutes (faster when the L2 has transactions). +- **Estimate (not measured):** start with **0.1 ETH** and adjust to the real consumption once P6 is running; `TX_SUBMITTER_TX_FEE_LIMIT` has to be lowered. + +## Conclusion + +**The testnet coins needed are far fewer than I first feared: about 0.3 ETH in total is enough** (the deployment plus the submitter's running funds, without the optional challenger; with the challenger enabled add its 0.2 ETH top-up, see above). A faucet can usually give an amount of that order in one claim, so the risk R2 (not getting enough testnet coins) goes down, but claiming from a faucet has not been verified yet. diff --git a/ops/native-hoodi/notes/config-audit.md b/ops/native-hoodi/notes/config-audit.md new file mode 100644 index 000000000..4b50a765e --- /dev/null +++ b/ops/native-hoodi/notes/config-audit.md @@ -0,0 +1,44 @@ +# Configuration audit (P3-4 ~ P3-7) + +Conclusion first: **nobody needs to send coins to any staking address or to BLOCK_SIGNER on Hoodi; the deployer, however, must keep extra funds for the submitter's stake.** + +## 1. Keys and addresses in the configuration + +| Config item | Nature | Where it is used | What to do on Hoodi | +|---|---|---|---| +| `BLOCK_SIGNER_PRIVATE_KEY` | **public Anvil key** | only in `ops/devnet-morph/devnet/__init__.py:190`, to send 10 ETH to `l2StakingAddresses` on the devnet's L1; the Go genesis tool **does not read it at all** | remove | +| `BLOCK_SIGNER_ADDRESS` | address | nothing in the code reads it | keep the field, put the sequencer address in it; no real effect | +| `l2StakingAddresses / TmKeys / BlsKeys` | addresses and **public keys** | only go into the **L2 genesis** (`immutables.go`, the sequencer set of the L2Staking contract); never used to send a transaction on L1 | keep as is; **no need to fund them on Hoodi** | +| `l2StakingPks` | upstream devnet test private keys | nothing in this repository reads it (the devnet driver used it for the funding above) | **removed from `hoodidev-deploy-config.json`**, so that no private key is stored in this configuration | +| `finalSystemOwner / proxyAdminOwner / gasPriceOracleOwner / recordOracleAddress / morphTokenOwner` | owners of L2 contracts | L2 genesis | the deployer address, filled in by `deploy-l1.sh` (placeholder `REPLACE_WITH_DEPLOYER_ADDRESS` in the tracked file) | +| `l1FeeVaultRecipient / sequencerFeeVaultRecipient / l2BridgeFeeVaultRecipient` | fee recipient addresses | L2 genesis | the deployer address, filled in the same way | + +## 2. `l1StartingBlockTag` (P3-5) + +- Format: geth's `rpc.BlockNumberOrHash`. It can be a label such as `"earliest"` / `"latest"`, a hexadecimal block number string (for example `"0x3da3eb"`), or `{"blockHash": ...}`. +- The genesis tool (`cmd/genesis/cmd.go`) fetches this L1 block with `BlockByNumber` / `BlockByHash` and writes its **hash, height and timestamp** into `rollup.json` (`L2Time = l1StartBlock.Time()`). +- The default `earliest` is block 0 of Hoodi, which would make the L1 starting point of rollup.json the genesis block of March 2025. +- **How to set it:** before sending the first deployment transaction, take the latest Hoodi block number at that moment (hexadecimal), write it into the configuration, then run the genesis tool. +- The tracked file holds a placeholder that **cannot be parsed on purpose**, `REPLACE_WITH_HOODI_START_BLOCK_HEX`, so forgetting to replace it fails at once instead of silently using a wrong value. +- The node's `MORPH_NODE_SYNC_START_HEIGHT` uses the same block number. + +## 3. Fields that main.py injects at run time (our driver has to handle them itself) + +| Field written by main.py | Does it take effect | What we do | +|---|---|---| +| `l1GenesisBlockTimestamp` | **No.** The `DeployConfig` struct has no such field, so it is ignored | do not write it | +| `l1StartingBlockTag = earliest` | Yes, but it does not suit Hoodi | replace it with the starting block number at deployment time | +| `l1StakingProxy = 0x...dEaD` | **Required.** When it is 0, `config.go` first looks for a deployed L1Staking and fails if it finds none; L1Staking is retired | written straight into `hoodidev-deploy-config.json` (done) | + +## 4. `register` and staking (P3-6) + +- `hardhat register` (`contracts/deploy/021-SubmitterRegister.ts`): the owner first calls `addSubmitter(submitter)`, then `stake(submitter, {value: minimumStake - currentStake})`. +- **The owner (deployer) pays the stake**, not the submitter. +- `submitterMinimumStake` and `submitterChallengeDeposit` default to **1 ETH** each in the configuration. The contract only requires them to be greater than 0. +- We set both to **0.01 ETH** (in `hoodidev.ts`), so the deployer needs only about 0.01 ETH extra for the stake. +- Whether such a small value is converted correctly by `parseEther` and the like was checked in the anvil fork dry run. + +## 5. `hardhat fund` (P3-7) + +- It sends **100 ETH** to every account in `batchSubmitterPks` (when the balance is below about 10 ETH). That is not feasible on Hoodi. +- **The driver does not call it.** When needed, send the submitter a small amount by hand (the amount is determined by the dry run of P2-5). diff --git a/ops/native-hoodi/notes/hoodi-probe-raw.txt b/ops/native-hoodi/notes/hoodi-probe-raw.txt new file mode 100644 index 000000000..d04fc1bb5 --- /dev/null +++ b/ops/native-hoodi/notes/hoodi-probe-raw.txt @@ -0,0 +1,19 @@ +== concurrency 20 x 3 rounds +EL https://0xrpc.io/hoodi 200x60 avg=0.92s max=1.25s n=60 +EL https://rpc.hoodi.ethpandaops.io 200x60 avg=0.39s max=0.63s n=60 +BEACON https://beacon.hoodi.ethpandaops.io 200x60 avg=0.46s max=0.71s n=60 +BEACON https://ethereum-hoodi-beacon-api.publicnode.com 200x60 avg=0.06s max=0.19s n=60 + +== eth_getLogs: range limit (Morph's L1 sync uses it) + https://0xrpc.io/hoodi span=1000 ok + https://0xrpc.io/hoodi span=5000 ok + https://0xrpc.io/hoodi span=10000 Request contains invalid block params + https://0xrpc.io/hoodi span=50000 Request contains invalid block params + https://rpc.hoodi.ethpandaops.io span=1000 ok + https://rpc.hoodi.ethpandaops.io span=5000 ok + https://rpc.hoodi.ethpandaops.io span=10000 ok + https://rpc.hoodi.ethpandaops.io span=50000 getLogs request exceeded max allowed range + +== beacon: blob_sidecars of 5 consecutive recent slots + https://beacon.hoodi.ethpandaops.io head_slot=4398552 ok=4 fail=1 + https://ethereum-hoodi-beacon-api.publicnode.com head_slot=4398552 ok=4 fail=1 diff --git a/ops/native-hoodi/notes/hoodi-probe.md b/ops/native-hoodi/notes/hoodi-probe.md new file mode 100644 index 000000000..f85edbc43 --- /dev/null +++ b/ops/native-hoodi/notes/hoodi-probe.md @@ -0,0 +1,32 @@ +# Hoodi public endpoint probe results (P2-1, P2-2) + +Probed on 2026-11-18. Script: `scripts/probe-hoodi.sh` (concurrency 20 x 3 rounds, read-only, only small-scale concurrency against public services). Raw output: `notes/hoodi-probe-raw.txt`. + +## Rate limits + +| Endpoint | Type | Result of 60 requests | Mean latency | +|---|---|---|---| +| `https://0xrpc.io/hoodi` | EL | all 200 | 0.92 s | +| `https://rpc.hoodi.ethpandaops.io` | EL | all 200 | 0.39 s | +| `https://beacon.hoodi.ethpandaops.io` | beacon | all 200 | 0.46 s | +| `https://ethereum-hoodi-beacon-api.publicnode.com` | beacon | all 200 | 0.06 s | + +**There was no rate limiting at this concurrency.** The limits under higher or sustained concurrency were not measured. + +## eth_getLogs range limit + +| Endpoint | 1000 | 5000 | 10000 | 50000 | +|---|---|---|---|---| +| 0xrpc.io | ok | ok | `invalid block params` | `invalid block params` | +| ethpandaops | ok | ok | ok | `exceeded max allowed range` | + +**Morph's L1 sync fetches only 100 blocks at a time** (`DefaultFetchBlockRange = 100` in `node/sync/config.go`), far below the limit of both, so it is not affected. + +## Beacon blob_sidecars + +Both beacon endpoints return sidecars for recent slots. When 5 consecutive slots were fetched the first time, one of them failed on each endpoint; a second check of the 5 slots succeeded in full. The likely explanation is a slot without a block or without blobs, so it is occasional. Effect on Morph: when fetching a blob fails, it falls back to the next endpoint in order, see `node/derivation/beacon.go`. + +## Conclusion + +- Use **ethpandaops** as the main EL endpoint (low latency, higher getLogs limit) and 0xrpc.io as the fallback. **This is the opposite of the first plan ("0xrpc.io as the main one")**; `env/hoodi.env.example` and `env/secrets.env` were adjusted to match. +- morphnode gets two beacon endpoints (ethpandaops first, publicnode second); gas-oracle can take only one. diff --git a/ops/native-hoodi/notes/issues.md b/ops/native-hoodi/notes/issues.md new file mode 100644 index 000000000..eb339d84f --- /dev/null +++ b/ops/native-hoodi/notes/issues.md @@ -0,0 +1,270 @@ +# Problems and how they were handled + +In time order, one record per item: symptom, cause, handling, effect on the plan. + +--- + +## 2026-11-18 + +### I-001 morph-geth fails to build with the command in the plan - solved + +- **Symptom:** `cd repos/morph/go-ethereum && go run build/ci.go install ./cmd/geth` fails with + `build/ci.go:63:2: use of internal package github.com/morph-l2/go-ethereum/internal/build not allowed` +- **Cause:** the `go-ethereum` directory lives inside the Morph repository, the repository root has a `go.work`, but `go.work` does not list `./go-ethereum`. Go therefore treats `github.com/morph-l2/go-ethereum` as a **downloaded external dependency** instead of a local directory, and `internal` packages may not be accessed. The Docker build has no such problem because it copies `go-ethereum` on its own to `/go-ethereum`, where no `go.work` sits above it. +- **Handling:** add `GOWORK=off`. Morph's own top-level Makefile does the same for its `geth` target (`env GO111MODULE=on GOWORK=off go run build/ci.go install ./cmd/geth`). I had copied the command from the Dockerfile and missed this. +- **Result:** the build succeeds in 23 seconds; `geth version` shows `Version: 2.2.8-mainnet`, matching the submodule tag `morph-v2.2.8`. +- **Effect on the plan:** the command of TODO P1-2 was changed. + +### I-002 morphnode does not support `--version` + +- **Symptom:** `morphnode --version` fails with `flag provided but not defined: -version`. +- **Handling:** the version is confirmed by checking that `morphnode --help` runs, and by `tendermint version` (0.37.0-alpha.1) for tendermint. tx-submitter supports `--version` and prints `v1.0.0-2.2.8-mainnet-ae987b15-...`. +- **Effect on the plan:** none. In the acceptance criteria of P1, "can print its version" becomes "`--help` prints normally" for morphnode. + +### I-003 the version string of tx-submitter contains `mainnet` + +- **Symptom:** `tx-submitter version v1.0.0-2.2.8-mainnet-ae987b15-...`; morph-geth is also `2.2.8-mainnet`. +- **Note:** this is only a build tag, it does not mean they connect to mainnet. The chain used at run time is decided by the configuration and the genesis (`TX_SUBMITTER_BUILD_ENV=dev`, `--networkid=53077`). Recorded here to avoid confusion when the word `mainnet` shows up later. + +### I-004 gas-oracle panics at start: the log directory is not writable - a way around was found + +- **Symptom:** running `bin/gas-oracle/app` directly panics at `src/main.rs:58` with `OutputIo(PermissionDenied)`. +- **Cause:** the log directory defaults to `/data/logs/morph-gas-price-oracle` (`setup_logging` in `main.rs`). In Docker it runs as root and the path is writable; on this machine there is no root and `/data` is not writable. +- **Handling:** set the environment variable `GAS_ORACLE_LOG_DIR` to a writable directory (the plan uses `run/logs/gas-oracle/`). With it set, the program starts normally and prints `Starting update gas oracle...`, then panics because `L2_GAS_ORACLE_PRIVATE_KEY` is missing, which is expected. +- **Effect on the plan:** the list of gas-oracle environment variables in P6-3 has to include `GAS_ORACLE_LOG_DIR`. + +### I-005 the beacon address of gas-oracle supports only one endpoint - confirmed + +- **Symptom / evidence:** `l1_beacon_rpc: String` at `gas_price_oracle.rs:36`; `da_scalar/blob_client.rs` uses it as a URL prefix and appends `/eth/v1/beacon/blob_sidecars/` directly, with no comma splitting and no fallback. +- **Conclusion:** `GAS_ORACLE_L1_BEACON_RPC` **cannot** take several comma separated endpoints, only one. This differs from morphnode (several, tried in order). +- **Handling:** gas-oracle uses `https://beacon.hoodi.ethpandaops.io`; morphnode gets two. +- **Effect on the plan:** this was the "to be confirmed" item of TODO P6-3; it is confirmed now and the comment in `env/hoodi.env.example` was corrected to match. + +### I-006 the contracts toolchain works on Node 24 - risk R8 is gone + +- **Result:** `yarn hardhat compile` and the full `yarn build` both pass on Node v24.19.0. +- **Effect on the plan:** the fallback "install Node 18/20 if it fails" of TODO P1-6 is no longer needed. Risk R8 of the PLAN can be closed. + +### I-007 node-1 does not run Tendermint, only node-0 does - this simplified P5 + +- **Evidence:** the comment in `ops/devnet-morph/devnet/setup_nodes.py`: "node-1 runs with `MORPH_NODE_DERIVATION_VERIFY_MODE=layer1` and never starts tendermint; node-2 has no compose service at all". `TENDERMINT_PEERS = ("node0", "ha-node0", "ha-node1", "ha-node2")` does not contain node1. +- **Conclusion:** in single-sequencer mode only node-0 is a Tendermint node; node-1 rebuilds blocks entirely from the L1 batches and blobs. The `persistent_peers` of PBFT peers therefore has almost no use in this mode. +- **Effect on the plan:** node-1 loses its Tendermint ports in the port table of section 6 of the PLAN; TODO P5-1 gets a smaller scope. It also means that **whether node-1 agrees with node-0 depends entirely on whether the beacon chain blobs can be fetched**, which makes P7-2 more important. + +### I-008 setup_nodes.py uses only the standard library - P1-8 passes + +- **Result:** its only imports are `base64 hashlib json os re shutil subprocess sys`; Python 3.12.3 runs it directly, no `pip install` needed. +- **Note:** the script starts by checking whether `tendermint` is on PATH and calls `make install-tendermint` if not. When our driver copies that logic it must use the full path `bin/morphnode/tendermint` and not depend on PATH. + +### I-009 a git commit is stopped by GPG signing - staged changes plus a patch instead + +- **Symptom:** `git commit` fails with `gpg failed to sign the data ... Operation cancelled`. +- **Cause:** the git configuration of the repository forces commit signing, and this environment has no interactive GPG signing. +- **Handling:** I did **not** turn signing off to be able to commit (that is your signing policy). The three changed files stay in the **git index**, and a patch was exported to `patches/0001-hoodidev-config.patch` (166 lines). +- **Check:** none of our private keys appears in the patch; the public Anvil private key appears once, in the "forbidden" comparison constant of `hardhat.config.ts`. +- **For you to do:** if you want a commit on the `native-hoodi` branch, commit once yourself (with your signing), or tell me that I may skip signing on this branch for now. + +### I-010 the "to be confirmed" items of P3 in the original plan are now all confirmed + +See `notes/config-audit.md`. The two most important: `BLOCK_SIGNER_PRIVATE_KEY` is only used by the devnet to fund the staking addresses and is simply deleted on Hoodi; the stake of `register` is paid by the deployer, and the amount was lowered from 1 ETH to 0.01 ETH. + +### I-011 `printf '%x'` overflows for 1e20 in the dry-run script - fixed + +- **Symptom:** `printf: warning: 100000000000000000000: Numerical result out of range`; the balance set for the accounts in the fork was cut to 2^64-1 (about 18.4 ETH). +- **Cause:** bash `printf` only handles 64-bit integers. +- **Handling:** use `cast to-hex` instead. It made no difference to this dry run (18.4 ETH is enough), only the balance was not the 100 ETH that was intended. + +### I-012 the gas price in the fork is much lower than what I measured + +- **Symptom:** at 09:19 I asked Hoodi directly and got `eth_gasPrice` of about 1.08 gwei, while the deployer's real gas spend in the dry run works out to about 0.15 gwei. +- **Cause (a guess, not verified):** the anvil fork starts from the base fee of the fork point block, and the gas price of Hoodi itself fluctuates. +- **Handling:** the budget multiplies the total gas (which is certain) by several price levels, see `notes/budget.md`. Check the live price again before the real deployment. + +### I-013 the fork is closed after the dry run, so the on-chain state cannot be sampled + +- **Note:** `dryrun-fork.sh` stops the anvil it started when it ends, so after the dry run `cast call` can no longer check the state of the Rollup / L1Sequencer (TODO P4-11). +- **Guarantees that exist:** every step exited successfully; `s11_verify_deploy` checked that every deployed contract has code; `s32` checked that the owner of the L1Sequencer equals the deployer. +- **Suggestion:** do the sampling of P4-11 after the real deployment; or start another fork that **stays up** and rehearse P5 to P7 on it (see below). + +### I-014 `tendermint testnet --n` is the number of **non-validators**, not the total - fixed + +- **Symptom:** `tendermint testnet --v 1 --n 2 --hostname ... --hostname ...` fails with `testnet needs precisely 3 hostnames (number of validators plus non-validators)`. +- **Cause:** the number of hostnames is `--v` + `--n`. Upstream uses `--v 1 --n 5` with 6 hostnames; I took `--n` for the total. +- **Handling:** changed to `--v 1 --n 1` (1 validator node0 + 1 non-validator node1). +- **Verification:** `scripts/setup-nodes.py` was run in `run/nodes-test/` with the genesis files left by the dry run: the genesis block hash `be3cbc..5540f9` produced by both geth initialisations equals the L2 genesis hash in the `rollup.json` of the dry run; the node0 configuration has rpc/p2p/abci 26657/26656/26658, prometheus 26660, `block_sync=true`, `pex=false`, `persistent_peers=""`; node1 has no validator key; the validator public key in the genesis matches the `priv_validator_key` of node0. +- **Note:** `run/nodes-test/` is only a test product (it uses the L1 starting point of the dry run) and **cannot** be used for a real run; for a real run use `--run-dir run/l2` and the `genesis-l2.json` produced by the real deployment. + +### I-015 the default metrics ports of three processes collide - separated in morph-native.sh + +| Process | Default | Collides with | Handling | +|---|---|---|---| +| gas-oracle | `GAS_ORACLE_METRIC_ADDRESS` defaults to `0.0.0.0:6060` | metrics 6060 of morph-el-0 | set to `127.0.0.1:6070` | +| morphnode (node-1, layer1 verify mode) | `MORPH_NODE_METRICS_PORT` defaults to 26660 | the Tendermint prometheus 26660 of node-0 | set `MORPH_NODE_METRICS_SERVER_ENABLE=true`, `MORPH_NODE_METRICS_PORT=27660` | +| tx-submitter | metrics off by default (also off in compose) | - | enabled with `TX_SUBMITTER_METRICS_PORT=8060` for easier observation | + +### I-016 `scripts/morph-native.sh` is written and tested without side effects + +- **Tested:** syntax, usage without arguments, `status` (with no processes), `up` refusing before a deployment, an unknown process name, reading the contract addresses from the deployment file of the dry run. +- **Not tested:** really starting the processes. Reason: another devnet on this machine still holds 8545 and 8551 (the `el-0 :8545` in `status` read the height of another chain, which confirms the collision). It has to wait until that one is stopped and the L1 deployment is done before it can be verified end to end. + +### I-017 the deployer becomes the user's own account + +- **Background:** the user supplied their own deployer private key (not recorded here), which holds 36 ETH on Hoodi. +- **Warned:** it is better that a private key does not pass through the conversation. The user still gave it in the conversation, so that key is in the conversation record. It is a testnet account; **from now on treat it as "exposed"**, do not use it to hold real assets and do not reuse it on mainnet. +- **Handling:** written to `env/secrets.env` with mode 600; checked that the derived address equals the given address; replaced the old deployer address everywhere (4 places in `hoodidev.ts` and 8 in `hoodidev-deploy-config.json`) with the new one, staged again and exported the patch. 0 private keys in the patch. +- **Effect:** the owner of every contract is this account of the user. The previously generated account `0x0129…1A2c` never received any coins and is retired. +- **1 ETH is sent from the deployer to the submitter** as running funds for batch submission (`SUBMITTER_FUND_ETH=1`). + +### I-018 first real deployment fails: "not readable right after it was mined" on the public RPC - hardened, rerun + +- **Symptom:** the first contract (ProxyAdmin) of the deployment on real Hoodi was mined (transaction `0xbbcab7c1…`), but the following `owner()` call returned empty data (`CALL_EXCEPTION, data="0x"`) and the deployment script exited. The same scripts work perfectly on the anvil fork. +- **Check:** querying again right after the failure, the contract has code (2059 bytes) and `owner()` is the deployer - the contract is fine, the read request was just too early. +- **Cause (partly verified):** for each contract the deployment code does `await contract.deployed()` and immediately `assertContractVariable(...)` to read state. Several nodes sit behind a public RPC, and the node that confirmed the block may differ from the one that handles the next read. I observed that the block height of `0xrpc.io` jumps between two adjacent values (consistent with this model); ethpandaops was very stable in my 30 quick probes, so **this mechanism is an inference, not a direct proof of that one failure**. +- **Handling:** in `contracts/src/deploy-utils.ts` the two assertion functions (51 call sites) get a retry that is **off by default**: `MORPH_READ_RETRIES` (default 0 = as before), `MORPH_READ_RETRY_DELAY_MS` (default 2000). `deploy-l1.sh` sets 15 retries, 2 seconds apart, by default. A failed read or a value mismatch is retried, the result of the last attempt is thrown unchanged, so the assertion still reports the real problem. +- **Side effect:** the failed run left an orphan contract `0x2637…EEF45` (ProxyAdmin) and the deployer nonce is 1. The rerun deploys a whole new set; the orphan can be ignored and cost only a few cents of testnet coins. +- **Limit:** only the reads inside the assertion functions are covered. The `register` step has a few other reads (such as `registered()`); if the same problem shows up there, it needs the same treatment. + +### I-019 second real deployment fails + switch to a consistency proxy at the request layer - rerun + +- **Symptom:** after adding the assertion retries the run failed at another place, `console.log(await IProxyContract.admin())` at `deploy/013-DeployProxys.ts:27/227` (a debug print). 9 transactions had been sent by then (up to `Proxy__L1GatewayRouter`). It is a second read point of the same root cause; later steps such as `register` have more read points, and patching them one by one is not a way. +- **Handling:** I wrote `scripts/rpc-consistency-proxy.js` (about 100 lines, no dependencies) and put it between hardhat / the genesis tool / cast and the public RPC: + 1. it remembers "the highest block seen so far" (from receipts and `eth_blockNumber`), called the floor; + 2. it rewrites every state read on `latest` / `pending` to that concrete floor block number; + 3. when the upstream has not caught up yet, it waits and retries (every 500 ms, at most 30 seconds); + 4. write transactions, requests with an explicit block number and all other methods pass through unchanged. +- **A detail that only verification revealed:** this upstream does **not return an error for a block it has not caught up with, it returns `result: null`** (`eth_call`, `getBalance`, `getCode`, `getTransactionCount`, `getStorageAt` and `getBlockByNumber` all do; only `eth_estimateGas` reports `header not found`). My first version only recognised error text, which means it fixed nothing. Now a `null` result of a rewritten read is also treated as "not caught up yet". +- **Verification:** (1) pass-through, rewriting, a monotonically increasing `eth_blockNumber` and batch requests all work; (2) with a test hook making the proxy believe it had seen head+2: `owner()` was held for 17 seconds (21 retries) and then returned the correct deployer address, later reads took 276 ms; (3) requests with an explicit block number return at once and are not affected. +- **Wiring:** `deploy-l1.sh` enables it by default for an `https://` RPC (`USE_CONSISTENCY_PROXY=auto`), not for a local anvil; the proxy is stopped automatically on exit. +- **Limit:** it was written for the behaviour we measured (`null` / `header not found`). With another upstream the "not caught up" behaviour may differ; the proxy only guarantees monotonic reads and not correctness across a reorg, which is enough for a devnet deployment. +- **Leftover:** the first two failures left about 10 orphan transactions (a few orphan contracts); the deployer balance is 35.99 ETH, the effect is negligible. + +### I-020 third real deployment fails: the upstream returns `rate-limit exceeded` - the proxy gets backoff and fallback endpoints + +- **Symptom:** after about 100 seconds of progress through the consistency proxy, an `eth_call` (`admin()`) got `ProviderError: rate-limit exceeded`, which ethers throws as `CALL_EXCEPTION`, and the deployment exited. The proxy log shows not a single read retry, so this was not read inconsistency but rate limiting. +- **Investigation:** with plain `curl`, 150 requests each of `eth_blockNumber`, `eth_call`, `eth_estimateGas`, `eth_getTransactionCount`, `eth_getTransactionReceipt` and `eth_getBlockByNumber`, plus 150 `eth_blockNumber` on each of the other two endpoints, in a row: **none was rate limited**. So the limit is not triggered steadily by "the number of sustained requests" or "one method"; it looks more like a **momentary limit** of the public service (a shared quota). This is an inference, with no direct proof for that one occurrence. +- **Handling:** the proxy now has: + 1. on rate limiting (HTTP 429/503, or an error message containing rate limit / too many requests / quota / exceeded) and on network errors it **switches to the next upstream at once**; when every upstream refuses it backs off exponentially 0.5 -> 1 -> 2 -> 4 -> 8 seconds, at most 8 rounds; + 2. support for fallback upstreams (comma separated); `deploy-l1.sh` uses `0xrpc.io` and `publicnode` as fallbacks by default; + 3. `/stats` counts requests per method, rate-limit hits and failovers, so the traffic makes up can be seen later. +- **Verification (with a local fake upstream):** (A) the primary is rate limited all the time and the fallback is real Hoodi: the failover completes in 332 ms and returns the correct chain id and balance; (B) a single upstream that is limited for the first 3 requests and then recovers: backoff 0.5+1+2 seconds, success after 3568 ms in total. +- **Risk:** the block headers of several upstreams may be slightly ahead of or behind each other. Reads are pinned to a concrete block number by the floor, a lagging node returns null and is retried, so this risk is covered; a sent transaction may go to any upstream, and the receipt is polled by the client, so it is eventually consistent. +- **Leftover:** the three failures left about 20 orphan transactions in total; the deployer balance is 35.98 ETH, about 0.017 ETH was spent. + +### I-021 fourth real deployment hangs in `initialize`: the floor of the consistency proxy is frozen - a bug of the proxy, fixed + +- **Symptom:** `s10_deploy` (deployment) passed at once, `s11`, `s20` (genesis) and `s21` also passed, then `s30_initialize` hung for more than 18 minutes at "Upgrading the L1CrossDomainMessenger proxy...". The process used almost no CPU; in the proxy statistics `rateLimited=0`, `retries=0`, `eth_sendRawTransaction` stood at 38 while `eth_call` and `eth_chainId` slowly increased. +- **Root cause (reproduced by a self-test):** `deploy/015-MessengerInit.ts` sends an `upgradeToAndCall` transaction **without waiting for the receipt** and then polls `implementation()` every 3 seconds until it becomes the new address. My proxy pins reads on `latest` to the floor, and the floor is only updated when the client calls `eth_blockNumber` or gets a receipt - neither happens here, so the floor froze at the block **before** the upgrade transaction and the polling read the old state forever. **This is a bug of the proxy I wrote, not a problem of the RPC or the chain.** +- **Fix:** + 1. before handling a rewritten read, ask the upstream for its latest height at most once per second and update the floor (`PROXY_HEAD_REFRESH_MS`, default 1000); + 2. the `pending` nonce is handled separately: take the maximum of "the upstream pending", "the count at the floor block" and "the next nonce of the transactions the proxy itself has seen being sent", so that a transaction that was sent but not mined is not missed and a nonce is not reused; + 3. a new optional throttle `PROXY_MIN_INTERVAL_MS` (default 0 = off), for the need of "sleep between requests when rate limited". +- **Verification:** `scripts/rpc-consistency-proxy.selftest.js` reproduces the bug with a fake chain that produces a block per second: with refreshing off the polling still read the old value after 12 seconds (FAIL); with it on the new value was read 3 seconds after the chain passed the changing block. All four checks pass (the floor follows the chain, the pending nonce, the latest nonce is not polluted, explicit block numbers pass through). +- **About adding sleeps:** the proxy statistics of the fourth run show `rateLimited=0` and `failovers=0`, so **rate limiting was not triggered** and no sleep between contract deployments was needed this time. If rate limiting is triggered later, turn on `PROXY_MIN_INTERVAL_MS` (for example 300); the deployment code does not need to change. +- **Cleanup:** the directory of the hung run stays in `run/l1-attempt4-stuck/`. The contracts it had deployed and the upgrade transaction stay on the chain as orphans; since `initialize` deploys the implementation contracts again and the genesis file embeds the contract addresses, it cannot be continued in place, so the whole set is redone. +- **Another observation:** the deployer balance went from 35.98 ETH to 68.93 ETH in the meantime (not sent by me); it looks as if someone sent more coins. + +### I-022 `cast send` does not read `ETH_PRIVATE_KEY`, and the step runner swallows errors - `setFirstSequencer` was once not sent, fixed and checked + +- **Symptom:** `s33_fund_submitter` reports `Error accessing local wallet`; tracing it showed that `s32_first_sequencer` had **failed the same way** but was marked "ok" within 0 seconds. On the chain `getSequencer()` was still `no sequencer configured`. +- **Root cause 1:** the `cast send` of this cast version (Foundry 1.9.0) does not read the environment variable `ETH_PRIVATE_KEY` (earlier I had only tested it with `cast wallet address` and wrongly generalised the result to `cast send`). +- **Root cause 2:** `step()` calls the step function as `if ! "${fn}" ...`. In the context of an `if` condition bash **turns `set -e` off**, so a command failing in the middle of the function does not abort it and only the status of the last command decides; the last command of `s32` is an `echo`, so it "succeeded". +- **Fix:** (1) a new `scripts/send-tx.js` sends transactions with ethers, and the private key only comes in through the environment variable `KEY`, never on the command line; (2) `step()` becomes `set +e; ( set -e; fn ) ...; rc=$?; set -e`, so errexit really works inside a step; (3) `s32` and `s33` **read the result back from the chain** inside the step before they count as successful. +- **Lesson:** exit codes alone cannot be trusted. When a hardhat task goes wrong it often prints one line and then `return`s with exit code 0. So a new `scripts/verify-l1.sh` ignores the step exit codes completely and compares the on-chain state with the expectation. +- **Result:** after the fix the continued run succeeded for `s32`, `s33` and `s40`; `verify-l1.sh` has **53 passed, 0 failed** (owners and mutual references of Rollup/Messenger/MessageQueue/Submitter/L1Sequencer, the L2 chain id and genesis batch of the Rollup, the submitter's registration and stake, implementation and admin of all 21 proxies, the first sequencer). +- **Cleanup:** the wrong `s32` marker is kept as `run/l1/state/s32_first_sequencer.done.WRONG-nothing-was-sent`. + +### I-023 the deployer balance rose by about 32 ETH again + +- During the deployment the deployer balance went from 68.93 ETH to 100.87 ETH (the "spent" in the summary of `deploy-l1.sh` shows a negative number because it uses the balance recorded before the first attempt). It was not sent by me; presumably you sent more coins. Recorded only. + +### I-024 port 6060 is taken by the Coder workspace agent - the morph-geth metrics move to 6160/6161 + +- **Symptom:** while checking the ports Morph needs, 6060 was held by the workspace's own agent, which must not be touched. So the geth metrics ports start at 6160. +- **Handling:** in `morph-native.sh` the metrics ports of morph-geth changed from 6060/6061 to 6160/6161; the port table in section 6 of the PLAN was changed to match. +- **Reminder:** 6060 is also geth's default metrics port, so every geth-like process started on this machine has to avoid 6060. + +### I-025 the oracle key is not allowed to update the GasPriceOracle - in the upstream devnet owner and oracle are the same account, we split them + +- **Symptom (found before starting the oracle):** in the L2 genesis `gasPriceOracleOwner` is the user's deployer, while the oracle process uses the separately generated `L2_GAS_ORACLE_PRIVATE_KEY`. On the chain `GasPriceOracle.owner()` is the deployer, the oracle key has `isAllowed=false` and an L2 balance of 0. All update functions (`setL1BaseFee...`) are `onlyAllowed` (owner or allow list). +- **Cause:** in the upstream devnet `gasPriceOracleOwner` and `L2_GAS_ORACLE_PRIVATE_KEY` are the same Anvil #0 account, so nobody noticed this coupling. +- **Handling:** `scripts/l2-bootstrap.sh`: with the development account that the L2 genesis pre-funds (the public Anvil #0 account, used only on this local private L2 that listens on 127.0.0.1) it sends 100 ETH to the deployer and 10 ETH to the oracle, and then the deployer calls `setAllowList([oracle],[true])` and reads back `isAllowed=true`. +- **Result:** the oracle's first update then succeeded (L2 transaction `0x7fa3…`). + +### I-026 node-1 scans L1 at only 1 to 2 blocks every 15 seconds + +- **Symptom:** in the log of node-1 (layer1 verify mode), 1 to 2 L1 blocks are fetched every 15 seconds (`derivation start pull rollupData form l1 startBlock=… end=…`). Hoodi has a block every 12 seconds, about 1.25 blocks per 15 seconds, and it handles 1 to 2 blocks per round, so the margin to catch up is small. +- **Effect:** the batch was at L1 block 4043361 and node-1 at 4043352; it took about 2 minutes to catch up and rebuild the blocks. Correctness is not affected, but **the rebuild delay depends on the L1 block time and on this polling rhythm**; it is not real time. +- **Not done:** the polling interval or range parameters were not tuned (the corresponding flag is not confirmed). If a lower rebuild delay is needed, this is the place to tune. + +### I-027 the first L1 to L2 deposit fails: the L1 message was included but failed to execute on the L2 (status 0) + +- **Symptom:** first run of `scripts/deposit-test.sh`: the L1 deposit transaction succeeded in Hoodi block 4043381 (status 1, gas 241464), the message was queued (`L1MessageQueue.nextCrossDomainMessageIndex = 1`). But the balance of the fresh receiving address `0x50d3…831b` on the L2 stayed 0 for 10 minutes and the script timed out. +- **Investigation:** + 1. the node-0 log only has 2 lines `failed to fetch L1 messages … block range extends beyond current head block` (see the item that hardened the proxy after I-026), which looked like a read problem; + 2. but the node-0 metrics `morphnode_syncer_message_count = 1` and `morphnode_executor_next_l1_message_queue_index = 1` show that the message **was read and included in a block**; + 3. scanning all L2 blocks found the only transaction of type `0x7e` (L1 message), in **L2 block 342**: `to` is the L2CrossDomainMessenger (`0x5300…0007`), `gas` 110000, **receipt status 0**, `gasUsed` 108798, 0 logs, calling `relayMessage`. +- **Conclusion (an inference, to be verified by the second deposit):** I reused `_gasLimit = 110000` from the repository's example task `deposit-l1-eth`; on this set of contracts the whole call chain of `relayMessage` fails after using 98.9% of the gas, so it is mostly **not enough gas**. **It is not that the L1 message was not delivered, and not that the L2 did not include it.** +- **The 0.01 ETH of the first deposit:** it is locked in the L1 gateway and did not arrive on the L2. It is testnet coin. The L1 Messenger of Morph has `replayMessage` (replay with more gas); no replay was done this time. +- **Another lesson (mine):** I had piped the deposit script into `| cut`, so the output was buffered until the script ended and I could see no progress during the 10 minutes of waiting; it now writes to a file directly. +- **Effect on the plan:** the default gas limit of `deposit-test.sh` is now 400000 and can be overridden with `GAS_LIMIT`. The result of the second deposit is in the next item. + +#### I-027 conclusion (second deposit, gas limit 400000) - confirmed + +- 0.01 ETH was deposited to the new address `0xA2ac…6357` in Hoodi block 4043433 (L1 gas 224386). **It arrived on node-0 after about 25 seconds**; **on node-1 after 391 seconds** (it has to wait until the batch 4 containing that L2 block is committed to L1 and then rebuild it from the blob). +- So the first failure really was an **insufficient `_gasLimit = 110000`**, not a problem of the path or the configuration. The 110000 of the repository's example task cannot be used on this deployment; give deposits at least a few hundred thousand. +- Afterwards all blocks that node-1 had (0 to 796) were compared with node-0 hash by hash: **0 differences**. The range contains both block 342 (with the failed L1 message transaction) and the block of the successful deposit, which shows that on both paths what node-1 rebuilds agrees with node-0. +- **Not done:** the `replayMessage` replay of the 0.01 ETH of the first failed deposit (testnet coin, small amount). + +### I-028 after a restart the block producer node-0 never produces blocks again - a topology with a single Tendermint node cannot be restarted (restart test T5 fails) + +- **Symptom:** T5 of `scripts/restart-test.sh` (stop node-0 for 15 seconds, start it again): the process is running, the RPC answers, the log has no error, but the L2 height is frozen (7675) and **the chain has stopped**. The block hashes from before the restart are unchanged (T5b passes, no fork). +- **Log signature (the same as the "silent stall" described in Morph's `ops/README.md`):** `ABCI Handshake height=7675` -> `Reactor waitSync=true` -> `Already upgraded to sequencer mode, consensus reactor will not start height=3 upgradeHeight=2` -> the last line is `derivation skipped: sequencer mode`, **and then no output at all**; the block production routine was not started. +- **Root cause (confirmed in the code, not guessed):** + 1. the block production routine is only started with `StartSequencerRoutines()` in `blocksync/reactor.go` after `if bcR.pool.IsCaughtUp()` (no configuration can get around it); + 2. the first line of `IsCaughtUp()` in `blocksync/pool.go` is `if len(pool.peers) == 0 { return false }` ("Need at least 1 peer to be considered caught up"); + 3. in our topology node-0 is the **only** node running Tendermint (node-1 is in layer1 verify mode and does not start Tendermint), `persistent_peers` is empty, and the pool has no peer. + 4. The first start can produce blocks because it starts from height 0 and the single validator first runs the PBFT phase and upgrades into block production mode, which does not take this path; **after a restart the height is already beyond the upgrade height, the block pool has to be used, and so it hangs.** +- **This is an inherent limit of this topology, not introduced by running natively:** item 3 of the prerequisites in Morph's `ops/README.md` says "at least two nodes running Tendermint are needed, a node in layer1 verify mode does not count", and the single-sequencer topology of the upstream docker setup (node-0 + layer1 node-1) should have the same limit. **I have not verified this on the docker version; this sentence is inferred from the code.** +- **Handling:** a new `scripts/add-node2.py` adds a standard full node **node-2 (with morph-el-2, without a block production key)** to the existing run directory; it runs Tendermint and is the peer that always exists in the block pool of node-0; the `persistent_peers` of node-0 gets node-2. **node-1 stays unchanged**, because I do not want to lose its verification of "rebuilding independently from the L1 blob". Ports: Tendermint of node-2 26666/26667/26670, morph-el-2 8745/8746/8751/30305/6162. +- **A previous conclusion needs correcting:** when I reported "main line verification done" before, restart recovery was not included, which was exactly the item then listed under "not verified"; it is now proven that it really has a problem. + +#### I-028 conclusion (full restart test rerun after adding node-2) + +- `scripts/restart-test.sh` (T1 to T6, T8): **19 checks all pass, 0 fail**: + - T1 `kill -9` node-1: it is started again by the supervisor shell within 5 seconds, continues rebuilding, the tip hash agrees; + - T2 / T3 restart morph-el-1 / node-1: it continues rebuilding, the hashes agree; + - T4 stop the L1 proxy for 20 seconds: L1 sync recovers, node-0 did not stop, no process exited; + - **T5 restart the block producer node-0: block production resumes within 24 seconds (it used to stall forever), the block hashes from before the restart are unchanged, no fork;** + - T6 restart morph-el-0: node-0 resumes block production; + - T8 down and up everything: the height continues from 8196 (not from 0), the history block hashes are unchanged, every process is running, the tip hash of node-1 agrees. +- The 7563 block hashes that the three nodes already had were compared one by one during the recovery, 0 differences: that stall caused no fork. +- A text in the test script ("all 7 processes") became outdated after node-2 was added; the check itself uses the complete process list, and the text was changed. +- T7 (restart tx-submitter and wait for the next batch) was run separately, see the next item. + +### Verification record: L2 to L1 withdrawal (P7-5) passes + +- `scripts/withdraw-test.sh`: a 0.005 ETH withdrawal was initiated in L2 block 8341 (leaf index 0, `from` is the ETH gateway on the L2, `to` is the ETH gateway on L1); 343 seconds later the L1 Rollup lists the withdrawal root containing it; a sparse Merkle tree of depth 32 was rebuilt locally from all `AppendMessage` events of the L2, and **the rebuilt root agrees with the one on the chain**; L1 `proveAndRelayMessage` (block 4044651, status 1, gas 167527) emitted `RelayedMessage`; the balance of the new L1 receiving address went from 0.0 to 0.005 ETH. +- Offline self-test of the proof algorithm (`scripts/withdraw-proof.selftest.js`): it copies the contract's `_appendMessageHash` / `getTreeRoot` / `verifyMerkleProof` line by line, and all 210 cases (1 to 20 leaves x every index) agree. +- Only **one** withdrawal was verified (the tree holds a single leaf). With several withdrawals the siblings of a proof contain real leaves; the algorithm is covered by the offline self-test, but several withdrawals were not tried on the chain yet. + +--- + +## 2026-11-27 (added with the challenger and the address changes of the pull request) + +### I-029 node-2 is built from the genesis of `run/l1` whatever `L1_RUN` says - the whole L2 stops producing blocks + +- **Symptom:** with a second deployment in another directory (`run/l1-v2` next to the old `run/l1`), the new L2 stopped after about 220 blocks and the committed batch index stayed at 1. All processes were `running`; the node-0 log showed `Error reconnecting to peer ... connection refused` (dialling node-2), the node-2 log `NewL2Block failed ... wrong parent hash`, and the height of el-2 stayed at 0. +- **Cause:** `add-node2.py` read the L2 genesis from `/../l1/genesis/genesis-l2.json`. node-0 and node-1 were initialised from `L1_RUN` (correct), node-2 from `run/l1` (the old deployment). The block 0 hashes differ (`0x6d00d673…` on el-0, `0x4e07ce7e…` on el-2), so node-2 rejects every block; node-0 then has no Tendermint peer, which is I-028. +- **Fix:** `add-node2.py` takes an optional `--genesis`; `morph-native.sh setup` passes `"${L1_RUN}/genesis/genesis-l2.json"`. Without the flag the old default is kept. +- **How to recognise it:** `cast block 0 --field hash` on 8545 and 8745 must be equal; the node-2 log must not contain `wrong parent hash`. +- **Handling of the live environment:** `down`, move the wrong `nodes/node2` and `el2` to `run/archive/node2-wrong-genesis-