Commit d2263b19 authored by Adrian Sutton's avatar Adrian Sutton Committed by GitHub

challenger: Load ABIs from the snapshots dir (#10225)

* challenger: Load ABIs from the snapshots dir

Removes dependency on generated bindings

* Move loader to snapshots and convert the remaining challenger contract bindings

* Update tests

* Remove remaining references to bindings package.

* Fix comment
parent dbe5b0ec
......@@ -5,10 +5,10 @@ import (
"fmt"
"math/big"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts/metrics"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum/go-ethereum/common"
)
......@@ -28,7 +28,7 @@ type WithdrawalRequest struct {
}
func NewDelayedWETHContract(metrics metrics.ContractMetricer, addr common.Address, caller *batching.MultiCaller) (*DelayedWETHContract, error) {
contractAbi, err := bindings.DelayedWETHMetaData.GetAbi()
contractAbi, err := snapshots.LoadDelayedWETHABI()
if err != nil {
return nil, fmt.Errorf("failed to load delayed weth ABI: %w", err)
}
......
......@@ -5,11 +5,11 @@ import (
"math/big"
"testing"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
contractMetrics "github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts/metrics"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
batchingTest "github.com/ethereum-optimism/optimism/op-service/sources/batching/test"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
......@@ -42,7 +42,7 @@ func TestDelayedWeth_GetWithdrawals(t *testing.T) {
}
func setupDelayedWethTest(t *testing.T) (*batchingTest.AbiBasedRpc, *DelayedWETHContract) {
delayedWethAbi, err := bindings.DelayedWETHMetaData.GetAbi()
delayedWethAbi, err := snapshots.LoadDelayedWETHABI()
require.NoError(t, err)
stubRpc := batchingTest.NewAbiBasedRpc(t, delayedWeth, delayedWethAbi)
caller := batching.NewMultiCaller(stubRpc, batching.DefaultBatchSize)
......
......@@ -8,13 +8,13 @@ import (
"math/big"
"time"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts/metrics"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
gameTypes "github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum/go-ethereum/common"
)
......@@ -58,7 +58,7 @@ type Proposal struct {
}
func NewFaultDisputeGameContract(metrics metrics.ContractMetricer, addr common.Address, caller *batching.MultiCaller) (*FaultDisputeGameContract, error) {
contractAbi, err := bindings.FaultDisputeGameMetaData.GetAbi()
contractAbi, err := snapshots.LoadFaultDisputeGameABI()
if err != nil {
return nil, fmt.Errorf("failed to load fault dispute game ABI: %w", err)
}
......
......@@ -8,7 +8,6 @@ import (
"testing"
"time"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
contractMetrics "github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts/metrics"
faultTypes "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
......@@ -16,6 +15,7 @@ import (
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
batchingTest "github.com/ethereum-optimism/optimism/op-service/sources/batching/test"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
......@@ -456,12 +456,12 @@ func TestFaultDisputeGame_ClaimCreditTx(t *testing.T) {
}
func setupFaultDisputeGameTest(t *testing.T) (*batchingTest.AbiBasedRpc, *FaultDisputeGameContract) {
fdgAbi, err := bindings.FaultDisputeGameMetaData.GetAbi()
fdgAbi, err := snapshots.LoadFaultDisputeGameABI()
require.NoError(t, err)
vmAbi, err := bindings.MIPSMetaData.GetAbi()
vmAbi, err := snapshots.LoadMIPSABI()
require.NoError(t, err)
oracleAbi, err := bindings.PreimageOracleMetaData.GetAbi()
oracleAbi, err := snapshots.LoadPreimageOracleABI()
require.NoError(t, err)
stubRpc := batchingTest.NewAbiBasedRpc(t, fdgAddr, fdgAbi)
......
......@@ -5,12 +5,12 @@ import (
"fmt"
"math/big"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts/metrics"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum/go-ethereum/common"
)
......@@ -30,7 +30,7 @@ type DisputeGameFactoryContract struct {
}
func NewDisputeGameFactoryContract(m metrics.ContractMetricer, addr common.Address, caller *batching.MultiCaller) (*DisputeGameFactoryContract, error) {
factoryAbi, err := bindings.DisputeGameFactoryMetaData.GetAbi()
factoryAbi, err := snapshots.LoadDisputeGameFactoryABI()
if err != nil {
return nil, fmt.Errorf("failed to load dispute game factory ABI: %w", err)
}
......
......@@ -7,12 +7,12 @@ import (
"slices"
"testing"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts/metrics"
"github.com/ethereum-optimism/optimism/op-challenger/game/types"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
batchingTest "github.com/ethereum-optimism/optimism/op-service/sources/batching/test"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
......@@ -224,7 +224,7 @@ func TestCreateTx(t *testing.T) {
}
func setupDisputeGameFactoryTest(t *testing.T) (*batchingTest.AbiBasedRpc, *DisputeGameFactoryContract) {
fdgAbi, err := bindings.DisputeGameFactoryMetaData.GetAbi()
fdgAbi, err := snapshots.LoadDisputeGameFactoryABI()
require.NoError(t, err)
stubRpc := batchingTest.NewAbiBasedRpc(t, factoryAddr, fdgAbi)
......
......@@ -9,7 +9,6 @@ import (
"math/big"
"sync/atomic"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/merkle"
keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
......@@ -17,6 +16,7 @@ import (
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum/go-ethereum/common"
)
......@@ -48,6 +48,18 @@ var (
ErrUnsupportedKeyType = errors.New("unsupported preimage key type")
)
// preimageOracleLeaf matches the contract representation of a large preimage leaf
type preimageOracleLeaf struct {
Input []byte
Index *big.Int
StateCommitment [32]byte
}
// libKeccakStateMatrix matches the contract representation of a keccak state matrix
type libKeccakStateMatrix struct {
State [25]uint64
}
// PreimageOracleContract is a binding that works with contracts implementing the IPreimageOracle interface
type PreimageOracleContract struct {
addr common.Address
......@@ -62,9 +74,9 @@ type PreimageOracleContract struct {
minBondSizeLPP atomic.Uint64
}
// toPreimageOracleLeaf converts a Leaf to the contract [bindings.PreimageOracleLeaf] type.
func toPreimageOracleLeaf(l keccakTypes.Leaf) bindings.PreimageOracleLeaf {
return bindings.PreimageOracleLeaf{
// toPreimageOracleLeaf converts a Leaf to the contract format.
func toPreimageOracleLeaf(l keccakTypes.Leaf) preimageOracleLeaf {
return preimageOracleLeaf{
Input: l.Input[:],
Index: new(big.Int).SetUint64(l.Index),
StateCommitment: l.StateCommitment,
......@@ -72,7 +84,7 @@ func toPreimageOracleLeaf(l keccakTypes.Leaf) bindings.PreimageOracleLeaf {
}
func NewPreimageOracleContract(addr common.Address, caller *batching.MultiCaller) (*PreimageOracleContract, error) {
oracleAbi, err := bindings.PreimageOracleMetaData.GetAbi()
oracleAbi, err := snapshots.LoadPreimageOracleABI()
if err != nil {
return nil, fmt.Errorf("failed to load preimage oracle ABI: %w", err)
}
......@@ -192,8 +204,8 @@ func (c *PreimageOracleContract) Squeeze(
return call.ToTxCandidate()
}
func abiEncodeSnapshot(packedState keccakTypes.StateSnapshot) bindings.LibKeccakStateMatrix {
return bindings.LibKeccakStateMatrix{State: packedState}
func abiEncodeSnapshot(packedState keccakTypes.StateSnapshot) libKeccakStateMatrix {
return libKeccakStateMatrix{State: packedState}
}
func (c *PreimageOracleContract) GetActivePreimages(ctx context.Context, blockHash common.Hash) ([]keccakTypes.LargePreimageMetaData, error) {
......
......@@ -8,7 +8,6 @@ import (
"math/rand"
"testing"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/merkle"
keccakTypes "github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
......@@ -17,6 +16,7 @@ import (
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
batchingTest "github.com/ethereum-optimism/optimism/op-service/sources/batching/test"
"github.com/ethereum-optimism/optimism/op-service/testutils"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
......@@ -355,7 +355,7 @@ func setupPreimageOracleTestWithProposals(t *testing.T, block rpcblock.Block) (*
}
func setupPreimageOracleTest(t *testing.T) (*batchingTest.AbiBasedRpc, *PreimageOracleContract) {
oracleAbi, err := bindings.PreimageOracleMetaData.GetAbi()
oracleAbi, err := snapshots.LoadPreimageOracleABI()
require.NoError(t, err)
stubRpc := batchingTest.NewAbiBasedRpc(t, oracleAddr, oracleAbi)
......@@ -593,7 +593,7 @@ func TestChallenge_First(t *testing.T) {
stubRpc.SetResponse(oracleAddr, methodChallengeFirstLPP, rpcblock.Latest,
[]interface{}{
ident.Claimant, ident.UUID,
bindings.PreimageOracleLeaf{
preimageOracleLeaf{
Input: challenge.Poststate.Input[:],
Index: new(big.Int).SetUint64(challenge.Poststate.Index),
StateCommitment: challenge.Poststate.StateCommitment,
......@@ -631,14 +631,14 @@ func TestChallenge_NotFirst(t *testing.T) {
stubRpc.SetResponse(oracleAddr, methodChallengeLPP, rpcblock.Latest,
[]interface{}{
ident.Claimant, ident.UUID,
bindings.LibKeccakStateMatrix{State: challenge.StateMatrix},
bindings.PreimageOracleLeaf{
libKeccakStateMatrix{State: challenge.StateMatrix},
preimageOracleLeaf{
Input: challenge.Prestate.Input[:],
Index: new(big.Int).SetUint64(challenge.Prestate.Index),
StateCommitment: challenge.Prestate.StateCommitment,
},
challenge.PrestateProof,
bindings.PreimageOracleLeaf{
preimageOracleLeaf{
Input: challenge.Poststate.Input[:],
Index: new(big.Int).SetUint64(challenge.Poststate.Index),
StateCommitment: challenge.Poststate.StateCommitment,
......
......@@ -4,9 +4,9 @@ import (
"context"
"fmt"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum/go-ethereum/common"
)
......@@ -21,7 +21,7 @@ type VMContract struct {
}
func NewVMContract(addr common.Address, caller *batching.MultiCaller) (*VMContract, error) {
mipsAbi, err := bindings.MIPSMetaData.GetAbi()
mipsAbi, err := snapshots.LoadMIPSABI()
if err != nil {
return nil, fmt.Errorf("failed to load VM ABI: %w", err)
}
......
......@@ -4,18 +4,18 @@ import (
"context"
"testing"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
preimage "github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
batchingTest "github.com/ethereum-optimism/optimism/op-service/sources/batching/test"
"github.com/ethereum-optimism/optimism/packages/contracts-bedrock/snapshots"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)
func TestVMContract_Oracle(t *testing.T) {
vmAbi, err := bindings.MIPSMetaData.GetAbi()
vmAbi, err := snapshots.LoadMIPSABI()
require.NoError(t, err)
stubRpc := batchingTest.NewAbiBasedRpc(t, vmAddr, vmAbi)
......
......@@ -8,6 +8,7 @@
!/op-bootnode
!/op-chain-ops
!/op-challenger
!/packages/contracts-bedrock/snapshots
!/op-dispute-mon
!/op-conductor
!/op-heartbeat
......
#!/usr/bin/env bash
set -euo pipefail
NAME=${1:?Must specify release name}
git describe --tags --candidates=100 --match="${NAME}/*" | sed "s/${NAME}\///"
package snapshots
import (
"embed"
"fmt"
"path/filepath"
"github.com/ethereum/go-ethereum/accounts/abi"
)
//go:embed abi
var abis embed.FS
func LoadDisputeGameFactoryABI() (*abi.ABI, error) {
return loadABI("DisputeGameFactory")
}
func LoadFaultDisputeGameABI() (*abi.ABI, error) {
return loadABI("FaultDisputeGame")
}
func LoadPreimageOracleABI() (*abi.ABI, error) {
return loadABI("PreimageOracle")
}
func LoadMIPSABI() (*abi.ABI, error) {
return loadABI("MIPS")
}
func LoadDelayedWETHABI() (*abi.ABI, error) {
return loadABI("DelayedWETH")
}
func loadABI(name string) (*abi.ABI, error) {
in, err := abis.Open(filepath.Join("abi", name+".json"))
if err != nil {
return nil, fmt.Errorf("failed to load ABI for contract %v: %w", name, err)
}
if parsed, err := abi.JSON(in); err != nil {
return nil, err
} else {
return &parsed, nil
}
}
package snapshots
import (
"testing"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/stretchr/testify/require"
)
func TestLoadABIs(t *testing.T) {
tests := []struct {
contract string
method func() (*abi.ABI, error)
}{
{"DisputeGameFactory", LoadDisputeGameFactoryABI},
{"FaultDisputeGame", LoadFaultDisputeGameABI},
{"PreimageOracle", LoadPreimageOracleABI},
{"MIPS", LoadMIPSABI},
{"DelayedWETH", LoadDelayedWETHABI},
}
for _, test := range tests {
test := test
t.Run(test.contract, func(t *testing.T) {
actual, err := test.method()
require.NoError(t, err)
require.NotNil(t, actual)
})
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment