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

Function test_emulate_external_hash

bitvm/src/chunk/helpers.rs:204–250  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

202 #[test]
203 #[allow(clippy::needless_range_loop)]
204 fn test_emulate_external_hash() {
205 fn emulate_extern_hash_fps_scripted(msgs: Vec<ark_bn254::Fq>) -> [u8; 64] {
206 assert!(
207 msgs.len() == 4
208 || msgs.len() == 2
209 || msgs.len() == 12
210 || msgs.len() == 14
211 || msgs.len() == 6
212 || msgs.len() == 8
213 );
214
215 let scr = script! {
216 for i in 0..msgs.len() {
217 {Fq::push(msgs[i])}
218 }
219 if msgs.len() == 4 {
220 {hash_fp4()}
221 } else if msgs.len() == 2 {
222 {hash_fp2()}
223 } else if msgs.len() == 6 {
224 {hash_fp6()}
225 } else if msgs.len() == 14 {
226 {hash_fp14()}
227 }
228 {unpack_limbs_to_nibbles()}
229 };
230 let exec_result = execute_script(scr.clone());
231 let mut arr = [0u8; 64];
232 for i in 0..exec_result.final_stack.len() {
233 let v = exec_result.final_stack.get(i);
234 if v.is_empty() {
235 arr[i] = 0;
236 } else {
237 arr[i] = v[0];
238 }
239 }
240 arr
241 }
242
243 let mut prng = ChaCha20Rng::seed_from_u64(0);
244 let _f = ark_bn254::Fq12::rand(&mut prng);
245
246 let ps = vec![ark_bn254::Fq::ONE + ark_bn254::Fq::ONE; 14];
247 let res = emulate_extern_hash_fps_scripted(ps.clone());
248 let res2 = extern_hash_fps(ps);
249 assert_eq!(res, res2);
250 }
251}

Callers

nothing calls this directly

Calls 3

extern_hash_fpsFunction · 0.85
cloneMethod · 0.80

Tested by

no test coverage detected