Commit bb87eef8 authored by Inphi's avatar Inphi Committed by GitHub

cannon: Consistent state serialization (#12151)

* cannon: Consistent state serialization

* nosilent cmp

* fix run input

* add elf target dep
parent a0eee5cc
...@@ -43,6 +43,26 @@ contract: ...@@ -43,6 +43,26 @@ contract:
test: elf contract test: elf contract
go test -v ./... go test -v ./...
diff-%-cannon: cannon elf
$$OTHER_CANNON load-elf --type $* --path ./testdata/example/bin/hello.elf --out ./bin/prestate-other.bin.gz --meta ""
./bin/cannon load-elf --type $* --path ./testdata/example/bin/hello.elf --out ./bin/prestate.bin.gz --meta ""
@cmp ./bin/prestate-other.bin.gz ./bin/prestate.bin.gz
@if [ $$? -eq 0 ]; then \
echo "Generated identical prestates"; \
else \
echo "Generated different prestates"; \
exit 1; \
fi
$$OTHER_CANNON run --proof-at '=0' --stop-at '=100000000' --input=./bin/prestate.bin.gz --output ./bin/out-other.bin.gz --meta ""
./bin/cannon run --proof-at '=0' --stop-at '=100000000' --input=./bin/prestate.bin.gz --output ./bin/out.bin.gz --meta ""
@cmp ./bin/out-other.bin.gz ./bin/out.bin.gz
@if [ $$? -eq 0 ]; then \
echo "Generated identical states"; \
else \
echo "Generated different prestates"; \
exit 1; \
fi
fuzz: fuzz:
# Common vm tests # Common vm tests
go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz=FuzzStateSyscallBrk ./mipsevm/tests go test $(FUZZLDFLAGS) -run NOTAREALTEST -v -fuzztime 10s -fuzz=FuzzStateSyscallBrk ./mipsevm/tests
...@@ -65,4 +85,5 @@ fuzz: ...@@ -65,4 +85,5 @@ fuzz:
clean \ clean \
test \ test \
lint \ lint \
fuzz fuzz \
diff-%-cannon
...@@ -6,9 +6,11 @@ import ( ...@@ -6,9 +6,11 @@ import (
"fmt" "fmt"
"io" "io"
"math/bits" "math/bits"
"slices"
"sort" "sort"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"golang.org/x/exp/maps"
) )
// Note: 2**12 = 4 KiB, the min phys page size in the Go runtime. // Note: 2**12 = 4 KiB, the min phys page size in the Go runtime.
...@@ -299,7 +301,11 @@ func (m *Memory) Serialize(out io.Writer) error { ...@@ -299,7 +301,11 @@ func (m *Memory) Serialize(out io.Writer) error {
if err := binary.Write(out, binary.BigEndian, uint32(m.PageCount())); err != nil { if err := binary.Write(out, binary.BigEndian, uint32(m.PageCount())); err != nil {
return err return err
} }
for pageIndex, page := range m.pages { indexes := maps.Keys(m.pages)
// iterate sorted map keys for consistent serialization
slices.Sort(indexes)
for _, pageIndex := range indexes {
page := m.pages[pageIndex]
if err := binary.Write(out, binary.BigEndian, pageIndex); err != nil { if err := binary.Write(out, binary.BigEndian, pageIndex); err != nil {
return err return err
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment