| 37 | // mirror of the function get_segments_from_assertion() |
| 38 | #[allow(clippy::needless_range_loop)] |
| 39 | pub(crate) fn get_assertion_from_segments(segments: &[Segment]) -> Assertions { |
| 40 | // extract output {hash or field elements} from all but final script (final script doesn't have output) |
| 41 | let mut arr_of_output_state: Vec<CompressedStateObject> = vec![]; |
| 42 | for v in segments { |
| 43 | if v.scr_type.is_final_script() { |
| 44 | continue; |
| 45 | } |
| 46 | let x = v.result.0.to_hash(); |
| 47 | arr_of_output_state.push(x); |
| 48 | } |
| 49 | |
| 50 | // Serialize and Collect: |
| 51 | // Segments that were collected in order [PublicInputSegments, ProofInputSegments, IntermediateHashSegment, FinalScriptSegment] |
| 52 | // are now serialized in the same order and collected as such => [PublicInputAssertion, ProofInputAssertion, IntermediateHashAssertion] |
| 53 | let mut public_input_assertion_data = vec![]; |
| 54 | for i in 0..NUM_PUBS { |
| 55 | let val = &arr_of_output_state[i]; |
| 56 | let val: [u8; 32] = val.serialize_to_byte_array().try_into().unwrap(); |
| 57 | public_input_assertion_data.push(val); |
| 58 | } |
| 59 | let public_input_assertion_data: [[u8; 32]; NUM_PUBS] = |
| 60 | public_input_assertion_data.try_into().unwrap(); |
| 61 | |
| 62 | let len = public_input_assertion_data.len(); |
| 63 | let mut proof_input_assertion_data = vec![]; |
| 64 | for i in 0..NUM_U256 { |
| 65 | let val = &arr_of_output_state[i + len]; |
| 66 | let val: [u8; 32] = val.serialize_to_byte_array().try_into().unwrap(); |
| 67 | proof_input_assertion_data.push(val); |
| 68 | } |
| 69 | let proof_input_assertion_data: [[u8; 32]; NUM_U256] = |
| 70 | proof_input_assertion_data.try_into().unwrap(); |
| 71 | |
| 72 | let len = public_input_assertion_data.len() + proof_input_assertion_data.len(); |
| 73 | let mut intermediate_hash_assertion_data = vec![]; |
| 74 | for i in 0..NUM_HASH { |
| 75 | let val = &arr_of_output_state[i + len]; |
| 76 | let val: [u8; BLAKE3_HASH_LENGTH] = val.serialize_to_byte_array().try_into().unwrap(); |
| 77 | intermediate_hash_assertion_data.push(val); |
| 78 | } |
| 79 | let batch3: [[u8; BLAKE3_HASH_LENGTH]; NUM_HASH] = |
| 80 | intermediate_hash_assertion_data.try_into().unwrap(); |
| 81 | |
| 82 | ( |
| 83 | public_input_assertion_data, |
| 84 | proof_input_assertion_data, |
| 85 | batch3, |
| 86 | ) |
| 87 | } |
| 88 | |
| 89 | // deserialize assertions to CompressedState (i.e. concrete types of bigint and hasbytes) and get proof |
| 90 | fn utils_deserialize_assertions( |