Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get standard wasm root from mainnet #41

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions examples/verify-rollup/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,3 @@ export const WASMModuleRoots = [
'0xf559b6d4fa869472dabce70fe1c15221bdda837533dfd891916836975b434dec', // consensus-v10.3
'0xf4389b835497a910d7ba3ebfb77aa93da985634f3c052de1290360635be40c4a', // consensus-v11
];

export const currentMainnetWasmModuleRootIndex = WASMModuleRoots.indexOf(
'0x6b94a7fc388fd8ef3def759297828dc311761e88d8179c7ee8d3887dc554f3c3',
);
64 changes: 44 additions & 20 deletions examples/verify-rollup/src/partial-handlers/rollup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RollupCore__factory } from '@arbitrum/sdk/dist/lib/abi/factories/RollupCore__factory';
import { Ownable__factory } from '@arbitrum/sdk/dist/lib/abi/factories/Ownable__factory';
import { getL2Network } from '@arbitrum/sdk';
import { OrbitHandler } from '../lib/client';
import { Abi, AbiEventItem, RollupInformationFromRollupCreatedEvent } from '../lib/types';
import {
Expand All @@ -13,7 +14,9 @@ import {
} from '../lib/utils';
import { zeroAddress } from 'viem';
import { SequencerInbox__factory } from '@arbitrum/sdk/dist/lib/abi/factories/SequencerInbox__factory';
import { currentMainnetWasmModuleRootIndex, WASMModuleRoots } from '../lib/constants';
import { WASMModuleRoots } from '../lib/constants';
import { createPublicClient, http } from 'viem';
import { mainnet, arbitrum } from 'viem/chains';

// Constants
const minConfirmPeriodBlocks = 45818;
Expand Down Expand Up @@ -472,31 +475,52 @@ export const rollupHandler = async (
// STF verification
//

// get the wasmModuleRoot of the given orbit chain
const moduleRoot = (await orbitHandler.readContract(
'parent',
rollupAddress,
[...RollupCore__factory.abi, ...Ownable__factory.abi] as Abi,
'wasmModuleRoot',
)) as `0x${string}`;
const parentChainPublicClient = createPublicClient({
chain: mainnet,
transport: http(),
});

const l2Network = await getL2Network(arbitrum.id);

// get the wasmModuleRoot of arb1
const mainnetModuleRoot = (await parentChainPublicClient.readContract({
address: l2Network.ethBridge.rollup as `0x${string}`,
abi: RollupCore__factory.abi,
functionName: 'wasmModuleRoot',
})) as `0x${string}`;

const index = WASMModuleRoots.indexOf(moduleRoot);
let currentMainnetWasmModuleRootIndex = WASMModuleRoots.indexOf(mainnetModuleRoot);

if (currentMainnetWasmModuleRootIndex === -1) {
console.log('This script version is old, need to update wasm module lsit');
} else {
// get the wasmModuleRoot of the given orbit chain
const moduleRoot = (await orbitHandler.readContract(
'parent',
rollupAddress,
[...RollupCore__factory.abi, ...Ownable__factory.abi] as Abi,
'wasmModuleRoot',
)) as `0x${string}`;

// check if this wasmModuleRoot belongs to one of mainnet version
if (0 <= index) {
console.log('The state transition function is standard version');
// check if the rollups' arbos version is latest or not
if (index < currentMainnetWasmModuleRootIndex) {
const index = WASMModuleRoots.indexOf(moduleRoot);

// check if this wasmModuleRoot belongs to one of mainnet version
if (0 <= index) {
console.log('The state transition function is standard version');
// check if the rollups' arbos version is latest or not
if (index < currentMainnetWasmModuleRootIndex) {
warningMessages.push(
`Arbos version is old, Rollup wasmModuleRoot is ${moduleRoot}. Latest standard wasmModuleRoot is ${WASMModuleRoots[currentMainnetWasmModuleRootIndex]}.`,
);
}
} else {
console.log('The state transition function is not standard version');
warningMessages.push(
`Arbos version is old, Rollup wasmModuleRoot is ${moduleRoot}. Latest standard wasmModuleRoot is ${WASMModuleRoots[currentMainnetWasmModuleRootIndex]}.`,
`The node is using a customized state transition function, the wasmModule root is ${moduleRoot}`,
);
}
} else {
console.log('The state transition function is not standard version');
warningMessages.push(
`The node is using a customized state transition function, the wasmModule root is ${moduleRoot}`,
);
}

console.log('');

return warningMessages;
Expand Down