(mode: &str)
| 32 | |
| 33 | const ACCOUNT_RENT_EXEMPTION: u64 = 1000000000000u64; |
| 34 | pub fn get_ref_value(mode: &str) -> Vec<u8> { |
| 35 | let bytes; |
| 36 | let ix_data = read_test_data(String::from("deposit.txt")); |
| 37 | let public_inputs_bytes = ix_data[9..233].to_vec(); // 224 length |
| 38 | let pvk_unprepped = get_vk_from_file().unwrap(); |
| 39 | let pvk = prepare_verifying_key(&pvk_unprepped); |
| 40 | let public_inputs = get_public_inputs_from_bytes(&public_inputs_bytes).unwrap(); |
| 41 | let prepared_inputs = prepare_inputs(&pvk, &public_inputs).unwrap(); |
| 42 | if mode == "prepared_inputs" { |
| 43 | // We must convert to affine here since the program converts projective into affine already as the last step of prepare_inputs. |
| 44 | // While the native library implementation does the conversion only when the millerloop is called. |
| 45 | // The reason we're doing it as part of prepare_inputs is that it takes >1 ix to compute the conversion. |
| 46 | let as_affine = (prepared_inputs).into_affine(); |
| 47 | let mut affine_bytes = vec![0; 64]; |
| 48 | parse_x_group_affine_to_bytes(as_affine, &mut affine_bytes); |
| 49 | bytes = affine_bytes; |
| 50 | } else { |
| 51 | let proof_bytes = ix_data[233..489].to_vec(); // 256 length |
| 52 | let proof = get_proof_from_bytes(&proof_bytes); |
| 53 | let miller_output = |
| 54 | <ark_ec::models::bn::Bn<ark_bn254::Parameters> as ark_ec::PairingEngine>::miller_loop( |
| 55 | [ |
| 56 | (proof.a.into(), proof.b.into()), |
| 57 | ( |
| 58 | (prepared_inputs).into_affine().into(), |
| 59 | pvk.gamma_g2_neg_pc.clone(), |
| 60 | ), |
| 61 | (proof.c.into(), pvk.delta_g2_neg_pc.clone()), |
| 62 | ] |
| 63 | .iter(), |
| 64 | ); |
| 65 | if mode == "miller_output" { |
| 66 | let mut miller_output_bytes = vec![0; 384]; |
| 67 | parse_f_to_bytes(miller_output, &mut miller_output_bytes); |
| 68 | bytes = miller_output_bytes; |
| 69 | } else if mode == "final_exponentiation" { |
| 70 | let res = <ark_ec::models::bn::Bn::<ark_bn254::Parameters> as ark_ec::PairingEngine>::final_exponentiation(&miller_output).unwrap(); |
| 71 | let mut res_bytes = vec![0; 384]; |
| 72 | parse_f_to_bytes(res, &mut res_bytes); |
| 73 | bytes = res_bytes; |
| 74 | } else { |
| 75 | bytes = vec![]; |
| 76 | } |
| 77 | } |
| 78 | bytes |
| 79 | } |
| 80 | |
| 81 | pub fn get_proof_from_bytes( |
| 82 | proof_bytes: &Vec<u8>, |
no test coverage detected