Skip to content

Commit

Permalink
cannon: Generate mt prestate as gzipped binary.
Browse files Browse the repository at this point in the history
Use different versions for singlethreaded and multithreaded states.
  • Loading branch information
ajsutton committed Sep 5, 2024
1 parent 3523437 commit dd07897
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ cannon-prestate: op-program cannon ## Generates prestate using cannon and op-pro
.PHONY: cannon-prestate

cannon-prestate-mt: op-program cannon ## Generates prestate using cannon and op-program in the multithreaded cannon format
./cannon/bin/cannon load-elf --type cannon-mt --path op-program/bin/op-program-client.elf --out op-program/bin/prestate-mt.json --meta op-program/bin/meta-mt.json
./cannon/bin/cannon run --type cannon-mt --proof-at '=0' --stop-at '=1' --input op-program/bin/prestate-mt.json --meta op-program/bin/meta-mt.json --proof-fmt 'op-program/bin/%d-mt.json' --output ""
./cannon/bin/cannon load-elf --type cannon-mt --path op-program/bin/op-program-client.elf --out op-program/bin/prestate-mt.bin.gz --meta op-program/bin/meta-mt.json
./cannon/bin/cannon run --type cannon-mt --proof-at '=0' --stop-at '=1' --input op-program/bin/prestate-mt.bin.gz --meta op-program/bin/meta-mt.json --proof-fmt 'op-program/bin/%d-mt.json' --output ""
mv op-program/bin/0-mt.json op-program/bin/prestate-proof-mt.json
.PHONY: cannon-prestate

Expand Down
6 changes: 4 additions & 2 deletions cannon/mipsevm/multithreaded/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const (
LEFT_THREADS_ROOT_WITNESS_OFFSET = TRAVERSE_RIGHT_WITNESS_OFFSET + 1
RIGHT_THREADS_ROOT_WITNESS_OFFSET = LEFT_THREADS_ROOT_WITNESS_OFFSET + 32
THREAD_ID_WITNESS_OFFSET = RIGHT_THREADS_ROOT_WITNESS_OFFSET + 32

StateVersion = uint8(1)
)

type State struct {
Expand Down Expand Up @@ -222,7 +224,7 @@ func (s *State) ThreadCount() int {

func (s *State) Serialize(out io.Writer) error {
// Write the version byte to the buffer.
if err := binary.Write(out, binary.BigEndian, uint8(0)); err != nil {
if err := binary.Write(out, binary.BigEndian, StateVersion); err != nil {
return err
}

Expand Down Expand Up @@ -332,7 +334,7 @@ func (s *State) Deserialize(in io.Reader) error {
if err := binary.Read(in, binary.BigEndian, &version); err != nil {
return err
}
if version != 0 {
if version != StateVersion {
return fmt.Errorf("invalid state encoding version %d", version)
}
s.Memory = memory.NewMemory()
Expand Down
6 changes: 4 additions & 2 deletions cannon/mipsevm/singlethreaded/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
// STATE_WITNESS_SIZE is the size of the state witness encoding in bytes.
const STATE_WITNESS_SIZE = 226

const StateVersion = uint8(0)

type State struct {
Memory *memory.Memory `json:"memory"`

Expand Down Expand Up @@ -180,7 +182,7 @@ func (s *State) EncodeWitness() ([]byte, common.Hash) {

func (s *State) Serialize(out io.Writer) error {
// Write the version byte to the buffer.
if err := binary.Write(out, binary.BigEndian, uint8(0)); err != nil {
if err := binary.Write(out, binary.BigEndian, StateVersion); err != nil {
return err
}

Expand Down Expand Up @@ -268,7 +270,7 @@ func (s *State) Deserialize(in io.Reader) error {
if err := binary.Read(in, binary.BigEndian, &version); err != nil {
return err
}
if version != 0 {
if version != StateVersion {
return fmt.Errorf("invalid state encoding version %d", version)
}
s.Memory = memory.NewMemory()
Expand Down

0 comments on commit dd07897

Please sign in to comment.