From 6ecadc3ffb613d8e1b915e89312c2d44b7ec5853 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Thu, 28 Sep 2023 20:19:23 -0600 Subject: [PATCH] Add wavmio preimage test to go prover test --- Makefile | 2 +- arbitrator/prover/test-cases/go/main.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 38ffb96200..4221100961 100644 --- a/Makefile +++ b/Makefile @@ -295,7 +295,7 @@ contracts/test/prover/proofs/rust-%.json: $(arbitrator_cases)/rust/target/wasm32 $(arbitrator_prover_bin) $< $(arbitrator_wasm_lib_flags_nogo) -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 $(arbitrator_cases)/rust/data/preimages.bin contracts/test/prover/proofs/go.json: $(arbitrator_cases)/go/main $(arbitrator_prover_bin) $(arbitrator_wasm_libs) - $(arbitrator_prover_bin) $< $(arbitrator_wasm_lib_flags) -o $@ -i 5000000 --require-success + $(arbitrator_prover_bin) $< $(arbitrator_wasm_lib_flags) -o $@ -i 5000000 --require-success --preimages $(arbitrator_cases)/rust/data/preimages.bin # avoid testing read-inboxmsg-10 in onestepproofs. It's used for go challenge testing. contracts/test/prover/proofs/read-inboxmsg-10.json: diff --git a/arbitrator/prover/test-cases/go/main.go b/arbitrator/prover/test-cases/go/main.go index a5a1028fb0..7ac669f8a6 100644 --- a/arbitrator/prover/test-cases/go/main.go +++ b/arbitrator/prover/test-cases/go/main.go @@ -5,14 +5,18 @@ package main import ( "bytes" + "encoding/hex" "fmt" "os" "runtime" "time" + "github.com/ethereum/go-ethereum/common" merkletree "github.com/wealdtech/go-merkletree" "github.com/offchainlabs/nitro/arbcompress" + "github.com/offchainlabs/nitro/arbutil" + "github.com/offchainlabs/nitro/wavmio" ) // MerkleSample is an example using the Merkle tree to generate and verify proofs. @@ -95,4 +99,19 @@ func main() { testCompression([]byte("This is a test string la la la la la la la la la la")) println("test compression passed!\n") + + checkPreimage := func(ty arbutil.PreimageType, hash common.Hash) { + preimage, err := wavmio.ResolveTypedPreimage(ty, hash) + if err != nil { + panic(fmt.Sprintf("failed to resolve preimage of type %v: %v", ty, err)) + } + if !bytes.Equal(preimage, []byte("hello world")) { + panic(fmt.Sprintf("got wrong preimage of type %v: %v", ty, hex.EncodeToString(preimage))) + } + } + + checkPreimage(arbutil.Keccak256PreimageType, common.HexToHash("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad")) + checkPreimage(arbutil.Sha2_256PreimageType, common.HexToHash("b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9")) + + println("verified preimage resolution!\n") }