Skip to content

Commit bce2a6d

Browse files
zhiyong1997hczphn
andauthored
allow hint with warning (#195)
* allow hint with warning * format * add a hint test * fix fmt issue --------- Co-authored-by: hczphn <hczphn@polyhedra.network>
1 parent 306b515 commit bce2a6d

2 files changed

Lines changed: 41 additions & 9 deletions

File tree

circuit-std-rs/tests/logup.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ use circuit_std_rs::{
77
use expander_compiler::{
88
field::{BN254Fr, Goldilocks},
99
frontend::*,
10-
zkcuda::{context::*, kernel::*, proving_system::*, shape::Reshape},
10+
zkcuda::{
11+
context::*,
12+
kernel::*,
13+
proving_system::{expander::config::ZKCudaBN254Hyrax, *},
14+
shape::Reshape,
15+
},
1116
};
17+
use serdes::ExpSerde;
1218

1319
#[test]
1420
fn logup_test() {
@@ -196,3 +202,31 @@ fn rangeproof_zkcuda_test_fail() {
196202
);
197203
assert!(P::verify(&verifier_setup, &computation_graph, &proof));
198204
}
205+
206+
#[test]
207+
fn rangeproof_zkcuda_no_oversubscribe_test() {
208+
let mut hint_registry = HintRegistry::<BN254Fr>::new();
209+
hint_registry.register("myhint.querycounthint", query_count_hint);
210+
hint_registry.register("myhint.rangeproofhint", rangeproof_hint);
211+
//compile and test
212+
let kernel: KernelPrimitive<BN254Config> = compile_rangeproof_test_kernel().unwrap();
213+
let mut ctx: Context<BN254Config, _> = Context::new(hint_registry);
214+
215+
let a = BN254Fr::from((1 << 9) as u32);
216+
let a = ctx.copy_to_device(&a);
217+
let a = a.reshape(&[1]);
218+
call_kernel!(ctx, kernel, 1, a).unwrap();
219+
220+
let computation_graph = ctx.compile_computation_graph().unwrap();
221+
ctx.solve_witness().unwrap();
222+
let (prover_setup, _) = ExpanderNoOverSubscribe::<ZKCudaBN254Hyrax>::setup(&computation_graph);
223+
let proof = ExpanderNoOverSubscribe::<ZKCudaBN254Hyrax>::prove(
224+
&prover_setup,
225+
&computation_graph,
226+
ctx.export_device_memories(),
227+
);
228+
let file = std::fs::File::create("proof.txt").unwrap();
229+
let writer = std::io::BufWriter::new(file);
230+
proof.serialize_into(writer).expect("serialize failed");
231+
<ExpanderNoOverSubscribe<ZKCudaBN254Hyrax> as ProvingSystem<BN254Config>>::post_process();
232+
}

expander_compiler/src/zkcuda/mpi_mem_share.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,16 @@ impl<C: Config> MPISharedMemory for ComputationGraph<C> {
6565

6666
impl<C: Config> MPISharedMemory for Kernel<C> {
6767
fn bytes_size(&self) -> usize {
68-
assert!(
69-
self.hint_solver.is_none(),
70-
"Hint solver is not supported in MPISharedMemory for Kernel"
71-
);
68+
if self.hint_solver.is_some() {
69+
eprintln!("Warning: Shared Memory will ignore the hint solver in Kernel");
70+
}
7271
self.layered_circuit.bytes_size() + self.layered_circuit_input.bytes_size()
7372
}
7473

7574
fn to_memory(&self, ptr: &mut *mut u8) {
76-
assert!(
77-
self.hint_solver.is_none(),
78-
"Hint solver is not supported in MPISharedMemory for Kernel"
79-
);
75+
if self.hint_solver.is_some() {
76+
eprintln!("Warning: Shared Memory will ignore the hint solver in Kernel");
77+
}
8078
self.layered_circuit.to_memory(ptr);
8179
self.layered_circuit_input.to_memory(ptr);
8280
}

0 commit comments

Comments
 (0)