Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion crates/go-runtime/zkvm_runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ func SyscallWrite(fd int, write_buf []byte, nbytes int) int
func SyscallHintLen() int
func SyscallHintRead(ptr []byte, len int)
func SyscallCommit(index int, word uint32)
func SyscallCommitDeferredProofs(index int, word uint32)
func SyscallExit(code int)
func SyscallEnterUnconstrained() int
func SyscallExitUnconstrained()
func SyscallKeccakSponge(input unsafe.Pointer, result unsafe.Pointer)
func SyscallVerifyZKMProof(vkDigest unsafe.Pointer, pvDigest unsafe.Pointer)

// secp256k1 precompiles
func SyscallSecp256k1Add(p unsafe.Pointer, q unsafe.Pointer)
Expand Down Expand Up @@ -81,7 +83,7 @@ func HintSlice(data []byte) {
func ReadHintVec() []byte {
// Read length prefix (4 bytes LE)
lenLen := SyscallHintLen()
lenBuf := make([]byte, ((lenLen + 3) / 4) * 4)
lenBuf := make([]byte, ((lenLen+3)/4)*4)
SyscallHintRead(lenBuf, lenLen)
dataLen := int(lenBuf[0]) | int(lenBuf[1])<<8 | int(lenBuf[2])<<16 | int(lenBuf[3])<<24

Expand All @@ -94,6 +96,7 @@ func ReadHintVec() []byte {
}

var PublicValuesHasher hash.Hash = sha256.New()
var DeferredProofsDigest [8]uint32

const EMBEDDED_RESERVED_INPUT_REGION_SIZE int = 1024 * 1024 * 1024
const MAX_MEMORY int = 0x7f000000
Expand Down Expand Up @@ -127,6 +130,17 @@ func Commit[T any](value T) {
SyscallWrite(13, bytes, length)
}

func VerifyZKMProof(vkDigest *[8]uint32, pvDigest *[32]byte) {
SyscallVerifyZKMProof(unsafe.Pointer(vkDigest), unsafe.Pointer(pvDigest))
}

func CommitDeferredProofsDigest(digest [8]uint32) {
DeferredProofsDigest = digest
for i, word := range digest {
SyscallCommitDeferredProofs(i, word)
}
}

//go:linkname RuntimeExit zkvm.RuntimeExit
func RuntimeExit(code int) {
hashBytes := PublicValuesHasher.Sum(nil)
Expand All @@ -136,6 +150,7 @@ func RuntimeExit(code int) {
word := binary.LittleEndian.Uint32(hashBytes[i*4 : (i+1)*4])
SyscallCommit(i, word)
}
CommitDeferredProofsDigest(DeferredProofsDigest)

SyscallExit(code)
}
Expand Down
14 changes: 14 additions & 0 deletions crates/go-runtime/zkvm_runtime/syscall_mipsle.s
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ TEXT ·SyscallCommit(SB), $0-8
SYSCALL
RET

TEXT ·SyscallCommitDeferredProofs(SB), $0-8
MOVW index+0(FP), R4
MOVW word+4(FP), R5
MOVW $0x1A, R2
SYSCALL
RET

TEXT ·SyscallExit(SB), $0-4
MOVW code+0(FP), R4 // a0 = code
MOVW $0, R2 // v0 = syscall 0
Expand All @@ -62,6 +69,13 @@ TEXT ·SyscallKeccakSponge(SB), $0-8
SYSCALL
RET

TEXT ·SyscallVerifyZKMProof(SB), $0-8
MOVW $0x1B, R2
MOVW vkDigest+0(FP), R4
MOVW pvDigest+4(FP), R5
SYSCALL
RET

// secp256k1 elliptic curve precompiles

TEXT ·SyscallSecp256k1Add(SB), $0-8
Expand Down