| 53 | } |
| 54 | |
| 55 | fn execute(&self, op: &Self::Op, input: &[G], record: &mut QueryRecord) -> Vec<G> { |
| 56 | match op { |
| 57 | Blake3Op::GFunction => { |
| 58 | if let Some(result) = record.blake3_g_function.get_mut(input) { |
| 59 | result.multiplicity += G::ONE; |
| 60 | return result.output.to_vec(); |
| 61 | } |
| 62 | |
| 63 | let u8_bits = |x, record: &mut QueryRecord| -> [G; 8] { |
| 64 | Bytes1 |
| 65 | .execute(&Bytes1Op::BitDecomposition, &[x], record) |
| 66 | .try_into() |
| 67 | .expect("Wrong output size") |
| 68 | }; |
| 69 | let u8_add = |a, b, record: &mut QueryRecord| -> [G; 2] { |
| 70 | Bytes2 |
| 71 | .execute(&Bytes2Op::Add, &[a, b], record) |
| 72 | .try_into() |
| 73 | .expect("Wrong output size") |
| 74 | }; |
| 75 | let u8_xor = |a, b, record: &mut QueryRecord| { |
| 76 | Bytes2 |
| 77 | .execute(&Bytes2Op::Xor, &[a, b], record) |
| 78 | .pop() |
| 79 | .expect("Missing output") |
| 80 | }; |
| 81 | let u32_add = |a: [G; 4], b: [G; 4], record: &mut QueryRecord| { |
| 82 | let [a0, a1, a2, a3] = a; |
| 83 | let [b0, b1, b2, b3] = b; |
| 84 | |
| 85 | // Byte 0 addition (no initial carry) |
| 86 | let [sum0, carry1] = u8_add(a0, b0, record); |
| 87 | |
| 88 | // Byte 1 addition |
| 89 | let [sum1, overflow1] = u8_add(a1, b1, record); |
| 90 | let [sum1_with_carry, carry1a] = u8_add(sum1, carry1, record); |
| 91 | let carry2 = u8_xor(overflow1, carry1a, record); |
| 92 | |
| 93 | // Byte 2 addition |
| 94 | let [sum2, overflow2] = u8_add(a2, b2, record); |
| 95 | let [sum2_with_carry, carry2a] = u8_add(sum2, carry2, record); |
| 96 | let carry3 = u8_xor(overflow2, carry2a, record); |
| 97 | |
| 98 | // Byte 3 addition |
| 99 | let [sum3, _] = u8_add(a3, b3, record); |
| 100 | let [sum3_with_carry, _] = u8_add(sum3, carry3, record); |
| 101 | |
| 102 | [sum0, sum1_with_carry, sum2_with_carry, sum3_with_carry] |
| 103 | }; |
| 104 | let u32_xor = |a: [G; 4], b: [G; 4], record: &mut QueryRecord| { |
| 105 | let [a0, a1, a2, a3] = a; |
| 106 | let [b0, b1, b2, b3] = b; |
| 107 | let c0 = u8_xor(a0, b0, record); |
| 108 | let c1 = u8_xor(a1, b1, record); |
| 109 | let c2 = u8_xor(a2, b2, record); |
| 110 | let c3 = u8_xor(a3, b3, record); |
| 111 | [c0, c1, c2, c3] |
| 112 | }; |