Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
48ad2f56
Commit
48ad2f56
authored
Jun 07, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add logic for parsing output proposed logs.
parent
daaf917b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
0 deletions
+54
-0
output.go
op-challenger/challenger/output.go
+15
-0
output_test.go
op-challenger/challenger/output_test.go
+39
-0
No files found.
op-challenger/challenger/output.go
View file @
48ad2f56
...
...
@@ -5,6 +5,8 @@ import (
"errors"
"math/big"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum-optimism/optimism/op-node/eth"
)
...
...
@@ -15,8 +17,21 @@ var (
ErrInvalidBlockNumber
=
errors
.
New
(
"invalid block number"
)
// ErrUnsupportedL2OOVersion is returned when the output version is not supported.
ErrUnsupportedL2OOVersion
=
errors
.
New
(
"unsupported l2oo version"
)
// ErrInvalidOutputLogTopic is returned when the output log topic is invalid.
ErrInvalidOutputLogTopic
=
errors
.
New
(
"invalid output log topic"
)
)
// ParseOutputLog parses a log from the L2OutputOracle contract.
func
(
c
*
Challenger
)
ParseOutputLog
(
log
*
types
.
Log
)
(
*
big
.
Int
,
eth
.
Bytes32
,
error
)
{
// Validate the first topic is the output log topic
if
log
.
Topics
[
0
]
!=
c
.
l2ooABI
.
Events
[
"OutputProposed"
]
.
ID
{
return
nil
,
eth
.
Bytes32
{},
ErrInvalidOutputLogTopic
}
l2BlockNumber
:=
new
(
big
.
Int
)
.
SetBytes
(
log
.
Topics
[
3
][
:
])
expected
:=
log
.
Topics
[
1
]
return
l2BlockNumber
,
eth
.
Bytes32
(
expected
),
nil
}
// 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
func
(
c
*
Challenger
)
ValidateOutput
(
ctx
context
.
Context
,
l2BlockNumber
*
big
.
Int
,
expected
eth
.
Bytes32
)
(
bool
,
*
eth
.
Bytes32
,
error
)
{
...
...
op-challenger/challenger/output_test.go
View file @
48ad2f56
...
...
@@ -10,13 +10,49 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/metrics"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/testlog"
)
func
TestParseOutputLog_Succeeds
(
t
*
testing
.
T
)
{
challenger
:=
newTestChallenger
(
t
,
eth
.
OutputResponse
{},
true
)
expectedBlockNumber
:=
big
.
NewInt
(
0x04
)
expectedOutputRoot
:=
eth
.
Bytes32
{
0x02
}
logTopic
:=
challenger
.
l2ooABI
.
Events
[
"OutputProposed"
]
.
ID
log
:=
types
.
Log
{
Topics
:
[]
common
.
Hash
{
logTopic
,
common
.
Hash
(
expectedOutputRoot
),
{
0x03
},
common
.
BigToHash
(
expectedBlockNumber
)},
}
parsedBlockNumber
,
parsedOutputRoot
,
err
:=
challenger
.
ParseOutputLog
(
&
log
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
expectedBlockNumber
,
parsedBlockNumber
)
require
.
Equal
(
t
,
expectedOutputRoot
,
parsedOutputRoot
)
}
func
TestParseOutputLog_WrongLogTopic_Errors
(
t
*
testing
.
T
)
{
challenger
:=
newTestChallenger
(
t
,
eth
.
OutputResponse
{},
true
)
_
,
_
,
err
:=
challenger
.
ParseOutputLog
(
&
types
.
Log
{
Topics
:
[]
common
.
Hash
{{
0x01
},
{
0x02
},
{
0x03
},
{
0x04
}},
})
require
.
ErrorIs
(
t
,
err
,
ErrInvalidOutputLogTopic
)
}
func
TestParseOutputLog_BadLog_Panics
(
t
*
testing
.
T
)
{
challenger
:=
newTestChallenger
(
t
,
eth
.
OutputResponse
{},
true
)
logTopic
:=
challenger
.
l2ooABI
.
Events
[
"OutputProposed"
]
.
ID
require
.
Panics
(
t
,
func
()
{
log
:=
types
.
Log
{
Topics
:
[]
common
.
Hash
{
logTopic
,
{
0x02
},
{
0x03
}},
}
_
,
_
,
_
=
challenger
.
ParseOutputLog
(
&
log
)
})
}
func
TestChallenger_ValidateOutput_RollupClientErrors
(
t
*
testing
.
T
)
{
output
:=
eth
.
OutputResponse
{
Version
:
supportedL2OutputVersion
,
...
...
@@ -127,11 +163,14 @@ func newTestChallenger(t *testing.T, output eth.OutputResponse, errors bool) *Ch
outputApi
:=
newMockOutputApi
(
output
,
errors
)
log
:=
testlog
.
Logger
(
t
,
log
.
LvlError
)
metr
:=
metrics
.
NewMetrics
(
"test"
)
parsedL2oo
,
err
:=
bindings
.
L2OutputOracleMetaData
.
GetAbi
()
require
.
NoError
(
t
,
err
)
challenger
:=
Challenger
{
rollupClient
:
outputApi
,
log
:
log
,
metr
:
metr
,
networkTimeout
:
time
.
Duration
(
5
)
*
time
.
Second
,
l2ooABI
:
parsedL2oo
,
}
return
&
challenger
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment