From 4b346d9fc64ed4de38589a424c9649c69063f7f5 Mon Sep 17 00:00:00 2001 From: Yuval Shekel Date: Wed, 4 Dec 2024 23:04:56 +0200 Subject: [PATCH] rust: sumcheck prove takes input as HostOrDeviceSlice --- wrappers/rust/icicle-core/src/sumcheck/mod.rs | 11 +++++++---- wrappers/rust/icicle-core/src/sumcheck/tests.rs | 4 +++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/wrappers/rust/icicle-core/src/sumcheck/mod.rs b/wrappers/rust/icicle-core/src/sumcheck/mod.rs index 6cbd1ecc7..b6b3d2a92 100644 --- a/wrappers/rust/icicle-core/src/sumcheck/mod.rs +++ b/wrappers/rust/icicle-core/src/sumcheck/mod.rs @@ -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, @@ -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 { + // TODO Yuval: instead of returning an 'impl SumcheckOps' I could return a Box>. + // This will make it runtime polymorphism but allow the returned object to be stored in a user struct. REQUIRED? fn new(transcript_config: &SumcheckTranscriptConfig) -> Result, eIcicleError>; } pub trait SumcheckOps { // TODO replace with sumcheck proof type - fn prove(&self) -> String; + fn prove(&self, input: &(impl HostOrDeviceSlice + ?Sized)) -> String; fn verify(&self, proof: &str) -> bool; } @@ -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; @@ -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") } diff --git a/wrappers/rust/icicle-core/src/sumcheck/tests.rs b/wrappers/rust/icicle-core/src/sumcheck/tests.rs index e403f7152..e8e4c197e 100644 --- a/wrappers/rust/icicle-core/src/sumcheck/tests.rs +++ b/wrappers/rust/icicle-core/src/sumcheck/tests.rs @@ -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(hash: &Hasher) where @@ -55,7 +56,8 @@ where ); let sumcheck = Sumcheck::new::(&config).unwrap(); - let proof = sumcheck.prove(); + let dummy_input: Vec = F::Config::generate_random(5); + let proof = sumcheck.prove(HostSlice::from_slice(&dummy_input)); println!("proof = {}", proof); let _valid = sumcheck.verify(&proof); }