Skip to content

Commit

Permalink
fix: contract bindings (#89)
Browse files Browse the repository at this point in the history
* fix: use correct bindings

* fix

* fix

* fix

---------

Co-authored-by: Ubuntu <[email protected]>
  • Loading branch information
ratankaliani and Ubuntu authored Aug 30, 2024
1 parent 8c86a57 commit 2b5c98c
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/compile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
build_and_run:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/op_proposer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ on:
- main
paths:
- 'op-proposer-go/**'
push:
branches:
- main
paths:
- 'op-proposer-go/**'

jobs:
test_op_proposer_go:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/pr_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ on:
types:
- opened
- edited
push:
branches:
- main

permissions:
pull-requests: read

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:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:

env:
Expand Down
2 changes: 1 addition & 1 deletion contracts/zkconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"startingBlockNumber": 16592800,
"startingBlockNumber": 16621800,
"l2RollupNode": "",
"submissionInterval": 150,
"l2BlockTime": 2,
Expand Down
16 changes: 10 additions & 6 deletions op-proposer-go/proposer/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -84,7 +88,7 @@ type L2OutputSubmitter struct {
l2ooContract L2OOContract
l2ooABI *abi.ABI

dgfContract *bindings.DisputeGameFactoryCaller
dgfContract *opbindings.DisputeGameFactoryCaller
dgfABI *abi.ABI

db db.ProofDB
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
120 changes: 120 additions & 0 deletions op-proposer-go/proposer/proposer_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 2b5c98c

Please sign in to comment.