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
f28b7f23
Unverified
Commit
f28b7f23
authored
Sep 27, 2023
by
Adrian Sutton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-e2e: Use helper to create dishonest helper.
Reduces the amount of boilerplate required in the actual test.
parent
bd7e7965
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
119 additions
and
107 deletions
+119
-107
alphabet_helper.go
op-e2e/e2eutils/disputegame/alphabet_helper.go
+5
-1
dishonest_helper.go
op-e2e/e2eutils/disputegame/dishonest_helper.go
+113
-0
game_helper.go
op-e2e/e2eutils/disputegame/game_helper.go
+0
-104
faultproof_test.go
op-e2e/faultproof_test.go
+1
-2
No files found.
op-e2e/e2eutils/disputegame/alphabet_helper.go
View file @
f28b7f23
...
@@ -35,7 +35,7 @@ func (g *AlphabetGameHelper) StartChallenger(ctx context.Context, l1Endpoint str
...
@@ -35,7 +35,7 @@ func (g *AlphabetGameHelper) StartChallenger(ctx context.Context, l1Endpoint str
return
c
return
c
}
}
func
(
g
*
AlphabetGameHelper
)
CreateHonestActor
(
ctx
context
.
Context
,
alphabetTrace
string
,
depth
uint64
)
*
HonestHelper
{
func
(
g
*
AlphabetGameHelper
)
CreateHonestActor
(
alphabetTrace
string
,
depth
uint64
)
*
HonestHelper
{
return
&
HonestHelper
{
return
&
HonestHelper
{
t
:
g
.
t
,
t
:
g
.
t
,
require
:
g
.
require
,
require
:
g
.
require
,
...
@@ -43,3 +43,7 @@ func (g *AlphabetGameHelper) CreateHonestActor(ctx context.Context, alphabetTrac
...
@@ -43,3 +43,7 @@ func (g *AlphabetGameHelper) CreateHonestActor(ctx context.Context, alphabetTrac
correctTrace
:
alphabet
.
NewTraceProvider
(
alphabetTrace
,
depth
),
correctTrace
:
alphabet
.
NewTraceProvider
(
alphabetTrace
,
depth
),
}
}
}
}
func
(
g
*
AlphabetGameHelper
)
CreateDishonestHelper
(
alphabetTrace
string
,
depth
uint64
,
defender
bool
)
*
DishonestHelper
{
return
newDishonestHelper
(
&
g
.
FaultGameHelper
,
g
.
CreateHonestActor
(
alphabetTrace
,
depth
),
defender
)
}
op-e2e/e2eutils/disputegame/dishonest_helper.go
0 → 100644
View file @
f28b7f23
package
disputegame
import
(
"context"
"errors"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum/go-ethereum/common"
)
type
dishonestClaim
struct
{
ParentIndex
int64
IsAttack
bool
Valid
bool
}
type
DishonestHelper
struct
{
*
FaultGameHelper
*
HonestHelper
claims
map
[
dishonestClaim
]
bool
defender
bool
}
func
newDishonestHelper
(
g
*
FaultGameHelper
,
correctTrace
*
HonestHelper
,
defender
bool
)
*
DishonestHelper
{
return
&
DishonestHelper
{
g
,
correctTrace
,
make
(
map
[
dishonestClaim
]
bool
),
defender
}
}
func
(
t
*
DishonestHelper
)
Attack
(
ctx
context
.
Context
,
claimIndex
int64
)
{
c
:=
dishonestClaim
{
claimIndex
,
true
,
false
}
if
t
.
claims
[
c
]
{
return
}
t
.
claims
[
c
]
=
true
t
.
FaultGameHelper
.
Attack
(
ctx
,
claimIndex
,
common
.
Hash
{
byte
(
claimIndex
)})
}
func
(
t
*
DishonestHelper
)
Defend
(
ctx
context
.
Context
,
claimIndex
int64
)
{
c
:=
dishonestClaim
{
claimIndex
,
false
,
false
}
if
t
.
claims
[
c
]
{
return
}
t
.
claims
[
c
]
=
true
t
.
FaultGameHelper
.
Defend
(
ctx
,
claimIndex
,
common
.
Hash
{
byte
(
claimIndex
)})
}
func
(
t
*
DishonestHelper
)
AttackCorrect
(
ctx
context
.
Context
,
claimIndex
int64
)
{
c
:=
dishonestClaim
{
claimIndex
,
true
,
true
}
if
t
.
claims
[
c
]
{
return
}
t
.
claims
[
c
]
=
true
t
.
HonestHelper
.
Attack
(
ctx
,
claimIndex
)
}
func
(
t
*
DishonestHelper
)
DefendCorrect
(
ctx
context
.
Context
,
claimIndex
int64
)
{
c
:=
dishonestClaim
{
claimIndex
,
false
,
true
}
if
t
.
claims
[
c
]
{
return
}
t
.
claims
[
c
]
=
true
t
.
HonestHelper
.
Defend
(
ctx
,
claimIndex
)
}
// ExhaustDishonestClaims makes all possible significant moves (mod honest challenger's) in a game.
// It is very inefficient and should NOT be used on games with large depths
func
(
d
*
DishonestHelper
)
ExhaustDishonestClaims
(
ctx
context
.
Context
)
{
depth
:=
d
.
MaxDepth
(
ctx
)
move
:=
func
(
claimIndex
int64
,
claimData
ContractClaim
)
{
// dishonest level, valid attack
// dishonest level, invalid attack
// dishonest level, valid defense
// dishonest level, invalid defense
// honest level, invalid attack
// honest level, invalid defense
pos
:=
types
.
NewPositionFromGIndex
(
claimData
.
Position
.
Uint64
())
if
int64
(
pos
.
Depth
())
==
depth
{
return
}
d
.
LogGameData
(
ctx
)
d
.
FaultGameHelper
.
t
.
Logf
(
"Dishonest moves against claimIndex %d"
,
claimIndex
)
agreeWithLevel
:=
d
.
defender
==
(
pos
.
Depth
()
%
2
==
0
)
if
!
agreeWithLevel
{
d
.
AttackCorrect
(
ctx
,
claimIndex
)
if
claimIndex
!=
0
{
d
.
DefendCorrect
(
ctx
,
claimIndex
)
}
}
d
.
Attack
(
ctx
,
claimIndex
)
if
claimIndex
!=
0
{
d
.
Defend
(
ctx
,
claimIndex
)
}
}
var
numClaimsSeen
int64
for
{
newCount
,
err
:=
d
.
WaitForNewClaim
(
ctx
,
numClaimsSeen
)
if
errors
.
Is
(
err
,
context
.
DeadlineExceeded
)
{
// we assume that the honest challenger has stopped responding
// There's nothing to respond to.
break
}
d
.
FaultGameHelper
.
require
.
NoError
(
err
)
for
i
:=
numClaimsSeen
;
i
<
newCount
;
i
++
{
claimData
:=
d
.
getClaim
(
ctx
,
numClaimsSeen
)
move
(
numClaimsSeen
,
claimData
)
numClaimsSeen
++
}
}
}
op-e2e/e2eutils/disputegame/game_helper.go
View file @
f28b7f23
...
@@ -2,7 +2,6 @@ package disputegame
...
@@ -2,7 +2,6 @@ package disputegame
import
(
import
(
"context"
"context"
"errors"
"fmt"
"fmt"
"math/big"
"math/big"
"testing"
"testing"
...
@@ -383,106 +382,3 @@ func (g *FaultGameHelper) gameData(ctx context.Context) string {
...
@@ -383,106 +382,3 @@ func (g *FaultGameHelper) gameData(ctx context.Context) string {
func
(
g
*
FaultGameHelper
)
LogGameData
(
ctx
context
.
Context
)
{
func
(
g
*
FaultGameHelper
)
LogGameData
(
ctx
context
.
Context
)
{
g
.
t
.
Log
(
g
.
gameData
(
ctx
))
g
.
t
.
Log
(
g
.
gameData
(
ctx
))
}
}
type
dishonestClaim
struct
{
ParentIndex
int64
IsAttack
bool
Valid
bool
}
type
DishonestHelper
struct
{
*
FaultGameHelper
*
HonestHelper
claims
map
[
dishonestClaim
]
bool
defender
bool
}
func
NewDishonestHelper
(
g
*
FaultGameHelper
,
correctTrace
*
HonestHelper
,
defender
bool
)
*
DishonestHelper
{
return
&
DishonestHelper
{
g
,
correctTrace
,
make
(
map
[
dishonestClaim
]
bool
),
defender
}
}
func
(
t
*
DishonestHelper
)
Attack
(
ctx
context
.
Context
,
claimIndex
int64
)
{
c
:=
dishonestClaim
{
claimIndex
,
true
,
false
}
if
t
.
claims
[
c
]
{
return
}
t
.
claims
[
c
]
=
true
t
.
FaultGameHelper
.
Attack
(
ctx
,
claimIndex
,
common
.
Hash
{
byte
(
claimIndex
)})
}
func
(
t
*
DishonestHelper
)
Defend
(
ctx
context
.
Context
,
claimIndex
int64
)
{
c
:=
dishonestClaim
{
claimIndex
,
false
,
false
}
if
t
.
claims
[
c
]
{
return
}
t
.
claims
[
c
]
=
true
t
.
FaultGameHelper
.
Defend
(
ctx
,
claimIndex
,
common
.
Hash
{
byte
(
claimIndex
)})
}
func
(
t
*
DishonestHelper
)
AttackCorrect
(
ctx
context
.
Context
,
claimIndex
int64
)
{
c
:=
dishonestClaim
{
claimIndex
,
true
,
true
}
if
t
.
claims
[
c
]
{
return
}
t
.
claims
[
c
]
=
true
t
.
HonestHelper
.
Attack
(
ctx
,
claimIndex
)
}
func
(
t
*
DishonestHelper
)
DefendCorrect
(
ctx
context
.
Context
,
claimIndex
int64
)
{
c
:=
dishonestClaim
{
claimIndex
,
false
,
true
}
if
t
.
claims
[
c
]
{
return
}
t
.
claims
[
c
]
=
true
t
.
HonestHelper
.
Defend
(
ctx
,
claimIndex
)
}
// ExhaustDishonestClaims makes all possible significant moves (mod honest challenger's) in a game.
// It is very inefficient and should NOT be used on games with large depths
func
(
d
*
DishonestHelper
)
ExhaustDishonestClaims
(
ctx
context
.
Context
)
{
depth
:=
d
.
MaxDepth
(
ctx
)
move
:=
func
(
claimIndex
int64
,
claimData
ContractClaim
)
{
// dishonest level, valid attack
// dishonest level, invalid attack
// dishonest level, valid defense
// dishonest level, invalid defense
// honest level, invalid attack
// honest level, invalid defense
pos
:=
types
.
NewPositionFromGIndex
(
claimData
.
Position
.
Uint64
())
if
int64
(
pos
.
Depth
())
==
depth
{
return
}
d
.
LogGameData
(
ctx
)
d
.
FaultGameHelper
.
t
.
Logf
(
"Dishonest moves against claimIndex %d"
,
claimIndex
)
agreeWithLevel
:=
d
.
defender
==
(
pos
.
Depth
()
%
2
==
0
)
if
!
agreeWithLevel
{
d
.
AttackCorrect
(
ctx
,
claimIndex
)
if
claimIndex
!=
0
{
d
.
DefendCorrect
(
ctx
,
claimIndex
)
}
}
d
.
Attack
(
ctx
,
claimIndex
)
if
claimIndex
!=
0
{
d
.
Defend
(
ctx
,
claimIndex
)
}
}
var
numClaimsSeen
int64
for
{
newCount
,
err
:=
d
.
WaitForNewClaim
(
ctx
,
numClaimsSeen
)
if
errors
.
Is
(
err
,
context
.
DeadlineExceeded
)
{
// we assume that the honest challenger has stopped responding
// There's nothing to respond to.
break
}
d
.
FaultGameHelper
.
require
.
NoError
(
err
)
for
i
:=
numClaimsSeen
;
i
<
newCount
;
i
++
{
claimData
:=
d
.
getClaim
(
ctx
,
numClaimsSeen
)
move
(
numClaimsSeen
,
claimData
)
numClaimsSeen
++
}
}
}
op-e2e/faultproof_test.go
View file @
f28b7f23
...
@@ -208,8 +208,7 @@ func TestChallengerCompleteExhaustiveDisputeGame(t *testing.T) {
...
@@ -208,8 +208,7 @@ func TestChallengerCompleteExhaustiveDisputeGame(t *testing.T) {
)
)
// Start dishonest challenger
// Start dishonest challenger
correctTrace
:=
game
.
CreateHonestActor
(
ctx
,
disputegame
.
CorrectAlphabet
,
4
)
dishonestHelper
:=
game
.
CreateDishonestHelper
(
disputegame
.
CorrectAlphabet
,
4
,
!
isRootCorrect
)
dishonestHelper
:=
disputegame
.
NewDishonestHelper
(
&
game
.
FaultGameHelper
,
correctTrace
,
!
isRootCorrect
)
dishonestHelper
.
ExhaustDishonestClaims
(
ctx
)
dishonestHelper
.
ExhaustDishonestClaims
(
ctx
)
// Wait until we've reached max depth before checking for inactivity
// Wait until we've reached max depth before checking for inactivity
...
...
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