Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

program_test: add recursive tests #221

Open
wants to merge 15 commits into
base: stylus
Choose a base branch
from
Open
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
fail-fast: false
matrix:
test-mode: [defaults, race, challenge, stylus]
test-mode: [defaults, race, challenge, stylus, long]

steps:
- name: Checkout
Expand Down Expand Up @@ -168,8 +168,14 @@ jobs:
if: matrix.test-mode == 'stylus'
run: |
packages=`go list ./...`
stdbuf -oL gotestsum --format short-verbose --packages="$packages" --rerun-fails=1 --no-color=false -- ./... -coverprofile=coverage.txt -covermode=atomic -coverpkg=./...,./go-ethereum/... -parallel=8 -tags=stylustest -run=TestProgramArbitrator > >(stdbuf -oL tee full.log | grep -vE "INFO|seal")
stdbuf -oL gotestsum --format short-verbose --packages="$packages" --rerun-fails=1 --no-color=false -- ./... -timeout 60m -coverprofile=coverage.txt -covermode=atomic -coverpkg=./...,./go-ethereum/... -parallel=8 -tags=stylustest -run="TestProgramArbitrator" > >(stdbuf -oL tee full.log | grep -vE "INFO|seal")

- name: run long stylus tests
if: matrix.test-mode == 'long'
run: |
packages=`go list ./...`
stdbuf -oL gotestsum --format short-verbose --packages="$packages" --rerun-fails=1 --no-color=false -- ./... -timeout 60m -coverprofile=coverage.txt -covermode=atomic -coverpkg=./...,./go-ethereum/... -parallel=8 -tags=stylustest -run="TestProgramLong" > >(stdbuf -oL tee full.log | grep -vE "INFO|seal")

- name: Archive detailed run log
uses: actions/upload-artifact@v3
with:
Expand Down
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ $(arbitrator_jit): $(DEP_PREDICATE) $(jit_files)
$(arbitrator_cases)/rust/$(wasm32_wasi)/%.wasm: $(arbitrator_cases)/rust/src/bin/%.rs $(arbitrator_cases)/rust/src/lib.rs
cargo build --manifest-path $(arbitrator_cases)/rust/Cargo.toml --release --target wasm32-wasi --bin $(patsubst $(arbitrator_cases)/rust/$(wasm32_wasi)/%.wasm,%, $@)

