Commit 92e86c9d authored by refcell's avatar refcell

feat(op-challenger): load local context in the alphabet trace provider

get step data method.
parent 73ef726b
...@@ -7,8 +7,11 @@ import ( ...@@ -7,8 +7,11 @@ import (
"math/big" "math/big"
"strings" "strings"
preimage "github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum-optimism/optimism/cannon/mipsevm" "github.com/ethereum-optimism/optimism/cannon/mipsevm"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
) )
...@@ -50,7 +53,12 @@ func (ap *AlphabetTraceProvider) GetStepData(ctx context.Context, i types.Positi ...@@ -50,7 +53,12 @@ func (ap *AlphabetTraceProvider) GetStepData(ctx context.Context, i types.Positi
if traceIndex.Cmp(big.NewInt(int64(len(ap.state)))) >= 0 { if traceIndex.Cmp(big.NewInt(int64(len(ap.state)))) >= 0 {
return ap.GetStepData(ctx, types.NewPosition(int(ap.depth), big.NewInt(int64(len(ap.state))))) return ap.GetStepData(ctx, types.NewPosition(int(ap.depth), big.NewInt(int64(len(ap.state)))))
} }
return BuildAlphabetPreimage(traceIndex, ap.state[traceIndex.Uint64()]), []byte{}, nil, nil key := preimage.LocalIndexKey(4).PreimageKey()
// For alphabet output bisection, the state is the local context - that is, the
// pre-state l2 block number. So we can just use [ap.state] as the localContext.
localContext := common.HexToHash(strings.Join(ap.state, ""))
localContextData := types.NewPreimageOracleData(localContext, key[:], nil, 0)
return BuildAlphabetPreimage(traceIndex, ap.state[traceIndex.Uint64()]), []byte{}, localContextData, nil
} }
// Get returns the claim value at the given index in the trace. // Get returns the claim value at the given index in the trace.
......
...@@ -5,7 +5,10 @@ import ( ...@@ -5,7 +5,10 @@ import (
"math/big" "math/big"
"testing" "testing"
preimage "github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types" "github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
...@@ -58,7 +61,10 @@ func TestGetStepData_Succeeds(t *testing.T) { ...@@ -58,7 +61,10 @@ func TestGetStepData_Succeeds(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, expected, retrieved) require.Equal(t, expected, retrieved)
require.Empty(t, proof) require.Empty(t, proof)
require.Nil(t, data) localContext := common.HexToHash("abc")
key := preimage.LocalIndexKey(4).PreimageKey()
expectedLocalContextData := types.NewPreimageOracleData(localContext, key[:], nil, 0)
require.Equal(t, expectedLocalContextData, data)
} }
// TestGetPreimage_TooLargeIndex_Fails tests the GetPreimage // TestGetPreimage_TooLargeIndex_Fails tests the GetPreimage
......
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