Commit 8d720b21 authored by OptimismBot's avatar OptimismBot Committed by GitHub

Merge pull request #6353 from ethereum-optimism/refcell/enforce-step-on-non-agree

fix(op-challenger): Enforce Step Response
parents a4ae46d3 47902841
...@@ -95,7 +95,8 @@ func (a *Agent) step(claim Claim, game Game) error { ...@@ -95,7 +95,8 @@ func (a *Agent) step(claim Claim, game Game) error {
return nil return nil
} }
if game.AgreeWithClaimLevel(claim) { agreeWithClaimLevel := game.AgreeWithClaimLevel(claim)
if agreeWithClaimLevel {
a.log.Warn("Agree with leaf claim, skipping step", "claim_depth", claim.Depth(), "maxDepth", a.maxDepth) a.log.Warn("Agree with leaf claim, skipping step", "claim_depth", claim.Depth(), "maxDepth", a.maxDepth)
return nil return nil
} }
...@@ -106,7 +107,7 @@ func (a *Agent) step(claim Claim, game Game) error { ...@@ -106,7 +107,7 @@ func (a *Agent) step(claim Claim, game Game) error {
} }
a.log.Info("Attempting step", "claim_depth", claim.Depth(), "maxDepth", a.maxDepth) a.log.Info("Attempting step", "claim_depth", claim.Depth(), "maxDepth", a.maxDepth)
step, err := a.solver.AttemptStep(claim) step, err := a.solver.AttemptStep(claim, agreeWithClaimLevel)
if err != nil { if err != nil {
a.log.Warn("Failed to get a step", "err", err) a.log.Warn("Failed to get a step", "err", err)
return err return err
......
...@@ -71,10 +71,13 @@ type StepData struct { ...@@ -71,10 +71,13 @@ type StepData struct {
// AttemptStep determines what step should occur for a given leaf claim. // AttemptStep determines what step should occur for a given leaf claim.
// An error will be returned if the claim is not at the max depth. // An error will be returned if the claim is not at the max depth.
func (s *Solver) AttemptStep(claim Claim) (StepData, error) { func (s *Solver) AttemptStep(claim Claim, agreeWithClaimLevel bool) (StepData, error) {
if claim.Depth() != s.gameDepth { if claim.Depth() != s.gameDepth {
return StepData{}, errors.New("cannot step on non-leaf claims") return StepData{}, errors.New("cannot step on non-leaf claims")
} }
if agreeWithClaimLevel {
return StepData{}, errors.New("cannot step on claims we agree with")
}
claimCorrect, err := s.agreeWithClaim(claim.ClaimData) claimCorrect, err := s.agreeWithClaim(claim.ClaimData)
if err != nil { if err != nil {
return StepData{}, err return StepData{}, err
......
...@@ -111,18 +111,29 @@ func TestAttemptStep(t *testing.T) { ...@@ -111,18 +111,29 @@ func TestAttemptStep(t *testing.T) {
}, },
} }
step, err := solver.AttemptStep(bottom) step, err := solver.AttemptStep(bottom, false)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, bottom, step.LeafClaim) require.Equal(t, bottom, step.LeafClaim)
require.True(t, step.IsAttack) require.True(t, step.IsAttack)
require.Equal(t, step.PreState, BuildAlphabetPreimage(3, "d")) require.Equal(t, step.PreState, BuildAlphabetPreimage(3, "d"))
_, err = solver.AttemptStep(middle) _, err = solver.AttemptStep(middle, false)
require.Error(t, err) require.Error(t, err)
step, err = solver.AttemptStep(zero) step, err = solver.AttemptStep(zero, false)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, zero, step.LeafClaim) require.Equal(t, zero, step.LeafClaim)
require.True(t, step.IsAttack) require.True(t, step.IsAttack)
require.Equal(t, canonicalProvider.AbsolutePreState(), step.PreState) require.Equal(t, canonicalProvider.AbsolutePreState(), step.PreState)
} }
func TestAttempStep_AgreeWithClaimLevel_Fails(t *testing.T) {
maxDepth := 3
canonicalProvider := NewAlphabetProvider("abcdefgh", uint64(maxDepth))
solver := NewSolver(maxDepth, canonicalProvider)
_, _, middle, _ := createTestClaims()
step, err := solver.AttemptStep(middle, true)
require.Error(t, err)
require.Equal(t, StepData{}, step)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment