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

Zero Division Error on latest main branch #248

Closed
LiuJiazheng opened this issue Apr 17, 2024 · 2 comments
Closed

Zero Division Error on latest main branch #248

LiuJiazheng opened this issue Apr 17, 2024 · 2 comments

Comments

@LiuJiazheng
Copy link

Statement

Program crashes on setup stage

Case

Any wasm,

--host standard -k 18 --function zkmain --param params --output ./output --wasm "fibonacci-guest"/target/guest.wasm setup
write params K=18 to "params/K18.params"
write params K=22 to "params/K22.params"
quotient_poly_degree 4
Start:   Assign
··Start:   Init range chip
··End:     Init range chip .........................................................55.401ms
··Start:   Assign external host call table
··End:     Assign external host call table .........................................18.501ms
··Start:   Prepare memory info for etable
··End:     Prepare memory info for etable ..........................................1.092µs
··Start:   Assign etable
··End:     Assign etable ...........................................................2.203ms
··Start:   Assign mtable
··End:     Assign mtable ...........................................................2.118ms
··Start:   Assign frame table
··End:     Assign frame table ......................................................2.953ms
··Start:   Assign bit table
··End:     Assign bit table ........................................................8.997ms
··Start:   Prepare memory info for etable
··End:     Prepare memory info for etable ..........................................50ns
··Start:   Assign etable
··End:     Assign etable ...........................................................3.596ms
··Start:   Assign mtable
··End:     Assign mtable ...........................................................3.549ms
··Start:   Assign frame table
··End:     Assign frame table ......................................................1.229ms
··Start:   Assign bit table
··End:     Assign bit table ........................................................7.629ms
··Start:   Assign context cont chip
··End:     Assign context cont chip ................................................1.282µs
··Start:   Assign Image Table
··End:     Assign Image Table ......................................................429.771µs
End:     Assign ....................................................................116.090ms
thread 'main' panicked at 'attempt to divide by zero', /home/frank/.cargo/git/checkouts/halo2-gpu-specific-4d08aed75011eb52/9ac1080/halo2_proofs/src/arithmetic.rs:426:24
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The code:

#[cfg(feature = "cuda")]
pub fn gpu_multiexp_bound<C: CurveAffine>(
    coeffs: &[C::Scalar],
    bases: &[C],
    max_bits: usize,
) -> C::Curve {
    use ec_gpu_gen::rust_gpu_tools::Device;
    use std::str::FromStr;

    if max_bits == 0 || coeffs.len() == 0 {
        C::Curve::identity()
    } else {
        //let timer = start_timer!(|| "msm gpu");
        let n_gpu = *crate::plonk::N_GPU;
        let part_len = (coeffs.len() + n_gpu - 1) / n_gpu;

        let c = coeffs
            .par_chunks(part_len)
            .zip(bases.par_chunks(part_len))
            .map(|(c, b)| gpu_multiexp_single_gpu_with_bound(c, b, max_bits))
            .collect::<Vec<_>>()
            .into_iter()
            .reduce(|acc, x| acc + x)
            .unwrap();

        //end_timer!(timer);
        c
    }
}

Guess N_GPU is initialized as 0 but somehow not been updated ever since.

Git commit

commit 7b18f0d75546136de76f24ff365627c49c913731 (HEAD -> main, origin/main, origin/HEAD)
Author: Zhang Junyu <junyu92@gmail.com>
Date:   Sat Feb 3 21:19:47 2024 +0800

WAT

In case you need a small WASM:

(module
  (type (;0;) (func (result i64)))
  (type (;1;) (func (param i32) (result i64)))
  (type (;2;) (func (param i32)))
  (type (;3;) (func))
  (import "env" "wasm_input" (func (;0;) (type 1)))
  (import "env" "require" (func (;1;) (type 2)))
  (func (;2;) (type 0) (result i64)
    i32.const 1
    call 0)
  (func (;3;) (type 0) (result i64)
    i32.const 0
    call 0)
  (func (;4;) (type 3)
    i32.const 0
    call 0
    i32.const 0
    call 0
    i64.add
    i32.const 1
    call 0
    i64.eq
    call 1)
  (memory (;0;) 0)
  (export "read_public_input" (func 2))
  (export "read_private_input" (func 3))
  (export "zkmain" (func 4))
  (export "memory" (memory 0)))
@LiuJiazheng
Copy link
Author

FYI, tag v1.2 is fine. Just one commit among a few between v1.2 and head shall be blamed.

@junyu0312
Copy link
Collaborator

junyu0312 commented May 17, 2024

The reason is no available GPU can be detected, maybe you could check your driver, or build zkWasm without '--features cuda'. The commit changed basically nothing except renaming a structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants