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

Function test_tap_msm_valid_inputs

bitvm/src/chunk/taps_msm.rs:402–474  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

400
401 #[test]
402 fn test_tap_msm_valid_inputs() {
403 let mut prng = ChaCha20Rng::seed_from_u64(1);
404 let q = ark_bn254::G1Affine::rand(&mut prng);
405 let scalar = ark_bn254::Fr::rand(&mut prng);
406 let scalars = vec![scalar.into()];
407 let qs = vec![q];
408
409 let hints_msm = chunk_msm(scalars.clone(), qs.clone());
410
411 for msm_chunk_index in 0..hints_msm.len() {
412 let input_is_valid = hints_msm[msm_chunk_index].1;
413 assert!(input_is_valid);
414 let hint_in = if msm_chunk_index > 0 {
415 DataType::G1Data(hints_msm[msm_chunk_index - 1].0)
416 } else {
417 DataType::G1Data(ark_bn254::G1Affine::identity())
418 };
419 let hint_out = DataType::G1Data(hints_msm[msm_chunk_index].0);
420
421 let bitcom_scr = script! {
422 {hint_out.to_hash().as_hint_type().push()}
423 {Fq::toaltstack()}
424 if msm_chunk_index > 0 {
425 {hint_in.to_hash().as_hint_type().push()}
426 {Fq::toaltstack()}
427 }
428
429 {Fr::push(ark_bn254::Fr::from(scalar))}
430 {Fr::toaltstack()}
431 };
432
433 let mut op_hints = vec![];
434 if msm_chunk_index > 0 {
435 op_hints.extend_from_slice(&hint_in.to_witness(ElementType::G1));
436 }
437
438 let hash_script = script! {
439 if msm_chunk_index == 0 {
440 //M: [G1AccDash]
441 //A: [G1AccDashHash]
442 {hash_messages(vec![ElementType::G1])}
443 } else {
444 // [G1Acc, G1AccDash] [G1AccDashHash, G1AccHash]
445 {hash_messages(vec![ElementType::G1, ElementType::G1])}
446 }
447 OP_TRUE
448 };
449 let script = script! {
450 for h in &hints_msm[msm_chunk_index].3 {
451 {h.push()}
452 }
453 for i in op_hints {
454 {i.push()}
455 }
456 {bitcom_scr}
457 {hints_msm[msm_chunk_index].2.clone()}
458 {hash_script}
459 };

Callers

nothing calls this directly

Calls 5

chunk_msmFunction · 0.85
execute_scriptFunction · 0.85
cloneMethod · 0.80
lenMethod · 0.80
to_witnessMethod · 0.80

Tested by

no test coverage detected