MCPcopy Create free account
hub / github.com/BitVM/BitVM / wrap_hint_msm

Function wrap_hint_msm

bitvm/src/chunk/g16_runner_utils.rs:289–352  ·  view source on GitHub ↗
(
    skip: bool,
    segment_id: usize,
    scalars: Vec<Segment>,
    pub_vky: Vec<ark_bn254::G1Affine>,
)

Source from the content-addressed store, hash-verified

287}
288
289pub(crate) fn wrap_hint_msm(
290 skip: bool,
291 segment_id: usize,
292 scalars: Vec<Segment>,
293 pub_vky: Vec<ark_bn254::G1Affine>,
294) -> Vec<Segment> {
295 let num_chunks_per_scalar = (Fr::N_BITS + WINDOW_G1_MSM * BATCH_SIZE_PER_CHUNK - 1)
296 / (WINDOW_G1_MSM * BATCH_SIZE_PER_CHUNK);
297
298 let hint_scalars: Vec<ark_ff::BigInt<4>> = scalars
299 .iter()
300 .map(|f| f.result.0.try_into().unwrap())
301 .collect();
302
303 let mut segments = vec![];
304 if !skip {
305 let houts = chunk_msm(hint_scalars, pub_vky.clone());
306 assert_eq!(houts.len(), num_chunks_per_scalar as usize * scalars.len());
307 for (msm_chunk_index, (hout_msm, is_valid_input, scr, op_hints)) in
308 houts.into_iter().enumerate()
309 {
310 let mut input_segment_info: Vec<(SegmentID, ElementType)> = vec![];
311 if msm_chunk_index > 0 {
312 let prev_msm_id = (segment_id + msm_chunk_index - 1) as u32;
313 input_segment_info.push((prev_msm_id, ElementType::G1));
314 }
315
316 let sc = &scalars[msm_chunk_index / num_chunks_per_scalar as usize];
317 input_segment_info.push((sc.id, ElementType::ScalarElem));
318
319 segments.push(Segment {
320 id: (segment_id + msm_chunk_index) as u32,
321 is_valid_input,
322 parameter_ids: input_segment_info,
323 result: (DataType::G1Data(hout_msm), ElementType::G1),
324 hints: op_hints,
325 scr_type: ScriptType::MSM(msm_chunk_index as u32),
326 scr: scr.compile(),
327 });
328 }
329 } else {
330 let hout_msm: ark_bn254::G1Affine = ark_bn254::G1Affine::identity();
331 for msm_chunk_index in 0..num_chunks_per_scalar * scalars.len() as u32 {
332 let mut input_segment_info: Vec<(SegmentID, ElementType)> = vec![];
333 if msm_chunk_index > 0 {
334 let prev_msm_id = segment_id as u32 + msm_chunk_index - 1;
335 input_segment_info.push((prev_msm_id, ElementType::G1));
336 }
337 let sc = &scalars[(msm_chunk_index / num_chunks_per_scalar) as usize];
338 input_segment_info.push((sc.id, ElementType::ScalarElem));
339
340 segments.push(Segment {
341 id: (segment_id as u32 + msm_chunk_index),
342 is_valid_input: true,
343 parameter_ids: input_segment_info,
344 result: (DataType::G1Data(hout_msm), ElementType::G1),
345 hints: vec![],
346 scr_type: ScriptType::MSM(msm_chunk_index),

Callers 1

Calls 4

chunk_msmFunction · 0.85
cloneMethod · 0.80
lenMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected