mirror of
https://github.com/eth-act/ere.git
synced 2026-04-03 03:00:17 -04:00
Update zisk to v0.14.0 (#220)
This commit is contained in:
@@ -3,6 +3,11 @@ module basic_go
|
||||
go 1.24.4
|
||||
|
||||
require (
|
||||
github.com/eth-act/skunkworks-tama v0.0.0-20251105112532-eff8e3af014b // indirect
|
||||
github.com/usbarmory/tamago v0.0.0-20250710154000-3dd21eabac74 // indirect
|
||||
github.com/eth-act/skunkworks-tama v0.0.0-20251105112532-eff8e3af014b
|
||||
github.com/fxamacker/cbor/v2 v2.9.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/usbarmory/tamago v0.0.0-20250710154000-3dd21eabac74 // indirect
|
||||
github.com/x448/float16 v0.8.4 // indirect
|
||||
)
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
github.com/eth-act/skunkworks-tama v0.0.0-20251105112532-eff8e3af014b h1:Nm1FYhFjCWnKkaRZzSjGmeWdqevsunbpOnYOayWpuoM=
|
||||
github.com/eth-act/skunkworks-tama v0.0.0-20251105112532-eff8e3af014b/go.mod h1:M9fXNuyicUdFmj5nBlXRTNcUbJIDLMMs4eY1QoZHM3g=
|
||||
github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM=
|
||||
github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
|
||||
github.com/usbarmory/tamago v0.0.0-20250710154000-3dd21eabac74 h1:zH22Y68S2cpwW278H+9v4r2SWpdP+JwUk/AwVc9LOlw=
|
||||
github.com/usbarmory/tamago v0.0.0-20250710154000-3dd21eabac74/go.mod h1:0Bc0GnC88LvCAoCRUcd3DBFl7cribfVbCsiMJUbXyAE=
|
||||
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
|
||||
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
|
||||
|
||||
@@ -3,12 +3,88 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
_ "github.com/eth-act/skunkworks-tama/tamaboards/zkvm"
|
||||
"encoding/binary"
|
||||
"unsafe"
|
||||
|
||||
"github.com/eth-act/skunkworks-tama/tamaboards/zkvm"
|
||||
"github.com/eth-act/skunkworks-tama/tamaboards/zkvm/zisk_runtime"
|
||||
"github.com/fxamacker/cbor/v2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x := 10
|
||||
y := 11
|
||||
fmt.Println("Hello World", x + y)
|
||||
// According to crates/test-utils/src/program/basic.rs
|
||||
type BasicProgramInput struct {
|
||||
ShouldPanic bool `cbor:"should_panic"`
|
||||
A uint8 `cbor:"a"`
|
||||
B uint16 `cbor:"b"`
|
||||
C uint32 `cbor:"c"`
|
||||
D uint64 `cbor:"d"`
|
||||
E []byte `cbor:"e"`
|
||||
}
|
||||
|
||||
// According to crates/test-utils/src/program/basic.rs
|
||||
type BasicProgramOutput struct {
|
||||
E []byte `cbor:"e"`
|
||||
D uint64 `cbor:"d"`
|
||||
C uint32 `cbor:"c"`
|
||||
B uint16 `cbor:"b"`
|
||||
A uint8 `cbor:"a"`
|
||||
}
|
||||
|
||||
func readWholeInput() []byte {
|
||||
lengthBytes := make([]byte, 8)
|
||||
src := unsafe.Pointer(uintptr(zkvm.INPUT_ADDR + 8))
|
||||
for i := 0; i < 8; i++ {
|
||||
lengthBytes[i] = *(*byte)(unsafe.Add(src, i))
|
||||
}
|
||||
length := binary.LittleEndian.Uint64(lengthBytes)
|
||||
|
||||
inputBytes := zisk_runtime.UnsafeReadBytes(int(length))
|
||||
return inputBytes
|
||||
}
|
||||
|
||||
func unmarshalInput(inputBytes []byte) BasicProgramInput {
|
||||
var input BasicProgramInput
|
||||
if err := cbor.Unmarshal(inputBytes[4:], &input); err != nil {
|
||||
panic("failed to deserialize input")
|
||||
}
|
||||
return input
|
||||
}
|
||||
|
||||
func compute(input BasicProgramInput) BasicProgramOutput {
|
||||
if input.ShouldPanic {
|
||||
panic("invalid data")
|
||||
}
|
||||
|
||||
output := BasicProgramOutput{
|
||||
A: input.A + 1,
|
||||
B: input.B + 1,
|
||||
C: input.C + 1,
|
||||
D: input.D + 1,
|
||||
E: make([]byte, len(input.E)),
|
||||
}
|
||||
for i, b := range input.E {
|
||||
output.E[i] = b + 1
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
func marshalOutput(output BasicProgramOutput) []byte {
|
||||
outputBytes, err := cbor.Marshal(output)
|
||||
if err != nil {
|
||||
panic("failed to serialize output")
|
||||
}
|
||||
return outputBytes
|
||||
}
|
||||
|
||||
func writeWholeOutput(outputBytes []byte) {
|
||||
zisk_runtime.CommitBytes(outputBytes)
|
||||
}
|
||||
|
||||
func main() {
|
||||
inputBytes := readWholeInput()
|
||||
input := unmarshalInput(inputBytes)
|
||||
output := compute(input)
|
||||
outputBytes := marshalOutput(output)
|
||||
writeWholeOutput(outputBytes)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user