From e6c849c22a9b7dfdbaa15546aa55ff0914c41f60 Mon Sep 17 00:00:00 2001 From: Michael de Hoog Date: Thu, 12 Dec 2024 02:29:21 -1000 Subject: [PATCH] Restructure repo (#35) * Move submodules * Move submodules * Move submodules * Move contracts to contracts subdir * Move Dockerfile to op-enclave subdirectory * Fix deployment file * Fix Makefile and tests * Move example * Add README for register-signer * Comment about public key * Add README --- .github/workflows/docker.yml | 2 +- .github/workflows/test.yml | 3 ++ .gitignore | 3 -- .gitmodules | 6 +-- Makefile | 30 ++++++------ README.md | 44 ++++++++++++++++++ contracts/.gitignore | 3 ++ .../84532/run-1733865565.json | 0 .../84532/run-1731373076.json | 0 .../84532/run-1727993682.json | 0 .../84532/run-1733867021.json | 0 .../deploy-config}/example.json | 0 .../deployments}/84532-certmanager.json | 0 .../deployments}/84532-deploy.json | 0 foundry.toml => contracts/foundry.toml | 0 {lib => contracts/lib}/forge-std | 0 {lib => contracts/lib}/nitro-validator | 0 {lib => contracts/lib}/optimism | 0 remappings.txt => contracts/remappings.txt | 0 .../script}/DeployCertManager.s.sol | 0 .../script}/DeployDeployChain.s.sol | 0 .../script}/DeploySystem.s.sol | 0 .../script}/UpgradeSystemConfigGlobal.s.sol | 0 .../script}/UpgradeSystemConfigOwnable.s.sol | 0 {src => contracts/src}/DeployChain.sol | 0 {src => contracts/src}/OutputOracle.sol | 0 {src => contracts/src}/OwnableConfig.sol | 0 {src => contracts/src}/OwnerConfig.sol | 0 {src => contracts/src}/Portal.sol | 0 {src => contracts/src}/ResolvingProxy.sol | 0 .../src}/ResolvingProxyFactory.sol | 0 {src => contracts/src}/SystemConfigGlobal.sol | 2 + .../src}/SystemConfigOwnable.sol | 0 .../test}/ResolvingProxyFactory.t.sol | 0 .../test}/SystemConfigGlobal.t.sol | 0 .../nitro-attestation/sample_attestation.bin | Bin .../nitro-attestation/sample_attestation2.bin | Bin .dockerignore => op-enclave/.dockerignore | 0 Dockerfile => op-enclave/Dockerfile | 10 ++-- {eif => op-enclave/eif}/cmdline-aarch64 | 0 {eif => op-enclave/eif}/cmdline-x86_64 | 0 {eif => op-enclave/eif}/init-ramdisk.yaml | 0 {eif => op-enclave/eif}/user-ramdisk.yaml | 0 op-withdrawer/example/README.md | 3 ++ {example => op-withdrawer/example}/main.go | 0 register-signer/README.md | 29 ++++++++++++ register-signer/main.go | 31 +++--------- 47 files changed, 115 insertions(+), 51 deletions(-) create mode 100644 README.md create mode 100644 contracts/.gitignore rename {broadcast => contracts/broadcast}/DeployCertManager.s.sol/84532/run-1733865565.json (100%) rename {broadcast => contracts/broadcast}/DeployDeployChain.s.sol/84532/run-1731373076.json (100%) rename {broadcast => contracts/broadcast}/DeploySystem.s.sol/84532/run-1727993682.json (100%) rename {broadcast => contracts/broadcast}/DeploySystem.s.sol/84532/run-1733867021.json (100%) rename {deploy-config => contracts/deploy-config}/example.json (100%) rename {deployments => contracts/deployments}/84532-certmanager.json (100%) rename {deployments => contracts/deployments}/84532-deploy.json (100%) rename foundry.toml => contracts/foundry.toml (100%) rename {lib => contracts/lib}/forge-std (100%) rename {lib => contracts/lib}/nitro-validator (100%) rename {lib => contracts/lib}/optimism (100%) rename remappings.txt => contracts/remappings.txt (100%) rename {script => contracts/script}/DeployCertManager.s.sol (100%) rename {script => contracts/script}/DeployDeployChain.s.sol (100%) rename {script => contracts/script}/DeploySystem.s.sol (100%) rename {script => contracts/script}/UpgradeSystemConfigGlobal.s.sol (100%) rename {script => contracts/script}/UpgradeSystemConfigOwnable.s.sol (100%) rename {src => contracts/src}/DeployChain.sol (100%) rename {src => contracts/src}/OutputOracle.sol (100%) rename {src => contracts/src}/OwnableConfig.sol (100%) rename {src => contracts/src}/OwnerConfig.sol (100%) rename {src => contracts/src}/Portal.sol (100%) rename {src => contracts/src}/ResolvingProxy.sol (100%) rename {src => contracts/src}/ResolvingProxyFactory.sol (100%) rename {src => contracts/src}/SystemConfigGlobal.sol (92%) rename {src => contracts/src}/SystemConfigOwnable.sol (100%) rename {test => contracts/test}/ResolvingProxyFactory.t.sol (100%) rename {test => contracts/test}/SystemConfigGlobal.t.sol (100%) rename {test => contracts/test}/nitro-attestation/sample_attestation.bin (100%) rename {test => contracts/test}/nitro-attestation/sample_attestation2.bin (100%) rename .dockerignore => op-enclave/.dockerignore (100%) rename Dockerfile => op-enclave/Dockerfile (88%) rename {eif => op-enclave/eif}/cmdline-aarch64 (100%) rename {eif => op-enclave/eif}/cmdline-x86_64 (100%) rename {eif => op-enclave/eif}/init-ramdisk.yaml (100%) rename {eif => op-enclave/eif}/user-ramdisk.yaml (100%) create mode 100644 op-withdrawer/example/README.md rename {example => op-withdrawer/example}/main.go (100%) create mode 100644 register-signer/README.md diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index a09c2de..0db4bff 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -41,7 +41,7 @@ jobs: - name: Build and push the Docker image uses: docker/build-push-action@v4 with: - context: . + context: op-enclave push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eb62b8e..b0b8c24 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,15 +29,18 @@ jobs: - name: Run Forge fmt run: | + cd contracts forge fmt --check id: fmt - name: Run Forge build run: | + cd contracts forge build --sizes id: build - name: Run Forge tests run: | + cd contracts forge test -vvv id: test diff --git a/.gitignore b/.gitignore index 30bd392..9824a6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ /.idea/ .DS_Store -/out/ -/cache/ /testnet/data/ /testnet/.env -/deployments/*-*-*.json /bin/ diff --git a/.gitmodules b/.gitmodules index c382449..508436d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,9 @@ [submodule "lib/forge-std"] - path = lib/forge-std + path = contracts/lib/forge-std url = https://github.com/foundry-rs/forge-std [submodule "lib/optimism"] - path = lib/optimism + path = contracts/lib/optimism url = https://github.com/ethereum-optimism/optimism [submodule "lib/nitro-validator"] - path = lib/nitro-validator + path = contracts/lib/nitro-validator url = https://github.com/base-org/nitro-validator diff --git a/Makefile b/Makefile index 6152388..2f7ce69 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,10 @@ guard-%: define abigen echo "Generating bindings for $(1)" - cp out/$(1).sol/$(1).$(3).json out/$(1).sol/$(1).json 2>/dev/null || true - jq -r '.bytecode.object' out/$(1).sol/$(1).json > out/$(1).sol/$(1).bin - jq -r '.abi' out/$(1).sol/$(1).json > out/$(1).sol/$(1).abi - abigen --abi out/$(1).sol/$(1).abi --bin out/$(1).sol/$(1).bin --pkg bindings --type $(1) --out bindings/$(2).go + cp contracts/out/$(1).sol/$(1).$(3).json contracts/out/$(1).sol/$(1).json 2>/dev/null || true + jq -r '.bytecode.object' contracts/out/$(1).sol/$(1).json > contracts/out/$(1).sol/$(1).bin + jq -r '.abi' contracts/out/$(1).sol/$(1).json > contracts/out/$(1).sol/$(1).abi + abigen --abi contracts/out/$(1).sol/$(1).abi --bin contracts/out/$(1).sol/$(1).bin --pkg bindings --type $(1) --out bindings/$(2).go endef define verify @@ -17,18 +17,20 @@ define verify name=$$(jq -r --arg address "$$address" '.transactions[] | select((.transactionType=="CREATE" or .transactionType=="CREATE2") and .contractAddress==$$address) | .contractName' $$deploy); \ arguments=$$(jq -r --arg address "$$address" '.transactions[] | select((.transactionType=="CREATE" or .transactionType=="CREATE2") and .contractAddress==$$address) | .arguments // [] | join(" ")' $$deploy); \ namewithoutversion=$${name%.*.*.*}; \ - constructor=$$(jq '.abi[] | select(.type=="constructor")' out/$$namewithoutversion.sol/$$name.json | jq -r '.inputs | map(.type) | join(",")'); \ + constructor=$$(jq '.abi[] | select(.type=="constructor")' contracts/out/$$namewithoutversion.sol/$$name.json | jq -r '.inputs | map(.type) | join(",")'); \ echo; \ echo "Verifying $$namewithoutversion @ $$address using constructor($$constructor) $$arguments"; \ constructor_args=$$(cast abi-encode "constructor($$constructor)" $$arguments); \ - forge verify-contract --compiler-version $$version --watch --verifier-url https://api-sepolia.basescan.org/api --constructor-args $$constructor_args $$address $$namewithoutversion ; \ + cd contracts; \ + forge verify-contract --compiler-version $$version --watch --verifier-url https://api-sepolia.basescan.org/api --constructor-args $$constructor_args $$address $$namewithoutversion; \ + cd ..; \ done endef .PHONY: bindings bindings: go install github.com/ethereum/go-ethereum/cmd/abigen@v1.14.11 - forge build + cd contracts && forge build mkdir -p bindings @$(call abigen,"OutputOracle","output_oracle","0.8.15") @$(call abigen,"Portal","portal","0.8.15") @@ -39,26 +41,26 @@ bindings: .PHONY: deploy-cert-manager deploy-cert-manager: guard-IMPL_SALT guard-DEPLOY_PRIVATE_KEY guard-RPC_URL - @forge script DeployCertManager --rpc-url $(RPC_URL) \ + @cd contracts && forge script DeployCertManager --rpc-url $(RPC_URL) \ --private-key $(DEPLOY_PRIVATE_KEY) --broadcast .PHONY: deploy deploy: guard-IMPL_SALT guard-DEPLOY_CONFIG_PATH guard-DEPLOY_PRIVATE_KEY guard-RPC_URL - @forge script DeploySystem --sig deploy --rpc-url $(RPC_URL) \ + @cd contracts && forge script DeploySystem --sig deploy --rpc-url $(RPC_URL) \ --private-key $(DEPLOY_PRIVATE_KEY) --broadcast .PHONY: deploy-deploy-chain deploy-deploy-chain: guard-IMPL_SALT guard-DEPLOY_PRIVATE_KEY guard-RPC_URL - @forge script DeployDeployChain --rpc-url $(RPC_URL) \ + @cd contracts && forge script DeployDeployChain --rpc-url $(RPC_URL) \ --private-key $(DEPLOY_PRIVATE_KEY) --broadcast .PHONY: testnet testnet: guard-L1_URL guard-DEPLOY_PRIVATE_KEY - DEPLOY_CHAIN_ADDRESS=$${DEPLOY_CHAIN_ADDRESS:-$$(jq -r ".DeployChain" deployments/84532-deploy.json)} \ + DEPLOY_CHAIN_ADDRESS=$${DEPLOY_CHAIN_ADDRESS:-$$(jq -r ".DeployChain" contracts/deployments/84532-deploy.json)} \ go run ./testnet .PHONY: verify verify: - @$(call verify,"broadcast/DeployCertManager.s.sol/84532/run-1733890597.json","0.8.24") - @$(call verify,"broadcast/DeploySystem.s.sol/84532/run-1733867021.json","0.8.15") - @$(call verify,"broadcast/DeployDeployChain.s.sol/84532/run-1733884066.json","0.8.15") + @$(call verify,"contracts/broadcast/DeployCertManager.s.sol/84532/run-1733890597.json","0.8.24") + @$(call verify,"contracts/broadcast/DeploySystem.s.sol/84532/run-1733867021.json","0.8.15") + @$(call verify,"contracts/broadcast/DeployDeployChain.s.sol/84532/run-1733884066.json","0.8.15") diff --git a/README.md b/README.md new file mode 100644 index 0000000..3e33726 --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +# op-enclave + +`op-enclave` is a relatively small modification to the [op-stack](https://github.com/ethereum-optimism/optimism/) +that proofs state transitions in a AWS Nitro Enclave, and submits the resulting state roots to the L1 chain. +This removes the need for the 7-day challenge period, and allows for immediate withdrawals. + +## Directory Structure + +
+├── bindings: Go bindings for various contracts, generated by `make bindings`
+├── contracts: Solidity contracts
+├── op-batcher: Batcher modification that submits batches immediately after withdrawals are detected
+├── op-da: Data availability service for writing to S3 / file system
+├── op-enclave: Stateless transition function, for running in a AWS Nitro TEE
+├── op-proposer: L2-Output Submitter, communicates with op-enclave and submits proposals to L1
+├── op-withdrawer: Withdrawal utility for submitting withdrawals to L1
+├── register-signer: Registers a enclave signer key from a Nitro attestation with the SystemConfigGlobal contract
+├── testnet: Dockerized testnet for running the op-enclave stack
+
+ +## Running a testnet + +1. Deploy the Nitro certificate manager using `make deploy-cert-manager`: +```bash +IMPL_SALT=0 DEPLOY_PRIVATE_KEY= RPC_URL=https://sepolia.base.org make deploy-cert-manager +``` + +2. Deploy the system contracts using `make deploy`: +```bash +IMPL_SALT=0 DEPLOY_PRIVATE_KEY= DEPLOY_CONFIG_PATH=deploy-config/example.json RPC_URL=https://sepolia.base.org make deploy +``` + +3. Generate a testnet genesis block and deploy the proxy contracts for a new chain using `make testnet`: +```bash +DEPLOY_PRIVATE_KEY= L1_URL=https://sepolia.base.org make testnet +``` + +4. Copy `testnet/.env.example` to `testnet/.env` and fill in the environment variables, +in particular the `# per deploy` section at the top. + +5. Run the testnet: +```bash +docker-compose -f testnet/Dockerfile up +``` diff --git a/contracts/.gitignore b/contracts/.gitignore new file mode 100644 index 0000000..de11e6a --- /dev/null +++ b/contracts/.gitignore @@ -0,0 +1,3 @@ +/out/ +/cache/ +/deployments/*-*-*.json diff --git a/broadcast/DeployCertManager.s.sol/84532/run-1733865565.json b/contracts/broadcast/DeployCertManager.s.sol/84532/run-1733865565.json similarity index 100% rename from broadcast/DeployCertManager.s.sol/84532/run-1733865565.json rename to contracts/broadcast/DeployCertManager.s.sol/84532/run-1733865565.json diff --git a/broadcast/DeployDeployChain.s.sol/84532/run-1731373076.json b/contracts/broadcast/DeployDeployChain.s.sol/84532/run-1731373076.json similarity index 100% rename from broadcast/DeployDeployChain.s.sol/84532/run-1731373076.json rename to contracts/broadcast/DeployDeployChain.s.sol/84532/run-1731373076.json diff --git a/broadcast/DeploySystem.s.sol/84532/run-1727993682.json b/contracts/broadcast/DeploySystem.s.sol/84532/run-1727993682.json similarity index 100% rename from broadcast/DeploySystem.s.sol/84532/run-1727993682.json rename to contracts/broadcast/DeploySystem.s.sol/84532/run-1727993682.json diff --git a/broadcast/DeploySystem.s.sol/84532/run-1733867021.json b/contracts/broadcast/DeploySystem.s.sol/84532/run-1733867021.json similarity index 100% rename from broadcast/DeploySystem.s.sol/84532/run-1733867021.json rename to contracts/broadcast/DeploySystem.s.sol/84532/run-1733867021.json diff --git a/deploy-config/example.json b/contracts/deploy-config/example.json similarity index 100% rename from deploy-config/example.json rename to contracts/deploy-config/example.json diff --git a/deployments/84532-certmanager.json b/contracts/deployments/84532-certmanager.json similarity index 100% rename from deployments/84532-certmanager.json rename to contracts/deployments/84532-certmanager.json diff --git a/deployments/84532-deploy.json b/contracts/deployments/84532-deploy.json similarity index 100% rename from deployments/84532-deploy.json rename to contracts/deployments/84532-deploy.json diff --git a/foundry.toml b/contracts/foundry.toml similarity index 100% rename from foundry.toml rename to contracts/foundry.toml diff --git a/lib/forge-std b/contracts/lib/forge-std similarity index 100% rename from lib/forge-std rename to contracts/lib/forge-std diff --git a/lib/nitro-validator b/contracts/lib/nitro-validator similarity index 100% rename from lib/nitro-validator rename to contracts/lib/nitro-validator diff --git a/lib/optimism b/contracts/lib/optimism similarity index 100% rename from lib/optimism rename to contracts/lib/optimism diff --git a/remappings.txt b/contracts/remappings.txt similarity index 100% rename from remappings.txt rename to contracts/remappings.txt diff --git a/script/DeployCertManager.s.sol b/contracts/script/DeployCertManager.s.sol similarity index 100% rename from script/DeployCertManager.s.sol rename to contracts/script/DeployCertManager.s.sol diff --git a/script/DeployDeployChain.s.sol b/contracts/script/DeployDeployChain.s.sol similarity index 100% rename from script/DeployDeployChain.s.sol rename to contracts/script/DeployDeployChain.s.sol diff --git a/script/DeploySystem.s.sol b/contracts/script/DeploySystem.s.sol similarity index 100% rename from script/DeploySystem.s.sol rename to contracts/script/DeploySystem.s.sol diff --git a/script/UpgradeSystemConfigGlobal.s.sol b/contracts/script/UpgradeSystemConfigGlobal.s.sol similarity index 100% rename from script/UpgradeSystemConfigGlobal.s.sol rename to contracts/script/UpgradeSystemConfigGlobal.s.sol diff --git a/script/UpgradeSystemConfigOwnable.s.sol b/contracts/script/UpgradeSystemConfigOwnable.s.sol similarity index 100% rename from script/UpgradeSystemConfigOwnable.s.sol rename to contracts/script/UpgradeSystemConfigOwnable.s.sol diff --git a/src/DeployChain.sol b/contracts/src/DeployChain.sol similarity index 100% rename from src/DeployChain.sol rename to contracts/src/DeployChain.sol diff --git a/src/OutputOracle.sol b/contracts/src/OutputOracle.sol similarity index 100% rename from src/OutputOracle.sol rename to contracts/src/OutputOracle.sol diff --git a/src/OwnableConfig.sol b/contracts/src/OwnableConfig.sol similarity index 100% rename from src/OwnableConfig.sol rename to contracts/src/OwnableConfig.sol diff --git a/src/OwnerConfig.sol b/contracts/src/OwnerConfig.sol similarity index 100% rename from src/OwnerConfig.sol rename to contracts/src/OwnerConfig.sol diff --git a/src/Portal.sol b/contracts/src/Portal.sol similarity index 100% rename from src/Portal.sol rename to contracts/src/Portal.sol diff --git a/src/ResolvingProxy.sol b/contracts/src/ResolvingProxy.sol similarity index 100% rename from src/ResolvingProxy.sol rename to contracts/src/ResolvingProxy.sol diff --git a/src/ResolvingProxyFactory.sol b/contracts/src/ResolvingProxyFactory.sol similarity index 100% rename from src/ResolvingProxyFactory.sol rename to contracts/src/ResolvingProxyFactory.sol diff --git a/src/SystemConfigGlobal.sol b/contracts/src/SystemConfigGlobal.sol similarity index 92% rename from src/SystemConfigGlobal.sol rename to contracts/src/SystemConfigGlobal.sol index 737a99d..01bf099 100644 --- a/src/SystemConfigGlobal.sol +++ b/contracts/src/SystemConfigGlobal.sol @@ -59,6 +59,8 @@ contract SystemConfigGlobal is OwnableUpgradeable, ISemver, NitroValidator { require(ptrs.timestamp + MAX_AGE > block.timestamp, "attestation too old"); + // The publicKey is encoded in the form specified in section 4.3.6 of ANSI X9.62, which is a + // 0x04 byte followed by the x and y coordinates of the public key. We ignore the first byte. bytes32 publicKeyHash = attestationTbs.keccak(ptrs.publicKey.start() + 1, ptrs.publicKey.length() - 1); address enclaveAddress = address(uint160(uint256(publicKeyHash))); validSigners[enclaveAddress] = true; diff --git a/src/SystemConfigOwnable.sol b/contracts/src/SystemConfigOwnable.sol similarity index 100% rename from src/SystemConfigOwnable.sol rename to contracts/src/SystemConfigOwnable.sol diff --git a/test/ResolvingProxyFactory.t.sol b/contracts/test/ResolvingProxyFactory.t.sol similarity index 100% rename from test/ResolvingProxyFactory.t.sol rename to contracts/test/ResolvingProxyFactory.t.sol diff --git a/test/SystemConfigGlobal.t.sol b/contracts/test/SystemConfigGlobal.t.sol similarity index 100% rename from test/SystemConfigGlobal.t.sol rename to contracts/test/SystemConfigGlobal.t.sol diff --git a/test/nitro-attestation/sample_attestation.bin b/contracts/test/nitro-attestation/sample_attestation.bin similarity index 100% rename from test/nitro-attestation/sample_attestation.bin rename to contracts/test/nitro-attestation/sample_attestation.bin diff --git a/test/nitro-attestation/sample_attestation2.bin b/contracts/test/nitro-attestation/sample_attestation2.bin similarity index 100% rename from test/nitro-attestation/sample_attestation2.bin rename to contracts/test/nitro-attestation/sample_attestation2.bin diff --git a/.dockerignore b/op-enclave/.dockerignore similarity index 100% rename from .dockerignore rename to op-enclave/.dockerignore diff --git a/Dockerfile b/op-enclave/Dockerfile similarity index 88% rename from Dockerfile rename to op-enclave/Dockerfile index 9483c32..26bdb23 100644 --- a/Dockerfile +++ b/op-enclave/Dockerfile @@ -10,14 +10,14 @@ RUN go install github.com/linuxkit/linuxkit/src/cmd/linuxkit@270fd1c5aa1986977b3 WORKDIR /build RUN mkdir -p /build -COPY op-enclave/go.mod op-enclave/go.sum op-enclave/ -RUN cd op-enclave && go mod download +COPY go.mod go.sum ./ +RUN go mod download -COPY op-enclave/ op-enclave/ +COPY . . -RUN cd op-enclave && CGO_ENABLED=0 go build -o ../bin/enclave ./cmd/enclave +RUN CGO_ENABLED=0 go build -o bin/enclave ./cmd/enclave -COPY eif/ eif/ +COPY eif eif/ COPY --from=bootstrap /build/out bootstrap RUN linuxkit build --format kernel+initrd --no-sbom --name init-ramdisk ./eif/init-ramdisk.yaml RUN linuxkit build --format kernel+initrd --no-sbom --name user-ramdisk ./eif/user-ramdisk.yaml diff --git a/eif/cmdline-aarch64 b/op-enclave/eif/cmdline-aarch64 similarity index 100% rename from eif/cmdline-aarch64 rename to op-enclave/eif/cmdline-aarch64 diff --git a/eif/cmdline-x86_64 b/op-enclave/eif/cmdline-x86_64 similarity index 100% rename from eif/cmdline-x86_64 rename to op-enclave/eif/cmdline-x86_64 diff --git a/eif/init-ramdisk.yaml b/op-enclave/eif/init-ramdisk.yaml similarity index 100% rename from eif/init-ramdisk.yaml rename to op-enclave/eif/init-ramdisk.yaml diff --git a/eif/user-ramdisk.yaml b/op-enclave/eif/user-ramdisk.yaml similarity index 100% rename from eif/user-ramdisk.yaml rename to op-enclave/eif/user-ramdisk.yaml diff --git a/op-withdrawer/example/README.md b/op-withdrawer/example/README.md new file mode 100644 index 0000000..4c85d6e --- /dev/null +++ b/op-withdrawer/example/README.md @@ -0,0 +1,3 @@ +# Deposit + Withdraw example + +This directory contains an example Golang script that demonstrates how to deposit and withdraw funds from a deployed chain. diff --git a/example/main.go b/op-withdrawer/example/main.go similarity index 100% rename from example/main.go rename to op-withdrawer/example/main.go diff --git a/register-signer/README.md b/register-signer/README.md new file mode 100644 index 0000000..47eecdc --- /dev/null +++ b/register-signer/README.md @@ -0,0 +1,29 @@ +# Signer registration utility + +This utility can be used to register an op-enclave signer key with the +[SystemConfigGlobal](../contracts/src/SystemConfigGlobal.sol) contract. + +## Installation + +``` +go install github.com/base-org/op-enclave/register-signer +``` + +## Usage + +Query an AWS Nitro attestation from op-enclave server: +```bash +curl -d '{"id":0,"jsonrpc":"2.0","method":"enclave_signerAttestation"}' -H "Content-Type: application/json" http://op-enclave:7333 +``` + +``` +Usage of register-signer: + -attestation string + attestation hex + -deployment string + deployment file (default "deployments/84532-deploy.json") + -private-key string + private key + -rpc string + rpc url (default "https://sepolia.base.org") +``` diff --git a/register-signer/main.go b/register-signer/main.go index 12794a1..53c8f6c 100644 --- a/register-signer/main.go +++ b/register-signer/main.go @@ -1,9 +1,7 @@ package main import ( - "bytes" "context" - "encoding/json" "flag" "fmt" "os" @@ -20,22 +18,18 @@ import ( "github.com/hf/nitrite" ) -type deployment struct { - SystemConfigGlobalProxy common.Address `json:"SystemConfigGlobalProxy"` -} - func main() { var attestationHex string var rpcUrl string var privateKeyHex string - var deploymentFile string + var configAddress string flag.StringVar(&attestationHex, "attestation", "", "attestation hex") flag.StringVar(&rpcUrl, "rpc", "https://sepolia.base.org", "rpc url") flag.StringVar(&privateKeyHex, "private-key", "", "private key") - flag.StringVar(&deploymentFile, "deployment", "deployments/84532-deploy.json", "deployment file") + flag.StringVar(&configAddress, "address", "", "address of the SystemConfigGlobal proxy contract") flag.Parse() - if attestationHex == "" || privateKeyHex == "" { + if attestationHex == "" || privateKeyHex == "" || configAddress == "" { flag.Usage() os.Exit(1) } @@ -60,20 +54,6 @@ func main() { panic(err) } - deploy, err := os.ReadFile(deploymentFile) - if err != nil { - panic(err) - } - var d deployment - err = json.Unmarshal(deploy, &d) - if err != nil { - panic(err) - } - - if bytes.Equal(common.Address{}.Bytes(), d.SystemConfigGlobalProxy.Bytes()) { - panic("SystemConfigGlobalProxy address not found in deployment file") - } - key, err := crypto.ToECDSA(privateKey) if err != nil { panic(err) @@ -91,7 +71,7 @@ func main() { }, } - systemConfigGlobal, err := bindings.NewSystemConfigGlobal(d.SystemConfigGlobalProxy, client) + systemConfigGlobal, err := bindings.NewSystemConfigGlobal(common.HexToAddress(configAddress), client) if err != nil { panic(err) } @@ -106,10 +86,11 @@ func main() { panic(err) } fmt.Printf("Public key: %s\n", hexutil.Encode(res.Document.PublicKey)) - fmt.Printf("Signer: %s\n", signerAddr.String()) if validSigner { fmt.Printf("Signer already registered: %s\n", signerAddr.String()) return + } else { + fmt.Printf("Registering signer: %s\n", signerAddr.String()) } certManagerAddr, err := systemConfigGlobal.CertManager(&bind.CallOpts{})