Skip to content

Commit

Permalink
Merge pull request #114 from ethereum-optimism/feature/mininny/audit-28
Browse files Browse the repository at this point in the history
Check lastPreimage != nil before accessing the cached preimage
  • Loading branch information
mininny authored Jan 15, 2025
2 parents 1ea4ef9 + 1203fc4 commit f75a5bc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rvgo/fast/instrumented.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions rvgo/fast/instrumented_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit f75a5bc

Please sign in to comment.