Skip to content

Commit

Permalink
system_tests: check for unexpected extra asm in checkWasmStoreContent
Browse files Browse the repository at this point in the history
  • Loading branch information
magicxyyz committed Oct 23, 2024
1 parent 8914c57 commit 1abc820
Showing 1 changed file with 38 additions and 25 deletions.
63 changes: 38 additions & 25 deletions system_tests/program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func keccakTest(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder)) {
programAddress := deployWasm(t, ctx, auth, l2client, rustFile("keccak"))

wasmDb := builder.L2.ExecNode.Backend.ArbInterface().BlockChain().StateCache().WasmStore()
checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1)
checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1)

wasm, _ := readWasmFile(t, rustFile("keccak"))
otherAddressSameCode := deployContract(t, ctx, auth, l2client, wasm)
Expand All @@ -87,7 +87,7 @@ func keccakTest(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder)) {
Fatal(t, "activate should have failed with ProgramUpToDate", err)
}
})
checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1)
checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1)

if programAddress == otherAddressSameCode {
Fatal(t, "expected to deploy at two separate program addresses")
Expand Down Expand Up @@ -205,7 +205,7 @@ func testActivateTwice(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder)
multiAddr := deployWasm(t, ctx, auth, l2client, rustFile("multicall"))

wasmDb := builder.L2.ExecNode.Backend.ArbInterface().BlockChain().StateCache().WasmStore()
checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1)
checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1)

preimage := []byte("it's time to du-du-du-du d-d-d-d-d-d-d de-duplicate")

Expand All @@ -230,7 +230,7 @@ func testActivateTwice(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder)

// Calling the contract pre-activation should fail.
checkReverts()
checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1)
checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1)

// mechanisms for creating calldata
activateProgram, _ := util.NewCallParser(pgen.ArbWasmABI, "activateProgram")
Expand All @@ -253,15 +253,15 @@ func testActivateTwice(t *testing.T, jit bool, builderOpts ...func(*NodeBuilder)

// Ensure the revert also reverted keccak's activation
checkReverts()
checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1)
checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1)

// Activate keccak program A, then call into B, which should succeed due to being the same codehash
args = argsForMulticall(vm.CALL, types.ArbWasmAddress, oneEth, pack(activateProgram(keccakA)))
args = multicallAppend(args, vm.CALL, mockAddr, pack(callKeccak(keccakB, keccakArgs)))

tx = l2info.PrepareTxTo("Owner", &multiAddr, 1e9, oneEth, args)
ensure(tx, l2client.SendTransaction(ctx, tx))
checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 2)
checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 2)

validateBlocks(t, 7, jit, builder)
}
Expand Down Expand Up @@ -1917,7 +1917,7 @@ func TestWasmStoreRebuilding(t *testing.T) {
storeMap, err := createMapFromDb(wasmDb)
Require(t, err)

checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.ExtraArchs, 1)
checkWasmStoreContent(t, wasmDb, builder.execConfig.StylusTarget.WasmTargets(), 1)
// close nodeB
cleanupB()

Expand Down Expand Up @@ -1974,7 +1974,7 @@ func TestWasmStoreRebuilding(t *testing.T) {
}
}

checkWasmStoreContent(t, wasmDbAfterRebuild, builder.execConfig.StylusTarget.ExtraArchs, 1)
checkWasmStoreContent(t, wasmDbAfterRebuild, builder.execConfig.StylusTarget.WasmTargets(), 1)
cleanupB()
}

Expand All @@ -2001,30 +2001,43 @@ func readModuleHashes(t *testing.T, wasmDb ethdb.KeyValueStore) []common.Hash {
return modules
}

func checkWasmStoreContent(t *testing.T, wasmDb ethdb.KeyValueStore, targets []string, numModules int) {
func checkWasmStoreContent(t *testing.T, wasmDb ethdb.KeyValueStore, expectedTargets []ethdb.WasmTarget, numModules int) {
t.Helper()
modules := readModuleHashes(t, wasmDb)
if len(modules) != numModules {
t.Fatalf("Unexpected number of module hashes found in wasm store, want: %d, have: %d", numModules, len(modules))
}
for _, module := range modules {
for _, target := range targets {
wasmTarget := ethdb.WasmTarget(target)
if !rawdb.IsSupportedWasmTarget(wasmTarget) {
t.Fatalf("internal test error - unsupported target passed to checkWasmStoreContent: %v", target)
}
func() {
t.Helper()
defer func() {
if r := recover(); r != nil {
t.Fatalf("Failed to read activated asm for target: %v, module: %v", target, module)
}
}()
asm := rawdb.ReadActivatedAsm(wasmDb, wasmTarget, module)
if len(asm) == 0 {
t.Fatalf("Missing activated asm for target: %v, module: %v", target, module)
readAsm := func(module common.Hash, target string) []byte {
wasmTarget := ethdb.WasmTarget(target)
if !rawdb.IsSupportedWasmTarget(wasmTarget) {
t.Fatalf("internal test error - unsupported target passed to checkWasmStoreContent: %v", target)
}
return func() []byte {
t.Helper()
defer func() {
if r := recover(); r != nil {
t.Fatalf("Failed to read activated asm for target: %v, module: %v", target, module)
}
}()
return rawdb.ReadActivatedAsm(wasmDb, wasmTarget, module)
}()
}
for _, module := range modules {
for _, target := range allWasmTargets {
var expected bool
for _, expectedTarget := range expectedTargets {
if ethdb.WasmTarget(target) == expectedTarget {
expected = true
break
}
}
asm := readAsm(module, target)
if expected && len(asm) == 0 {
t.Fatalf("Missing asm for target: %v, module: %v", target, module)
}
if !expected && len(asm) > 0 {
t.Fatalf("Found asm for target: %v, module: %v, expected targets: %v", target, module, expectedTargets)
}
}
}
}
Expand Down

0 comments on commit 1abc820

Please sign in to comment.