From 2b5c98cb609d847cc6513fc260c5b395ef11dd8d Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Fri, 30 Aug 2024 13:17:53 -0700 Subject: [PATCH] fix: contract bindings (#89) * fix: use correct bindings * fix * fix * fix --------- Co-authored-by: Ubuntu --- .github/workflows/compile.yaml | 3 + .github/workflows/op_proposer.yaml | 5 + .github/workflows/pr_lint.yml | 8 +- .github/workflows/test.yml | 3 + contracts/zkconfig.json | 2 +- op-proposer-go/proposer/driver.go | 16 +-- op-proposer-go/proposer/proposer_test.go | 120 +++++++++++++++++++++++ 7 files changed, 149 insertions(+), 8 deletions(-) create mode 100644 op-proposer-go/proposer/proposer_test.go diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index f959eef1..44098822 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -4,6 +4,9 @@ on: pull_request: branches: - main + push: + branches: + - main jobs: build_and_run: diff --git a/.github/workflows/op_proposer.yaml b/.github/workflows/op_proposer.yaml index ce539292..e358fe30 100644 --- a/.github/workflows/op_proposer.yaml +++ b/.github/workflows/op_proposer.yaml @@ -6,6 +6,11 @@ on: - main paths: - 'op-proposer-go/**' + push: + branches: + - main + paths: + - 'op-proposer-go/**' jobs: test_op_proposer_go: diff --git a/.github/workflows/pr_lint.yml b/.github/workflows/pr_lint.yml index 72857c67..ef3452ad 100644 --- a/.github/workflows/pr_lint.yml +++ b/.github/workflows/pr_lint.yml @@ -5,6 +5,9 @@ on: types: - opened - edited + push: + branches: + - main permissions: pull-requests: read @@ -12,7 +15,10 @@ permissions: jobs: main: name: Title - runs-on: warp-ubuntu-latest-arm64-4x + runs-on: + - runs-on + - runner=2cpu-linux-x64 + - run-id=${{ github.run_id }} steps: - uses: amannn/action-semantic-pull-request@v5 env: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 07b7d225..2c8417c2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,6 +4,9 @@ on: pull_request: branches: - main + push: + branches: + - main workflow_dispatch: env: diff --git a/contracts/zkconfig.json b/contracts/zkconfig.json index 48e56eb5..26fa0387 100644 --- a/contracts/zkconfig.json +++ b/contracts/zkconfig.json @@ -1,5 +1,5 @@ { - "startingBlockNumber": 16592800, + "startingBlockNumber": 16621800, "l2RollupNode": "", "submissionInterval": 150, "l2BlockTime": 2, diff --git a/op-proposer-go/proposer/driver.go b/op-proposer-go/proposer/driver.go index 9d7d4f3c..d07e8fdd 100644 --- a/op-proposer-go/proposer/driver.go +++ b/op-proposer-go/proposer/driver.go @@ -18,7 +18,11 @@ import ( "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/log" - "github.com/ethereum-optimism/optimism/op-proposer/bindings" + // Original Optimism Bindings + opbindings "github.com/ethereum-optimism/optimism/op-proposer/bindings" + // OP Succinct Contract Bindings + opsuccinctbindings "github.com/succinctlabs/op-succinct-go/bindings" + "github.com/ethereum-optimism/optimism/op-proposer/metrics" "github.com/ethereum-optimism/optimism/op-service/dial" "github.com/ethereum-optimism/optimism/op-service/eth" @@ -84,7 +88,7 @@ type L2OutputSubmitter struct { l2ooContract L2OOContract l2ooABI *abi.ABI - dgfContract *bindings.DisputeGameFactoryCaller + dgfContract *opbindings.DisputeGameFactoryCaller dgfABI *abi.ABI db db.ProofDB @@ -112,7 +116,7 @@ func NewL2OutputSubmitter(setup DriverSetup) (_ *L2OutputSubmitter, err error) { } func newL2OOSubmitter(ctx context.Context, cancel context.CancelFunc, setup DriverSetup) (*L2OutputSubmitter, error) { - l2ooContract, err := bindings.NewL2OutputOracleCaller(*setup.Cfg.L2OutputOracleAddr, setup.L1Client) + l2ooContract, err := opsuccinctbindings.NewZKL2OutputOracleCaller(*setup.Cfg.L2OutputOracleAddr, setup.L1Client) if err != nil { cancel() return nil, fmt.Errorf("failed to create L2OO at address %s: %w", setup.Cfg.L2OutputOracleAddr, err) @@ -127,7 +131,7 @@ func newL2OOSubmitter(ctx context.Context, cancel context.CancelFunc, setup Driv } log.Info("Connected to L2OutputOracle", "address", setup.Cfg.L2OutputOracleAddr, "version", version) - parsed, err := bindings.L2OutputOracleMetaData.GetAbi() + parsed, err := opsuccinctbindings.ZKL2OutputOracleMetaData.GetAbi() if err != nil { cancel() return nil, err @@ -153,7 +157,7 @@ func newL2OOSubmitter(ctx context.Context, cancel context.CancelFunc, setup Driv // Create a new submitter for the DisputeGameFactory. Note: This is unused in OP-Succinct. func newDGFSubmitter(ctx context.Context, cancel context.CancelFunc, setup DriverSetup) (*L2OutputSubmitter, error) { - dgfCaller, err := bindings.NewDisputeGameFactoryCaller(*setup.Cfg.DisputeGameFactoryAddr, setup.L1Client) + dgfCaller, err := opbindings.NewDisputeGameFactoryCaller(*setup.Cfg.DisputeGameFactoryAddr, setup.L1Client) if err != nil { cancel() return nil, fmt.Errorf("failed to create DGF at address %s: %w", setup.Cfg.DisputeGameFactoryAddr, err) @@ -168,7 +172,7 @@ func newDGFSubmitter(ctx context.Context, cancel context.CancelFunc, setup Drive } log.Info("Connected to DisputeGameFactory", "address", setup.Cfg.DisputeGameFactoryAddr, "version", version) - parsed, err := bindings.DisputeGameFactoryMetaData.GetAbi() + parsed, err := opbindings.DisputeGameFactoryMetaData.GetAbi() if err != nil { cancel() return nil, err diff --git a/op-proposer-go/proposer/proposer_test.go b/op-proposer-go/proposer/proposer_test.go new file mode 100644 index 00000000..15e3975d --- /dev/null +++ b/op-proposer-go/proposer/proposer_test.go @@ -0,0 +1,120 @@ +package proposer + +import ( + "context" + "flag" + "fmt" + "math/big" + "os" + "testing" + + opsuccinctbindings "github.com/succinctlabs/op-succinct-go/bindings" + "github.com/ethereum-optimism/optimism/op-proposer/metrics" + opservice "github.com/ethereum-optimism/optimism/op-service" + oplog "github.com/ethereum-optimism/optimism/op-service/log" + "github.com/ethereum-optimism/optimism/op-service/txmgr" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + "github.com/joho/godotenv" + "github.com/succinctlabs/op-succinct-go/proposer/flags" + "github.com/urfave/cli/v2" +) + +// Tests checkpointing a block hash on an L2OO contract. +func TestCheckpointBlockHash(t *testing.T) { + app := cli.NewApp() + app.Flags = flags.Flags + flagSet := flag.NewFlagSet("test", flag.ContinueOnError) + for _, f := range app.Flags { + f.Apply(flagSet) + } + cliCtx := cli.NewContext(app, flagSet, nil) + + err := godotenv.Load("../../.env.server") + if err != nil { + t.Fatalf("Error loading .env file: %v", err) + } + + err = cliCtx.Set(flags.L1EthRpcFlag.Name, os.Getenv("L1_RPC")) + if err != nil { + t.Fatalf("failed to set L1EthRpcFlag: %v", err) + } + err = cliCtx.Set(flags.RollupRpcFlag.Name, os.Getenv("L2_NODE_RPC")) + if err != nil { + t.Fatalf("failed to set RollupRpcFlag: %v", err) + } + err = cliCtx.Set(flags.L2OOAddressFlag.Name, os.Getenv("L2OO_ADDRESS")) + if err != nil { + t.Fatalf("failed to set L2OOAddressFlag: %v", err) + } + err = cliCtx.Set(flags.PollIntervalFlag.Name, os.Getenv("POLL_INTERVAL")) + if err != nil { + t.Fatalf("failed to set PollIntervalFlag: %v", err) + } + err = cliCtx.Set(flags.BeaconRpcFlag.Name, os.Getenv("L1_BEACON_RPC")) + if err != nil { + t.Fatalf("failed to set BeaconRpcFlag: %v", err) + } + err = cliCtx.Set(flags.L2ChainIDFlag.Name, os.Getenv("L2_CHAIN_ID")) + if err != nil { + t.Fatalf("failed to set L2ChainIDFlag: %v", err) + } + err = cliCtx.Set(txmgr.PrivateKeyFlagName, os.Getenv("PRIVATE_KEY")) + if err != nil { + t.Fatalf("failed to set PrivateKeyFlag: %v", err) + } + + if err := flags.CheckRequired(cliCtx); err != nil { + t.Fatalf("failed to check required flags: %v", err) + } + cfg := NewConfig(cliCtx) + if err := cfg.Check(); err != nil { + t.Fatalf("invalid CLI flags: %v", err) + } + + l := oplog.NewLogger(oplog.AppOut(cliCtx), cfg.LogConfig) + oplog.SetGlobalLogHandler(l.Handler()) + opservice.ValidateEnvVars(flags.EnvVarPrefix, flags.Flags, l) + + txMgrConfig := txmgr.ReadCLIConfig(cliCtx) + procName := "default" + metrics := metrics.NewMetrics(procName) + txManager, err := txmgr.NewSimpleTxManager("proposer", l, metrics, txMgrConfig) + if err != nil { + t.Fatalf("failed to create tx manager: %v", err) + } + + l2ooABI, err := opsuccinctbindings.ZKL2OutputOracleMetaData.GetAbi() + if err != nil { + t.Fatalf("failed to get L2OutputOracle ABI: %v", err) + } + + var receipt *types.Receipt + blockNumber := big.NewInt(6601696) + blockHash := common.HexToHash("0x80958d9d5b18f4e189d12ae568576f5bb7d3b132f247bdc0475b9d7d00e638e0") + data, err := l2ooABI.Pack("checkpointBlockHash", blockNumber, blockHash) + if err != nil { + t.Fatalf("failed to pack checkpointBlockHash: %v", err) + } + + ctx := context.Background() + + fmt.Println("txMgr RPC URL:", txMgrConfig.L1RPCURL) + fmt.Println("Private Key:", txMgrConfig.PrivateKey) + + l2OutputOracleAddr := common.HexToAddress("0x7c1bb3c873f3c3f9d895ecafbb06ae3b93948447") + receipt, err = txManager.Send(ctx, txmgr.TxCandidate{ + TxData: data, + To: &l2OutputOracleAddr, + GasLimit: 1000000, + }) + if err != nil { + t.Fatalf("failed to send transaction: %v", err) + } + + if receipt.Status == types.ReceiptStatusFailed { + t.Fatalf("checkpoint blockhash tx successfully published but reverted %v", receipt.TxHash) + } else { + t.Fatalf("checkpoint blockhash tx successfully published %v", receipt.TxHash) + } +}