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

Function test_tap_hash_var_p

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

Source from the content-addressed store, hash-verified

339
340 #[test]
341 fn test_tap_hash_var_p() {
342 let mut prng = ChaCha20Rng::seed_from_u64(1);
343 let q = ark_bn254::G1Affine::rand(&mut prng);
344 let t = ark_bn254::G1Affine::rand(&mut prng);
345 let r = (t + q).into_affine();
346
347 for should_corrupt_output_hash in [true, false] {
348 let (hint_out, input_is_valid, op_scr, mut hint_script) = chunk_hash_p(t, q);
349 assert!(input_is_valid);
350 assert_eq!(r, hint_out);
351 let t = DataType::G1Data(t);
352 let hint_out = DataType::G1Data(hint_out);
353 hint_script.extend_from_slice(&t.to_witness(ElementType::G1));
354
355 let mut output_hash = hint_out.to_hash();
356
357 if should_corrupt_output_hash {
358 if let CompressedStateObject::Hash(r) = output_hash {
359 let random_hash = extern_hash_nibbles(vec![r, r]);
360 output_hash = CompressedStateObject::Hash(random_hash);
361 }
362 }
363
364 let bitcom_scr = script! {
365 {output_hash.as_hint_type().push()}
366 {Fq::toaltstack()}
367 {t.to_hash().as_hint_type().push()}
368 {Fq::toaltstack()}
369 };
370 let hash_script = script! {
371 {hash_messages(vec![ElementType::G1, ElementType::G1])}
372 OP_TRUE
373 };
374
375 let tap_len = op_scr.len();
376 let script = script! {
377 for h in hint_script {
378 { h.push() }
379 }
380 {bitcom_scr}
381 {op_scr}
382 {hash_script}
383 };
384
385 let res = execute_script(script);
386 if res.final_stack.len() > 1 {
387 for i in 0..res.final_stack.len() {
388 println!("{i:} {:?}", res.final_stack.get(i));
389 }
390 }
391 assert_eq!(res.success, should_corrupt_output_hash);
392 assert!(res.final_stack.len() == 1);
393
394 println!(
395 "chunk_hash_p disprovable({}) script {} stack {}",
396 should_corrupt_output_hash, tap_len, res.stats.max_nb_stack_items
397 );
398 }

Callers

nothing calls this directly

Calls 6

chunk_hash_pFunction · 0.85
extern_hash_nibblesFunction · 0.85
execute_scriptFunction · 0.85
to_witnessMethod · 0.80
to_hashMethod · 0.80
lenMethod · 0.80

Tested by

no test coverage detected