Skip to content

Commit

Permalink
Add wavmio preimage test to go prover test
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed Sep 29, 2023
1 parent 64b4ddc commit 6ecadc3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions arbitrator/prover/test-cases/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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")
}

0 comments on commit 6ecadc3

Please sign in to comment.