Skip to content

Commit

Permalink
op-challenger: Asterisc Support with Refactoring (ethereum-optimism#1…
Browse files Browse the repository at this point in the history
…0094)

* op-challenger: Refactor cannon trace provider

Move gzip method to ioutil

* op-challenger: Expose cannon tracer methods

* op-challenger: asterisc implementation

Basic unit tests mirrored from cannon.

* op-challenger: asterisc flags and configs

* op-challenger: asterisc metric helper

* op-challenger: asterisc registration and add types

* op-dispute-mon: enable asterisc type

* Fix typo

* Fix l2RPC when registering asterisc

* Deduplicate preimageOpts for testing

* Fix comments

* Style issue fix

* Deduplicate network flag for testing

* Remove redundant prefix at filename

* Add config test for using both cannon and asterisc

* Refactor asterisc/cannon provider using utils

* Remove redundant prefix at filename

* Fix comments

* Style issue fix

* Refactor asterisc/cannon provider using utils

* Remove unused methods

* op-challenger: add l2-rpc flag and deprecate cannon-l2 flag
  • Loading branch information
pcw109550 authored Apr 22, 2024
1 parent 48771c8 commit c38ce09
Show file tree
Hide file tree
Showing 45 changed files with 2,005 additions and 327 deletions.
2 changes: 1 addition & 1 deletion docs/fault-proof-alpha/run-challenger.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ make op-challenger op-program cannon
--cannon-bin ./cannon/bin/cannon \
--cannon-server ./op-program/bin/op-program \
--cannon-prestate <PRESTATE> \
--cannon-l2 <L2_URL> \
--l2-rpc <L2_URL> \
--private-key <PRIVATE_KEY>
```

Expand Down
2 changes: 1 addition & 1 deletion op-challenger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ DISPUTE_GAME_FACTORY=$(jq -r .DisputeGameFactoryProxy .devnet/addresses.json)
--cannon-bin ./cannon/bin/cannon \
--cannon-server ./op-program/bin/op-program \
--cannon-prestate ./op-program/bin/prestate.json \
--cannon-l2 http://localhost:9545 \
--l2-rpc http://localhost:9545 \
--mnemonic "test test test test test test test test test test test junk" \
--hd-path "m/44'/60'/0'/0/8" \
--num-confirmations 1
Expand Down
222 changes: 211 additions & 11 deletions op-challenger/cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ var (
l1Beacon = "http://example.com:9000"
gameFactoryAddressValue = "0xbb00000000000000000000000000000000000000"
cannonNetwork = "op-mainnet"
otherCannonNetwork = "op-sepolia"
testNetwork = "op-sepolia"
l2Rpc = "http://example.com:9545"
cannonBin = "./bin/cannon"
cannonServer = "./bin/op-program"
cannonPreState = "./pre.json"
datadir = "./test_data"
cannonL2 = "http://example.com:9545"
rollupRpc = "http://example.com:8555"
asteriscNetwork = "op-mainnet"
asteriscBin = "./bin/asterisc"
asteriscServer = "./bin/op-program"
asteriscPreState = "./pre.json"
)

func TestLogLevel(t *testing.T) {
Expand Down Expand Up @@ -111,14 +115,18 @@ func TestMultipleTraceTypes(t *testing.T) {
t.Run("WithAllOptions", func(t *testing.T) {
argsMap := requiredArgs(config.TraceTypeCannon)
addRequiredOutputArgs(argsMap)
// Add Asterisc required flags
addRequiredAsteriscArgs(argsMap)
args := toArgList(argsMap)
// Add extra trace types (cannon is already specified)
args = append(args,
"--trace-type", config.TraceTypeAlphabet.String())
args = append(args,
"--trace-type", config.TraceTypePermissioned.String())
args = append(args,
"--trace-type", config.TraceTypeAsterisc.String())
cfg := configForArgs(t, args)
require.Equal(t, []config.TraceType{config.TraceTypeCannon, config.TraceTypeAlphabet, config.TraceTypePermissioned}, cfg.TraceTypes)
require.Equal(t, []config.TraceType{config.TraceTypeCannon, config.TraceTypeAlphabet, config.TraceTypePermissioned, config.TraceTypeAsterisc}, cfg.TraceTypes)
})
t.Run("WithSomeOptions", func(t *testing.T) {
argsMap := requiredArgs(config.TraceTypeCannon)
Expand Down Expand Up @@ -243,6 +251,178 @@ func TestPollInterval(t *testing.T) {
})
}

func TestAsteriscRequiredArgs(t *testing.T) {
for _, traceType := range []config.TraceType{config.TraceTypeAsterisc} {
traceType := traceType
t.Run(fmt.Sprintf("TestAsteriscBin-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(config.TraceTypeAlphabet, "--asterisc-bin"))
})

t.Run("Required", func(t *testing.T) {
verifyArgsInvalid(t, "flag asterisc-bin is required", addRequiredArgsExcept(traceType, "--asterisc-bin"))
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-bin", "--asterisc-bin=./asterisc"))
require.Equal(t, "./asterisc", cfg.AsteriscBin)
})
})

t.Run(fmt.Sprintf("TestAsteriscServer-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(config.TraceTypeAlphabet, "--asterisc-server"))
})

t.Run("Required", func(t *testing.T) {
verifyArgsInvalid(t, "flag asterisc-server is required", addRequiredArgsExcept(traceType, "--asterisc-server"))
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-server", "--asterisc-server=./op-program"))
require.Equal(t, "./op-program", cfg.AsteriscServer)
})
})

t.Run(fmt.Sprintf("TestAsteriscAbsolutePrestate-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(config.TraceTypeAlphabet, "--asterisc-prestate"))
})

t.Run("Required", func(t *testing.T) {
verifyArgsInvalid(t, "flag asterisc-prestate is required", addRequiredArgsExcept(traceType, "--asterisc-prestate"))
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-prestate", "--asterisc-prestate=./pre.json"))
require.Equal(t, "./pre.json", cfg.AsteriscAbsolutePreState)
})
})

t.Run(fmt.Sprintf("TestL2Rpc-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTraceLegacy", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(config.TraceTypeAlphabet, "--cannon-l2"))
})

t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(config.TraceTypeAlphabet, "--l2-rpc"))
})

t.Run("RequiredForAsteriscTrace", func(t *testing.T) {
verifyArgsInvalid(t, "flag l2-rpc is required", addRequiredArgsExcept(traceType, "--l2-rpc"))
})

t.Run("ValidLegacy", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--l2-rpc", fmt.Sprintf("--cannon-l2=%s", l2Rpc)))
require.Equal(t, l2Rpc, cfg.L2Rpc)
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgs(traceType))
require.Equal(t, l2Rpc, cfg.L2Rpc)
})

t.Run("InvalidUsingBothFlags", func(t *testing.T) {
verifyArgsInvalid(t, "flag cannon-l2 and l2-rpc must not be both set", addRequiredArgsExcept(traceType, "", fmt.Sprintf("--cannon-l2=%s", l2Rpc)))
})
})

t.Run(fmt.Sprintf("TestAsteriscSnapshotFreq-%v", traceType), func(t *testing.T) {
t.Run("UsesDefault", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgs(traceType))
require.Equal(t, config.DefaultAsteriscSnapshotFreq, cfg.AsteriscSnapshotFreq)
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgs(traceType, "--asterisc-snapshot-freq=1234"))
require.Equal(t, uint(1234), cfg.AsteriscSnapshotFreq)
})

t.Run("Invalid", func(t *testing.T) {
verifyArgsInvalid(t, "invalid value \"abc\" for flag -asterisc-snapshot-freq",
addRequiredArgs(traceType, "--asterisc-snapshot-freq=abc"))
})
})

t.Run(fmt.Sprintf("TestAsteriscInfoFreq-%v", traceType), func(t *testing.T) {
t.Run("UsesDefault", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgs(traceType))
require.Equal(t, config.DefaultAsteriscInfoFreq, cfg.AsteriscInfoFreq)
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgs(traceType, "--asterisc-info-freq=1234"))
require.Equal(t, uint(1234), cfg.AsteriscInfoFreq)
})

t.Run("Invalid", func(t *testing.T) {
verifyArgsInvalid(t, "invalid value \"abc\" for flag -asterisc-info-freq",
addRequiredArgs(traceType, "--asterisc-info-freq=abc"))
})
})

t.Run(fmt.Sprintf("TestRequireEitherAsteriscNetworkOrRollupAndGenesis-%v", traceType), func(t *testing.T) {
verifyArgsInvalid(
t,
"flag asterisc-network or asterisc-rollup-config and asterisc-l2-genesis is required",
addRequiredArgsExcept(traceType, "--asterisc-network"))
verifyArgsInvalid(
t,
"flag asterisc-network or asterisc-rollup-config and asterisc-l2-genesis is required",
addRequiredArgsExcept(traceType, "--asterisc-network", "--asterisc-rollup-config=rollup.json"))
verifyArgsInvalid(
t,
"flag asterisc-network or asterisc-rollup-config and asterisc-l2-genesis is required",
addRequiredArgsExcept(traceType, "--asterisc-network", "--asterisc-l2-genesis=gensis.json"))
})

t.Run(fmt.Sprintf("TestMustNotSpecifyNetworkAndRollup-%v", traceType), func(t *testing.T) {
verifyArgsInvalid(
t,
"flag asterisc-network can not be used with asterisc-rollup-config and asterisc-l2-genesis",
addRequiredArgsExcept(traceType, "--asterisc-network",
"--asterisc-network", asteriscNetwork, "--asterisc-rollup-config=rollup.json"))
})

t.Run(fmt.Sprintf("TestAsteriscNetwork-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(config.TraceTypeAlphabet, "--asterisc-network"))
})

t.Run("NotRequiredWhenRollupAndGenesIsSpecified", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-network",
"--asterisc-rollup-config=rollup.json", "--asterisc-l2-genesis=genesis.json"))
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-network", "--asterisc-network", testNetwork))
require.Equal(t, testNetwork, cfg.AsteriscNetwork)
})
})

t.Run(fmt.Sprintf("TestAsteriscRollupConfig-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(config.TraceTypeAlphabet, "--asterisc-rollup-config"))
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-network", "--asterisc-rollup-config=rollup.json", "--asterisc-l2-genesis=genesis.json"))
require.Equal(t, "rollup.json", cfg.AsteriscRollupConfigPath)
})
})

t.Run(fmt.Sprintf("TestAsteriscL2Genesis-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(config.TraceTypeAlphabet, "--asterisc-l2-genesis"))
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--asterisc-network", "--asterisc-rollup-config=rollup.json", "--asterisc-l2-genesis=genesis.json"))
require.Equal(t, "genesis.json", cfg.AsteriscL2GenesisPath)
})
})
}
}
func TestCannonRequiredArgs(t *testing.T) {
for _, traceType := range []config.TraceType{config.TraceTypeCannon, config.TraceTypePermissioned} {
traceType := traceType
Expand Down Expand Up @@ -291,18 +471,27 @@ func TestCannonRequiredArgs(t *testing.T) {
})
})

t.Run(fmt.Sprintf("TestCannonL2-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
t.Run(fmt.Sprintf("TestL2Rpc-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTraceLegacy", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(config.TraceTypeAlphabet, "--cannon-l2"))
})

t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(config.TraceTypeAlphabet, "--l2-rpc"))
})

t.Run("RequiredForCannonTrace", func(t *testing.T) {
verifyArgsInvalid(t, "flag cannon-l2 is required", addRequiredArgsExcept(traceType, "--cannon-l2"))
verifyArgsInvalid(t, "flag l2-rpc is required", addRequiredArgsExcept(traceType, "--l2-rpc"))
})

t.Run("ValidLegacy", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--l2-rpc", fmt.Sprintf("--cannon-l2=%s", l2Rpc)))
require.Equal(t, l2Rpc, cfg.L2Rpc)
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgs(traceType))
require.Equal(t, cannonL2, cfg.CannonL2)
require.Equal(t, l2Rpc, cfg.L2Rpc)
})
})

Expand Down Expand Up @@ -374,8 +563,8 @@ func TestCannonRequiredArgs(t *testing.T) {
})

t.Run("Valid", func(t *testing.T) {
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--cannon-network", "--cannon-network", otherCannonNetwork))
require.Equal(t, otherCannonNetwork, cfg.CannonNetwork)
cfg := configForArgs(t, addRequiredArgsExcept(traceType, "--cannon-network", "--cannon-network", testNetwork))
require.Equal(t, testNetwork, cfg.CannonNetwork)
})
})

Expand All @@ -390,7 +579,7 @@ func TestCannonRequiredArgs(t *testing.T) {
})
})

t.Run(fmt.Sprintf("TestCannonL2Genesis-%v", traceType), func(t *testing.T) {
t.Run(fmt.Sprintf("TestCannonL2qGenesis-%v", traceType), func(t *testing.T) {
t.Run("NotRequiredForAlphabetTrace", func(t *testing.T) {
configForArgs(t, addRequiredArgsExcept(config.TraceTypeAlphabet, "--cannon-l2-genesis"))
})
Expand Down Expand Up @@ -560,6 +749,8 @@ func requiredArgs(traceType config.TraceType) map[string]string {
switch traceType {
case config.TraceTypeCannon, config.TraceTypePermissioned:
addRequiredCannonArgs(args)
case config.TraceTypeAsterisc:
addRequiredAsteriscArgs(args)
case config.TraceTypeAlphabet:
addRequiredOutputArgs(args)
}
Expand All @@ -571,7 +762,16 @@ func addRequiredCannonArgs(args map[string]string) {
args["--cannon-bin"] = cannonBin
args["--cannon-server"] = cannonServer
args["--cannon-prestate"] = cannonPreState
args["--cannon-l2"] = cannonL2
args["--l2-rpc"] = l2Rpc
addRequiredOutputArgs(args)
}

func addRequiredAsteriscArgs(args map[string]string) {
args["--asterisc-network"] = asteriscNetwork
args["--asterisc-bin"] = asteriscBin
args["--asterisc-server"] = asteriscServer
args["--asterisc-prestate"] = asteriscPreState
args["--l2-rpc"] = l2Rpc
addRequiredOutputArgs(args)
}

Expand Down
Loading

0 comments on commit c38ce09

Please sign in to comment.