Skip to content

Commit

Permalink
rust: sumcheck prove takes input as HostOrDeviceSlice
Browse files Browse the repository at this point in the history
  • Loading branch information
yshekel committed Dec 4, 2024
1 parent aef9f5f commit 4b346d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 7 additions & 4 deletions wrappers/rust/icicle-core/src/sumcheck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod tests;

use crate::hash::Hasher;
use crate::traits::FieldImpl;
use icicle_runtime::eIcicleError;
use icicle_runtime::{eIcicleError, memory::HostOrDeviceSlice};

pub struct SumcheckTranscriptConfig<'a, S> {
pub hash: &'a Hasher,
Expand All @@ -14,13 +14,16 @@ pub struct SumcheckTranscriptConfig<'a, S> {
pub seed_rng: S,
}
// This trait is implemented on FieldConfig to enable Sumcheck struct to create a sumcheck prover

pub trait SumcheckConstructor<F> {
// TODO Yuval: instead of returning an 'impl SumcheckOps<F>' I could return a Box<dyn SumcheckOps<F>>.
// This will make it runtime polymorphism but allow the returned object to be stored in a user struct. REQUIRED?
fn new(transcript_config: &SumcheckTranscriptConfig<F>) -> Result<impl SumcheckOps<F>, eIcicleError>;
}

pub trait SumcheckOps<F> {
// TODO replace with sumcheck proof type
fn prove(&self) -> String;
fn prove(&self, input: &(impl HostOrDeviceSlice<F> + ?Sized)) -> String;
fn verify(&self, proof: &str) -> bool;
}

Expand Down Expand Up @@ -97,7 +100,7 @@ macro_rules! impl_sumcheck {
) => {
use icicle_core::sumcheck::{SumcheckConstructor, SumcheckOps, SumcheckTranscriptConfig};
use icicle_core::traits::FieldImpl;
use icicle_runtime::eIcicleError;
use icicle_runtime::{eIcicleError, memory::HostOrDeviceSlice};
use std::ffi::c_void;

pub type SumcheckHandle = *const c_void;
Expand Down Expand Up @@ -126,7 +129,7 @@ macro_rules! impl_sumcheck {
}

impl SumcheckOps<$field> for SumcheckInternal {
fn prove(&self) -> String {
fn prove(&self, input: &(impl HostOrDeviceSlice<$field> + ?Sized)) -> String {
String::from("hello")
}

Expand Down
4 changes: 3 additions & 1 deletion wrappers/rust/icicle-core/src/sumcheck/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::hash::Hasher;
use crate::sumcheck::{Sumcheck, SumcheckConstructor, SumcheckOps, SumcheckTranscriptConfig};
use crate::traits::{FieldImpl, GenerateRandom};
use icicle_runtime::memory::HostSlice;

pub fn check_sumcheck_transcript_config<F: FieldImpl>(hash: &Hasher)
where
Expand Down Expand Up @@ -55,7 +56,8 @@ where
);

let sumcheck = Sumcheck::new::<F>(&config).unwrap();
let proof = sumcheck.prove();
let dummy_input: Vec<F> = F::Config::generate_random(5);
let proof = sumcheck.prove(HostSlice::from_slice(&dummy_input));
println!("proof = {}", proof);
let _valid = sumcheck.verify(&proof);
}

0 comments on commit 4b346d9

Please sign in to comment.