Skip to content

Commit f3c8ff8

Browse files
hczphnclaude
andcommitted
Add commit_single to ProvingSystem trait and device_memory_id getter
- Add ProvingSystem::commit_single() method that returns serialized commitment bytes for Fiat-Shamir transcript hashing in two-round LogUp binding protocol - Implement for Expander, ExpanderLocalDeferred, DummyProvingSystem (real commit), and stub for remote backends - Add DeviceMemoryHandleRaw::device_memory_id() public getter These changes support the cross-kernel bus binding security fix in KlawdVM where LogUp bus messages must be cryptographically bound to committed witness polynomials. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 464f687 commit f3c8ff8

File tree

8 files changed

+71
-0
lines changed

8 files changed

+71
-0
lines changed

expander_compiler/src/zkcuda/context.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ pub struct DeviceMemoryHandleRaw {
3636
shape_history: ShapeHistory,
3737
}
3838

39+
impl DeviceMemoryHandleRaw {
40+
/// Returns the device memory index (position in the device_memories vector).
41+
pub fn device_memory_id(&self) -> usize {
42+
self.id
43+
}
44+
}
45+
3946
pub type DeviceMemoryHandle = Option<DeviceMemoryHandleRaw>;
4047

4148
#[derive(Clone, ExpSerde)]

expander_compiler/src/zkcuda/proving_system/dummy.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ impl<C: Config> ProvingSystem<C> for DummyProvingSystem<C> {
215215
verified.iter().all(|x| *x)
216216
}
217217

218+
fn commit_single(
219+
prover_setup: &Self::ProverSetup,
220+
device_memory: &[SIMDField<C>],
221+
) -> Vec<u8> {
222+
let (commitment, _state) =
223+
<Self as KernelWiseProvingSystem<C>>::commit(prover_setup, device_memory);
224+
let mut buf = Vec::new();
225+
serdes::ExpSerde::serialize_into(&commitment, &mut buf).expect("commitment serialization");
226+
buf
227+
}
228+
218229
fn post_process() {
219230
<Self as KernelWiseProvingSystem<C>>::post_process();
220231
}

expander_compiler/src/zkcuda/proving_system/expander/api_single_thread.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,17 @@ impl<C: GKREngine, ECCConfig: Config<FieldConfig = C::FieldConfig>> ProvingSyste
256256
verified.iter().all(|x| *x)
257257
}
258258

259+
fn commit_single(
260+
prover_setup: &Self::ProverSetup,
261+
device_memory: &[SIMDField<ECCConfig>],
262+
) -> Vec<u8> {
263+
let (commitment, _state) =
264+
<Self as KernelWiseProvingSystem<ECCConfig>>::commit(prover_setup, device_memory);
265+
let mut buf = Vec::new();
266+
serdes::ExpSerde::serialize_into(&commitment, &mut buf).expect("commitment serialization");
267+
buf
268+
}
269+
259270
fn post_process() {
260271
<Self as KernelWiseProvingSystem<ECCConfig>>::post_process();
261272
}

expander_compiler/src/zkcuda/proving_system/expander_local_deferred/api.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ impl<C: GKREngine, ECCConfig: Config<FieldConfig = C::FieldConfig>> ProvingSyste
7171
CombinedProof { commitments, proofs }
7272
}
7373

74+
fn commit_single(
75+
ps: &Self::ProverSetup,
76+
device_memory: &[SIMDField<ECCConfig>],
77+
) -> Vec<u8> {
78+
use crate::zkcuda::proving_system::expander::commit_impl::local_commit_impl;
79+
let (commitment, _state) = local_commit_impl::<C, ECCConfig>(
80+
ps.p_keys.get(&device_memory.len()).unwrap(), device_memory,
81+
);
82+
let mut buf = Vec::new();
83+
serdes::ExpSerde::serialize_into(&commitment, &mut buf).expect("commitment serialization");
84+
buf
85+
}
86+
7487
fn verify(vs: &Self::VerifierSetup, cg: &ComputationGraph<ECCConfig>, proof: &Self::Proof) -> bool {
7588
use crate::zkcuda::proving_system::expander::verify_impl::verify_pcs_opening_and_aggregation_no_mpi;
7689
// Parallel template verification — each template is independent

expander_compiler/src/zkcuda/proving_system/expander_no_oversubscribe/api_no_oversubscribe.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ where
6969
}
7070
}
7171

72+
fn commit_single(
73+
_prover_setup: &Self::ProverSetup,
74+
_device_memory: &[SIMDField<ZC::ECCConfig>],
75+
) -> Vec<u8> {
76+
unimplemented!("commit_single not supported for ExpanderNoOverSubscribe")
77+
}
78+
7279
fn post_process() {
7380
wait_async(ClientHttpHelper::request_exit())
7481
}

expander_compiler/src/zkcuda/proving_system/expander_parallelized/api_parallel.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ impl<C: GKREngine, ECCConfig: Config<FieldConfig = C::FieldConfig>> ProvingSyste
8181
verified.iter().all(|x| *x)
8282
}
8383

84+
fn commit_single(
85+
_prover_setup: &Self::ProverSetup,
86+
_device_memory: &[SIMDField<ECCConfig>],
87+
) -> Vec<u8> {
88+
unimplemented!("commit_single not supported for ParallelizedExpander")
89+
}
90+
8491
fn post_process() {
8592
wait_async(ClientHttpHelper::request_exit())
8693
}

expander_compiler/src/zkcuda/proving_system/expander_pcs_defered/api_pcs_defered.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ where
5959
super::verify_impl::verify(verifier_setup, computation_graph, proof.clone())
6060
}
6161

62+
fn commit_single(
63+
_prover_setup: &Self::ProverSetup,
64+
_device_memory: &[SIMDField<ECCConfig>],
65+
) -> Vec<u8> {
66+
unimplemented!("commit_single not supported for ExpanderPCSDefered")
67+
}
68+
6269
fn post_process() {
6370
wait_async(ClientHttpHelper::request_exit())
6471
}

expander_compiler/src/zkcuda/proving_system/traits.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ pub trait ProvingSystem<C: Config> {
7979
proof: &Self::Proof,
8080
) -> bool;
8181

82+
/// Commit a single device memory and return the serialized commitment bytes.
83+
/// Used for deriving challenges from Round 1 commitments in two-round protocols.
84+
/// Default implementation is not provided — each backend must implement this.
85+
fn commit_single(
86+
prover_setup: &Self::ProverSetup,
87+
device_memory: &[SIMDField<C>],
88+
) -> Vec<u8>;
89+
8290
/// This is a dedicated function to stop the running service
8391
/// For most proving systems, this is a no-op
8492
fn post_process() {}

0 commit comments

Comments
 (0)