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

Function test_wots_hash_sig_to_byte_array

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

Source from the content-addressed store, hash-verified

105
106 #[test]
107 fn test_wots_hash_sig_to_byte_array() {
108 // wots sig to limbs
109 let mut prng = ChaCha20Rng::seed_from_u64(97);
110 let a = ark_bn254::Fq6::rand(&mut prng);
111 let a = extern_hash_fps(
112 a.to_base_prime_field_elements()
113 .collect::<Vec<ark_bn254::Fq>>(),
114 );
115 let a = CompressedStateObject::Hash(a);
116 let a_bytes: [u8; 16] = a
117 .clone()
118 .serialize_to_byte_array()
119 .try_into()
120 .expect("should be 16 bytes");
121
122 let secret =
123 Vec::from_hex("a138982ce17ac813d505a5b40b665d404e9528e7").expect("should be valid hex");
124
125 let signature = Wots16::sign(&secret, &a_bytes);
126 let msg_bytes = Wots16::signature_to_message(&signature);
127 assert_eq!(msg_bytes, a_bytes);
128 let msg = CompressedStateObject::deserialize_from_byte_array(msg_bytes.to_vec());
129 assert_eq!(a, msg);
130
131 let compact_signature_witness = Wots16::compact_sign_to_raw_witness(&secret, &a_bytes);
132 let pub_key = WOTSPubKey::PHash(Wots16::generate_public_key(&secret));
133 let scr = script! {
134 {compact_signature_witness}
135 {checksig_verify_to_limbs(&pub_key)}
136 {a.as_hint_type().push()}
137 {Fq::equalverify(1, 0)}
138 OP_TRUE
139 };
140 let tap_len = scr.len();
141 let res = execute_script(scr);
142 assert!(res.success && res.final_stack.len() == 1);
143 println!("script {} stack {}", tap_len, res.stats.max_nb_stack_items);
144 }
145
146 #[test]
147 fn test_witness_signature_conversions() {

Callers

nothing calls this directly

Calls 6

extern_hash_fpsFunction · 0.85
generate_public_keyFunction · 0.85
execute_scriptFunction · 0.85
cloneMethod · 0.80
lenMethod · 0.80

Tested by

no test coverage detected