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
5d0c3b3e
Commit
5d0c3b3e
authored
Sep 25, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Localized positions
parent
181c74a3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
11 deletions
+29
-11
provider.go
op-challenger/game/fault/trace/split/provider.go
+11
-4
provider_test.go
op-challenger/game/fault/trace/split/provider_test.go
+9
-7
position.go
op-challenger/game/fault/types/position.go
+9
-0
No files found.
op-challenger/game/fault/trace/split/provider.go
View file @
5d0c3b3e
...
...
@@ -35,13 +35,17 @@ func NewTraceProvider(logger log.Logger, providers []types.TraceProvider, depthT
}
}
func
(
s
*
SplitTraceProvider
)
providerForDepth
(
depth
uint64
)
types
.
TraceProvider
{
func
(
s
*
SplitTraceProvider
)
providerForDepth
(
depth
uint64
)
(
uint64
,
types
.
TraceProvider
)
{
reduced
:=
uint64
(
0
)
for
i
,
tier
:=
range
s
.
depthTiers
{
if
depth
<=
tier
{
return
s
.
providers
[
i
]
return
reduced
,
s
.
providers
[
i
]
}
if
i
<
len
(
s
.
providers
)
-
1
{
reduced
+=
tier
}
}
return
s
.
providers
[
len
(
s
.
providers
)
-
1
]
return
reduced
,
s
.
providers
[
len
(
s
.
providers
)
-
1
]
}
// Get routes the Get request to the internal [types.TraceProvider] that
...
...
@@ -50,7 +54,10 @@ func (s *SplitTraceProvider) Get(ctx context.Context, pos types.Position) (commo
if
len
(
s
.
providers
)
==
0
{
return
common
.
Hash
{},
NoProvidersErr
}
return
s
.
providerForDepth
(
uint64
(
pos
.
Depth
()))
.
Get
(
ctx
,
pos
.
TraceIndex
(
pos
.
Depth
()))
reduced
,
provider
:=
s
.
providerForDepth
(
uint64
(
pos
.
Depth
()))
localizedPosition
:=
pos
.
Localize
(
reduced
)
// todo(refcell): we should just pass the localized position once `Get` is updated to accept a Position
return
provider
.
Get
(
ctx
,
localizedPosition
.
ToGIndex
())
}
// AbsolutePreStateCommitment returns the absolute prestate from the lowest internal [types.TraceProvider]
...
...
op-challenger/game/fault/trace/split/provider_test.go
View file @
5d0c3b3e
...
...
@@ -2,7 +2,7 @@ package split
import
(
"context"
"
fmt
"
"
errors
"
"testing"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
...
...
@@ -14,7 +14,7 @@ import (
)
var
(
mockGetError
=
fmt
.
Errorf
(
"mock get error"
)
mockGetError
=
errors
.
New
(
"mock get error"
)
mockOutput
=
common
.
HexToHash
(
"0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
)
mockCommitment
=
common
.
HexToHash
(
"0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
)
)
...
...
@@ -38,9 +38,10 @@ func TestGet(t *testing.T) {
providers
:
[]
types
.
TraceProvider
{
&
mockOutputProvider
},
depthTiers
:
[]
uint64
{
40
,
20
},
}
output
,
err
:=
splitProvider
.
Get
(
context
.
Background
(),
types
.
NewPosition
(
1
,
0
))
output
,
err
:=
splitProvider
.
Get
(
context
.
Background
(),
types
.
NewPosition
(
6
,
3
))
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
mockOutput
,
output
)
expectedGIndex
:=
types
.
NewPosition
(
6
,
3
)
.
ToGIndex
()
require
.
Equal
(
t
,
common
.
BytesToHash
([]
byte
{
byte
(
expectedGIndex
)}),
output
)
})
t
.
Run
(
"ReturnsCorrectOutputWithMultipleProviders"
,
func
(
t
*
testing
.
T
)
{
...
...
@@ -51,9 +52,10 @@ func TestGet(t *testing.T) {
providers
:
[]
types
.
TraceProvider
{
&
firstOutputProvider
,
&
secondOutputProvider
},
depthTiers
:
[]
uint64
{
40
,
20
},
}
output
,
err
:=
splitProvider
.
Get
(
context
.
Background
(),
types
.
NewPosition
(
4
1
,
0
))
output
,
err
:=
splitProvider
.
Get
(
context
.
Background
(),
types
.
NewPosition
(
4
2
,
17
))
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
mockOutput
,
output
)
expectedGIndex
:=
types
.
NewPosition
(
2
,
1
)
.
ToGIndex
()
require
.
Equal
(
t
,
common
.
BytesToHash
([]
byte
{
byte
(
expectedGIndex
)}),
output
)
})
}
...
...
@@ -121,7 +123,7 @@ func (m *mockTraceProvider) Get(ctx context.Context, i uint64) (common.Hash, err
if
m
.
getError
!=
nil
{
return
common
.
Hash
{},
m
.
getError
}
return
m
.
getOutput
,
nil
return
common
.
BytesToHash
([]
byte
{
byte
(
i
)})
,
nil
}
func
(
m
*
mockTraceProvider
)
AbsolutePreStateCommitment
(
ctx
context
.
Context
)
(
hash
common
.
Hash
,
err
error
)
{
...
...
op-challenger/game/fault/types/position.go
View file @
5d0c3b3e
...
...
@@ -25,6 +25,15 @@ func (p Position) MoveRight() Position {
}
}
// Localize returns a new position for a subtree.
// reduced is the number of levels to reduce the depth by.
func
(
p
Position
)
Localize
(
reduced
uint64
)
Position
{
newPosDepth
:=
uint64
(
p
.
depth
)
-
reduced
nodesAtDepth
:=
1
<<
newPosDepth
newIndexAtDepth
:=
p
.
indexAtDepth
%
nodesAtDepth
return
NewPosition
(
int
(
newPosDepth
),
newIndexAtDepth
)
}
func
(
p
Position
)
Depth
()
int
{
return
p
.
depth
}
...
...
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