Skip to content

Commit

Permalink
feat(native): journal descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby committed Dec 18, 2024
1 parent 8ff9318 commit dbeba7f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions rvgo/fast/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type VMState struct {

Registers [32]uint64 `json:"registers"`

Journal []byte `json:"journal,omitempty"`

// LastHint is optional metadata, and not part of the VM state itself.
// It is used to remember the last pre-image hint,
// so a VM can start from any state without fetching prior pre-images,
Expand All @@ -65,6 +67,7 @@ func NewVMState() *VMState {
return &VMState{
Memory: NewMemory(),

Check failure on line 68 in rvgo/fast/state.go

View workflow job for this annotation

GitHub Actions / rvgo-lint

File is not `goimports`-ed (goimports)
Heap: 1 << 28, // 0.25 GiB of program code space
Journal: make([]byte, 0),
}
}

Expand Down Expand Up @@ -100,6 +103,8 @@ func (state *VMState) EncodeWitness() StateWitness {
for _, r := range state.Registers {
out = binary.BigEndian.AppendUint64(out, r)
}
out = binary.BigEndian.AppendUint64(out, uint64(len(state.Journal)))
out = append(out, state.Journal...)
return out
}

Expand Down Expand Up @@ -209,6 +214,9 @@ func (s *VMState) Serialize(out io.Writer) error {
if err := bout.WriteHash(s.StateHash); err != nil {
return err
}
if err := bout.WriteBytes(s.Journal); err != nil {
return err
}

return nil
}
Expand Down Expand Up @@ -257,6 +265,9 @@ func (s *VMState) Deserialize(in io.Reader) error {
if err := bin.ReadHash(&s.StateHash); err != nil {
return err
}
if err := bin.ReadBytes((*[]byte)(&s.Journal)); err != nil {
return err
}

return nil
}
Expand Down
5 changes: 5 additions & 0 deletions rvgo/fast/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,11 @@ func (inst *InstrumentedState) riscvStep() (outErr error) {
case riscv.FdPreimageWrite: // pre-image key write
n = writePreimageKey(addr, count)
errCode = toU64(0) // no error
case riscv.FdJournalWrite: // journal write
journalData, _ := io.ReadAll(s.Memory.ReadMemoryRange(addr, count))
s.Journal = append(s.Journal, journalData...)
n = count
errCode = toU64(0)
default: // any other file, including (3) hint read (5) preimage read
n = u64Mask() // -1 (writing error)
errCode = toU64(0x4d) // EBADF
Expand Down
1 change: 1 addition & 0 deletions rvgo/riscv/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
FdHintWrite = 4
FdPreimageRead = 5
FdPreimageWrite = 6
FdJournalWrite = 7

ErrUnrecognizedResource = uint64(0xf0012)
ErrUnknownAtomicOperation = uint64(0xf001a70)
Expand Down

0 comments on commit dbeba7f

Please sign in to comment.