Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: quick start example fails to compile #274

Closed
benma opened this issue Aug 20, 2024 · 4 comments · Fixed by #276
Closed

[BUG]: quick start example fails to compile #274

benma opened this issue Aug 20, 2024 · 4 comments · Fixed by #276
Labels
bug Something isn't working

Comments

@benma
Copy link

benma commented Aug 20, 2024

Following https://docs.nexus.xyz/zkvm/sdk-quick-start

with the given host and guest example programs:

#![cfg_attr(target_arch = "riscv32", no_std, no_main)]
 
use nexus_rt::{println, read_private_input, write_output};
 
#[nexus_rt::main]
fn main() {
    let input = read_private_input::<(u32, u32)>();
 
    let mut z: i32 = -1;
    if let Ok((x, y)) = input {
        println!("Read private input: ({}, {})", x, y);
 
        z = (x * y) as i32;
    } else {
        println!("No private input provided...");
    }
 
    write_output::<i32>(&z)
}
use nexus_sdk::{
    compile::CompileOpts,
    nova::seq::{Generate, Nova, PP},
    Local, Prover, Verifiable,
};
 
type Input = (u32, u32);
type Output = i32;
 
const PACKAGE: &str = "guest";
 
fn main() {
    println!("Setting up Nova public parameters...");
    let pp: PP = PP::generate().expect("failed to generate parameters");
 
    let mut opts = CompileOpts::new(PACKAGE);
    opts.set_memlimit(8); // use an 8mb memory
 
    println!("Compiling guest program...");
    let prover: Nova<Local> = Nova::compile(&opts).expect("failed to compile guest program");
 
    let input: Input = (3, 5);
 
    print!("Proving execution of vm...");
    let proof = prover
        .prove_with_input::<Input>(&pp, &input)
        .expect("failed to prove program");
 
    println!(
        " output is {}!",
        proof
            .output::<Output>()
            .expect("failed to deserialize output")
    );
 
    println!(">>>>> Logging\n{}<<<<<", proof.logs().join("\n"));
 
    print!("Verifying execution...");
    proof.verify(&pp).expect("failed to verify proof");
 
    println!("  Succeeded!");
}

Then running cargo run -r fails with

cargo run -r
warning: Patch `ark-pallas v0.4.0 (https://github.com/arkworks-rs/curves/?rev=8c0256a#8c0256ac)` was not used in the crate graph.
Patch `ark-test-curves v0.4.2 (https://github.com/arkworks-rs/algebra/?rev=2a80c54#2a80c546)` was not used in the crate graph.
Patch `ark-vesta v0.4.0 (https://github.com/arkworks-rs/curves/?rev=8c0256a#8c0256ac)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
    Finished `release` profile [optimized] target(s) in 0.29s
     Running `target/release/nexus-host`
Setting up Nova public parameters...

Compiling guest program...
warning: Patch `ark-pallas v0.4.0 (https://github.com/arkworks-rs/curves/?rev=8c0256a#8c0256ac)` was not used in the crate graph.
Patch `ark-test-curves v0.4.2 (https://github.com/arkworks-rs/algebra/?rev=2a80c54#2a80c546)` was not used in the crate graph.
Patch `ark-vesta v0.4.0 (https://github.com/arkworks-rs/curves/?rev=8c0256a#8c0256ac)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
   Compiling postcard v1.0.9
error[E0432]: unresolved import `alloc::sync`
   --> /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/postcard-1.0.9/src/max_size.rs:5:33
    |
5   | use alloc::{boxed::Box, rc::Rc, sync::Arc};
    |                                 ^^^^ could not find `sync` in `alloc`
    |
note: found an item that was configured out
   --> /home/user/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/lib.rs:254:9
    |
254 | pub mod sync;
    |         ^^^^

For more information about this error, try `rustc --explain E0432`.
error: could not compile `postcard` (lib) due to 1 previous error
thread 'main' panicked at src/main.rs:20:52:
failed to compile guest program: BuildError(CompilerError)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Project Information

No response

Reproduction Steps

See above

What is expected?

Output like documented:

Setting up Nova public parameters...
Proving execution of vm... output is 15!
>>>>> Logging
Read private input: (3, 5)
<<<<<
Verifying execution...  Succeeded!

What is actually happening?

See above

System Information

No response

Any additional comments?

No response

@benma benma added the bug Something isn't working label Aug 20, 2024
@sjudson
Copy link
Contributor

sjudson commented Aug 20, 2024

Thanks for the report. This coincides with a new release to postcard, and we're investigating the root cause and working on a fix.

duc-nx pushed a commit that referenced this issue Aug 20, 2024
This fixes #274


Summary:

Test Plan:
duc-nx pushed a commit that referenced this issue Aug 20, 2024
This fixes #274


Summary:

Test Plan:
duc-nx pushed a commit that referenced this issue Aug 20, 2024
This fixes #274


Summary:

Test Plan:
duc-nx pushed a commit that referenced this issue Aug 20, 2024
This fixes #274


Summary:

Test Plan:
@duc-nx duc-nx closed this as completed in cf86ffd Aug 21, 2024
@benma
Copy link
Author

benma commented Aug 21, 2024

Thanks, but how do I know fix my existing nexus-host example program from the quickstart docs?

@sjudson
Copy link
Contributor

sjudson commented Aug 21, 2024

Opened upstream issue: jamesmunns/postcard#167

@sjudson
Copy link
Contributor

sjudson commented Aug 21, 2024

@benma a new patch release with a fix (v0.2.2) just went out. The easiest way to fix is likely to restart the quickstart (including reinstalling cargo-nexus) using the updated version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants