diff --git a/rvgo/fast/instrumented.go b/rvgo/fast/instrumented.go index 80187cc..c2a4c9d 100644 --- a/rvgo/fast/instrumented.go +++ b/rvgo/fast/instrumented.go @@ -73,7 +73,7 @@ func (m *InstrumentedState) Step(proof bool) (wit *StepWitness, err error) { func (m *InstrumentedState) readPreimage(key [32]byte, offset uint64) (dat [32]byte, datLen uint64, err error) { preimage := m.lastPreimage - if key != m.lastPreimageKey { + if preimage == nil || key != m.lastPreimageKey { m.lastPreimageKey = key data := m.preimageOracle.GetPreimage(key) // add the length prefix diff --git a/rvgo/fast/instrumented_test.go b/rvgo/fast/instrumented_test.go new file mode 100644 index 0000000..636bd35 --- /dev/null +++ b/rvgo/fast/instrumented_test.go @@ -0,0 +1,43 @@ +package fast + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +type MockPreimageOracle struct { +} + +func (oracle *MockPreimageOracle) Hint(v []byte) { +} + +func (oracle *MockPreimageOracle) GetPreimage(k [32]byte) []byte { + return make([]byte, 32) +} + +func (oracle *MockPreimageOracle) ReadPreimagePart(key [32]byte, offset uint64) ([32]byte, uint8, error) { + return [32]byte{}, 32, nil +} + +func TestReadPreimage(t *testing.T) { + + vmState := VMState{ + PC: 0, + Memory: NewMemory(), + Registers: [32]uint64{}, + ExitCode: 0, + Exited: false, + Heap: 0x7f_00_00_00_00_00, + } + + // instruction ecall + vmState.Memory.SetUnaligned(0, []byte{0x73}) + vmState.Registers[17] = 63 + vmState.Registers[10] = 5 + + instState := NewInstrumentedState(&vmState, &MockPreimageOracle{}, nil, nil) + + _, err := instState.Step(true) + require.NoError(t, err) +}