Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rvgo/cmd/load_elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func LoadELF(ctx *cli.Context) error {
if err != nil {
return fmt.Errorf("failed to compute program metadata: %w", err)
}
// Must set witness and stateHash after initial state is prepared
if err := state.SetWitnessAndStateHash(); err != nil {
return fmt.Errorf("failed to set witness and stateHash: %w", err)
}
if err := jsonutil.WriteJSON[*Metadata](ctx.Path(cannon.LoadELFMetaFlag.Name), meta, OutFilePerm); err != nil {
return fmt.Errorf("failed to output metadata: %w", err)
}
Expand Down
4 changes: 4 additions & 0 deletions rvgo/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ func Run(ctx *cli.Context) error {
}
}

if err := state.SetWitnessAndStateHash(); err != nil {
return fmt.Errorf("failed to set witness and stateHash: %w", err)
}

if err := jsonutil.WriteJSON(ctx.Path(cannon.RunOutputFlag.Name), state, OutFilePerm); err != nil {
return fmt.Errorf("failed to write state output: %w", err)
}
Expand Down
16 changes: 16 additions & 0 deletions rvgo/fast/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ type VMState struct {
// Warning: the hint MAY NOT BE COMPLETE. I.e. this is buffered,
// and should only be read when len(LastHint) > 4 && uint32(LastHint[:4]) >= len(LastHint[4:])
LastHint hexutil.Bytes `json:"lastHint,omitempty"`

// VMState must hold these values because if not, we must ask FPVM again to
// compute these values.
Witness []byte `json:"witness,omitempty"`
StateHash [32]byte `json:"stateHash,omitempty"`
}

func NewVMState() *VMState {
Expand All @@ -59,6 +64,17 @@ func NewVMState() *VMState {
}
}

func (state *VMState) SetWitnessAndStateHash() error {
witness := state.EncodeWitness()
state.Witness = witness
stateHash, err := witness.StateHash()
if err != nil {
return fmt.Errorf("failed to compute stateHash: %w", err)
}
state.StateHash = stateHash
return nil
}

func (state *VMState) GetStep() uint64 { return state.Step }

func (state *VMState) EncodeWitness() StateWitness {
Expand Down