diff --git a/bun.lockb b/bun.lockb index 7079cf5c..0e9acdd2 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/op-gateway/package.json b/op-gateway/package.json index d6caced4..e5198d99 100644 --- a/op-gateway/package.json +++ b/op-gateway/package.json @@ -57,11 +57,9 @@ "@chainlink/ccip-read-server": "^0.2.1", "@commander-js/extra-typings": "^11.0.0", "@ensdomains/evm-gateway": "^0.1.0", - "@eth-optimism/sdk": "^3.1.4", "@ethereumjs/block": "^5.0.0", "@nomicfoundation/ethereumjs-block": "^5.0.2", "commander": "^11.0.0", - "ethers": "^6.7.1", - "ethers5": "npm:ethers@5" + "ethers": "^6.7.1" } } diff --git a/op-gateway/src/OPProofService.ts b/op-gateway/src/OPProofService.ts index 09c5b5d0..6e54e0f5 100644 --- a/op-gateway/src/OPProofService.ts +++ b/op-gateway/src/OPProofService.ts @@ -1,12 +1,4 @@ -import { AbiCoder, type AddressLike, JsonRpcProvider } from 'ethers'; -import { ethers as ethers5 } from 'ethers5'; - -import { - asL2Provider, - CrossChainMessenger, - type DeepPartial, - type OEContractsLike, -} from '@eth-optimism/sdk'; +import { AbiCoder, type AddressLike, JsonRpcProvider, Contract } from 'ethers'; import { EVMProofHelper, type IProofService } from '@ensdomains/evm-gateway'; import { type JsonRpcBlock } from '@ethereumjs/block'; @@ -15,52 +7,34 @@ export interface OPProvableBlock { l2OutputIndex: number; } +const L2_OUTPUT_ORACLE_ABI = [ + 'function latestOutputIndex() external view returns (uint256)', + 'function getL2Output(uint256 _l2OutputIndex) external view returns (tuple(bytes32 outputRoot, uint128 timestamp, uint128 l2BlockNumber))', +]; + +const L2_TO_L1_MESSAGE_PASSER_ADDRESS = "0x4200000000000000000000000000000000000016"; + /** * The proofService class can be used to calculate proofs for a given target and slot on the Optimism Bedrock network. * It's also capable of proofing long types such as mappings or string by using all included slots in the proof. * */ export class OPProofService implements IProofService { - readonly crossChainMessenger: CrossChainMessenger; - private readonly provider: JsonRpcProvider; + private readonly l2OutputOracle: Contract; + private readonly l2Provider: JsonRpcProvider; private readonly helper: EVMProofHelper; private readonly delay: number; - static async create( - l1ProviderUrl: string, - l2ProviderUrl: string, - delay: number, - contracts?: DeepPartial - ) { - const provider = new JsonRpcProvider(l2ProviderUrl); - const v5l1Provider = new ethers5.providers.StaticJsonRpcProvider( - l1ProviderUrl - ); - const v5l2Provider = new ethers5.providers.StaticJsonRpcProvider( - l2ProviderUrl - ); - const opts: ConstructorParameters[0] = { - l1ChainId: (await v5l1Provider.getNetwork()).chainId, - l2ChainId: (await v5l2Provider.getNetwork()).chainId, - l1SignerOrProvider: v5l1Provider, - l2SignerOrProvider: asL2Provider(v5l2Provider), - }; - if (contracts) { - opts.contracts = contracts; - } - const crossChainMessenger = new CrossChainMessenger(opts); - return new OPProofService(crossChainMessenger, provider, delay); - } - - private constructor( - crossChainMessenger: CrossChainMessenger, - provider: JsonRpcProvider, + constructor( + l1Provider: JsonRpcProvider, + l2Provider: JsonRpcProvider, + l2OutputOracleAddress: string, delay: number ) { - this.crossChainMessenger = crossChainMessenger; - this.provider = provider; - this.helper = new EVMProofHelper(provider); + this.l2Provider = l2Provider; + this.helper = new EVMProofHelper(l2Provider); this.delay = delay; + this.l2OutputOracle = new Contract(l2OutputOracleAddress, L2_OUTPUT_ORACLE_ABI, l1Provider); } /** @@ -72,9 +46,9 @@ export class OPProofService implements IProofService { * We go a few batches backwards to avoid errors like delays between nodes * */ - const l2OutputIndex = ( - await this.crossChainMessenger.contracts.l1.L2OutputOracle.latestOutputIndex() - ).sub(this.delay); + const l2OutputIndex = + Number(await this.l2OutputOracle.latestOutputIndex()) - this.delay; + /** * struct OutputProposal { @@ -84,13 +58,13 @@ export class OPProofService implements IProofService { * } */ const outputProposal = - await this.crossChainMessenger.contracts.l1.L2OutputOracle.getL2Output( + await this.l2OutputOracle.getL2Output( l2OutputIndex ); return { - number: outputProposal.l2BlockNumber.toNumber(), - l2OutputIndex: l2OutputIndex.toNumber(), + number: outputProposal.l2BlockNumber, + l2OutputIndex: l2OutputIndex, }; } @@ -123,7 +97,7 @@ export class OPProofService implements IProofService { slots: bigint[] ): Promise { const proof = await this.helper.getProofs(block.number, address, slots); - const rpcBlock: JsonRpcBlock = await this.provider.send( + const rpcBlock: JsonRpcBlock = await this.l2Provider.send( 'eth_getBlockByNumber', ['0x' + block.number.toString(16), false] ); @@ -156,7 +130,7 @@ export class OPProofService implements IProofService { private async getMessagePasserStorageRoot(blockNo: number) { const { stateRoot } = await this.helper.getProofs( blockNo, - this.crossChainMessenger.contracts.l2.BedrockMessagePasser.address, + L2_TO_L1_MESSAGE_PASSER_ADDRESS, [] ); return stateRoot; diff --git a/op-gateway/src/index.ts b/op-gateway/src/index.ts index f3af0253..3cecb639 100644 --- a/op-gateway/src/index.ts +++ b/op-gateway/src/index.ts @@ -1,17 +1,19 @@ import { EVMGateway } from '@ensdomains/evm-gateway'; import { OPProofService, type OPProvableBlock } from './OPProofService.js'; -import type { DeepPartial, OEContractsLike } from '@eth-optimism/sdk'; +import { JsonRpcProvider } from 'ethers'; export type OPGateway = EVMGateway; export async function makeOPGateway( l1providerUrl: string, l2providerUrl: string, - delay: number, - contracts?: DeepPartial + l2OutputOracleAddress: string, + delay: number ): Promise { + const l1Provider = new JsonRpcProvider(l1providerUrl); + const l2Provider = new JsonRpcProvider(l2providerUrl); return new EVMGateway( - await OPProofService.create(l1providerUrl, l2providerUrl, delay, contracts) + await new OPProofService(l1Provider, l2Provider, l2OutputOracleAddress, delay) ); } diff --git a/op-gateway/src/server.ts b/op-gateway/src/server.ts index 98e329b0..07a00ed4 100644 --- a/op-gateway/src/server.ts +++ b/op-gateway/src/server.ts @@ -1,6 +1,7 @@ import { Command } from '@commander-js/extra-typings'; import { EVMGateway } from '@ensdomains/evm-gateway'; import { OPProofService } from './OPProofService.js'; +import { JsonRpcProvider } from 'ethers'; const program = new Command() .option('-p, --port ', 'port to listen on', '8080') @@ -14,6 +15,11 @@ const program = new Command() 'l2 provider url', 'http://localhost:9545/' ) + .option( + '-o --l2-output-oracle
', + 'address for L2 output oracle on the L1', + '' + ) .option('-d, --delay ', 'number of blocks delay to use', '5'); program.parse(); @@ -21,10 +27,14 @@ program.parse(); (async () => { const options = program.opts(); + const l1Provider = new JsonRpcProvider(options.l1ProviderUrl); + const l2Provider = new JsonRpcProvider(options.l2ProviderUrl); + const gateway = new EVMGateway( - await OPProofService.create( - options.l1ProviderUrl, - options.l2ProviderUrl, + new OPProofService( + l1Provider, + l2Provider, + options.l2OutputOracle, Number(options.delay) ) ); diff --git a/op-verifier/test/testOPVerifier.ts b/op-verifier/test/testOPVerifier.ts index 780c20b7..c7b6915d 100644 --- a/op-verifier/test/testOPVerifier.ts +++ b/op-verifier/test/testOPVerifier.ts @@ -8,13 +8,13 @@ import { Provider, ethers as ethersT, FetchRequest, - Signer + Signer, + JsonRpcProvider } from 'ethers'; import express from 'express'; import { ethers } from 'hardhat'; import { EthereumProvider } from 'hardhat/types'; import request from 'supertest'; -import fs from 'fs'; type ethersObj = typeof ethersT & Omit & { @@ -43,18 +43,12 @@ describe('OPVerifier', () => { signer = await provider.getSigner(0); const opAddresses = await (await fetch("http://localhost:8080/addresses.json")).json(); - opAddresses.StateCommitmentChain = '0x0000000000000000000000000000000000000000'; - opAddresses.CanonicalTransactionChain = '0x0000000000000000000000000000000000000000'; - opAddresses.BondManager = '0x0000000000000000000000000000000000000000'; - opAddresses.L2OutputOracle = opAddresses.L2OutputOracleProxy; const server = await makeOPGateway( (hre.network.config as any).url, (hre.config.networks[hre.network.companionNetworks.l2] as any).url, - 5, - { - l1: opAddresses - } + opAddresses.L2OutputOracleProxy, + 5, ); gateway = server.makeApp('/');