Commit 711bc7cf authored by Inphi's avatar Inphi Committed by GitHub

cannon: Fix 64-bit memory access (#12259)

* cannon: Fix 64-bit memory access

Also, replace `memory.GetMemory` with `memory.GetUint32`

* Rename SetWord to SetUint32

* fix comment
parent 6014026a
...@@ -410,7 +410,7 @@ func Run(ctx *cli.Context) error { ...@@ -410,7 +410,7 @@ func Run(ctx *cli.Context) error {
l.Info("processing", l.Info("processing",
"step", step, "step", step,
"pc", mipsevm.HexU32(state.GetPC()), "pc", mipsevm.HexU32(state.GetPC()),
"insn", mipsevm.HexU32(state.GetMemory().GetMemory(state.GetPC())), "insn", mipsevm.HexU32(state.GetMemory().GetUint32(state.GetPC())),
"ips", float64(step-startStep)/(float64(delta)/float64(time.Second)), "ips", float64(step-startStep)/(float64(delta)/float64(time.Second)),
"pages", state.GetMemory().PageCount(), "pages", state.GetMemory().PageCount(),
"mem", state.GetMemory().Usage(), "mem", state.GetMemory().Usage(),
......
...@@ -15,9 +15,9 @@ type MemoryTrackerImpl struct { ...@@ -15,9 +15,9 @@ type MemoryTrackerImpl struct {
lastMemAccess Word lastMemAccess Word
memProofEnabled bool memProofEnabled bool
// proof of first unique memory access // proof of first unique memory access
memProof [memory.MEM_PROOF_SIZE]byte memProof [memory.MemProofSize]byte
// proof of second unique memory access // proof of second unique memory access
memProof2 [memory.MEM_PROOF_SIZE]byte memProof2 [memory.MemProofSize]byte
} }
func NewMemoryTracker(memory *memory.Memory) *MemoryTrackerImpl { func NewMemoryTracker(memory *memory.Memory) *MemoryTrackerImpl {
...@@ -49,10 +49,10 @@ func (m *MemoryTrackerImpl) Reset(enableProof bool) { ...@@ -49,10 +49,10 @@ func (m *MemoryTrackerImpl) Reset(enableProof bool) {
m.lastMemAccess = ^Word(0) m.lastMemAccess = ^Word(0)
} }
func (m *MemoryTrackerImpl) MemProof() [memory.MEM_PROOF_SIZE]byte { func (m *MemoryTrackerImpl) MemProof() [memory.MemProofSize]byte {
return m.memProof return m.memProof
} }
func (m *MemoryTrackerImpl) MemProof2() [memory.MEM_PROOF_SIZE]byte { func (m *MemoryTrackerImpl) MemProof2() [memory.MemProofSize]byte {
return m.memProof2 return m.memProof2
} }
...@@ -19,7 +19,7 @@ const ( ...@@ -19,7 +19,7 @@ const (
) )
func GetInstructionDetails(pc Word, memory *memory.Memory) (insn, opcode, fun uint32) { func GetInstructionDetails(pc Word, memory *memory.Memory) (insn, opcode, fun uint32) {
insn = memory.GetMemory(pc) insn = memory.GetUint32(pc)
opcode = insn >> 26 // First 6-bits opcode = insn >> 26 // First 6-bits
fun = insn & 0x3f // Last 6-bits fun = insn & 0x3f // Last 6-bits
......
...@@ -16,6 +16,7 @@ import ( ...@@ -16,6 +16,7 @@ import (
// Note: 2**12 = 4 KiB, the min phys page size in the Go runtime. // Note: 2**12 = 4 KiB, the min phys page size in the Go runtime.
const ( const (
WordSize = arch.WordSize
PageAddrSize = arch.PageAddrSize PageAddrSize = arch.PageAddrSize
PageKeySize = arch.PageKeySize PageKeySize = arch.PageKeySize
PageSize = 1 << PageAddrSize PageSize = 1 << PageAddrSize
...@@ -23,10 +24,9 @@ const ( ...@@ -23,10 +24,9 @@ const (
MaxPageCount = 1 << PageKeySize MaxPageCount = 1 << PageKeySize
PageKeyMask = MaxPageCount - 1 PageKeyMask = MaxPageCount - 1
MemProofLeafCount = arch.MemProofLeafCount MemProofLeafCount = arch.MemProofLeafCount
MemProofSize = arch.MemProofSize
) )
const MEM_PROOF_SIZE = arch.MemProofSize
type Word = arch.Word type Word = arch.Word
func HashPair(left, right [32]byte) [32]byte { func HashPair(left, right [32]byte) [32]byte {
...@@ -98,8 +98,9 @@ func (m *Memory) invalidate(addr Word) { ...@@ -98,8 +98,9 @@ func (m *Memory) invalidate(addr Word) {
return return
} }
// find the gindex of the first page covering the address // find the gindex of the first page covering the address: i.e. ((1 << WordSize) | addr) >> PageAddrSize
gindex := ((uint64(1) << 32) | uint64(addr)) >> PageAddrSize // Avoid 64-bit overflow by distributing the right shift across the OR.
gindex := (uint64(1) << (WordSize - PageAddrSize)) | uint64(addr>>PageAddrSize)
for gindex > 0 { for gindex > 0 {
m.nodes[gindex] = nil m.nodes[gindex] = nil
...@@ -137,7 +138,7 @@ func (m *Memory) MerkleizeSubtree(gindex uint64) [32]byte { ...@@ -137,7 +138,7 @@ func (m *Memory) MerkleizeSubtree(gindex uint64) [32]byte {
return r return r
} }
func (m *Memory) MerkleProof(addr Word) (out [MEM_PROOF_SIZE]byte) { func (m *Memory) MerkleProof(addr Word) (out [MemProofSize]byte) {
proof := m.traverseBranch(1, addr, 0) proof := m.traverseBranch(1, addr, 0)
// encode the proof // encode the proof
for i := 0; i < MemProofLeafCount; i++ { for i := 0; i < MemProofLeafCount; i++ {
...@@ -147,17 +148,17 @@ func (m *Memory) MerkleProof(addr Word) (out [MEM_PROOF_SIZE]byte) { ...@@ -147,17 +148,17 @@ func (m *Memory) MerkleProof(addr Word) (out [MEM_PROOF_SIZE]byte) {
} }
func (m *Memory) traverseBranch(parent uint64, addr Word, depth uint8) (proof [][32]byte) { func (m *Memory) traverseBranch(parent uint64, addr Word, depth uint8) (proof [][32]byte) {
if depth == 32-5 { if depth == WordSize-5 {
proof = make([][32]byte, 0, 32-5+1) proof = make([][32]byte, 0, WordSize-5+1)
proof = append(proof, m.MerkleizeSubtree(parent)) proof = append(proof, m.MerkleizeSubtree(parent))
return return
} }
if depth > 32-5 { if depth > WordSize-5 {
panic("traversed too deep") panic("traversed too deep")
} }
self := parent << 1 self := parent << 1
sibling := self | 1 sibling := self | 1
if addr&(1<<(31-depth)) != 0 { if addr&(1<<((WordSize-1)-depth)) != 0 {
self, sibling = sibling, self self, sibling = sibling, self
} }
proof = m.traverseBranch(self, addr, depth+1) proof = m.traverseBranch(self, addr, depth+1)
...@@ -191,8 +192,8 @@ func (m *Memory) pageLookup(pageIndex Word) (*CachedPage, bool) { ...@@ -191,8 +192,8 @@ func (m *Memory) pageLookup(pageIndex Word) (*CachedPage, bool) {
return p, ok return p, ok
} }
func (m *Memory) SetMemory(addr Word, v uint32) { func (m *Memory) SetUint32(addr Word, v uint32) {
// addr must be aligned to 4 bytes // addr must be aligned to WordSizeBytes bytes
if addr&arch.ExtMask != 0 { if addr&arch.ExtMask != 0 {
panic(fmt.Errorf("unaligned memory access: %x", addr)) panic(fmt.Errorf("unaligned memory access: %x", addr))
} }
...@@ -230,10 +231,10 @@ func (m *Memory) SetWord(addr Word, v Word) { ...@@ -230,10 +231,10 @@ func (m *Memory) SetWord(addr Word, v Word) {
arch.ByteOrderWord.PutWord(p.Data[pageAddr:pageAddr+arch.WordSizeBytes], v) arch.ByteOrderWord.PutWord(p.Data[pageAddr:pageAddr+arch.WordSizeBytes], v)
} }
// GetMemory reads the 32-bit value located at the specified address. // GetUint32 returns the first 32 bits located at the specified location.
func (m *Memory) GetMemory(addr Word) uint32 { func (m *Memory) GetUint32(addr Word) uint32 {
// addr must be aligned to 4 bytes // addr must be aligned to 4 bytes
if addr&arch.ExtMask != 0 { if addr&3 != 0 {
panic(fmt.Errorf("unaligned memory access: %x", addr)) panic(fmt.Errorf("unaligned memory access: %x", addr))
} }
p, ok := m.pageLookup(addr >> PageAddrSize) p, ok := m.pageLookup(addr >> PageAddrSize)
...@@ -245,7 +246,7 @@ func (m *Memory) GetMemory(addr Word) uint32 { ...@@ -245,7 +246,7 @@ func (m *Memory) GetMemory(addr Word) uint32 {
} }
// GetWord reads the maximum sized value, [arch.Word], located at the specified address. // GetWord reads the maximum sized value, [arch.Word], located at the specified address.
// Note: Also known by the MIPS64 specification as a "double-word" memory access. // Note: Also referred to by the MIPS64 specification as a "double-word" memory access.
func (m *Memory) GetWord(addr Word) Word { func (m *Memory) GetWord(addr Word) Word {
// addr must be word aligned // addr must be word aligned
if addr&arch.ExtMask != 0 { if addr&arch.ExtMask != 0 {
......
//go:build cannon64
// +build cannon64
package memory
import (
"bytes"
"crypto/rand"
"encoding/binary"
"encoding/json"
"io"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// These tests are mostly copied from memory_test.go. With a few tweaks for 64-bit.
func TestMemory64MerkleProof(t *testing.T) {
t.Run("nearly empty tree", func(t *testing.T) {
m := NewMemory()
m.SetWord(0x10000, 0xAABBCCDD_EEFF1122)
proof := m.MerkleProof(0x10000)
require.Equal(t, uint64(0xAABBCCDD_EEFF1122), binary.BigEndian.Uint64(proof[:8]))
for i := 0; i < 64-5; i++ {
require.Equal(t, zeroHashes[i][:], proof[32+i*32:32+i*32+32], "empty siblings")
}
})
t.Run("fuller tree", func(t *testing.T) {
m := NewMemory()
m.SetWord(0x10000, 0xaabbccdd)
m.SetWord(0x80008, 42)
m.SetWord(0x13370000, 123)
root := m.MerkleRoot()
proof := m.MerkleProof(0x80008)
require.Equal(t, uint64(42), binary.BigEndian.Uint64(proof[8:16]))
node := *(*[32]byte)(proof[:32])
path := uint32(0x80008) >> 5
for i := 32; i < len(proof); i += 32 {
sib := *(*[32]byte)(proof[i : i+32])
if path&1 != 0 {
node = HashPair(sib, node)
} else {
node = HashPair(node, sib)
}
path >>= 1
}
require.Equal(t, root, node, "proof must verify")
})
}
func TestMemory64MerkleRoot(t *testing.T) {
t.Run("empty", func(t *testing.T) {
m := NewMemory()
root := m.MerkleRoot()
require.Equal(t, zeroHashes[64-5], root, "fully zeroed memory should have expected zero hash")
})
t.Run("empty page", func(t *testing.T) {
m := NewMemory()
m.SetWord(0xF000, 0)
root := m.MerkleRoot()
require.Equal(t, zeroHashes[64-5], root, "fully zeroed memory should have expected zero hash")
})
t.Run("single page", func(t *testing.T) {
m := NewMemory()
m.SetWord(0xF000, 1)
root := m.MerkleRoot()
require.NotEqual(t, zeroHashes[64-5], root, "non-zero memory")
})
t.Run("repeat zero", func(t *testing.T) {
m := NewMemory()
m.SetWord(0xF000, 0)
m.SetWord(0xF008, 0)
root := m.MerkleRoot()
require.Equal(t, zeroHashes[64-5], root, "zero still")
})
t.Run("two empty pages", func(t *testing.T) {
m := NewMemory()
m.SetWord(PageSize*3, 0)
m.SetWord(PageSize*10, 0)
root := m.MerkleRoot()
require.Equal(t, zeroHashes[64-5], root, "zero still")
})
t.Run("random few pages", func(t *testing.T) {
m := NewMemory()
m.SetWord(PageSize*3, 1)
m.SetWord(PageSize*5, 42)
m.SetWord(PageSize*6, 123)
p3 := m.MerkleizeSubtree((1 << PageKeySize) | 3)
p5 := m.MerkleizeSubtree((1 << PageKeySize) | 5)
p6 := m.MerkleizeSubtree((1 << PageKeySize) | 6)
z := zeroHashes[PageAddrSize-5]
r1 := HashPair(
HashPair(
HashPair(z, z), // 0,1
HashPair(z, p3), // 2,3
),
HashPair(
HashPair(z, p5), // 4,5
HashPair(p6, z), // 6,7
),
)
r2 := m.MerkleizeSubtree(1 << (PageKeySize - 3))
require.Equal(t, r1, r2, "expecting manual page combination to match subtree merkle func")
})
t.Run("invalidate page", func(t *testing.T) {
m := NewMemory()
m.SetWord(0xF000, 0)
require.Equal(t, zeroHashes[64-5], m.MerkleRoot(), "zero at first")
m.SetWord(0xF008, 1)
require.NotEqual(t, zeroHashes[64-5], m.MerkleRoot(), "non-zero")
m.SetWord(0xF008, 0)
require.Equal(t, zeroHashes[64-5], m.MerkleRoot(), "zero again")
})
}
func TestMemory64ReadWrite(t *testing.T) {
t.Run("large random", func(t *testing.T) {
m := NewMemory()
data := make([]byte, 20_000)
_, err := rand.Read(data[:])
require.NoError(t, err)
require.NoError(t, m.SetMemoryRange(0, bytes.NewReader(data)))
for _, i := range []Word{0, 8, 1000, 20_000 - 8} {
v := m.GetWord(i)
expected := binary.BigEndian.Uint64(data[i : i+8])
require.Equalf(t, expected, v, "read at %d", i)
}
})
t.Run("repeat range", func(t *testing.T) {
m := NewMemory()
data := []byte(strings.Repeat("under the big bright yellow sun ", 40))
require.NoError(t, m.SetMemoryRange(0x1337, bytes.NewReader(data)))
res, err := io.ReadAll(m.ReadMemoryRange(0x1337-10, Word(len(data)+20)))
require.NoError(t, err)
require.Equal(t, make([]byte, 10), res[:10], "empty start")
require.Equal(t, data, res[10:len(res)-10], "result")
require.Equal(t, make([]byte, 10), res[len(res)-10:], "empty end")
})
t.Run("read-write", func(t *testing.T) {
m := NewMemory()
m.SetWord(16, 0xAABBCCDD_EEFF1122)
require.Equal(t, Word(0xAABBCCDD_EEFF1122), m.GetWord(16))
require.Equal(t, uint32(0xAABBCCDD), m.GetUint32(16))
require.Equal(t, uint32(0xEEFF1122), m.GetUint32(20))
m.SetWord(16, 0xAABB1CDD_EEFF1122)
require.Equal(t, Word(0xAABB1CDD_EEFF1122), m.GetWord(16))
require.Equal(t, uint32(0xAABB1CDD), m.GetUint32(16))
require.Equal(t, uint32(0xEEFF1122), m.GetUint32(20))
m.SetWord(16, 0xAABB1CDD_EEFF1123)
require.Equal(t, Word(0xAABB1CDD_EEFF1123), m.GetWord(16))
require.Equal(t, uint32(0xAABB1CDD), m.GetUint32(16))
require.Equal(t, uint32(0xEEFF1123), m.GetUint32(20))
})
t.Run("unaligned read", func(t *testing.T) {
m := NewMemory()
m.SetWord(16, 0xAABBCCDD_EEFF1122)
m.SetWord(24, 0x11223344_55667788)
for i := Word(17); i < 24; i++ {
require.Panics(t, func() {
m.GetWord(i)
})
if i != 20 {
require.Panics(t, func() {
m.GetUint32(i)
})
}
}
require.Equal(t, Word(0x11223344_55667788), m.GetWord(24))
require.Equal(t, uint32(0x11223344), m.GetUint32(24))
require.Equal(t, Word(0), m.GetWord(32))
require.Equal(t, uint32(0), m.GetUint32(32))
require.Equal(t, Word(0xAABBCCDD_EEFF1122), m.GetWord(16))
require.Equal(t, uint32(0xAABBCCDD), m.GetUint32(16))
require.Equal(t, uint32(0xEEFF1122), m.GetUint32(20))
require.Equal(t, uint32(0x55667788), m.GetUint32(28))
})
t.Run("unaligned write", func(t *testing.T) {
m := NewMemory()
m.SetWord(16, 0xAABBCCDD_EEFF1122)
require.Panics(t, func() {
m.SetWord(17, 0x11223344)
})
require.Panics(t, func() {
m.SetWord(18, 0x11223344)
})
require.Panics(t, func() {
m.SetWord(19, 0x11223344)
})
require.Panics(t, func() {
m.SetWord(20, 0x11223344)
})
require.Panics(t, func() {
m.SetWord(21, 0x11223344)
})
require.Panics(t, func() {
m.SetWord(22, 0x11223344)
})
require.Panics(t, func() {
m.SetWord(23, 0x11223344)
})
require.Equal(t, Word(0xAABBCCDD_EEFF1122), m.GetWord(16))
require.Equal(t, uint32(0xAABBCCDD), m.GetUint32(16))
})
}
func TestMemory64JSON(t *testing.T) {
m := NewMemory()
m.SetWord(8, 0xAABBCCDD_EEFF1122)
dat, err := json.Marshal(m)
require.NoError(t, err)
var res Memory
require.NoError(t, json.Unmarshal(dat, &res))
require.Equal(t, Word(0xAABBCCDD_EEFF1122), res.GetWord(8))
require.Equal(t, uint32(0xAABBCCDD), res.GetUint32(8))
}
func TestMemory64Copy(t *testing.T) {
m := NewMemory()
m.SetWord(0xAABBCCDD_8000, 0x000000_AABB)
mcpy := m.Copy()
require.Equal(t, Word(0xAABB), mcpy.GetWord(0xAABBCCDD_8000))
require.Equal(t, uint32(0), mcpy.GetUint32(0xAABBCCDD_8000))
require.Equal(t, m.MerkleRoot(), mcpy.MerkleRoot())
}
//go:build !cannon64
// +build !cannon64
package memory package memory
import ( import (
...@@ -15,7 +18,7 @@ import ( ...@@ -15,7 +18,7 @@ import (
func TestMemoryMerkleProof(t *testing.T) { func TestMemoryMerkleProof(t *testing.T) {
t.Run("nearly empty tree", func(t *testing.T) { t.Run("nearly empty tree", func(t *testing.T) {
m := NewMemory() m := NewMemory()
m.SetMemory(0x10000, 0xaabbccdd) m.SetWord(0x10000, 0xaabbccdd)
proof := m.MerkleProof(0x10000) proof := m.MerkleProof(0x10000)
require.Equal(t, uint32(0xaabbccdd), binary.BigEndian.Uint32(proof[:4])) require.Equal(t, uint32(0xaabbccdd), binary.BigEndian.Uint32(proof[:4]))
for i := 0; i < 32-5; i++ { for i := 0; i < 32-5; i++ {
...@@ -24,9 +27,9 @@ func TestMemoryMerkleProof(t *testing.T) { ...@@ -24,9 +27,9 @@ func TestMemoryMerkleProof(t *testing.T) {
}) })
t.Run("fuller tree", func(t *testing.T) { t.Run("fuller tree", func(t *testing.T) {
m := NewMemory() m := NewMemory()
m.SetMemory(0x10000, 0xaabbccdd) m.SetWord(0x10000, 0xaabbccdd)
m.SetMemory(0x80004, 42) m.SetWord(0x80004, 42)
m.SetMemory(0x13370000, 123) m.SetWord(0x13370000, 123)
root := m.MerkleRoot() root := m.MerkleRoot()
proof := m.MerkleProof(0x80004) proof := m.MerkleProof(0x80004)
require.Equal(t, uint32(42), binary.BigEndian.Uint32(proof[4:8])) require.Equal(t, uint32(42), binary.BigEndian.Uint32(proof[4:8]))
...@@ -53,35 +56,35 @@ func TestMemoryMerkleRoot(t *testing.T) { ...@@ -53,35 +56,35 @@ func TestMemoryMerkleRoot(t *testing.T) {
}) })
t.Run("empty page", func(t *testing.T) { t.Run("empty page", func(t *testing.T) {
m := NewMemory() m := NewMemory()
m.SetMemory(0xF000, 0) m.SetWord(0xF000, 0)
root := m.MerkleRoot() root := m.MerkleRoot()
require.Equal(t, zeroHashes[32-5], root, "fully zeroed memory should have expected zero hash") require.Equal(t, zeroHashes[32-5], root, "fully zeroed memory should have expected zero hash")
}) })
t.Run("single page", func(t *testing.T) { t.Run("single page", func(t *testing.T) {
m := NewMemory() m := NewMemory()
m.SetMemory(0xF000, 1) m.SetWord(0xF000, 1)
root := m.MerkleRoot() root := m.MerkleRoot()
require.NotEqual(t, zeroHashes[32-5], root, "non-zero memory") require.NotEqual(t, zeroHashes[32-5], root, "non-zero memory")
}) })
t.Run("repeat zero", func(t *testing.T) { t.Run("repeat zero", func(t *testing.T) {
m := NewMemory() m := NewMemory()
m.SetMemory(0xF000, 0) m.SetWord(0xF000, 0)
m.SetMemory(0xF004, 0) m.SetWord(0xF004, 0)
root := m.MerkleRoot() root := m.MerkleRoot()
require.Equal(t, zeroHashes[32-5], root, "zero still") require.Equal(t, zeroHashes[32-5], root, "zero still")
}) })
t.Run("two empty pages", func(t *testing.T) { t.Run("two empty pages", func(t *testing.T) {
m := NewMemory() m := NewMemory()
m.SetMemory(PageSize*3, 0) m.SetWord(PageSize*3, 0)
m.SetMemory(PageSize*10, 0) m.SetWord(PageSize*10, 0)
root := m.MerkleRoot() root := m.MerkleRoot()
require.Equal(t, zeroHashes[32-5], root, "zero still") require.Equal(t, zeroHashes[32-5], root, "zero still")
}) })
t.Run("random few pages", func(t *testing.T) { t.Run("random few pages", func(t *testing.T) {
m := NewMemory() m := NewMemory()
m.SetMemory(PageSize*3, 1) m.SetWord(PageSize*3, 1)
m.SetMemory(PageSize*5, 42) m.SetWord(PageSize*5, 42)
m.SetMemory(PageSize*6, 123) m.SetWord(PageSize*6, 123)
p3 := m.MerkleizeSubtree((1 << PageKeySize) | 3) p3 := m.MerkleizeSubtree((1 << PageKeySize) | 3)
p5 := m.MerkleizeSubtree((1 << PageKeySize) | 5) p5 := m.MerkleizeSubtree((1 << PageKeySize) | 5)
p6 := m.MerkleizeSubtree((1 << PageKeySize) | 6) p6 := m.MerkleizeSubtree((1 << PageKeySize) | 6)
...@@ -101,11 +104,11 @@ func TestMemoryMerkleRoot(t *testing.T) { ...@@ -101,11 +104,11 @@ func TestMemoryMerkleRoot(t *testing.T) {
}) })
t.Run("invalidate page", func(t *testing.T) { t.Run("invalidate page", func(t *testing.T) {
m := NewMemory() m := NewMemory()
m.SetMemory(0xF000, 0) m.SetWord(0xF000, 0)
require.Equal(t, zeroHashes[32-5], m.MerkleRoot(), "zero at first") require.Equal(t, zeroHashes[32-5], m.MerkleRoot(), "zero at first")
m.SetMemory(0xF004, 1) m.SetWord(0xF004, 1)
require.NotEqual(t, zeroHashes[32-5], m.MerkleRoot(), "non-zero") require.NotEqual(t, zeroHashes[32-5], m.MerkleRoot(), "non-zero")
m.SetMemory(0xF004, 0) m.SetWord(0xF004, 0)
require.Equal(t, zeroHashes[32-5], m.MerkleRoot(), "zero again") require.Equal(t, zeroHashes[32-5], m.MerkleRoot(), "zero again")
}) })
} }
...@@ -119,9 +122,10 @@ func TestMemoryReadWrite(t *testing.T) { ...@@ -119,9 +122,10 @@ func TestMemoryReadWrite(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, m.SetMemoryRange(0, bytes.NewReader(data))) require.NoError(t, m.SetMemoryRange(0, bytes.NewReader(data)))
for _, i := range []Word{0, 4, 1000, 20_000 - 4} { for _, i := range []Word{0, 4, 1000, 20_000 - 4} {
v := m.GetMemory(i) v := m.GetWord(i)
expected := binary.BigEndian.Uint32(data[i : i+4]) expected := binary.BigEndian.Uint32(data[i : i+4])
require.Equalf(t, expected, v, "read at %d", i) require.Equalf(t, expected, v, "read at %d", i)
require.Equalf(t, expected, m.GetUint32(i), "read at %d", i)
} }
}) })
...@@ -138,60 +142,71 @@ func TestMemoryReadWrite(t *testing.T) { ...@@ -138,60 +142,71 @@ func TestMemoryReadWrite(t *testing.T) {
t.Run("read-write", func(t *testing.T) { t.Run("read-write", func(t *testing.T) {
m := NewMemory() m := NewMemory()
m.SetMemory(12, 0xAABBCCDD) m.SetWord(12, 0xAABBCCDD)
require.Equal(t, uint32(0xAABBCCDD), m.GetMemory(12)) require.Equal(t, uint32(0xAABBCCDD), m.GetWord(12))
m.SetMemory(12, 0xAABB1CDD) require.Equal(t, uint32(0xAABBCCDD), m.GetUint32(12))
require.Equal(t, uint32(0xAABB1CDD), m.GetMemory(12)) m.SetWord(12, 0xAABB1CDD)
require.Equal(t, uint32(0xAABB1CDD), m.GetWord(12))
require.Equal(t, uint32(0xAABB1CDD), m.GetUint32(12))
}) })
t.Run("unaligned read", func(t *testing.T) { t.Run("unaligned read", func(t *testing.T) {
m := NewMemory() m := NewMemory()
m.SetMemory(12, 0xAABBCCDD) m.SetWord(12, 0xAABBCCDD)
m.SetMemory(16, 0x11223344) m.SetWord(16, 0x11223344)
require.Panics(t, func() { require.Panics(t, func() {
m.GetMemory(13) m.GetWord(13)
m.GetUint32(13)
}) })
require.Panics(t, func() { require.Panics(t, func() {
m.GetMemory(14) m.GetWord(14)
m.GetUint32(14)
}) })
require.Panics(t, func() { require.Panics(t, func() {
m.GetMemory(15) m.GetWord(15)
m.GetUint32(15)
}) })
require.Equal(t, uint32(0x11223344), m.GetMemory(16)) require.Equal(t, uint32(0x11223344), m.GetWord(16))
require.Equal(t, uint32(0), m.GetMemory(20)) require.Equal(t, uint32(0x11223344), m.GetUint32(16))
require.Equal(t, uint32(0xAABBCCDD), m.GetMemory(12)) require.Equal(t, uint32(0), m.GetWord(20))
require.Equal(t, uint32(0), m.GetUint32(20))
require.Equal(t, uint32(0xAABBCCDD), m.GetWord(12))
require.Equal(t, uint32(0xAABBCCDD), m.GetUint32(12))
}) })
t.Run("unaligned write", func(t *testing.T) { t.Run("unaligned write", func(t *testing.T) {
m := NewMemory() m := NewMemory()
m.SetMemory(12, 0xAABBCCDD) m.SetWord(12, 0xAABBCCDD)
require.Panics(t, func() { require.Panics(t, func() {
m.SetMemory(13, 0x11223344) m.SetWord(13, 0x11223344)
}) })
require.Panics(t, func() { require.Panics(t, func() {
m.SetMemory(14, 0x11223344) m.SetWord(14, 0x11223344)
}) })
require.Panics(t, func() { require.Panics(t, func() {
m.SetMemory(15, 0x11223344) m.SetWord(15, 0x11223344)
}) })
require.Equal(t, uint32(0xAABBCCDD), m.GetMemory(12)) require.Equal(t, uint32(0xAABBCCDD), m.GetWord(12))
require.Equal(t, uint32(0xAABBCCDD), m.GetUint32(12))
}) })
} }
func TestMemoryJSON(t *testing.T) { func TestMemoryJSON(t *testing.T) {
m := NewMemory() m := NewMemory()
m.SetMemory(8, 123) m.SetWord(8, 0xAABBCCDD)
dat, err := json.Marshal(m) dat, err := json.Marshal(m)
require.NoError(t, err) require.NoError(t, err)
var res Memory var res Memory
require.NoError(t, json.Unmarshal(dat, &res)) require.NoError(t, json.Unmarshal(dat, &res))
require.Equal(t, uint32(123), res.GetMemory(8)) require.Equal(t, uint32(0xAABBCCDD), res.GetWord(8))
require.Equal(t, uint32(0xAABBCCDD), res.GetUint32(8))
} }
func TestMemoryCopy(t *testing.T) { func TestMemoryCopy(t *testing.T) {
m := NewMemory() m := NewMemory()
m.SetMemory(0x8000, 123) m.SetWord(0x8000, 123)
mcpy := m.Copy() mcpy := m.Copy()
require.Equal(t, uint32(123), mcpy.GetMemory(0x8000)) require.Equal(t, Word(123), mcpy.GetWord(0x8000))
require.Equal(t, Word(123), mcpy.GetUint32(0x8000))
require.Equal(t, m.MerkleRoot(), mcpy.MerkleRoot()) require.Equal(t, m.MerkleRoot(), mcpy.MerkleRoot())
} }
...@@ -363,7 +363,7 @@ func (m *InstrumentedState) handleRMWOps(insn, opcode uint32) error { ...@@ -363,7 +363,7 @@ func (m *InstrumentedState) handleRMWOps(insn, opcode uint32) error {
m.clearLLMemoryReservation() m.clearLLMemoryReservation()
rt := m.state.GetRegistersRef()[rtReg] rt := m.state.GetRegistersRef()[rtReg]
if opcode == exec.OpStoreConditional { if opcode == exec.OpStoreConditional {
m.state.Memory.SetMemory(effAddr, uint32(rt)) m.state.Memory.SetUint32(effAddr, uint32(rt))
} else { } else {
m.state.Memory.SetWord(effAddr, rt) m.state.Memory.SetWord(effAddr, rt)
} }
......
...@@ -120,7 +120,7 @@ func (e *ExpectedMTState) ExpectStep() { ...@@ -120,7 +120,7 @@ func (e *ExpectedMTState) ExpectStep() {
} }
func (e *ExpectedMTState) ExpectMemoryWrite(addr arch.Word, val uint32) { func (e *ExpectedMTState) ExpectMemoryWrite(addr arch.Word, val uint32) {
e.expectedMemory.SetMemory(addr, val) e.expectedMemory.SetUint32(addr, val)
e.MemoryRoot = e.expectedMemory.MerkleRoot() e.MemoryRoot = e.expectedMemory.MerkleRoot()
} }
...@@ -130,8 +130,8 @@ func (e *ExpectedMTState) ExpectMemoryWordWrite(addr arch.Word, val arch.Word) { ...@@ -130,8 +130,8 @@ func (e *ExpectedMTState) ExpectMemoryWordWrite(addr arch.Word, val arch.Word) {
} }
func (e *ExpectedMTState) ExpectMemoryWriteMultiple(addr arch.Word, val uint32, addr2 arch.Word, val2 uint32) { func (e *ExpectedMTState) ExpectMemoryWriteMultiple(addr arch.Word, val uint32, addr2 arch.Word, val2 uint32) {
e.expectedMemory.SetMemory(addr, val) e.expectedMemory.SetUint32(addr, val)
e.expectedMemory.SetMemory(addr2, val2) e.expectedMemory.SetUint32(addr2, val2)
e.MemoryRoot = e.expectedMemory.MerkleRoot() e.MemoryRoot = e.expectedMemory.MerkleRoot()
} }
......
...@@ -86,7 +86,7 @@ func TestEVM(t *testing.T) { ...@@ -86,7 +86,7 @@ func TestEVM(t *testing.T) {
if exitGroup && goVm.GetState().GetExited() { if exitGroup && goVm.GetState().GetExited() {
break break
} }
insn := state.GetMemory().GetMemory(state.GetPC()) insn := state.GetMemory().GetUint32(state.GetPC())
t.Logf("step: %4d pc: 0x%08x insn: 0x%08x", state.GetStep(), state.GetPC(), insn) t.Logf("step: %4d pc: 0x%08x insn: 0x%08x", state.GetStep(), state.GetPC(), insn)
stepWitness, err := goVm.Step(true) stepWitness, err := goVm.Step(true)
...@@ -107,9 +107,9 @@ func TestEVM(t *testing.T) { ...@@ -107,9 +107,9 @@ func TestEVM(t *testing.T) {
} else { } else {
require.Equal(t, arch.Word(testutil.EndAddr), state.GetPC(), "must reach end") require.Equal(t, arch.Word(testutil.EndAddr), state.GetPC(), "must reach end")
// inspect test result // inspect test result
done, result := state.GetMemory().GetMemory(testutil.BaseAddrEnd+4), state.GetMemory().GetMemory(testutil.BaseAddrEnd+8) done, result := state.GetMemory().GetWord(testutil.BaseAddrEnd+4), state.GetMemory().GetWord(testutil.BaseAddrEnd+8)
require.Equal(t, done, uint32(1), "must be done") require.Equal(t, done, Word(1), "must be done")
require.Equal(t, result, uint32(1), "must have success result") require.Equal(t, result, Word(1), "must have success result")
} }
}) })
} }
...@@ -140,7 +140,7 @@ func TestEVMSingleStep_Jump(t *testing.T) { ...@@ -140,7 +140,7 @@ func TestEVMSingleStep_Jump(t *testing.T) {
t.Run(testName, func(t *testing.T) { t.Run(testName, func(t *testing.T) {
goVm := v.VMFactory(nil, os.Stdout, os.Stderr, testutil.CreateLogger(), testutil.WithRandomization(int64(i)), testutil.WithPC(tt.pc), testutil.WithNextPC(tt.nextPC)) goVm := v.VMFactory(nil, os.Stdout, os.Stderr, testutil.CreateLogger(), testutil.WithRandomization(int64(i)), testutil.WithPC(tt.pc), testutil.WithNextPC(tt.nextPC))
state := goVm.GetState() state := goVm.GetState()
state.GetMemory().SetMemory(tt.pc, tt.insn) state.GetMemory().SetUint32(tt.pc, tt.insn)
step := state.GetStep() step := state.GetStep()
// Setup expectations // Setup expectations
...@@ -217,7 +217,7 @@ func TestEVMSingleStep_Operators(t *testing.T) { ...@@ -217,7 +217,7 @@ func TestEVMSingleStep_Operators(t *testing.T) {
state.GetRegistersRef()[baseReg] = tt.rs state.GetRegistersRef()[baseReg] = tt.rs
state.GetRegistersRef()[rtReg] = tt.rt state.GetRegistersRef()[rtReg] = tt.rt
} }
state.GetMemory().SetMemory(0, insn) state.GetMemory().SetUint32(0, insn)
step := state.GetStep() step := state.GetStep()
// Setup expectations // Setup expectations
...@@ -291,8 +291,8 @@ func TestEVMSingleStep_LoadStore(t *testing.T) { ...@@ -291,8 +291,8 @@ func TestEVMSingleStep_LoadStore(t *testing.T) {
state.GetRegistersRef()[rtReg] = tt.rt state.GetRegistersRef()[rtReg] = tt.rt
state.GetRegistersRef()[baseReg] = t1 state.GetRegistersRef()[baseReg] = t1
state.GetMemory().SetMemory(0, insn) state.GetMemory().SetUint32(0, insn)
state.GetMemory().SetMemory(t1+4, tt.memVal) state.GetMemory().SetUint32(t1+4, tt.memVal)
step := state.GetStep() step := state.GetStep()
// Setup expectations // Setup expectations
...@@ -345,7 +345,7 @@ func TestEVM_MMap(t *testing.T) { ...@@ -345,7 +345,7 @@ func TestEVM_MMap(t *testing.T) {
goVm := v.VMFactory(nil, os.Stdout, os.Stderr, testutil.CreateLogger(), testutil.WithRandomization(int64(i)), testutil.WithHeap(c.heap)) goVm := v.VMFactory(nil, os.Stdout, os.Stderr, testutil.CreateLogger(), testutil.WithRandomization(int64(i)), testutil.WithHeap(c.heap))
state := goVm.GetState() state := goVm.GetState()
state.GetMemory().SetMemory(state.GetPC(), syscallInsn) state.GetMemory().SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = arch.SysMmap state.GetRegistersRef()[2] = arch.SysMmap
state.GetRegistersRef()[4] = c.address state.GetRegistersRef()[4] = c.address
state.GetRegistersRef()[5] = c.size state.GetRegistersRef()[5] = c.size
...@@ -553,7 +553,7 @@ func TestEVMSysWriteHint(t *testing.T) { ...@@ -553,7 +553,7 @@ func TestEVMSysWriteHint(t *testing.T) {
err := state.GetMemory().SetMemoryRange(arch.Word(tt.memOffset), bytes.NewReader(tt.hintData)) err := state.GetMemory().SetMemoryRange(arch.Word(tt.memOffset), bytes.NewReader(tt.hintData))
require.NoError(t, err) require.NoError(t, err)
state.GetMemory().SetMemory(state.GetPC(), insn) state.GetMemory().SetUint32(state.GetPC(), insn)
step := state.GetStep() step := state.GetStep()
expected := testutil.NewExpectedState(state) expected := testutil.NewExpectedState(state)
...@@ -595,7 +595,7 @@ func TestEVMFault(t *testing.T) { ...@@ -595,7 +595,7 @@ func TestEVMFault(t *testing.T) {
t.Run(testName, func(t *testing.T) { t.Run(testName, func(t *testing.T) {
goVm := v.VMFactory(nil, os.Stdout, os.Stderr, testutil.CreateLogger(), testutil.WithNextPC(tt.nextPC)) goVm := v.VMFactory(nil, os.Stdout, os.Stderr, testutil.CreateLogger(), testutil.WithNextPC(tt.nextPC))
state := goVm.GetState() state := goVm.GetState()
state.GetMemory().SetMemory(0, tt.insn) state.GetMemory().SetUint32(0, tt.insn)
// set the return address ($ra) to jump into when test completes // set the return address ($ra) to jump into when test completes
state.GetRegistersRef()[31] = testutil.EndAddr state.GetRegistersRef()[31] = testutil.EndAddr
...@@ -630,7 +630,7 @@ func TestHelloEVM(t *testing.T) { ...@@ -630,7 +630,7 @@ func TestHelloEVM(t *testing.T) {
if goVm.GetState().GetExited() { if goVm.GetState().GetExited() {
break break
} }
insn := state.GetMemory().GetMemory(state.GetPC()) insn := state.GetMemory().GetUint32(state.GetPC())
if i%1000 == 0 { // avoid spamming test logs, we are executing many steps if i%1000 == 0 { // avoid spamming test logs, we are executing many steps
t.Logf("step: %4d pc: 0x%08x insn: 0x%08x", state.GetStep(), state.GetPC(), insn) t.Logf("step: %4d pc: 0x%08x insn: 0x%08x", state.GetStep(), state.GetPC(), insn)
} }
...@@ -683,7 +683,7 @@ func TestClaimEVM(t *testing.T) { ...@@ -683,7 +683,7 @@ func TestClaimEVM(t *testing.T) {
break break
} }
insn := state.GetMemory().GetMemory(state.GetPC()) insn := state.GetMemory().GetUint32(state.GetPC())
if i%1000 == 0 { // avoid spamming test logs, we are executing many steps if i%1000 == 0 { // avoid spamming test logs, we are executing many steps
t.Logf("step: %4d pc: 0x%08x insn: 0x%08x", state.GetStep(), state.GetPC(), insn) t.Logf("step: %4d pc: 0x%08x insn: 0x%08x", state.GetStep(), state.GetPC(), insn)
} }
...@@ -731,7 +731,7 @@ func TestEntryEVM(t *testing.T) { ...@@ -731,7 +731,7 @@ func TestEntryEVM(t *testing.T) {
if goVm.GetState().GetExited() { if goVm.GetState().GetExited() {
break break
} }
insn := state.GetMemory().GetMemory(state.GetPC()) insn := state.GetMemory().GetUint32(state.GetPC())
if i%10_000 == 0 { // avoid spamming test logs, we are executing many steps if i%10_000 == 0 { // avoid spamming test logs, we are executing many steps
t.Logf("step: %4d pc: 0x%08x insn: 0x%08x", state.GetStep(), state.GetPC(), insn) t.Logf("step: %4d pc: 0x%08x insn: 0x%08x", state.GetStep(), state.GetPC(), insn)
} }
......
...@@ -55,7 +55,7 @@ func TestEVM_MT_LL(t *testing.T) { ...@@ -55,7 +55,7 @@ func TestEVM_MT_LL(t *testing.T) {
// Set up state // Set up state
state.GetCurrentThread().Cpu.PC = pc state.GetCurrentThread().Cpu.PC = pc
state.GetCurrentThread().Cpu.NextPC = pc + 4 state.GetCurrentThread().Cpu.NextPC = pc + 4
state.GetMemory().SetMemory(pc, insn) state.GetMemory().SetUint32(pc, insn)
state.GetMemory().SetWord(c.effAddr, c.value) state.GetMemory().SetWord(c.effAddr, c.value)
state.GetRegistersRef()[baseReg] = c.base state.GetRegistersRef()[baseReg] = c.base
if withExistingReservation { if withExistingReservation {
...@@ -151,7 +151,7 @@ func TestEVM_MT_SC(t *testing.T) { ...@@ -151,7 +151,7 @@ func TestEVM_MT_SC(t *testing.T) {
state.GetCurrentThread().ThreadId = c.threadId state.GetCurrentThread().ThreadId = c.threadId
state.GetCurrentThread().Cpu.PC = pc state.GetCurrentThread().Cpu.PC = pc
state.GetCurrentThread().Cpu.NextPC = pc + 4 state.GetCurrentThread().Cpu.NextPC = pc + 4
state.GetMemory().SetMemory(pc, insn) state.GetMemory().SetUint32(pc, insn)
state.GetRegistersRef()[baseReg] = c.base state.GetRegistersRef()[baseReg] = c.base
state.GetRegistersRef()[rtReg] = c.value state.GetRegistersRef()[rtReg] = c.value
state.LLReservationActive = v.llReservationActive state.LLReservationActive = v.llReservationActive
...@@ -265,11 +265,11 @@ func TestEVM_MT_SysRead_Preimage(t *testing.T) { ...@@ -265,11 +265,11 @@ func TestEVM_MT_SysRead_Preimage(t *testing.T) {
state.GetRegistersRef()[4] = exec.FdPreimageRead state.GetRegistersRef()[4] = exec.FdPreimageRead
state.GetRegistersRef()[5] = c.addr state.GetRegistersRef()[5] = c.addr
state.GetRegistersRef()[6] = c.count state.GetRegistersRef()[6] = c.count
state.GetMemory().SetMemory(state.GetPC(), syscallInsn) state.GetMemory().SetUint32(state.GetPC(), syscallInsn)
state.LLReservationActive = v.llReservationActive state.LLReservationActive = v.llReservationActive
state.LLAddress = llAddress state.LLAddress = llAddress
state.LLOwnerThread = llOwnerThread state.LLOwnerThread = llOwnerThread
state.GetMemory().SetMemory(effAddr, c.prestateMem) state.GetMemory().SetUint32(effAddr, c.prestateMem)
// Setup expectations // Setup expectations
expected := mttestutil.NewExpectedMTState(state) expected := mttestutil.NewExpectedMTState(state)
...@@ -363,8 +363,8 @@ func TestEVM_MT_StoreOpsClearMemReservation(t *testing.T) { ...@@ -363,8 +363,8 @@ func TestEVM_MT_StoreOpsClearMemReservation(t *testing.T) {
state.GetCurrentThread().Cpu.NextPC = pc + 4 state.GetCurrentThread().Cpu.NextPC = pc + 4
state.GetRegistersRef()[rtReg] = rt state.GetRegistersRef()[rtReg] = rt
state.GetRegistersRef()[baseReg] = c.base state.GetRegistersRef()[baseReg] = c.base
state.GetMemory().SetMemory(state.GetPC(), insn) state.GetMemory().SetUint32(state.GetPC(), insn)
state.GetMemory().SetMemory(c.effAddr, c.preMem) state.GetMemory().SetUint32(c.effAddr, c.preMem)
state.LLReservationActive = v.llReservationActive state.LLReservationActive = v.llReservationActive
state.LLAddress = llAddress state.LLAddress = llAddress
state.LLOwnerThread = llOwnerThread state.LLOwnerThread = llOwnerThread
...@@ -413,7 +413,7 @@ func TestEVM_SysClone_FlagHandling(t *testing.T) { ...@@ -413,7 +413,7 @@ func TestEVM_SysClone_FlagHandling(t *testing.T) {
for _, c := range cases { for _, c := range cases {
t.Run(c.name, func(t *testing.T) { t.Run(c.name, func(t *testing.T) {
state := multithreaded.CreateEmptyState() state := multithreaded.CreateEmptyState()
state.Memory.SetMemory(state.GetPC(), syscallInsn) state.Memory.SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = arch.SysClone // Set syscall number state.GetRegistersRef()[2] = arch.SysClone // Set syscall number
state.GetRegistersRef()[4] = c.flags // Set first argument state.GetRegistersRef()[4] = c.flags // Set first argument
curStep := state.Step curStep := state.Step
...@@ -466,7 +466,7 @@ func TestEVM_SysClone_Successful(t *testing.T) { ...@@ -466,7 +466,7 @@ func TestEVM_SysClone_Successful(t *testing.T) {
goVm, state, contracts := setup(t, i, nil) goVm, state, contracts := setup(t, i, nil)
mttestutil.InitializeSingleThread(i*333, state, c.traverseRight) mttestutil.InitializeSingleThread(i*333, state, c.traverseRight)
state.Memory.SetMemory(state.GetPC(), syscallInsn) state.Memory.SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = arch.SysClone // the syscall number state.GetRegistersRef()[2] = arch.SysClone // the syscall number
state.GetRegistersRef()[4] = exec.ValidCloneFlags // a0 - first argument, clone flags state.GetRegistersRef()[4] = exec.ValidCloneFlags // a0 - first argument, clone flags
state.GetRegistersRef()[5] = stackPtr // a1 - the stack pointer state.GetRegistersRef()[5] = stackPtr // a1 - the stack pointer
...@@ -529,7 +529,7 @@ func TestEVM_SysGetTID(t *testing.T) { ...@@ -529,7 +529,7 @@ func TestEVM_SysGetTID(t *testing.T) {
mttestutil.InitializeSingleThread(i*789, state, false) mttestutil.InitializeSingleThread(i*789, state, false)
state.GetCurrentThread().ThreadId = c.threadId state.GetCurrentThread().ThreadId = c.threadId
state.Memory.SetMemory(state.GetPC(), syscallInsn) state.Memory.SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = arch.SysGetTID // Set syscall number state.GetRegistersRef()[2] = arch.SysGetTID // Set syscall number
step := state.Step step := state.Step
...@@ -572,7 +572,7 @@ func TestEVM_SysExit(t *testing.T) { ...@@ -572,7 +572,7 @@ func TestEVM_SysExit(t *testing.T) {
goVm, state, contracts := setup(t, i*133, nil) goVm, state, contracts := setup(t, i*133, nil)
mttestutil.SetupThreads(int64(i*1111), state, i%2 == 0, c.threadCount, 0) mttestutil.SetupThreads(int64(i*1111), state, i%2 == 0, c.threadCount, 0)
state.Memory.SetMemory(state.GetPC(), syscallInsn) state.Memory.SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = arch.SysExit // Set syscall number state.GetRegistersRef()[2] = arch.SysExit // Set syscall number
state.GetRegistersRef()[4] = Word(exitCode) // The first argument (exit code) state.GetRegistersRef()[4] = Word(exitCode) // The first argument (exit code)
step := state.Step step := state.Step
...@@ -680,7 +680,7 @@ func TestEVM_SysFutex_WaitPrivate(t *testing.T) { ...@@ -680,7 +680,7 @@ func TestEVM_SysFutex_WaitPrivate(t *testing.T) {
goVm, state, contracts := setup(t, i*1234, nil) goVm, state, contracts := setup(t, i*1234, nil)
step := state.GetStep() step := state.GetStep()
state.Memory.SetMemory(state.GetPC(), syscallInsn) state.Memory.SetUint32(state.GetPC(), syscallInsn)
state.Memory.SetWord(c.effAddr, c.actualValue) state.Memory.SetWord(c.effAddr, c.actualValue)
state.GetRegistersRef()[2] = arch.SysFutex // Set syscall number state.GetRegistersRef()[2] = arch.SysFutex // Set syscall number
state.GetRegistersRef()[4] = c.addressParam state.GetRegistersRef()[4] = c.addressParam
...@@ -751,7 +751,7 @@ func TestEVM_SysFutex_WakePrivate(t *testing.T) { ...@@ -751,7 +751,7 @@ func TestEVM_SysFutex_WakePrivate(t *testing.T) {
mttestutil.SetupThreads(int64(i*2244), state, c.traverseRight, c.activeThreadCount, c.inactiveThreadCount) mttestutil.SetupThreads(int64(i*2244), state, c.traverseRight, c.activeThreadCount, c.inactiveThreadCount)
step := state.Step step := state.Step
state.Memory.SetMemory(state.GetPC(), syscallInsn) state.Memory.SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = arch.SysFutex // Set syscall number state.GetRegistersRef()[2] = arch.SysFutex // Set syscall number
state.GetRegistersRef()[4] = c.addressParam state.GetRegistersRef()[4] = c.addressParam
state.GetRegistersRef()[5] = exec.FutexWakePrivate state.GetRegistersRef()[5] = exec.FutexWakePrivate
...@@ -836,7 +836,7 @@ func TestEVM_SysFutex_UnsupportedOp(t *testing.T) { ...@@ -836,7 +836,7 @@ func TestEVM_SysFutex_UnsupportedOp(t *testing.T) {
goVm, state, contracts := setup(t, int(op), nil) goVm, state, contracts := setup(t, int(op), nil)
step := state.GetStep() step := state.GetStep()
state.Memory.SetMemory(state.GetPC(), syscallInsn) state.Memory.SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = arch.SysFutex // Set syscall number state.GetRegistersRef()[2] = arch.SysFutex // Set syscall number
state.GetRegistersRef()[5] = op state.GetRegistersRef()[5] = op
...@@ -891,7 +891,7 @@ func runPreemptSyscall(t *testing.T, syscallName string, syscallNum uint32) { ...@@ -891,7 +891,7 @@ func runPreemptSyscall(t *testing.T, syscallName string, syscallNum uint32) {
goVm, state, contracts := setup(t, i*789, nil) goVm, state, contracts := setup(t, i*789, nil)
mttestutil.SetupThreads(int64(i*3259), state, traverseRight, c.activeThreads, c.inactiveThreads) mttestutil.SetupThreads(int64(i*3259), state, traverseRight, c.activeThreads, c.inactiveThreads)
state.Memory.SetMemory(state.GetPC(), syscallInsn) state.Memory.SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = Word(syscallNum) // Set syscall number state.GetRegistersRef()[2] = Word(syscallNum) // Set syscall number
step := state.Step step := state.Step
...@@ -921,7 +921,7 @@ func TestEVM_SysOpen(t *testing.T) { ...@@ -921,7 +921,7 @@ func TestEVM_SysOpen(t *testing.T) {
goVm, state, contracts := setup(t, 5512, nil) goVm, state, contracts := setup(t, 5512, nil)
state.Memory.SetMemory(state.GetPC(), syscallInsn) state.Memory.SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = arch.SysOpen // Set syscall number state.GetRegistersRef()[2] = arch.SysOpen // Set syscall number
step := state.Step step := state.Step
...@@ -946,7 +946,7 @@ func TestEVM_SysGetPID(t *testing.T) { ...@@ -946,7 +946,7 @@ func TestEVM_SysGetPID(t *testing.T) {
var tracer *tracing.Hooks var tracer *tracing.Hooks
goVm, state, contracts := setup(t, 1929, nil) goVm, state, contracts := setup(t, 1929, nil)
state.Memory.SetMemory(state.GetPC(), syscallInsn) state.Memory.SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = arch.SysGetpid // Set syscall number state.GetRegistersRef()[2] = arch.SysGetpid // Set syscall number
step := state.Step step := state.Step
...@@ -1029,7 +1029,7 @@ func testEVM_SysClockGettime(t *testing.T, clkid Word) { ...@@ -1029,7 +1029,7 @@ func testEVM_SysClockGettime(t *testing.T, clkid Word) {
llOwnerThread = state.GetCurrentThread().ThreadId + 1 llOwnerThread = state.GetCurrentThread().ThreadId + 1
} }
state.Memory.SetMemory(state.GetPC(), syscallInsn) state.Memory.SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = arch.SysClockGetTime // Set syscall number state.GetRegistersRef()[2] = arch.SysClockGetTime // Set syscall number
state.GetRegistersRef()[4] = clkid // a0 state.GetRegistersRef()[4] = clkid // a0
state.GetRegistersRef()[5] = c.timespecAddr // a1 state.GetRegistersRef()[5] = c.timespecAddr // a1
...@@ -1073,7 +1073,7 @@ func TestEVM_SysClockGettimeNonMonotonic(t *testing.T) { ...@@ -1073,7 +1073,7 @@ func TestEVM_SysClockGettimeNonMonotonic(t *testing.T) {
goVm, state, contracts := setup(t, 2101, nil) goVm, state, contracts := setup(t, 2101, nil)
timespecAddr := Word(0x1000) timespecAddr := Word(0x1000)
state.Memory.SetMemory(state.GetPC(), syscallInsn) state.Memory.SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = arch.SysClockGetTime // Set syscall number state.GetRegistersRef()[2] = arch.SysClockGetTime // Set syscall number
state.GetRegistersRef()[4] = 0xDEAD // a0 - invalid clockid state.GetRegistersRef()[4] = 0xDEAD // a0 - invalid clockid
state.GetRegistersRef()[5] = timespecAddr // a1 state.GetRegistersRef()[5] = timespecAddr // a1
...@@ -1134,7 +1134,7 @@ func TestEVM_NoopSyscall(t *testing.T) { ...@@ -1134,7 +1134,7 @@ func TestEVM_NoopSyscall(t *testing.T) {
t.Run(noopName, func(t *testing.T) { t.Run(noopName, func(t *testing.T) {
goVm, state, contracts := setup(t, int(noopVal), nil) goVm, state, contracts := setup(t, int(noopVal), nil)
state.Memory.SetMemory(state.GetPC(), syscallInsn) state.Memory.SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = Word(noopVal) // Set syscall number state.GetRegistersRef()[2] = Word(noopVal) // Set syscall number
step := state.Step step := state.Step
...@@ -1181,7 +1181,7 @@ func TestEVM_UnsupportedSyscall(t *testing.T) { ...@@ -1181,7 +1181,7 @@ func TestEVM_UnsupportedSyscall(t *testing.T) {
t.Parallel() t.Parallel()
goVm, state, contracts := setup(t, i*3434, nil) goVm, state, contracts := setup(t, i*3434, nil)
// Setup basic getThreadId syscall instruction // Setup basic getThreadId syscall instruction
state.Memory.SetMemory(state.GetPC(), syscallInsn) state.Memory.SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = Word(syscallNum) state.GetRegistersRef()[2] = Word(syscallNum)
// Set up post-state expectations // Set up post-state expectations
...@@ -1476,7 +1476,7 @@ func TestEVM_SchedQuantumThreshold(t *testing.T) { ...@@ -1476,7 +1476,7 @@ func TestEVM_SchedQuantumThreshold(t *testing.T) {
t.Run(c.name, func(t *testing.T) { t.Run(c.name, func(t *testing.T) {
goVm, state, contracts := setup(t, i*789, nil) goVm, state, contracts := setup(t, i*789, nil)
// Setup basic getThreadId syscall instruction // Setup basic getThreadId syscall instruction
state.Memory.SetMemory(state.GetPC(), syscallInsn) state.Memory.SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = arch.SysGetTID // Set syscall number state.GetRegistersRef()[2] = arch.SysGetTID // Set syscall number
state.StepsSinceLastContextSwitch = c.stepsSinceLastContextSwitch state.StepsSinceLastContextSwitch = c.stepsSinceLastContextSwitch
step := state.Step step := state.Step
......
...@@ -42,7 +42,7 @@ func TestEVM_LL(t *testing.T) { ...@@ -42,7 +42,7 @@ func TestEVM_LL(t *testing.T) {
insn := uint32((0b11_0000 << 26) | (baseReg & 0x1F << 21) | (rtReg & 0x1F << 16) | (0xFFFF & c.offset)) insn := uint32((0b11_0000 << 26) | (baseReg & 0x1F << 21) | (rtReg & 0x1F << 16) | (0xFFFF & c.offset))
goVm := v.VMFactory(nil, os.Stdout, os.Stderr, testutil.CreateLogger(), testutil.WithRandomization(int64(i)), testutil.WithPC(pc), testutil.WithNextPC(pc+4)) goVm := v.VMFactory(nil, os.Stdout, os.Stderr, testutil.CreateLogger(), testutil.WithRandomization(int64(i)), testutil.WithPC(pc), testutil.WithNextPC(pc+4))
state := goVm.GetState() state := goVm.GetState()
state.GetMemory().SetMemory(pc, insn) state.GetMemory().SetUint32(pc, insn)
state.GetMemory().SetWord(c.effAddr, c.value) state.GetMemory().SetWord(c.effAddr, c.value)
state.GetRegistersRef()[baseReg] = c.base state.GetRegistersRef()[baseReg] = c.base
step := state.GetStep() step := state.GetStep()
...@@ -92,7 +92,7 @@ func TestEVM_SC(t *testing.T) { ...@@ -92,7 +92,7 @@ func TestEVM_SC(t *testing.T) {
insn := uint32((0b11_1000 << 26) | (baseReg & 0x1F << 21) | (rtReg & 0x1F << 16) | (0xFFFF & c.offset)) insn := uint32((0b11_1000 << 26) | (baseReg & 0x1F << 21) | (rtReg & 0x1F << 16) | (0xFFFF & c.offset))
goVm := v.VMFactory(nil, os.Stdout, os.Stderr, testutil.CreateLogger(), testutil.WithRandomization(int64(i)), testutil.WithPC(pc), testutil.WithNextPC(pc+4)) goVm := v.VMFactory(nil, os.Stdout, os.Stderr, testutil.CreateLogger(), testutil.WithRandomization(int64(i)), testutil.WithPC(pc), testutil.WithNextPC(pc+4))
state := goVm.GetState() state := goVm.GetState()
state.GetMemory().SetMemory(pc, insn) state.GetMemory().SetUint32(pc, insn)
state.GetRegistersRef()[baseReg] = c.base state.GetRegistersRef()[baseReg] = c.base
state.GetRegistersRef()[rtReg] = c.value state.GetRegistersRef()[rtReg] = c.value
step := state.GetStep() step := state.GetStep()
...@@ -103,7 +103,7 @@ func TestEVM_SC(t *testing.T) { ...@@ -103,7 +103,7 @@ func TestEVM_SC(t *testing.T) {
expected.PC = pc + 4 expected.PC = pc + 4
expected.NextPC = pc + 8 expected.NextPC = pc + 8
expectedMemory := memory.NewMemory() expectedMemory := memory.NewMemory()
expectedMemory.SetMemory(pc, insn) expectedMemory.SetUint32(pc, insn)
expectedMemory.SetWord(c.effAddr, c.value) expectedMemory.SetWord(c.effAddr, c.value)
expected.MemoryRoot = expectedMemory.MerkleRoot() expected.MemoryRoot = expectedMemory.MerkleRoot()
if rtReg != 0 { if rtReg != 0 {
...@@ -170,8 +170,8 @@ func TestEVM_SysRead_Preimage(t *testing.T) { ...@@ -170,8 +170,8 @@ func TestEVM_SysRead_Preimage(t *testing.T) {
state.GetRegistersRef()[4] = exec.FdPreimageRead state.GetRegistersRef()[4] = exec.FdPreimageRead
state.GetRegistersRef()[5] = c.addr state.GetRegistersRef()[5] = c.addr
state.GetRegistersRef()[6] = c.count state.GetRegistersRef()[6] = c.count
state.GetMemory().SetMemory(state.GetPC(), syscallInsn) state.GetMemory().SetUint32(state.GetPC(), syscallInsn)
state.GetMemory().SetMemory(effAddr, c.prestateMem) state.GetMemory().SetUint32(effAddr, c.prestateMem)
// Setup expectations // Setup expectations
expected := testutil.NewExpectedState(state) expected := testutil.NewExpectedState(state)
......
...@@ -28,7 +28,7 @@ func FuzzStateSyscallBrk(f *testing.F) { ...@@ -28,7 +28,7 @@ func FuzzStateSyscallBrk(f *testing.F) {
goVm := v.VMFactory(nil, os.Stdout, os.Stderr, testutil.CreateLogger(), testutil.WithRandomization(seed)) goVm := v.VMFactory(nil, os.Stdout, os.Stderr, testutil.CreateLogger(), testutil.WithRandomization(seed))
state := goVm.GetState() state := goVm.GetState()
state.GetRegistersRef()[2] = arch.SysBrk state.GetRegistersRef()[2] = arch.SysBrk
state.GetMemory().SetMemory(state.GetPC(), syscallInsn) state.GetMemory().SetUint32(state.GetPC(), syscallInsn)
step := state.GetStep() step := state.GetStep()
expected := testutil.NewExpectedState(state) expected := testutil.NewExpectedState(state)
...@@ -68,7 +68,7 @@ func FuzzStateSyscallMmap(f *testing.F) { ...@@ -68,7 +68,7 @@ func FuzzStateSyscallMmap(f *testing.F) {
state.GetRegistersRef()[2] = arch.SysMmap state.GetRegistersRef()[2] = arch.SysMmap
state.GetRegistersRef()[4] = addr state.GetRegistersRef()[4] = addr
state.GetRegistersRef()[5] = siz state.GetRegistersRef()[5] = siz
state.GetMemory().SetMemory(state.GetPC(), syscallInsn) state.GetMemory().SetUint32(state.GetPC(), syscallInsn)
expected := testutil.NewExpectedState(state) expected := testutil.NewExpectedState(state)
expected.Step += 1 expected.Step += 1
...@@ -114,7 +114,7 @@ func FuzzStateSyscallExitGroup(f *testing.F) { ...@@ -114,7 +114,7 @@ func FuzzStateSyscallExitGroup(f *testing.F) {
state := goVm.GetState() state := goVm.GetState()
state.GetRegistersRef()[2] = arch.SysExitGroup state.GetRegistersRef()[2] = arch.SysExitGroup
state.GetRegistersRef()[4] = Word(exitCode) state.GetRegistersRef()[4] = Word(exitCode)
state.GetMemory().SetMemory(state.GetPC(), syscallInsn) state.GetMemory().SetUint32(state.GetPC(), syscallInsn)
step := state.GetStep() step := state.GetStep()
expected := testutil.NewExpectedState(state) expected := testutil.NewExpectedState(state)
...@@ -144,7 +144,7 @@ func FuzzStateSyscallFcntl(f *testing.F) { ...@@ -144,7 +144,7 @@ func FuzzStateSyscallFcntl(f *testing.F) {
state.GetRegistersRef()[2] = arch.SysFcntl state.GetRegistersRef()[2] = arch.SysFcntl
state.GetRegistersRef()[4] = fd state.GetRegistersRef()[4] = fd
state.GetRegistersRef()[5] = cmd state.GetRegistersRef()[5] = cmd
state.GetMemory().SetMemory(state.GetPC(), syscallInsn) state.GetMemory().SetUint32(state.GetPC(), syscallInsn)
step := state.GetStep() step := state.GetStep()
expected := testutil.NewExpectedState(state) expected := testutil.NewExpectedState(state)
...@@ -205,7 +205,7 @@ func FuzzStateHintRead(f *testing.F) { ...@@ -205,7 +205,7 @@ func FuzzStateHintRead(f *testing.F) {
state.GetRegistersRef()[4] = exec.FdHintRead state.GetRegistersRef()[4] = exec.FdHintRead
state.GetRegistersRef()[5] = addr state.GetRegistersRef()[5] = addr
state.GetRegistersRef()[6] = count state.GetRegistersRef()[6] = count
state.GetMemory().SetMemory(state.GetPC(), syscallInsn) state.GetMemory().SetUint32(state.GetPC(), syscallInsn)
step := state.GetStep() step := state.GetStep()
expected := testutil.NewExpectedState(state) expected := testutil.NewExpectedState(state)
...@@ -249,8 +249,8 @@ func FuzzStatePreimageRead(f *testing.F) { ...@@ -249,8 +249,8 @@ func FuzzStatePreimageRead(f *testing.F) {
state.GetRegistersRef()[4] = exec.FdPreimageRead state.GetRegistersRef()[4] = exec.FdPreimageRead
state.GetRegistersRef()[5] = addr state.GetRegistersRef()[5] = addr
state.GetRegistersRef()[6] = count state.GetRegistersRef()[6] = count
state.GetMemory().SetMemory(state.GetPC(), syscallInsn) state.GetMemory().SetUint32(state.GetPC(), syscallInsn)
state.GetMemory().SetMemory(effAddr, binary.BigEndian.Uint32(preexistingMemoryVal[:])) state.GetMemory().SetUint32(effAddr, binary.BigEndian.Uint32(preexistingMemoryVal[:]))
step := state.GetStep() step := state.GetStep()
alignment := addr & arch.ExtMask alignment := addr & arch.ExtMask
...@@ -331,7 +331,7 @@ func FuzzStateHintWrite(f *testing.F) { ...@@ -331,7 +331,7 @@ func FuzzStateHintWrite(f *testing.F) {
step := state.GetStep() step := state.GetStep()
err := state.GetMemory().SetMemoryRange(addr, bytes.NewReader(hintData[int(lastHintLen):])) err := state.GetMemory().SetMemoryRange(addr, bytes.NewReader(hintData[int(lastHintLen):]))
require.NoError(t, err) require.NoError(t, err)
state.GetMemory().SetMemory(state.GetPC(), syscallInsn) state.GetMemory().SetUint32(state.GetPC(), syscallInsn)
// Set up expectations // Set up expectations
expected := testutil.NewExpectedState(state) expected := testutil.NewExpectedState(state)
...@@ -394,8 +394,8 @@ func FuzzStatePreimageWrite(f *testing.F) { ...@@ -394,8 +394,8 @@ func FuzzStatePreimageWrite(f *testing.F) {
state.GetRegistersRef()[4] = exec.FdPreimageWrite state.GetRegistersRef()[4] = exec.FdPreimageWrite
state.GetRegistersRef()[5] = addr state.GetRegistersRef()[5] = addr
state.GetRegistersRef()[6] = count state.GetRegistersRef()[6] = count
state.GetMemory().SetMemory(state.GetPC(), syscallInsn) state.GetMemory().SetUint32(state.GetPC(), syscallInsn)
state.GetMemory().SetMemory(effAddr, binary.BigEndian.Uint32(preexistingMemoryVal[:])) state.GetMemory().SetUint32(effAddr, binary.BigEndian.Uint32(preexistingMemoryVal[:]))
step := state.GetStep() step := state.GetStep()
expectBytesWritten := count expectBytesWritten := count
......
...@@ -27,7 +27,7 @@ func FuzzStateSyscallCloneMT(f *testing.F) { ...@@ -27,7 +27,7 @@ func FuzzStateSyscallCloneMT(f *testing.F) {
// Setup // Setup
state.NextThreadId = nextThreadId state.NextThreadId = nextThreadId
state.GetMemory().SetMemory(state.GetPC(), syscallInsn) state.GetMemory().SetUint32(state.GetPC(), syscallInsn)
state.GetRegistersRef()[2] = arch.SysClone state.GetRegistersRef()[2] = arch.SysClone
state.GetRegistersRef()[4] = exec.ValidCloneFlags state.GetRegistersRef()[4] = exec.ValidCloneFlags
state.GetRegistersRef()[5] = stackPtr state.GetRegistersRef()[5] = stackPtr
......
...@@ -17,7 +17,7 @@ func FuzzStateSyscallCloneST(f *testing.F) { ...@@ -17,7 +17,7 @@ func FuzzStateSyscallCloneST(f *testing.F) {
goVm := v.VMFactory(nil, os.Stdout, os.Stderr, testutil.CreateLogger(), testutil.WithRandomization(seed)) goVm := v.VMFactory(nil, os.Stdout, os.Stderr, testutil.CreateLogger(), testutil.WithRandomization(seed))
state := goVm.GetState() state := goVm.GetState()
state.GetRegistersRef()[2] = arch.SysClone state.GetRegistersRef()[2] = arch.SysClone
state.GetMemory().SetMemory(state.GetPC(), syscallInsn) state.GetMemory().SetUint32(state.GetPC(), syscallInsn)
step := state.GetStep() step := state.GetStep()
expected := testutil.NewExpectedState(state) expected := testutil.NewExpectedState(state)
......
...@@ -166,7 +166,7 @@ func (e *ExpectedState) ExpectStep() { ...@@ -166,7 +166,7 @@ func (e *ExpectedState) ExpectStep() {
} }
func (e *ExpectedState) ExpectMemoryWrite(addr arch.Word, val uint32) { func (e *ExpectedState) ExpectMemoryWrite(addr arch.Word, val uint32) {
e.expectedMemory.SetMemory(addr, val) e.expectedMemory.SetUint32(addr, val)
e.MemoryRoot = e.expectedMemory.MerkleRoot() e.MemoryRoot = e.expectedMemory.MerkleRoot()
} }
......
...@@ -84,10 +84,10 @@ func RunVMTests_OpenMips[T mipsevm.FPVMState](t *testing.T, stateFactory StateFa ...@@ -84,10 +84,10 @@ func RunVMTests_OpenMips[T mipsevm.FPVMState](t *testing.T, stateFactory StateFa
require.NotEqual(t, arch.Word(EndAddr), us.GetState().GetPC(), "must not reach end") require.NotEqual(t, arch.Word(EndAddr), us.GetState().GetPC(), "must not reach end")
} else { } else {
require.Equal(t, arch.Word(EndAddr), us.GetState().GetPC(), "must reach end") require.Equal(t, arch.Word(EndAddr), us.GetState().GetPC(), "must reach end")
done, result := state.GetMemory().GetMemory(BaseAddrEnd+4), state.GetMemory().GetMemory(BaseAddrEnd+8) done, result := state.GetMemory().GetWord(BaseAddrEnd+4), state.GetMemory().GetWord(BaseAddrEnd+8)
// inspect test result // inspect test result
require.Equal(t, done, uint32(1), "must be done") require.Equal(t, done, arch.Word(1), "must be done")
require.Equal(t, result, uint32(1), "must have success result") require.Equal(t, result, arch.Word(1), "must have success result")
} }
}) })
} }
......
...@@ -369,7 +369,7 @@ func DiffTestUtils() { ...@@ -369,7 +369,7 @@ func DiffTestUtils() {
checkErr(err, "Error decoding addr") checkErr(err, "Error decoding addr")
insn, err := strconv.ParseUint(args[2], 10, 32) insn, err := strconv.ParseUint(args[2], 10, 32)
checkErr(err, "Error decoding insn") checkErr(err, "Error decoding insn")
mem.SetMemory(uint32(pc), uint32(insn)) mem.SetUint32(uint32(pc), uint32(insn))
var insnProof, memProof [896]byte var insnProof, memProof [896]byte
if len(args) >= 5 { if len(args) >= 5 {
...@@ -377,7 +377,7 @@ func DiffTestUtils() { ...@@ -377,7 +377,7 @@ func DiffTestUtils() {
checkErr(err, "Error decoding memAddr") checkErr(err, "Error decoding memAddr")
memValue, err := strconv.ParseUint(args[4], 10, 32) memValue, err := strconv.ParseUint(args[4], 10, 32)
checkErr(err, "Error decoding memValue") checkErr(err, "Error decoding memValue")
mem.SetMemory(uint32(memAddr), uint32(memValue)) mem.SetUint32(uint32(memAddr), uint32(memValue))
memProof = mem.MerkleProof(uint32(memAddr)) memProof = mem.MerkleProof(uint32(memAddr))
} }
if len(args) == 7 { if len(args) == 7 {
...@@ -385,7 +385,7 @@ func DiffTestUtils() { ...@@ -385,7 +385,7 @@ func DiffTestUtils() {
checkErr(err, "Error decoding memAddr") checkErr(err, "Error decoding memAddr")
memValue, err := strconv.ParseUint(args[6], 10, 32) memValue, err := strconv.ParseUint(args[6], 10, 32)
checkErr(err, "Error decoding memValue") checkErr(err, "Error decoding memValue")
mem.SetMemory(uint32(memAddr), uint32(memValue)) mem.SetUint32(uint32(memAddr), uint32(memValue))
memProof = mem.MerkleProof(uint32(memAddr)) memProof = mem.MerkleProof(uint32(memAddr))
} }
insnProof = mem.MerkleProof(uint32(pc)) insnProof = mem.MerkleProof(uint32(pc))
...@@ -411,14 +411,14 @@ func DiffTestUtils() { ...@@ -411,14 +411,14 @@ func DiffTestUtils() {
checkErr(err, "Error decoding addr") checkErr(err, "Error decoding addr")
insn, err := strconv.ParseUint(args[2], 10, 32) insn, err := strconv.ParseUint(args[2], 10, 32)
checkErr(err, "Error decoding insn") checkErr(err, "Error decoding insn")
mem.SetMemory(uint32(pc), uint32(insn)) mem.SetUint32(uint32(pc), uint32(insn))
var memProof [896]byte var memProof [896]byte
memAddr, err := strconv.ParseUint(args[3], 10, 32) memAddr, err := strconv.ParseUint(args[3], 10, 32)
checkErr(err, "Error decoding memAddr") checkErr(err, "Error decoding memAddr")
memValue, err := strconv.ParseUint(args[4], 10, 32) memValue, err := strconv.ParseUint(args[4], 10, 32)
checkErr(err, "Error decoding memValue") checkErr(err, "Error decoding memValue")
mem.SetMemory(uint32(memAddr), uint32(memValue)) mem.SetUint32(uint32(memAddr), uint32(memValue))
memAddr2, err := strconv.ParseUint(args[5], 10, 32) memAddr2, err := strconv.ParseUint(args[5], 10, 32)
checkErr(err, "Error decoding memAddr") checkErr(err, "Error decoding memAddr")
...@@ -444,14 +444,14 @@ func DiffTestUtils() { ...@@ -444,14 +444,14 @@ func DiffTestUtils() {
checkErr(err, "Error decoding addr") checkErr(err, "Error decoding addr")
insn, err := strconv.ParseUint(args[2], 10, 32) insn, err := strconv.ParseUint(args[2], 10, 32)
checkErr(err, "Error decoding insn") checkErr(err, "Error decoding insn")
mem.SetMemory(uint32(pc), uint32(insn)) mem.SetUint32(uint32(pc), uint32(insn))
var insnProof, memProof [896]byte var insnProof, memProof [896]byte
memAddr, err := strconv.ParseUint(args[3], 10, 32) memAddr, err := strconv.ParseUint(args[3], 10, 32)
checkErr(err, "Error decoding memAddr") checkErr(err, "Error decoding memAddr")
memValue, err := strconv.ParseUint(args[4], 10, 32) memValue, err := strconv.ParseUint(args[4], 10, 32)
checkErr(err, "Error decoding memValue") checkErr(err, "Error decoding memValue")
mem.SetMemory(uint32(memAddr), uint32(memValue)) mem.SetUint32(uint32(memAddr), uint32(memValue))
// Compute a valid proof for the root, but for the wrong leaves. // Compute a valid proof for the root, but for the wrong leaves.
memProof = mem.MerkleProof(uint32(memAddr + 32)) memProof = mem.MerkleProof(uint32(memAddr + 32))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment