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
cfc7d895
Commit
cfc7d895
authored
Jun 08, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the bindings output proposal wrapper.
parent
31dae9ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
20 deletions
+14
-20
output.go
op-challenger/challenger/output.go
+5
-11
output_test.go
op-challenger/challenger/output_test.go
+9
-9
No files found.
op-challenger/challenger/output.go
View file @
cfc7d895
...
...
@@ -7,6 +7,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-node/eth"
)
...
...
@@ -23,15 +24,8 @@ var (
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.
func
(
c
*
Challenger
)
ParseOutputLog
(
log
*
types
.
Log
)
(
*
OutputProposal
,
error
)
{
func
(
c
*
Challenger
)
ParseOutputLog
(
log
*
types
.
Log
)
(
*
bindings
.
Types
OutputProposal
,
error
)
{
// Check the length of log topics
if
len
(
log
.
Topics
)
!=
4
{
return
nil
,
ErrInvalidOutputTopicLength
...
...
@@ -42,7 +36,7 @@ func (c *Challenger) ParseOutputLog(log *types.Log) (*OutputProposal, error) {
}
l2BlockNumber
:=
new
(
big
.
Int
)
.
SetBytes
(
log
.
Topics
[
3
][
:
])
expected
:=
log
.
Topics
[
1
]
return
&
OutputProposal
{
return
&
bindings
.
Types
OutputProposal
{
L2BlockNumber
:
l2BlockNumber
,
OutputRoot
:
eth
.
Bytes32
(
expected
),
},
nil
...
...
@@ -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.
// 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
.
Types
OutputProposal
)
(
bool
,
eth
.
Bytes32
,
error
)
{
// Fetch the output from the rollup node
ctx
,
cancel
:=
context
.
WithTimeout
(
ctx
,
c
.
networkTimeout
)
defer
cancel
()
...
...
@@ -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.
func
(
c
*
Challenger
)
compareOutputRoots
(
received
*
eth
.
OutputResponse
,
expected
OutputProposal
)
(
bool
,
error
)
{
func
(
c
*
Challenger
)
compareOutputRoots
(
received
*
eth
.
OutputResponse
,
expected
bindings
.
Types
OutputProposal
)
(
bool
,
error
)
{
if
received
.
Version
!=
supportedL2OutputVersion
{
c
.
log
.
Error
(
"Unsupported l2 output version"
,
"version"
,
received
.
Version
)
return
false
,
ErrUnsupportedL2OOVersion
...
...
op-challenger/challenger/output_test.go
View file @
cfc7d895
...
...
@@ -31,7 +31,7 @@ func TestChallenger_OutputProposed_Signature(t *testing.T) {
func
TestParseOutputLog_Succeeds
(
t
*
testing
.
T
)
{
challenger
:=
newTestChallenger
(
t
,
eth
.
OutputResponse
{},
true
)
expectedBlockNumber
:=
big
.
NewInt
(
0x04
)
expectedOutputRoot
:=
eth
.
Bytes32
{
0x02
}
expectedOutputRoot
:=
[
32
]
byte
{
0x02
}
logTopic
:=
challenger
.
l2ooABI
.
Events
[
"OutputProposed"
]
.
ID
log
:=
types
.
Log
{
Topics
:
[]
common
.
Hash
{
logTopic
,
common
.
Hash
(
expectedOutputRoot
),
{
0x03
},
common
.
BigToHash
(
expectedBlockNumber
)},
...
...
@@ -68,7 +68,7 @@ func TestChallenger_ValidateOutput_RollupClientErrors(t *testing.T) {
challenger
:=
newTestChallenger
(
t
,
output
,
true
)
checked
:=
OutputProposal
{
checked
:=
bindings
.
Types
OutputProposal
{
L2BlockNumber
:
big
.
NewInt
(
0
),
OutputRoot
:
output
.
OutputRoot
,
}
...
...
@@ -87,7 +87,7 @@ func TestChallenger_ValidateOutput_ErrorsWithWrongVersion(t *testing.T) {
challenger
:=
newTestChallenger
(
t
,
output
,
false
)
checked
:=
OutputProposal
{
checked
:=
bindings
.
Types
OutputProposal
{
L2BlockNumber
:
big
.
NewInt
(
0
),
OutputRoot
:
output
.
OutputRoot
,
}
...
...
@@ -106,7 +106,7 @@ func TestChallenger_ValidateOutput_ErrorsInvalidBlockNumber(t *testing.T) {
challenger
:=
newTestChallenger
(
t
,
output
,
false
)
checked
:=
OutputProposal
{
checked
:=
bindings
.
Types
OutputProposal
{
L2BlockNumber
:
big
.
NewInt
(
1
),
OutputRoot
:
output
.
OutputRoot
,
}
...
...
@@ -125,7 +125,7 @@ func TestOutput_ValidateOutput(t *testing.T) {
challenger
:=
newTestChallenger
(
t
,
output
,
false
)
checked
:=
OutputProposal
{
checked
:=
bindings
.
Types
OutputProposal
{
L2BlockNumber
:
big
.
NewInt
(
0
),
OutputRoot
:
output
.
OutputRoot
,
}
...
...
@@ -144,7 +144,7 @@ func TestChallenger_CompareOutputRoots_ErrorsWithDifferentRoots(t *testing.T) {
challenger
:=
newTestChallenger
(
t
,
output
,
false
)
checked
:=
OutputProposal
{
checked
:=
bindings
.
Types
OutputProposal
{
L2BlockNumber
:
big
.
NewInt
(
0
),
OutputRoot
:
output
.
OutputRoot
,
}
...
...
@@ -162,7 +162,7 @@ func TestChallenger_CompareOutputRoots_ErrInvalidBlockNumber(t *testing.T) {
challenger
:=
newTestChallenger
(
t
,
output
,
false
)
checked
:=
OutputProposal
{
checked
:=
bindings
.
Types
OutputProposal
{
L2BlockNumber
:
big
.
NewInt
(
1
),
OutputRoot
:
output
.
OutputRoot
,
}
...
...
@@ -180,7 +180,7 @@ func TestChallenger_CompareOutputRoots_Succeeds(t *testing.T) {
challenger
:=
newTestChallenger
(
t
,
output
,
false
)
checked
:=
OutputProposal
{
checked
:=
bindings
.
Types
OutputProposal
{
L2BlockNumber
:
big
.
NewInt
(
0
),
OutputRoot
:
output
.
OutputRoot
,
}
...
...
@@ -188,7 +188,7 @@ func TestChallenger_CompareOutputRoots_Succeeds(t *testing.T) {
require
.
True
(
t
,
valid
)
require
.
NoError
(
t
,
err
)
checked
=
OutputProposal
{
checked
=
bindings
.
Types
OutputProposal
{
L2BlockNumber
:
big
.
NewInt
(
0
),
OutputRoot
:
eth
.
Bytes32
{
0x01
},
}
...
...
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