aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zkvms/nexus/guest/Cargo.toml13
-rw-r--r--zkvms/nexus/guest/guest.ld73
l---------zkvms/nexus/guest/guests1
l---------zkvms/nexus/guest/guests_macro1
-rw-r--r--zkvms/nexus/guest/src/main.rs17
-rw-r--r--zkvms/nexus/wrapper_macro/Cargo.toml7
-rw-r--r--zkvms/nexus/wrapper_macro/src/lib.rs22
7 files changed, 134 insertions, 0 deletions
diff --git a/zkvms/nexus/guest/Cargo.toml b/zkvms/nexus/guest/Cargo.toml
new file mode 100644
index 0000000..1d91504
--- /dev/null
+++ b/zkvms/nexus/guest/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "guest"
+version = "0.1.0"
+edition = "2021"
+
+[workspace]
+
+[dependencies]
+nexus-rt = { path = "/nix/store/krlanfap664k4g88qgsssxi0818z92r8-Nexus-zkVM-unstable-2024-12-18/runtime" }
+postcard = { version = "1.0.10", default-features = false, features = ["alloc"] }
+
+zkp = { path = "./src/zkp" }
+wrapper_macro = { version = "0.1.0", path = "../wrapper_macro" }
diff --git a/zkvms/nexus/guest/guest.ld b/zkvms/nexus/guest/guest.ld
new file mode 100644
index 0000000..5a4dd4a
--- /dev/null
+++ b/zkvms/nexus/guest/guest.ld
@@ -0,0 +1,73 @@
+ENTRY(_start);
+
+SECTIONS
+{
+ /* Set the default size of the stack. */
+ /* */
+ /* Because the stack will grow down from this point, and if the heap requests memory */
+ /* being used by the stack then the runtime will panic, this value also functions as */
+ /* the memory limit for the guest program execution more generally. */
+ __memory_top = 0x6400000;
+ . = 0;
+
+ .text : ALIGN(4)
+ {
+ KEEP(*(.init));
+ . = ALIGN(4);
+ KEEP(*(.init.rust));
+ *(.text .text.*);
+ }
+
+ . = ALIGN(8);
+ . = .* 2;
+
+ .data : ALIGN(4)
+ {
+ /* Must be called __global_pointer$ for linker relaxations to work. */
+ __global_pointer$ = . + 0x800;
+ *(.srodata .srodata.*);
+ *(.rodata .rodata.*);
+ *(.sdata .sdata.* .sdata2 .sdata2.*);
+ *(.data .data.*);
+
+ /* this is used by the global allocator (see:src/lib.rs) */
+ . = ALIGN(4);
+ _heap = .;
+ LONG(_ebss);
+ }
+
+ .bss (NOLOAD) : ALIGN(4)
+ {
+ *(.sbss .sbss.* .bss .bss.*);
+ . = ALIGN(4);
+ _ebss = .;
+ _end = .;
+ }
+
+ /* Dynamic relocations are unsupported. This section is only used to detect
+ relocatable code in the input files and raise an error if relocatable code
+ is found */
+ .got (INFO) :
+ {
+ KEEP(*(.got .got.*));
+ }
+
+ /DISCARD/ :
+ {
+ *(.comment*)
+ *(.debug*)
+ }
+
+ /* Stack unwinding is not supported, but we will keep these for now */
+ .eh_frame (INFO) : { KEEP(*(.eh_frame)) }
+ .eh_frame_hdr (INFO) : { *(.eh_frame_hdr) }
+}
+
+ASSERT(. < __memory_top, "Program is too large for the VM memory.");
+
+ASSERT(SIZEOF(.got) == 0, "
+.got section detected in the input files. Dynamic relocations are not
+supported. If you are linking to C code compiled using the `gcc` crate
+then modify your build script to compile the C code _without_ the
+-fPIC flag. See the documentation of the `gcc::Config.fpic` method for
+details.");
diff --git a/zkvms/nexus/guest/guests b/zkvms/nexus/guest/guests
new file mode 120000
index 0000000..69bc8ed
--- /dev/null
+++ b/zkvms/nexus/guest/guests
@@ -0,0 +1 @@
+../../../guests \ No newline at end of file
diff --git a/zkvms/nexus/guest/guests_macro b/zkvms/nexus/guest/guests_macro
new file mode 120000
index 0000000..143a0b5
--- /dev/null
+++ b/zkvms/nexus/guest/guests_macro
@@ -0,0 +1 @@
+../../../guests_macro \ No newline at end of file
diff --git a/zkvms/nexus/guest/src/main.rs b/zkvms/nexus/guest/src/main.rs
new file mode 100644
index 0000000..eb82cde
--- /dev/null
+++ b/zkvms/nexus/guest/src/main.rs
@@ -0,0 +1,17 @@
+#![cfg_attr(target_arch = "riscv32", no_std, no_main, allow(unused_imports))]
+
+use nexus_rt::{ postcard, println, read_private_input, write_output };
+
+extern crate alloc;
+use alloc::vec::Vec;
+use wrapper_macro::make_wrapper;
+
+type Input = (Vec<Vec<bool>>, u32, Vec<Vec<u32>>);
+type Output = bool;
+
+const VERTICES: usize = 100;
+
+#[nexus_rt::main]
+fn main() {
+ zkp::entrypoint_expr!()
+}
diff --git a/zkvms/nexus/wrapper_macro/Cargo.toml b/zkvms/nexus/wrapper_macro/Cargo.toml
new file mode 100644
index 0000000..14348e5
--- /dev/null
+++ b/zkvms/nexus/wrapper_macro/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "wrapper_macro"
+version = "0.1.0"
+edition = "2021"
+
+[lib]
+proc-macro = true
diff --git a/zkvms/nexus/wrapper_macro/src/lib.rs b/zkvms/nexus/wrapper_macro/src/lib.rs
new file mode 100644
index 0000000..21bf1bb
--- /dev/null
+++ b/zkvms/nexus/wrapper_macro/src/lib.rs
@@ -0,0 +1,22 @@
+use proc_macro::TokenStream;
+
+#[path = "../../../../guests_macro/src/parse_fn.rs"]
+mod parse_fn;
+use crate::parse_fn::{ split_fn, args_split, args_divide, group_streams };
+
+#[proc_macro]
+pub fn make_wrapper(item: TokenStream) -> TokenStream {
+ let (name, args, ret) = split_fn(&item);
+
+ let (patterns, types) = args_divide(&args);
+ let ts_patterns = group_streams(&patterns);
+ let ts_types = group_streams(&types);
+
+ let mut out = TokenStream::new();
+ out.extend(format!("let {} = read_private_input::<{}>().unwrap();", ts_patterns, ts_types).parse::<TokenStream>());
+ out.extend(format!("write_output::<{}>(&zkp::{}{});", ret, name, ts_patterns).parse::<TokenStream>());
+
+ let mut block = TokenStream::new();
+ block.extend(format!("{{ {} }}", out).parse::<TokenStream>());
+ block
+}