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
92b5bae6
Unverified
Commit
92b5bae6
authored
Jun 22, 2023
by
mergify[bot]
Committed by
GitHub
Jun 22, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into refcell/first/stylestack
parents
5f1c1478
07b0dc29
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
25 deletions
+26
-25
position.go
op-challenger/fault/cmd/examples/position.go
+6
-6
position.go
op-challenger/fault/position.go
+14
-10
position_test.go
op-challenger/fault/position_test.go
+1
-1
solver.go
op-challenger/fault/solver.go
+5
-8
No files found.
op-challenger/fault/cmd/examples/position.go
View file @
92b5bae6
...
@@ -11,11 +11,11 @@ func PositionExampleOne() {
...
@@ -11,11 +11,11 @@ func PositionExampleOne() {
// go left to d, then right to f, then left to e
// go left to d, then right to f, then left to e
p
:=
fault
.
Position
{}
p
:=
fault
.
Position
{}
p
.
Print
(
3
)
p
.
Print
(
3
)
p
.
Attack
()
p
=
p
.
Attack
()
p
.
Print
(
3
)
p
.
Print
(
3
)
p
.
Defend
()
p
=
p
.
Defend
()
p
.
Print
(
3
)
p
.
Print
(
3
)
p
.
Attack
()
p
=
p
.
Attack
()
p
.
Print
(
3
)
p
.
Print
(
3
)
}
}
...
@@ -26,10 +26,10 @@ func PositionExampleTwo() {
...
@@ -26,10 +26,10 @@ func PositionExampleTwo() {
// go left r, then left to b, then right to q
// go left r, then left to b, then right to q
p
:=
fault
.
Position
{}
p
:=
fault
.
Position
{}
p
.
Print
(
3
)
p
.
Print
(
3
)
p
.
Attack
()
p
=
p
.
Attack
()
p
.
Print
(
3
)
p
.
Print
(
3
)
p
.
Attack
()
p
=
p
.
Attack
()
p
.
Print
(
3
)
p
.
Print
(
3
)
p
.
Defend
()
p
=
p
.
Defend
()
p
.
Print
(
3
)
p
.
Print
(
3
)
}
}
op-challenger/fault/position.go
View file @
92b5bae6
...
@@ -28,11 +28,11 @@ func (p *Position) IndexAtDepth() int {
...
@@ -28,11 +28,11 @@ func (p *Position) IndexAtDepth() int {
// TraceIndex calculates the what the index of the claim value would be inside the trace.
// TraceIndex calculates the what the index of the claim value would be inside the trace.
// It is equivalent to going right until the final depth has been reached.
// It is equivalent to going right until the final depth has been reached.
func
(
p
*
Position
)
TraceIndex
(
maxDepth
int
)
int
{
func
(
p
*
Position
)
TraceIndex
(
maxDepth
int
)
uint64
{
// When we go right, we do a shift left and set the bottom bit to be 1.
// When we go right, we do a shift left and set the bottom bit to be 1.
// To do this in a single step, do all the shifts at once & or in all 1s for the bottom bits.
// To do this in a single step, do all the shifts at once & or in all 1s for the bottom bits.
rd
:=
maxDepth
-
p
.
depth
rd
:=
maxDepth
-
p
.
depth
return
p
.
indexAtDepth
<<
rd
|
((
1
<<
rd
)
-
1
)
return
uint64
(
p
.
indexAtDepth
<<
rd
|
((
1
<<
rd
)
-
1
)
)
}
}
// move goes to the left or right child.
// move goes to the left or right child.
...
@@ -55,16 +55,20 @@ func (p *Position) parent() {
...
@@ -55,16 +55,20 @@ func (p *Position) parent() {
p
.
indexAtDepth
=
p
.
indexAtDepth
>>
1
p
.
indexAtDepth
=
p
.
indexAtDepth
>>
1
}
}
// Attack moves this position to a position to the left which disagrees with this position.
// Attack creates a new position which is the attack position of this one.
func
(
p
*
Position
)
Attack
()
{
func
(
p
*
Position
)
Attack
()
Position
{
p
.
move
(
false
)
p2
:=
NewPosition
(
p
.
depth
,
p
.
indexAtDepth
)
p2
.
move
(
false
)
return
p2
}
}
// Defend moves this position to the right which agrees with this position. Note:
// Defend creates a new position which is the defend position of this one.
func
(
p
*
Position
)
Defend
()
{
func
(
p
*
Position
)
Defend
()
Position
{
p
.
parent
()
p2
:=
NewPosition
(
p
.
depth
,
p
.
indexAtDepth
)
p
.
move
(
true
)
p2
.
parent
()
p
.
move
(
false
)
p2
.
move
(
true
)
p2
.
move
(
false
)
return
p2
}
}
func
(
p
*
Position
)
Print
(
maxDepth
int
)
{
func
(
p
*
Position
)
Print
(
maxDepth
int
)
{
...
...
op-challenger/fault/position_test.go
View file @
92b5bae6
...
@@ -35,7 +35,7 @@ type testNodeInfo struct {
...
@@ -35,7 +35,7 @@ type testNodeInfo struct {
GIndex
uint64
GIndex
uint64
Depth
int
Depth
int
IndexAtDepth
int
IndexAtDepth
int
TraceIndex
int
TraceIndex
uint64
}
}
var
treeNodesMaxDepth4
=
[]
testNodeInfo
{
var
treeNodesMaxDepth4
=
[]
testNodeInfo
{
...
...
op-challenger/fault/solver.go
View file @
92b5bae6
...
@@ -58,8 +58,7 @@ func (s *Solver) doNothing() (*Response, error) {
...
@@ -58,8 +58,7 @@ func (s *Solver) doNothing() (*Response, error) {
// attack returns a response that attacks the claim.
// attack returns a response that attacks the claim.
func
(
s
*
Solver
)
attack
(
claim
Claim
)
(
*
Response
,
error
)
{
func
(
s
*
Solver
)
attack
(
claim
Claim
)
(
*
Response
,
error
)
{
claim
.
Position
.
Attack
()
value
,
err
:=
s
.
traceAtPosition
(
claim
.
Position
.
Attack
())
value
,
err
:=
s
.
traceAtPosition
(
&
claim
.
Position
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -68,8 +67,7 @@ func (s *Solver) attack(claim Claim) (*Response, error) {
...
@@ -68,8 +67,7 @@ func (s *Solver) attack(claim Claim) (*Response, error) {
// defend returns a response that defends the claim.
// defend returns a response that defends the claim.
func
(
s
*
Solver
)
defend
(
claim
Claim
)
(
*
Response
,
error
)
{
func
(
s
*
Solver
)
defend
(
claim
Claim
)
(
*
Response
,
error
)
{
claim
.
Position
.
Defend
()
value
,
err
:=
s
.
traceAtPosition
(
claim
.
Position
.
Defend
())
value
,
err
:=
s
.
traceAtPosition
(
&
claim
.
Position
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -78,14 +76,13 @@ func (s *Solver) defend(claim Claim) (*Response, error) {
...
@@ -78,14 +76,13 @@ func (s *Solver) defend(claim Claim) (*Response, error) {
// agreeWithClaim returns true if the [Claim] is correct according to the internal [TraceProvider].
// agreeWithClaim returns true if the [Claim] is correct according to the internal [TraceProvider].
func
(
s
*
Solver
)
agreeWithClaim
(
claim
Claim
)
(
bool
,
error
)
{
func
(
s
*
Solver
)
agreeWithClaim
(
claim
Claim
)
(
bool
,
error
)
{
ourValue
,
err
:=
s
.
traceAtPosition
(
&
claim
.
Position
)
ourValue
,
err
:=
s
.
traceAtPosition
(
claim
.
Position
)
return
ourValue
==
claim
.
Value
,
err
return
ourValue
==
claim
.
Value
,
err
}
}
// traceAtPosition returns the [common.Hash] from internal [TraceProvider] at the given [Position].
// traceAtPosition returns the [common.Hash] from internal [TraceProvider] at the given [Position].
func
(
s
*
Solver
)
traceAtPosition
(
p
*
Position
)
(
common
.
Hash
,
error
)
{
func
(
s
*
Solver
)
traceAtPosition
(
p
Position
)
(
common
.
Hash
,
error
)
{
// todo: update TraceIndex to return a uint64 to keep types consistent
index
:=
p
.
TraceIndex
(
s
.
gameDepth
)
index
:=
p
.
TraceIndex
(
s
.
gameDepth
)
hash
,
err
:=
s
.
Get
(
uint64
(
index
)
)
hash
,
err
:=
s
.
Get
(
index
)
return
hash
,
err
return
hash
,
err
}
}
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