Skip to content

Commit

Permalink
fixes, checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby committed Aug 10, 2024
1 parent a68b49f commit cdcfa77
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions cannon/mipsevm/exec/mips_instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func ExecuteMipsInstruction(insn, opcode, fun, rs, rt, mem uint64) uint64 {
return SignExtend((rt&0xFFFFFFFF)>>(rs&0x1F), 32)
case 0x07: // srav
return SignExtend((rt&0xFFFFFFFF)>>rs, 32-rs)
// MIPS32 functs in range [0x8, 0x1f] are handled specially by other functions
// functs in range [0x8, 0x1f] are handled specially by other functions
case 0x08: // jr
return rs
case 0x09: // jalr
Expand Down Expand Up @@ -379,17 +379,17 @@ func HandleBranch(cpu *mipsevm.CpuScalars, registers *[32]uint64, opcode, insn,
rt := registers[rtReg]
shouldBranch = (rs == rt && opcode == 4) || (rs != rt && opcode == 5)
} else if opcode == 6 {
shouldBranch = int32(rs) <= 0 // blez
shouldBranch = int64(rs) <= 0 // blez
} else if opcode == 7 {
shouldBranch = int32(rs) > 0 // bgtz
shouldBranch = int64(rs) > 0 // bgtz
} else if opcode == 1 {
// regimm
rtv := (insn >> 16) & 0x1F
if rtv == 0 { // bltz
shouldBranch = int32(rs) < 0
shouldBranch = int64(rs) < 0
}
if rtv == 1 { // bgez
shouldBranch = int32(rs) >= 0
shouldBranch = int64(rs) >= 0
}
}

Expand Down
2 changes: 1 addition & 1 deletion cannon/mipsevm/exec/mips_syscalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const (
SysReadlink = 5087
SysReadlinkAt = 5257
SysIoctl = 5015
SysEpollCreate1 = 5207
SysEpollCreate1 = 5285
SysPipe2 = 5287
SysEpollCtl = 5208
SysEpollPwait = 5272
Expand Down
8 changes: 4 additions & 4 deletions cannon/mipsevm/multithreaded/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ func TestState_EncodeWitness(t *testing.T) {
expectedWitness := make(StateWitness, STATE_WITNESS_SIZE)
setWitnessField(expectedWitness, MEMROOT_WITNESS_OFFSET, memRoot[:])
setWitnessField(expectedWitness, PREIMAGE_KEY_WITNESS_OFFSET, preimageKey[:])
setWitnessField(expectedWitness, PREIMAGE_OFFSET_WITNESS_OFFSET, []byte{0, 0, 0, byte(preimageOffset)})
setWitnessField(expectedWitness, HEAP_WITNESS_OFFSET, []byte{0, 0, 0, byte(heap)})
setWitnessField(expectedWitness, PREIMAGE_OFFSET_WITNESS_OFFSET, []byte{0, 0, 0, 0, 0, 0, 0, byte(preimageOffset)})
setWitnessField(expectedWitness, HEAP_WITNESS_OFFSET, []byte{0, 0, 0, 0, 0, 0, 0, byte(heap)})
setWitnessField(expectedWitness, EXITCODE_WITNESS_OFFSET, []byte{c.exitCode})
if c.exited {
setWitnessField(expectedWitness, EXITED_WITNESS_OFFSET, []byte{1})
}
setWitnessField(expectedWitness, STEP_WITNESS_OFFSET, []byte{0, 0, 0, 0, 0, 0, 0, byte(step)})
setWitnessField(expectedWitness, STEPS_SINCE_CONTEXT_SWITCH_WITNESS_OFFSET, []byte{0, 0, 0, 0, 0, 0, 0, byte(stepsSinceContextSwitch)})
setWitnessField(expectedWitness, WAKEUP_WITNESS_OFFSET, []byte{0xFF, 0xFF, 0xFF, 0xFF})
setWitnessField(expectedWitness, WAKEUP_WITNESS_OFFSET, []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF})
setWitnessField(expectedWitness, TRAVERSE_RIGHT_WITNESS_OFFSET, []byte{0})
setWitnessField(expectedWitness, LEFT_THREADS_ROOT_WITNESS_OFFSET, leftStackRoot[:])
setWitnessField(expectedWitness, RIGHT_THREADS_ROOT_WITNESS_OFFSET, rightStackRoot[:])
setWitnessField(expectedWitness, THREAD_ID_WITNESS_OFFSET, []byte{0, 0, 0, 1})
setWitnessField(expectedWitness, THREAD_ID_WITNESS_OFFSET, []byte{0, 0, 0, 0, 0, 0, 0, 1})

// Validate witness
actualWitness, actualStateHash := state.EncodeWitness()
Expand Down
2 changes: 1 addition & 1 deletion cannon/mipsevm/program/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func PatchGo(f *elf.File, st mipsevm.FPVMState) error {
"flag.init",
// We need to patch this out, we don't pass float64nan because we don't support floats
"runtime.check":
// MIPS32 patch: ret (pseudo instruction)
// MIPS64 patch: ret (pseudo instruction)
// 03e00008 = jr $ra = ret (pseudo instruction)
// 00000000 = nop (executes with delay-slot, but does nothing)
if err := st.GetMemory().SetMemoryRange(uint64(s.Value), bytes.NewReader([]byte{
Expand Down
4 changes: 2 additions & 2 deletions cannon/mipsevm/singlethreaded/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestStateHash(t *testing.T) {
{exited: true, exitCode: 3},
}

exitedOffset := 32*2 + 4*6
exitedOffset := 32*2 + 8*6
for _, c := range cases {
state := &State{
Memory: memory.NewMemory(),
Expand All @@ -40,7 +40,7 @@ func TestStateHash(t *testing.T) {
actualWitness, actualStateHash := state.EncodeWitness()
require.Equal(t, len(actualWitness), STATE_WITNESS_SIZE, "Incorrect witness size")

expectedWitness := make(StateWitness, 226)
expectedWitness := make(StateWitness, 378)
memRoot := state.Memory.MerkleRoot()
copy(expectedWitness[:32], memRoot[:])
expectedWitness[exitedOffset] = c.exitCode
Expand Down
4 changes: 2 additions & 2 deletions op-program/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ op-program-client:
env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -v -ldflags "$(PC_LDFLAGSSTRING)" -o ./bin/op-program-client ./client/cmd/main.go

op-program-client-mips:
env GO111MODULE=on GOOS=linux GOARCH=mips GOMIPS=softfloat go build -v -ldflags "$(PC_LDFLAGSSTRING)" -o ./bin/op-program-client.elf ./client/cmd/main.go
env GO111MODULE=on GOOS=linux GOARCH=mips64 GOMIPS64=softfloat go build -v -ldflags "$(PC_LDFLAGSSTRING)" -o ./bin/op-program-client.elf ./client/cmd/main.go
# verify output with: readelf -h bin/op-program-client.elf
# result is mips32, big endian, R3000
# result is mips64, big endian, R3000

op-program-client-riscv:
env GO111MODULE=on GOOS=linux GOARCH=riscv64 go build -v -gcflags="all=-d=softfloat" -ldflags "$(PC_LDFLAGSSTRING)" -o ./bin/op-program-client-riscv.elf ./client/cmd/main.go
Expand Down

0 comments on commit cdcfa77

Please sign in to comment.