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

Function test_wots256_sig_to_byte_array

bitvm/src/chunk/wrap_wots.rs:70–104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

68
69 #[test]
70 fn test_wots256_sig_to_byte_array() {
71 // wots sig to limbs
72 let mut prng = ChaCha20Rng::seed_from_u64(97);
73 let f = ark_bn254::Fq::rand(&mut prng);
74 let a: ark_ff::BigInt<4> = f.into();
75 let a = CompressedStateObject::U256(a);
76 let a_bytes: [u8; 32] = a
77 .clone()
78 .serialize_to_byte_array()
79 .try_into()
80 .expect("should be 32 bytes");
81
82 let secret =
83 Vec::from_hex("a138982ce17ac813d505a5b40b665d404e9528e7").expect("should be valid hex");
84 let signature = Wots32::sign(&secret, &a_bytes);
85
86 let msg_bytes = Wots32::signature_to_message(&signature);
87 assert_eq!(msg_bytes, a_bytes);
88 let msg = CompressedStateObject::deserialize_from_byte_array(msg_bytes.to_vec());
89 assert_eq!(a, msg);
90
91 let compact_signature_witness = Wots32::compact_sign_to_raw_witness(&secret, &a_bytes);
92 let pub_key = WOTSPubKey::P256(Wots32::generate_public_key(&secret));
93 let scr = script! {
94 {compact_signature_witness}
95 {checksig_verify_to_limbs(&pub_key)}
96 {a.as_hint_type().push()}
97 {Fq::equalverify(1, 0)}
98 OP_TRUE
99 };
100 let tap_len = scr.len();
101 let res = execute_script(scr);
102 assert!(res.success && res.final_stack.len() == 1);
103 println!("script {} stack {}", tap_len, res.stats.max_nb_stack_items);
104 }
105
106 #[test]
107 fn test_wots_hash_sig_to_byte_array() {

Callers

nothing calls this directly

Calls 6

generate_public_keyFunction · 0.85
execute_scriptFunction · 0.85
cloneMethod · 0.80
lenMethod · 0.80
intoMethod · 0.45

Tested by

no test coverage detected