Skip to content

Commit

Permalink
op-program: Allow l2 claim to be all zeros. (#8814)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajsutton authored Jan 3, 2024
1 parent 53fd3b4 commit fccf236
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
29 changes: 29 additions & 0 deletions op-e2e/faultproofs/output_cannon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,35 @@ func TestOutputCannonGame(t *testing.T) {
game.WaitForGameStatus(ctx, disputegame.StatusChallengerWins)
}

func TestOutputCannon_ChallengeAllZeroClaim(t *testing.T) {
// The dishonest actor always posts claims with all zeros.
op_e2e.InitParallel(t, op_e2e.UsesCannon, op_e2e.UseExecutor(outputCannonTestExecutor))
ctx := context.Background()
sys, l1Client := startFaultDisputeSystem(t)
t.Cleanup(sys.Close)

disputeGameFactory := disputegame.NewFactoryHelper(t, ctx, sys)
game := disputeGameFactory.StartOutputCannonGame(ctx, "sequencer", 3, common.Hash{})
game.LogGameData(ctx)

claim := game.DisputeLastBlock(ctx)
game.StartChallenger(ctx, "sequencer", "Challenger", challenger.WithPrivKey(sys.Cfg.Secrets.Alice))

game.DefendClaim(ctx, claim, func(parent *disputegame.ClaimHelper) *disputegame.ClaimHelper {
if parent.IsBottomGameRoot(ctx) {
return parent.Attack(ctx, common.Hash{})
}
return parent.Defend(ctx, common.Hash{})
})

game.LogGameData(ctx)

sys.TimeTravelClock.AdvanceTime(game.GameDuration(ctx))
require.NoError(t, wait.ForNextBlock(ctx, l1Client))
game.WaitForGameStatus(ctx, disputegame.StatusChallengerWins)
game.LogGameData(ctx)
}

func TestOutputCannon_PublishCannonRootClaim(t *testing.T) {
op_e2e.InitParallel(t, op_e2e.UsesCannon, op_e2e.UseExecutor(outputCannonTestExecutor))
tests := []struct {
Expand Down
10 changes: 10 additions & 0 deletions op-program/host/cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,16 @@ func TestL2Claim(t *testing.T) {
t.Run("Invalid", func(t *testing.T) {
verifyArgsInvalid(t, config.ErrInvalidL2Claim.Error(), replaceRequiredArg("--l2.claim", "something"))
})

t.Run("Allows all zero without prefix", func(t *testing.T) {
cfg := configForArgs(t, replaceRequiredArg("--l2.claim", "0000000000000000000000000000000000000000000000000000000000000000"))
require.EqualValues(t, common.Hash{}, cfg.L2Claim)
})

t.Run("Allows all zero with prefix", func(t *testing.T) {
cfg := configForArgs(t, replaceRequiredArg("--l2.claim", "0x0000000000000000000000000000000000000000000000000000000000000000"))
require.EqualValues(t, common.Hash{}, cfg.L2Claim)
})
}

func TestL2BlockNumber(t *testing.T) {
Expand Down
13 changes: 7 additions & 6 deletions op-program/host/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ func (c *Config) Check() error {
if c.L2OutputRoot == (common.Hash{}) {
return ErrInvalidL2OutputRoot
}
if c.L2Claim == (common.Hash{}) {
return ErrInvalidL2Claim
}
if c.L2ClaimBlockNumber == 0 {
return ErrInvalidL2ClaimBlock
}
Expand Down Expand Up @@ -151,9 +148,13 @@ func NewConfigFromCLI(log log.Logger, ctx *cli.Context) (*Config, error) {
if l2OutputRoot == (common.Hash{}) {
return nil, ErrInvalidL2OutputRoot
}
l2Claim := common.HexToHash(ctx.String(flags.L2Claim.Name))
if l2Claim == (common.Hash{}) {
return nil, ErrInvalidL2Claim
strClaim := ctx.String(flags.L2Claim.Name)
l2Claim := common.HexToHash(strClaim)
// Require a valid hash, with the zero hash explicitly allowed.
if l2Claim == (common.Hash{}) &&
strClaim != "0x0000000000000000000000000000000000000000000000000000000000000000" &&
strClaim != "0000000000000000000000000000000000000000000000000000000000000000" {
return nil, fmt.Errorf("%w: %v", ErrInvalidL2Claim, strClaim)
}
l2ClaimBlockNum := ctx.Uint64(flags.L2BlockNumber.Name)
l1Head := common.HexToHash(ctx.String(flags.L1Head.Name))
Expand Down
6 changes: 3 additions & 3 deletions op-program/host/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ func TestL2OutputRootRequired(t *testing.T) {
require.ErrorIs(t, err, ErrInvalidL2OutputRoot)
}

func TestL2ClaimRequired(t *testing.T) {
// The L2 claim may be provided by a dishonest actor so we must treat 0x00...00 as a real value.
func TestL2ClaimMayBeDefaultValue(t *testing.T) {
config := validConfig()
config.L2Claim = common.Hash{}
err := config.Check()
require.ErrorIs(t, err, ErrInvalidL2Claim)
require.NoError(t, config.Check())
}

func TestL2ClaimBlockNumberRequired(t *testing.T) {
Expand Down

0 comments on commit fccf236

Please sign in to comment.