Skip to content

fix(compute-provider): ComputeManager accepts batch_size Some(0) and then panics #1815

Description

@Toby1009

ComputeManager::new accepts batch_size: Some(0) without validation, and start() then panics
inside slice::chunks.

Reproduce

use e3_compute_provider::{ComputeInput, ComputeManager, ComputeProvider, FHEInputs};

struct Dummy;
impl ComputeProvider for Dummy {
    type Output = ();
    fn prove(&self, _: &ComputeInput) -> Self::Output {}
}

fn processor(_: &FHEInputs) -> Vec<u8> { Vec::new() }

fn main() {
    let inputs = FHEInputs { ciphertexts: vec![], params: vec![] };
    let mut m = ComputeManager::new(Dummy, inputs, processor, true, Some(0));
    println!("constructor accepted batch_size = Some(0)");
    let _ = m.start();
}

Output:

constructor accepted batch_size = Some(0)

thread 'main' panicked at crates/compute-provider/src/compute_manager.rs:84:14:
chunk size must be non-zero

Where

ComputeManager::new stores the value as given (src/compute_manager.rs:30-47).
start_parallel resolves it with unwrap_or(2) and passes it straight to chunks (:78, :84),
before any FHE work, so the panic happens on the first parallel run regardless of the input.

Reachability

No caller in this repository hits it. start_parallel has no external call sites, and all three
ComputeManager::new call sites pass use_parallel: false and batch_size: None
(crates/support-scripts/dev/src/main.rs:50, crates/support/host/src/lib.rs:431, :470).

ComputeManager is public API of the published e3-compute-provider crate, and
crates/compute-provider/Readme.md documents both parameters, so a downstream user can reach it.

Note on the documentation

The crate README claimed batch_size "must be a power of 2", which nothing enforced. #1813 corrects
that text to describe the current behaviour. This issue is about the code: whether the constructor
should reject Some(0), and whether the power-of-two constraint the README described was intended
and should be enforced too.

Happy to open a PR once the intended behaviour is settled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompute providerConcerned with the compute provider

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions