doesn't crash even if the proof may be incorrect should be used only for test purposes, as in production, its best to throw error if assertion is invalid <- always assuming honest operator
(
proof: ark_groth16::Proof<Bn<ark_bn254::Config>>,
scalars: Vec<ark_bn254::Fr>,
vk: &ark_groth16::VerifyingKey<Bn254>,
secrets: Vec<String>,
)
| 298 | // as in production, its best to throw error |
| 299 | // if assertion is invalid <- always assuming honest operator |
| 300 | pub fn generate_signatures_for_any_proof( |
| 301 | proof: ark_groth16::Proof<Bn<ark_bn254::Config>>, |
| 302 | scalars: Vec<ark_bn254::Fr>, |
| 303 | vk: &ark_groth16::VerifyingKey<Bn254>, |
| 304 | secrets: Vec<String>, |
| 305 | ) -> Signatures { |
| 306 | println!("generate_signatures; get_segments_from_groth16_proof"); |
| 307 | let (success, mut segments) = get_segments_from_groth16_proof(proof, scalars, vk); |
| 308 | if segments.len() != NUM_PUBS + NUM_U256 + NUM_HASH + VALIDATING_TAPS { |
| 309 | let mock_segments = generate_segments_using_mock_vk_and_mock_proof(); |
| 310 | segments.extend_from_slice(&mock_segments[segments.len()..]); |
| 311 | } |
| 312 | |
| 313 | println!( |
| 314 | "generate_signatures; get_segments_from_groth16_proof {}", |
| 315 | success |
| 316 | ); |
| 317 | println!("generate_signatures; segments len{}", segments.len()); |
| 318 | println!("generate_signatures; get_assertion_from_segments"); |
| 319 | let assn = get_assertion_from_segments(&segments); |
| 320 | println!("generate_signatures; get_signature_from_assertion"); |
| 321 | let sigs = get_signature_from_assertion(assn, secrets.clone()); |
| 322 | println!("generate_signatures; get_pubkeys"); |
| 323 | let pubkeys = get_pubkeys(secrets); |
| 324 | |
| 325 | println!("generate_signatures; partial_scripts_from_segments"); |
| 326 | let partial_scripts: Vec<ScriptBuf> = partial_scripts_from_segments(&segments) |
| 327 | .into_iter() |
| 328 | .collect(); |
| 329 | let partial_scripts: [ScriptBuf; NUM_TAPS] = partial_scripts.try_into().unwrap(); |
| 330 | println!("generate_signatures; append_bitcom_locking_script_to_partial_scripts"); |
| 331 | let disprove_scripts = |
| 332 | append_bitcom_locking_script_to_partial_scripts(pubkeys, partial_scripts.to_vec()); |
| 333 | let disprove_scripts: [ScriptBuf; NUM_TAPS] = disprove_scripts.try_into().unwrap(); |
| 334 | |
| 335 | println!("generate_signatures; execute_script_from_signature"); |
| 336 | let exec_res = execute_script_from_signature(&segments, sigs.clone(), &disprove_scripts); |
| 337 | if exec_res.is_some() { |
| 338 | let fault = exec_res.unwrap(); |
| 339 | println!( |
| 340 | "execute_script_from_assertion return fault at script index {}", |
| 341 | fault.0 |
| 342 | ); |
| 343 | } else { |
| 344 | println!("generate_signatures; validated signatures by executing all scripts"); |
| 345 | } |
| 346 | sigs |
| 347 | } |
| 348 | |
| 349 | #[cfg(test)] |
| 350 | mod test { |
no test coverage detected