From ad7c5672f2ddb872e41b64ed359241db17add26f Mon Sep 17 00:00:00 2001 From: psinelnikov Date: Sun, 13 Oct 2024 10:57:38 -0700 Subject: [PATCH] Fixed minor spelling errors and added dockerfile for MacOS compatability --- Dockerfile | 57 +++++++++++++++++++++++++++++++ host-program/src/bin/zkm-prove.rs | 12 +++---- 2 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..98b87ba6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,57 @@ +FROM rustlang/rust:nightly AS builder +RUN apt-get update && apt-get install -y \ + autoconf \ + automake \ + libtool \ + curl \ + make \ + gcc \ + g++ \ + unzip \ + pkg-config \ + openssl \ + libssl-dev \ + wget \ + vim \ + && rm -rf /var/lib/apt/lists/* + +# install musl cross compiler +RUN wget http://musl.cc/mips-linux-muslsf-cross.tgz +RUN mkdir -p "/root/.mipsrust" +RUN tar -xzf "mips-linux-muslsf-cross.tgz" -C "/root/.mipsrust" + +ENV CARGO_TARGET_MIPS_UNKNOWN_LINUX_MUSL_LINKER="/root/.mipsrust/mips-linux-muslsf-cross/bin/mips-linux-muslsf-gcc" +ENV CARGO_TARGET_MIPS_UNKNOWN_LINUX_MUSL_RUSTFLAGS='--cfg target_os="zkvm" -C target-feature=+crt-static -C link-arg=-g' + +# install golang +ENV GOLANG_VERSION=1.23.2 +ENV GOLANG_DOWNLOAD_URL=https://go.dev/dl/ +ENV GOLANG_DOWNLOAD_SHA256_AMD64=542d3c1705f1c6a1c5a80d5dc62e2e45171af291e755d591c5e6531ef63b454e +ENV GOLANG_DOWNLOAD_SHA256_ARM64=f626cdd92fc21a88b31c1251f419c17782933a42903db87a174ce74eeecc66a9 + +RUN ARCH=$(uname -m) && \ + if [ "$ARCH" = "x86_64" ]; then \ + GOARCH=amd64; \ + GO_SHA256=$GOLANG_DOWNLOAD_SHA256_AMD64; \ + elif [ "$ARCH" = "aarch64" ]; then \ + GOARCH=arm64; \ + GO_SHA256=$GOLANG_DOWNLOAD_SHA256_ARM64; \ + else \ + echo "Unsupported architecture"; exit 1; \ + fi && \ + wget ${GOLANG_DOWNLOAD_URL}go${GOLANG_VERSION}.linux-${GOARCH}.tar.gz && \ + echo "${GO_SHA256} go${GOLANG_VERSION}.linux-${GOARCH}.tar.gz" | sha256sum -c - && \ + tar -C /usr/local -xzf go${GOLANG_VERSION}.linux-${GOARCH}.tar.gz && \ + rm go${GOLANG_VERSION}.linux-${GOARCH}.tar.gz + +ENV PATH=/usr/local/go/bin:$PATH + +# docker build -t zkm/zkmips:compile . +# docker run -it --rm -v ./:/zkm zkm/zkmips:compile +# compile rust mips +# cd /zkm/prover/examples/sha2-rust && cargo build -r --target=mips-unknown-linux-musl +# cd /zkm/prover/examples/revme && cargo build -r --target=mips-unknown-linux-musl +# compile go mips +# cd /zkm/prover/examples/add-go && GOOS=linux GOARCH=mips GOMIPS=softfloat go build . +# cd /zkm/prover/examples/sha2-go && GOOS=linux GOARCH=mips GOMIPS=softfloat go build . + diff --git a/host-program/src/bin/zkm-prove.rs b/host-program/src/bin/zkm-prove.rs index ab0bc00a..8201de48 100644 --- a/host-program/src/bin/zkm-prove.rs +++ b/host-program/src/bin/zkm-prove.rs @@ -31,10 +31,10 @@ async fn main() -> Result<(), Box> { let input: ProverInput = match args[1].as_str() { "sha2-rust" => { - set_sha2_rust_intput(seg_size2, execute_only2).expect("set sha2-rust input error") + set_sha2_rust_input(seg_size2, execute_only2).expect("set sha2-rust input error") } - "sha2-go" => set_sha2_go_intput(seg_size2, execute_only2).expect("set sha2-go input error"), - "mem-alloc-vec" => set_mem_alloc_vec_intput(seg_size2, execute_only2) + "sha2-go" => set_sha2_go_input(seg_size2, execute_only2).expect("set sha2-go input error"), + "mem-alloc-vec" => set_mem_alloc_vec_input(seg_size2, execute_only2) .expect("set mem-alloc-vec input error"), "revme" => set_revme_input(seg_size2, execute_only2).expect("set revme input error"), _ => { @@ -139,7 +139,7 @@ async fn main() -> Result<(), Box> { Ok(()) } -fn set_sha2_rust_intput(seg_size_u: u32, execute_only_b: bool) -> anyhow::Result { +fn set_sha2_rust_input(seg_size_u: u32, execute_only_b: bool) -> anyhow::Result { let elf_path = env::var("ELF_PATH").expect("ELF PATH is missed"); let num_bytes: usize = 1024; //Notice! : if this value is small, it will not generate the snark proof. let pri_input = vec![5u8; num_bytes]; @@ -214,7 +214,7 @@ impl Data { } } -fn set_sha2_go_intput(seg_size_u: u32, execute_only_b: bool) -> anyhow::Result { +fn set_sha2_go_input(seg_size_u: u32, execute_only_b: bool) -> anyhow::Result { let elf_path = env::var("ELF_PATH").expect("ELF PATH is missed"); let args = env::var("ARGS").unwrap_or("data-to-hash".to_string()); // assume the arg[0] is the hash(input)(which is a public input), and the arg[1] is the input. @@ -237,7 +237,7 @@ fn set_sha2_go_intput(seg_size_u: u32, execute_only_b: bool) -> anyhow::Result

anyhow::Result { +fn set_mem_alloc_vec_input(seg_size_u: u32, execute_only_b: bool) -> anyhow::Result { let elf_path = env::var("ELF_PATH").expect("ELF PATH is missed"); let input = ProverInput { elf: read(elf_path).unwrap(),