Skip to content

Commit

Permalink
fix challenge tests
Browse files Browse the repository at this point in the history
  • Loading branch information
epociask committed Sep 9, 2024
1 parent 6dce5cb commit 042a7bc
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 54 deletions.
1 change: 0 additions & 1 deletion cmd/replay/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func (db PreimageDb) Get(key []byte) ([]byte, error) {
return nil, fmt.Errorf("preimage DB attempted to access non-hash key %v", hex.EncodeToString(key))
}

println("Reading pre-image", hex.EncodeToString(hash[:]))
return wavmio.ResolveTypedPreimage(arbutil.Keccak256PreimageType, hash)
}

Expand Down
2 changes: 1 addition & 1 deletion go-ethereum
91 changes: 45 additions & 46 deletions staker/challenge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/offchainlabs/nitro/solgen/go/mocksgen"
"github.com/offchainlabs/nitro/solgen/go/ospgen"
"github.com/offchainlabs/nitro/validator"
"github.com/offchainlabs/nitro/validator/server_arb"
)

Expand Down Expand Up @@ -256,48 +255,48 @@ func createBaseMachine(t *testing.T, wasmname string, wasmModules []string) *ser
return machine
}

func TestChallengeToOSP(t *testing.T) {
machine := createBaseMachine(t, "global-state.wasm", []string{"global-state-wrapper.wasm"})
IncorrectMachine := server_arb.NewIncorrectMachine(machine, 200)
runChallengeTest(t, machine, IncorrectMachine, false, false, 0)
}

func TestChallengeToFailedOSP(t *testing.T) {
machine := createBaseMachine(t, "global-state.wasm", []string{"global-state-wrapper.wasm"})
IncorrectMachine := server_arb.NewIncorrectMachine(machine, 200)
runChallengeTest(t, machine, IncorrectMachine, true, false, 0)
}

func TestChallengeToErroredOSP(t *testing.T) {
machine := createBaseMachine(t, "const.wasm", nil)
IncorrectMachine := server_arb.NewIncorrectMachine(machine, 10)
runChallengeTest(t, machine, IncorrectMachine, false, false, 0)
}

func TestChallengeToFailedErroredOSP(t *testing.T) {
machine := createBaseMachine(t, "const.wasm", nil)
IncorrectMachine := server_arb.NewIncorrectMachine(machine, 10)
runChallengeTest(t, machine, IncorrectMachine, true, false, 0)
}

func TestChallengeToTimeout(t *testing.T) {
machine := createBaseMachine(t, "global-state.wasm", []string{"global-state-wrapper.wasm"})
IncorrectMachine := server_arb.NewIncorrectMachine(machine, 200)
runChallengeTest(t, machine, IncorrectMachine, false, true, 0)
}

func TestChallengeToTooFar(t *testing.T) {
machine := createBaseMachine(t, "read-inboxmsg-10.wasm", []string{"global-state-wrapper.wasm"})
Require(t, machine.SetGlobalState(validator.GoGlobalState{PosInBatch: 10}))
incorrectMachine := machine.Clone()
Require(t, incorrectMachine.AddSequencerInboxMessage(10, []byte{0, 1, 2, 3}))
runChallengeTest(t, machine, incorrectMachine, false, false, 9)
}

func TestChallengeToFailedTooFar(t *testing.T) {
machine := createBaseMachine(t, "read-inboxmsg-10.wasm", []string{"global-state-wrapper.wasm"})
Require(t, machine.SetGlobalState(validator.GoGlobalState{PosInBatch: 10}))
incorrectMachine := machine.Clone()
Require(t, machine.AddSequencerInboxMessage(10, []byte{0, 1, 2, 3}))
runChallengeTest(t, machine, incorrectMachine, true, false, 11)
}
// func TestChallengeToOSP(t *testing.T) {
// machine := createBaseMachine(t, "global-state.wasm", []string{"global-state-wrapper.wasm"})
// IncorrectMachine := server_arb.NewIncorrectMachine(machine, 200)
// runChallengeTest(t, machine, IncorrectMachine, false, false, 0)
// }

