From ecb783bb3833df225720071af948aa8111af0266 Mon Sep 17 00:00:00 2001 From: Makoto Inoue <2630+makoto@users.noreply.github.com> Date: Tue, 17 Oct 2023 17:48:48 +0100 Subject: [PATCH] Add OP gateway worker --- l1-gateway/README.md | 4 +++ l1-gateway/env.example | 6 ++++ op-gateway/README.md | 48 +++++++++++++++++++++++++ op-gateway/src/worker.ts | 7 ++-- op-verifier/README.md | 4 +-- op-verifier/deploy_l1/00_op_verifier.ts | 19 ++++++---- op-verifier/hardhat.config.ts | 38 ++++++++++++++++++-- package.json | 1 - 8 files changed, 114 insertions(+), 13 deletions(-) create mode 100644 l1-gateway/env.example diff --git a/l1-gateway/README.md b/l1-gateway/README.md index af7c503a..04ff4681 100644 --- a/l1-gateway/README.md +++ b/l1-gateway/README.md @@ -43,3 +43,7 @@ PROVIDER_URL=$PROVIDER_URL TARGET_ADDRESS=$TARGET_ADDRESS yarn remote_test - Verifier = [0xA63381212fBf7AA2D0b4a2cAe453f8c361B11d06](https://goerli.etherscan.io/address/0xA63381212fBf7AA2D0b4a2cAe453f8c361B11d06) - TestL1 = [0xD5b1cB24f9BA18C9c35b3D090309E643bC77491e](https://goerli.etherscan.io/address/0xD5b1cB24f9BA18C9c35b3D090309E643bC77491e) - TestL2 = [0x43c0CBb8943E394FaE4C4def054D7702c29c9037](https://goerli.etherscan.io/address/0x43c0CBb8943E394FaE4C4def054D7702c29c9037) + +## Gateway + +- http://l1-gateway-worker.ens-cf.workers.dev diff --git a/l1-gateway/env.example b/l1-gateway/env.example new file mode 100644 index 00000000..2d637064 --- /dev/null +++ b/l1-gateway/env.example @@ -0,0 +1,6 @@ +DEPLOYER_PRIVATE_KEY="" +L1_PROVIDER_URL="" +L2_PROVIDER_URL="" +L1_ETHERSCAN_API_KEY="" +L2_ETHERSCAN_API_KEY="" +L2_OUTPUT_ORACLE="" diff --git a/op-gateway/README.md b/op-gateway/README.md index 7b1a570d..31273532 100644 --- a/op-gateway/README.md +++ b/op-gateway/README.md @@ -1,4 +1,52 @@ # @ensdomains/op-gateway + An instantiation of [evm-gateway](https://github.com/ensdomains/evmgateway/tree/main/evm-gateway) that targets Optimism - that is, it implements a CCIP-Read gateway that generates proofs of contract state on Optimism. For a detailed readme and usage instructions, see the [monorepo readme](https://github.com/ensdomains/evmgateway/tree/main). + +## How to use l1-gateway locally + +``` +cd l1-gateway +yarn +touch .dev.vars +## set L1_PROVIDER_URL, L2_PROVIDER_URL, DELAY=5 +yarn dev +``` + +## How to deploy l1-gateway to cloudflare + +``` +cd l1-gateway +npm install -g wrangler +wrngler login +wrangler secret put L1_PROVIDER_URL +wrangler secret put L2_PROVIDER_URL +wrangler secret put L2_OUTPUT_ORACLE +wrangler secret put DELAY +yarn deploy +``` + +## How to test + +``` +cd ../l1-verifier l1-gateway +PROVIDER_URL=$PROVIDER_URL TARGET_ADDRESS=$TARGET_ADDRESS yarn remote_test +``` + +## Current deployments + +## Deployments + +### Goerli + +- OPVerifier = [0x0c2746F20C9c97DBf718de10c04943cf408230A3](https://goerli.etherscan.io/address/0x0c2746F20C9c97DBf718de10c04943cf408230A3) +- TestL1 = [0x5057276e2BD7750Be043595ac6d21dE31e900c3c](https://goerli.etherscan.io/address/0x5057276e2BD7750Be043595ac6d21dE31e900c3c) + +### OptimismGoerli + +- TestL2 = [0x0FEcD0Fec173807204c7B31e36384acEeB048b0A](https://goerli-optimism.etherscan.io/address/0x0FEcD0Fec173807204c7B31e36384acEeB048b0A) + +## Gateway + +- http://op-gateway-worker.ens-cf.workers.dev diff --git a/op-gateway/src/worker.ts b/op-gateway/src/worker.ts index f41db65b..fcbe144a 100644 --- a/op-gateway/src/worker.ts +++ b/op-gateway/src/worker.ts @@ -2,6 +2,7 @@ import { Server } from '@ensdomains/ccip-read-cf-worker'; interface Env { L1_PROVIDER_URL: string L2_PROVIDER_URL: string + L2_OUTPUT_ORACLE: string DELAY: number } interface Router{ @@ -16,14 +17,16 @@ async function fetch(request:Request, env:Env){ const EVMGateway = (await import('@ensdomains/evm-gateway')).EVMGateway const OPProofService = (await import('./OPProofService.js')).OPProofService; // Set PROVIDER_URL under .dev.vars locally. Set the key as secret remotely with `wrangler secret put WORKER_PROVIDER_URL` - const { L1_PROVIDER_URL, L2_PROVIDER_URL, DELAY } = env; + const { L1_PROVIDER_URL, L2_PROVIDER_URL, L2_OUTPUT_ORACLE, DELAY } = env; const l1Provider = new ethers.JsonRpcProvider(L1_PROVIDER_URL); const l2Provider = new ethers.JsonRpcProvider(L2_PROVIDER_URL); + console.log({L1_PROVIDER_URL, L2_PROVIDER_URL, DELAY}) const proof = new EVMGateway( - await OPProofService.create( + new OPProofService( l1Provider, l2Provider, + L2_OUTPUT_ORACLE, Number(DELAY) ) ); diff --git a/op-verifier/README.md b/op-verifier/README.md index c2ec223d..caa6a4ec 100644 --- a/op-verifier/README.md +++ b/op-verifier/README.md @@ -11,13 +11,13 @@ Start up a devnet by following Optimism's instructions [here](https://community. Then, deploy the L2 contract: ``` -hardhat deploy --network opDevnetL2 +bun run hardhat deploy --network opDevnetL2 ``` Followed by the L1 contract: ``` -hardhat deploy --network opDevnetL1 +bun run hardhat deploy --network opDevnetL1 ``` The L1 contracts contain a reference to the L2 contract, and so will require redeploying if the L2 contract changes. diff --git a/op-verifier/deploy_l1/00_op_verifier.ts b/op-verifier/deploy_l1/00_op_verifier.ts index 2667dfc1..dd31d611 100644 --- a/op-verifier/deploy_l1/00_op_verifier.ts +++ b/op-verifier/deploy_l1/00_op_verifier.ts @@ -3,16 +3,23 @@ import {DeployFunction} from 'hardhat-deploy/types'; import fs from 'fs'; const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { - const {deployments, getNamedAccounts} = hre; + const {deployments, getNamedAccounts, network} = hre; const {deploy} = deployments; - const {deployer} = await getNamedAccounts(); - - const opAddresses = await (await fetch("http://localhost:8080/addresses.json")).json(); - + let L2_OUTPUT_ORACLE_ADDRESS, GATEWAY_URL + console.log('00_op_verifier1') + if(network.name === 'opDevnetL1'){ + GATEWAY_URL = 'http://localhost:8080/{sender}/{data}.json' + const opAddresses = await (await fetch("http://localhost:8080/addresses.json")).json(); + L2_OUTPUT_ORACLE_ADDRESS = opAddresses.L2OutputOracleProxy + }else if('goerli'){ + GATEWAY_URL = 'https://op-gateway-worker.ens-cf.workers.dev/{sender}/{data}.json' + L2_OUTPUT_ORACLE_ADDRESS = '0xE6Dfba0953616Bacab0c9A8ecb3a9BBa77FC15c0' + } + console.log('OPVerifier', [[GATEWAY_URL], L2_OUTPUT_ORACLE_ADDRESS]) await deploy('OPVerifier', { from: deployer, - args: [['test:'], opAddresses.L2OutputOracleProxy], + args: [[GATEWAY_URL], L2_OUTPUT_ORACLE_ADDRESS], log: true, }); }; diff --git a/op-verifier/hardhat.config.ts b/op-verifier/hardhat.config.ts index 9035c195..b46c844e 100644 --- a/op-verifier/hardhat.config.ts +++ b/op-verifier/hardhat.config.ts @@ -2,13 +2,18 @@ import '@nomicfoundation/hardhat-toolbox'; import 'hardhat-deploy'; import 'hardhat-deploy-ethers'; import { HardhatUserConfig } from 'hardhat/config'; +import 'ethers' +const DEPLOYER_PRIVATE_KEY = process.env.DEPLOYER_PRIVATE_KEY ?? "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; +const L1_PROVIDER_URL = process.env.L1_PROVIDER_URL +const L1_ETHERSCAN_API_KEY = process.env.L1_ETHERSCAN_API_KEY; +const L2_ETHERSCAN_API_KEY = process.env.L2_ETHERSCAN_API_KEY; const config: HardhatUserConfig = { solidity: '0.8.19', networks: { opDevnetL1: { url: "http://localhost:8545/", - accounts: ["ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"], + accounts: [DEPLOYER_PRIVATE_KEY], deploy: [ "deploy_l1/" ], companionNetworks: { l2: "opDevnetL2", @@ -16,9 +21,38 @@ const config: HardhatUserConfig = { }, opDevnetL2: { url: "http://localhost:9545/", - accounts: ["ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"], + accounts: [DEPLOYER_PRIVATE_KEY], deploy: [ "deploy_l2/" ], }, + goerli: { + url: L1_PROVIDER_URL, + accounts: [DEPLOYER_PRIVATE_KEY], + deploy: [ "deploy_l1/" ], + companionNetworks: { + l2: "optimismGoerli", + }, + }, + optimismGoerli: { + url: "https://goerli.optimism.io", + accounts: [DEPLOYER_PRIVATE_KEY], + deploy: [ "deploy_l2/" ], + } + }, + etherscan: { + apiKey: { + goerli: L1_ETHERSCAN_API_KEY, + optimismGoerli: L2_ETHERSCAN_API_KEY + }, + customChains: [ + { + network: "optimismGoerli", + chainId: 420, + urls: { + apiURL: "https://api-goerli-optimism.etherscan.io/api", + browserURL: "https://goerli-optimism.etherscan.io" + } + } + ] }, namedAccounts: { 'deployer': 0, diff --git a/package.json b/package.json index ab06afed..6b85f6b4 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,6 @@ "packages": [ "evm-gateway", "l1-gateway", - "l1-gateway-worker", "op-gateway", "evm-verifier", "l1-verifier",