Commit cfc7d895 authored by Andreas Bigger's avatar Andreas Bigger

Use the bindings output proposal wrapper.

parent 31dae9ec
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-node/eth" "github.com/ethereum-optimism/optimism/op-node/eth"
) )
...@@ -23,15 +24,8 @@ var ( ...@@ -23,15 +24,8 @@ var (
ErrInvalidOutputTopicLength = errors.New("invalid output log topic length") ErrInvalidOutputTopicLength = errors.New("invalid output log topic length")
) )
// OutputProposal is a proposal for an output root
// in the L2OutputOracle for a given L2 block number.
type OutputProposal struct {
L2BlockNumber *big.Int
OutputRoot eth.Bytes32
}
// ParseOutputLog parses a log from the L2OutputOracle contract. // ParseOutputLog parses a log from the L2OutputOracle contract.
func (c *Challenger) ParseOutputLog(log *types.Log) (*OutputProposal, error) { func (c *Challenger) ParseOutputLog(log *types.Log) (*bindings.TypesOutputProposal, error) {
// Check the length of log topics // Check the length of log topics
if len(log.Topics) != 4 { if len(log.Topics) != 4 {
return nil, ErrInvalidOutputTopicLength return nil, ErrInvalidOutputTopicLength
...@@ -42,7 +36,7 @@ func (c *Challenger) ParseOutputLog(log *types.Log) (*OutputProposal, error) { ...@@ -42,7 +36,7 @@ func (c *Challenger) ParseOutputLog(log *types.Log) (*OutputProposal, error) {
} }
l2BlockNumber := new(big.Int).SetBytes(log.Topics[3][:]) l2BlockNumber := new(big.Int).SetBytes(log.Topics[3][:])
expected := log.Topics[1] expected := log.Topics[1]
return &OutputProposal{ return &bindings.TypesOutputProposal{
L2BlockNumber: l2BlockNumber, L2BlockNumber: l2BlockNumber,
OutputRoot: eth.Bytes32(expected), OutputRoot: eth.Bytes32(expected),
}, nil }, nil
...@@ -50,7 +44,7 @@ func (c *Challenger) ParseOutputLog(log *types.Log) (*OutputProposal, error) { ...@@ -50,7 +44,7 @@ func (c *Challenger) ParseOutputLog(log *types.Log) (*OutputProposal, error) {
// ValidateOutput checks that a given output is expected via a trusted rollup node rpc. // ValidateOutput checks that a given output is expected via a trusted rollup node rpc.
// It returns: if the output is correct, the fetched output, error // It returns: if the output is correct, the fetched output, error
func (c *Challenger) ValidateOutput(ctx context.Context, proposal OutputProposal) (bool, eth.Bytes32, error) { func (c *Challenger) ValidateOutput(ctx context.Context, proposal bindings.TypesOutputProposal) (bool, eth.Bytes32, error) {
// Fetch the output from the rollup node // Fetch the output from the rollup node
ctx, cancel := context.WithTimeout(ctx, c.networkTimeout) ctx, cancel := context.WithTimeout(ctx, c.networkTimeout)
defer cancel() defer cancel()
...@@ -70,7 +64,7 @@ func (c *Challenger) ValidateOutput(ctx context.Context, proposal OutputProposal ...@@ -70,7 +64,7 @@ func (c *Challenger) ValidateOutput(ctx context.Context, proposal OutputProposal
} }
// compareOutputRoots compares the output root of the given block number to the expected output root. // compareOutputRoots compares the output root of the given block number to the expected output root.
func (c *Challenger) compareOutputRoots(received *eth.OutputResponse, expected OutputProposal) (bool, error) { func (c *Challenger) compareOutputRoots(received *eth.OutputResponse, expected bindings.TypesOutputProposal) (bool, error) {
if received.Version != supportedL2OutputVersion { if received.Version != supportedL2OutputVersion {
c.log.Error("Unsupported l2 output version", "version", received.Version) c.log.Error("Unsupported l2 output version", "version", received.Version)
return false, ErrUnsupportedL2OOVersion return false, ErrUnsupportedL2OOVersion
......
...@@ -31,7 +31,7 @@ func TestChallenger_OutputProposed_Signature(t *testing.T) { ...@@ -31,7 +31,7 @@ func TestChallenger_OutputProposed_Signature(t *testing.T) {
func TestParseOutputLog_Succeeds(t *testing.T) { func TestParseOutputLog_Succeeds(t *testing.T) {
challenger := newTestChallenger(t, eth.OutputResponse{}, true) challenger := newTestChallenger(t, eth.OutputResponse{}, true)
expectedBlockNumber := big.NewInt(0x04) expectedBlockNumber := big.NewInt(0x04)
expectedOutputRoot := eth.Bytes32{0x02} expectedOutputRoot := [32]byte{0x02}
logTopic := challenger.l2ooABI.Events["OutputProposed"].ID logTopic := challenger.l2ooABI.Events["OutputProposed"].ID
log := types.Log{ log := types.Log{
Topics: []common.Hash{logTopic, common.Hash(expectedOutputRoot), {0x03}, common.BigToHash(expectedBlockNumber)}, Topics: []common.Hash{logTopic, common.Hash(expectedOutputRoot), {0x03}, common.BigToHash(expectedBlockNumber)},
...@@ -68,7 +68,7 @@ func TestChallenger_ValidateOutput_RollupClientErrors(t *testing.T) { ...@@ -68,7 +68,7 @@ func TestChallenger_ValidateOutput_RollupClientErrors(t *testing.T) {
challenger := newTestChallenger(t, output, true) challenger := newTestChallenger(t, output, true)
checked := OutputProposal{ checked := bindings.TypesOutputProposal{
L2BlockNumber: big.NewInt(0), L2BlockNumber: big.NewInt(0),
OutputRoot: output.OutputRoot, OutputRoot: output.OutputRoot,
} }
...@@ -87,7 +87,7 @@ func TestChallenger_ValidateOutput_ErrorsWithWrongVersion(t *testing.T) { ...@@ -87,7 +87,7 @@ func TestChallenger_ValidateOutput_ErrorsWithWrongVersion(t *testing.T) {
challenger := newTestChallenger(t, output, false) challenger := newTestChallenger(t, output, false)
checked := OutputProposal{ checked := bindings.TypesOutputProposal{
L2BlockNumber: big.NewInt(0), L2BlockNumber: big.NewInt(0),
OutputRoot: output.OutputRoot, OutputRoot: output.OutputRoot,
} }
...@@ -106,7 +106,7 @@ func TestChallenger_ValidateOutput_ErrorsInvalidBlockNumber(t *testing.T) { ...@@ -106,7 +106,7 @@ func TestChallenger_ValidateOutput_ErrorsInvalidBlockNumber(t *testing.T) {
challenger := newTestChallenger(t, output, false) challenger := newTestChallenger(t, output, false)
checked := OutputProposal{ checked := bindings.TypesOutputProposal{
L2BlockNumber: big.NewInt(1), L2BlockNumber: big.NewInt(1),
OutputRoot: output.OutputRoot, OutputRoot: output.OutputRoot,
} }
...@@ -125,7 +125,7 @@ func TestOutput_ValidateOutput(t *testing.T) { ...@@ -125,7 +125,7 @@ func TestOutput_ValidateOutput(t *testing.T) {
challenger := newTestChallenger(t, output, false) challenger := newTestChallenger(t, output, false)
checked := OutputProposal{ checked := bindings.TypesOutputProposal{
L2BlockNumber: big.NewInt(0), L2BlockNumber: big.NewInt(0),
OutputRoot: output.OutputRoot, OutputRoot: output.OutputRoot,
} }
...@@ -144,7 +144,7 @@ func TestChallenger_CompareOutputRoots_ErrorsWithDifferentRoots(t *testing.T) { ...@@ -144,7 +144,7 @@ func TestChallenger_CompareOutputRoots_ErrorsWithDifferentRoots(t *testing.T) {
challenger := newTestChallenger(t, output, false) challenger := newTestChallenger(t, output, false)
checked := OutputProposal{ checked := bindings.TypesOutputProposal{
L2BlockNumber: big.NewInt(0), L2BlockNumber: big.NewInt(0),
OutputRoot: output.OutputRoot, OutputRoot: output.OutputRoot,
} }
...@@ -162,7 +162,7 @@ func TestChallenger_CompareOutputRoots_ErrInvalidBlockNumber(t *testing.T) { ...@@ -162,7 +162,7 @@ func TestChallenger_CompareOutputRoots_ErrInvalidBlockNumber(t *testing.T) {
challenger := newTestChallenger(t, output, false) challenger := newTestChallenger(t, output, false)
checked := OutputProposal{ checked := bindings.TypesOutputProposal{
L2BlockNumber: big.NewInt(1), L2BlockNumber: big.NewInt(1),
OutputRoot: output.OutputRoot, OutputRoot: output.OutputRoot,
} }
...@@ -180,7 +180,7 @@ func TestChallenger_CompareOutputRoots_Succeeds(t *testing.T) { ...@@ -180,7 +180,7 @@ func TestChallenger_CompareOutputRoots_Succeeds(t *testing.T) {
challenger := newTestChallenger(t, output, false) challenger := newTestChallenger(t, output, false)
checked := OutputProposal{ checked := bindings.TypesOutputProposal{
L2BlockNumber: big.NewInt(0), L2BlockNumber: big.NewInt(0),
OutputRoot: output.OutputRoot, OutputRoot: output.OutputRoot,
} }
...@@ -188,7 +188,7 @@ func TestChallenger_CompareOutputRoots_Succeeds(t *testing.T) { ...@@ -188,7 +188,7 @@ func TestChallenger_CompareOutputRoots_Succeeds(t *testing.T) {
require.True(t, valid) require.True(t, valid)
require.NoError(t, err) require.NoError(t, err)
checked = OutputProposal{ checked = bindings.TypesOutputProposal{
L2BlockNumber: big.NewInt(0), L2BlockNumber: big.NewInt(0),
OutputRoot: eth.Bytes32{0x01}, OutputRoot: eth.Bytes32{0x01},
} }
......
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