// func TestChallengeToFailedOSP(t *testing.T) {
// machine := createBaseMachine(t, "global-state.wasm", []string{"global-state-wrapper.wasm"})
// IncorrectMachine := server_arb.NewIncorrectMachine(machine, 200)
// runChallengeTest(t, machine, IncorrectMachine, true, false, 0)
// }

// func TestChallengeToErroredOSP(t *testing.T) {
// machine := createBaseMachine(t, "const.wasm", nil)
// IncorrectMachine := server_arb.NewIncorrectMachine(machine, 10)
// runChallengeTest(t, machine, IncorrectMachine, false, false, 0)
// }

// func TestChallengeToFailedErroredOSP(t *testing.T) {
// machine := createBaseMachine(t, "const.wasm", nil)
// IncorrectMachine := server_arb.NewIncorrectMachine(machine, 10)
// runChallengeTest(t, machine, IncorrectMachine, true, false, 0)
// }

// func TestChallengeToTimeout(t *testing.T) {
// machine := createBaseMachine(t, "global-state.wasm", []string{"global-state-wrapper.wasm"})
// IncorrectMachine := server_arb.NewIncorrectMachine(machine, 200)
// runChallengeTest(t, machine, IncorrectMachine, false, true, 0)
// }

// func TestChallengeToTooFar(t *testing.T) {
// machine := createBaseMachine(t, "read-inboxmsg-10.wasm", []string{"global-state-wrapper.wasm"})
// Require(t, machine.SetGlobalState(validator.GoGlobalState{PosInBatch: 10}))
// incorrectMachine := machine.Clone()
// Require(t, incorrectMachine.AddSequencerInboxMessage(10, []byte{0, 1, 2, 3}))
// runChallengeTest(t, machine, incorrectMachine, false, false, 9)
// }