$(arbitrator_cases)/go/testcase.wasm: $(arbitrator_cases)/go/*.go
$(arbitrator_cases)/go/testcase.wasm: $(arbitrator_cases)/go/*.go .make/solgen
cd $(arbitrator_cases)/go && GOOS=wasip1 GOARCH=wasm go build -o testcase.wasm

$(arbitrator_generated_header): $(DEP_PREDICATE) $(stylus_files)
Expand Down Expand Up @@ -439,8 +439,12 @@ target/testdata/preimages.bin:
contracts/test/prover/proofs/rust-%.json: $(arbitrator_cases)/rust/$(wasm32_wasi)/%.wasm $(prover_bin) $(arbitrator_wasm_libs) target/testdata/preimages.bin
$(prover_bin) $< $(arbitrator_wasm_lib_flags) -o $@ -b --allow-hostapi --require-success --inbox-add-stub-headers --inbox $(arbitrator_cases)/rust/data/msg0.bin --inbox $(arbitrator_cases)/rust/data/msg1.bin --delayed-inbox $(arbitrator_cases)/rust/data/msg0.bin --delayed-inbox $(arbitrator_cases)/rust/data/msg1.bin --preimages target/testdata/preimages.bin

contracts/test/prover/proofs/go.json: $(arbitrator_cases)/go/testcase.wasm $(prover_bin) $(arbitrator_wasm_libs) target/testdata/preimages.bin $(arbitrator_tests_link_deps)
$(prover_bin) $< $(arbitrator_wasm_lib_flags) -o $@ -i 50000000 --require-success --preimages target/testdata/preimages.bin
contracts/test/prover/proofs/go.json: $(arbitrator_cases)/go/testcase.wasm $(prover_bin) $(arbitrator_wasm_libs) target/testdata/preimages.bin $(arbitrator_tests_link_deps) $(arbitrator_cases)/user.wasm
$(prover_bin) $< $(arbitrator_wasm_lib_flags) -o $@ -b --require-success --preimages target/testdata/preimages.bin --stylus-modules $(arbitrator_cases)/user.wasm

# avoid testing user.wasm in onestepproofs. It can only run as stylus program.
contracts/test/prover/proofs/user.json:
echo "[]" > $@

# avoid testing read-inboxmsg-10 in onestepproofs. It's used for go challenge testing.
contracts/test/prover/proofs/read-inboxmsg-10.json:
Expand Down
5 changes: 4 additions & 1 deletion arbitrator/prover/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ fn main() -> Result<()> {

if opts.proving_backoff {
let mut extra_data = 0;
if matches!(next_opcode, Opcode::ReadInboxMessage | Opcode::ReadPreImage) {
if matches!(
next_opcode,
Opcode::ReadInboxMessage | Opcode::ReadPreImage | Opcode::SwitchThread
) {
extra_data = next_inst.argument_data;
}
let count_entry = proving_backoff
Expand Down
2 changes: 1 addition & 1 deletion arbitrator/prover/test-cases/dynamic.wat
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

;; WAVM Module hash
(data (i32.const 0x000)
"\3a\eb\a0\67\68\ef\f5\f9\4e\ec\84\88\ac\54\b7\b7\07\a5\12\9c\fb\73\50\37\33\d9\9e\90\ea\72\97\8c") ;; user
"\4c\39\43\0c\cb\0f\33\44\21\f9\32\8c\8c\61\af\05\35\e9\ce\35\69\8a\f2\a5\e3\0c\6a\6a\1d\44\cd\22") ;; user

(func $start (local $user i32) (local $internals i32)
;; link in user.wat
Expand Down
44 changes: 44 additions & 0 deletions arbitrator/prover/test-cases/go/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright 2021-2024, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE

//go:build wasm
// +build wasm

package main

import (
Expand All @@ -19,6 +22,7 @@ import (
merkletree "github.com/wealdtech/go-merkletree"

"github.com/offchainlabs/nitro/arbcompress"
"github.com/offchainlabs/nitro/arbos/programs"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/wavmio"
)
Expand Down Expand Up @@ -69,11 +73,51 @@ const BYTES_PER_FIELD_ELEMENT = 32

var BLS_MODULUS, _ = new(big.Int).SetString("52435875175126190479447740508185965837690552500527637822603658699938581184513", 10)

var stylusModuleHash = common.HexToHash("4c39430ccb0f334421f9328c8c61af0535e9ce35698af2a5e30c6a6a1d44cd22") // user.wat

func callStylusProgram(recurse int) {
evmData := programs.EvmData{}
progParams := programs.ProgParams{
MaxDepth: 10000,
InkPrice: 1,
DebugMode: true,
}
reqHandler := func(req programs.RequestType, input []byte) ([]byte, []byte, uint64) {
fmt.Printf("got request type %d req %v\n", req, input)
if req == programs.GetBytes32 {
if recurse > 0 {
callStylusProgram(recurse - 1)
}
answer := common.Hash{}
return answer[:], nil, 1
}

panic("unsupported call")
}
calldata := common.Hash{}.Bytes()
_, _, err := programs.CallProgramLoop(
stylusModuleHash,
calldata,
160000000,
&evmData,
&progParams,
reqHandler)
if err != nil {
panic(err)
}
}

func main() {
fmt.Printf("starting executable with %v arg(s): %v\n", len(os.Args), os.Args)
runtime.GC()
time.Sleep(time.Second)

fmt.Printf("Stylus test\n")

callStylusProgram(5)

fmt.Printf("Stylus test done!\n")

// Data for the tree
data := [][]byte{
[]byte("Foo"),
Expand Down
2 changes: 1 addition & 1 deletion arbitrator/prover/test-cases/link.wat
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
(data (i32.const 0x140)
"\7e\01\98\c8\a1\f4\74\be\92\8c\2c\ec\5d\5f\be\04\65\b1\c0\74\43\71\c3\63\00\db\20\b3\a9\17\9b\ac") ;; iops
(data (i32.const 0x160)
"\3a\eb\a0\67\68\ef\f5\f9\4e\ec\84\88\ac\54\b7\b7\07\a5\12\9c\fb\73\50\37\33\d9\9e\90\ea\72\97\8c") ;; user
"\4c\39\43\0c\cb\0f\33\44\21\f9\32\8c\8c\61\af\05\35\e9\ce\35\69\8a\f2\a5\e3\0c\6a\6a\1d\44\cd\22") ;; user
(data (i32.const 0x180)
"\fa\91\57\09\98\8a\54\d2\d5\96\71\13\da\71\ae\80\eb\b1\b3\68\5e\90\d7\8e\0e\7d\a2\c4\d8\d9\72\cf") ;; return

Expand Down
13 changes: 13 additions & 0 deletions arbitrator/prover/test-cases/user.wat
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
;; For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE

(module
(import "vm_hooks" "storage_load_bytes32" (func $storage_load_bytes32 (param i32 i32)))

(func $storage_load (result i32)
i32.const 0
i32.const 32
call $storage_load_bytes32
i32.const 0
)
(func $safe (result i32)
i32.const 5
)
Expand Down Expand Up @@ -35,6 +43,11 @@
(then (call $out_of_bounds) (return))
)

(i32.eq (local.get $args_len) (i32.const 32))
(if
(then (call $storage_load) (return))
)

unreachable
)
(memory (export "memory") 1 1))
Loading
Loading