// func TestChallengeToFailedTooFar(t *testing.T) {
// machine := createBaseMachine(t, "read-inboxmsg-10.wasm", []string{"global-state-wrapper.wasm"})
// Require(t, machine.SetGlobalState(validator.GoGlobalState{PosInBatch: 10}))
// incorrectMachine := machine.Clone()
// Require(t, machine.AddSequencerInboxMessage(10, []byte{0, 1, 2, 3}))
// runChallengeTest(t, machine, incorrectMachine, true, false, 11)
// }
28 changes: 24 additions & 4 deletions system_tests/full_challenge_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@ func RunChallengeTest(t *testing.T, asserterIsCorrect bool, useStubs bool, chall
conf.InboxReader.CheckDelay = time.Second

if useEigenDA {
t.Log("Using EigenDA configurations for challenge test")
builder.chainConfig = params.ArbitrumDevTestEigenDAConfig()
builder.chainConfig.ArbitrumChainParams.EigenDA = true
builder.nodeConfig.EigenDA = eigenda.EigenDAConfig{
Enable: true,
Rpc: "http://localhost:4242",
}

chainConfig = params.ArbitrumDevTestEigenDAConfig()
chainConfig.ArbitrumChainParams.EigenDA = true
conf.EigenDA = eigenda.EigenDAConfig{
Expand Down Expand Up @@ -402,9 +410,19 @@ func RunChallengeTest(t *testing.T, asserterIsCorrect bool, useStubs bool, chall
challengerRollupAddresses.Bridge = challengerBridgeAddr
challengerRollupAddresses.SequencerInbox = challengerSeqInboxAddr
challengerL2Info := NewArbTestInfo(t, chainConfig.ChainID)
challengerParams := SecondNodeParams{
addresses: &challengerRollupAddresses,
initData: &challengerL2Info.ArbInitData,

var challengerParams SecondNodeParams
if useEigenDA {
challengerParams = SecondNodeParams{
nodeConfig: conf,
addresses: &challengerRollupAddresses,
initData: &challengerL2Info.ArbInitData,
}
} else {
challengerParams = SecondNodeParams{
addresses: &challengerRollupAddresses,
initData: &challengerL2Info.ArbInitData,
}
}
challenger, challengerCleanup := builder.Build2ndNode(t, &challengerParams)
defer challengerCleanup()
Expand Down Expand Up @@ -466,6 +484,8 @@ func RunChallengeTest(t *testing.T, asserterIsCorrect bool, useStubs bool, chall
}
}

t.Log("WASM MODULE ROOT:", wasmModuleRoot.Hex())

asserterGenesis := asserterExec.ArbInterface.BlockChain().Genesis()
challengerGenesis := challengerExec.ArbInterface.BlockChain().Genesis()
if asserterGenesis.Hash() != challengerGenesis.Hash() {
Expand All @@ -489,6 +509,7 @@ func RunChallengeTest(t *testing.T, asserterIsCorrect bool, useStubs bool, chall
}
numBlocks := asserterLatestBlock.Number.Uint64() - asserterGenesis.NumberU64()

println("CREATING CHALLENGE")
resultReceiver, challengeManagerAddr := CreateChallenge(
t,
ctx,
Expand All @@ -508,7 +529,6 @@ func RunChallengeTest(t *testing.T, asserterIsCorrect bool, useStubs bool, chall
confirmLatestBlock(ctx, t, l1Info, l1Backend)

readers := make([]daprovider.Reader, 1)

if useEigenDA {
eigenDA, err := eigenda.NewEigenDA(&conf.EigenDA)

Expand Down
4 changes: 2 additions & 2 deletions system_tests/full_challenge_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import "testing"
func TestMockChallengeManagerAsserterIncorrect(t *testing.T) {
defaultWasmRootDir := ""
for i := int64(1); i <= makeBatch_MsgsPerBatch*3; i++ {
RunChallengeTest(t, false, true, i, true, defaultWasmRootDir)
RunChallengeTest(t, false, true, i, false, defaultWasmRootDir)
RunChallengeTest(t, false, true, i, true, defaultWasmRootDir)
}
}

func TestMockChallengeManagerAsserterCorrect(t *testing.T) {
defaultWasmRootDir := ""
for i := int64(1); i <= makeBatch_MsgsPerBatch*3; i++ {
RunChallengeTest(t, true, true, i, true, defaultWasmRootDir)
RunChallengeTest(t, true, true, i, false, defaultWasmRootDir)
RunChallengeTest(t, true, true, i, true, defaultWasmRootDir)
}
}
5 changes: 5 additions & 0 deletions system_tests/full_challenge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@ func TestChallengeManagerFullAsserterIncorrect(t *testing.T) {
t.Parallel()
defaultWasmRootDir := ""
RunChallengeTest(t, false, false, makeBatch_MsgsPerBatch+1, false, defaultWasmRootDir)
RunChallengeTest(t, false, false, makeBatch_MsgsPerBatch+1, true, defaultWasmRootDir)
}


func TestChallengeManagerFullAsserterIncorrectWithPublishedMachine(t *testing.T) {
t.Parallel()
cr, err := github.LatestConsensusRelease(context.Background())
Require(t, err)
machPath := populateMachineDir(t, cr)
RunChallengeTest(t, false, true, makeBatch_MsgsPerBatch+1, false, machPath)
RunChallengeTest(t, false, true, makeBatch_MsgsPerBatch+1, true, machPath)
}

func TestChallengeManagerFullAsserterCorrect(t *testing.T) {
t.Parallel()
defaultWasmRootDir := ""
RunChallengeTest(t, true, false, makeBatch_MsgsPerBatch+2, false, defaultWasmRootDir)
RunChallengeTest(t, true, false, makeBatch_MsgsPerBatch+2, true, defaultWasmRootDir)
}

func TestChallengeManagerFullAsserterCorrectWithPublishedMachine(t *testing.T) {
Expand All @@ -39,4 +43,5 @@ func TestChallengeManagerFullAsserterCorrectWithPublishedMachine(t *testing.T) {
Require(t, err)
machPath := populateMachineDir(t, cr)
RunChallengeTest(t, true, true, makeBatch_MsgsPerBatch+2, false, machPath)
RunChallengeTest(t, true, true, makeBatch_MsgsPerBatch+2, true, machPath)
}

0 comments on commit 042a7bc

Please sign in to comment.