precompute P
(
hint_in_p: ark_bn254::G1Affine,
)
| 115 | |
| 116 | // precompute P |
| 117 | pub(crate) fn chunk_precompute_p_from_hash( |
| 118 | hint_in_p: ark_bn254::G1Affine, |
| 119 | ) -> (ark_bn254::G1Affine, bool, Script, Vec<Hint>) { |
| 120 | let mut hints = vec![]; |
| 121 | |
| 122 | let mut px: ark_bn254::Fq = ark_bn254::Fq::ONE; |
| 123 | let mut py: ark_bn254::Fq = ark_bn254::Fq::ONE; |
| 124 | |
| 125 | let py_is_not_zero = hint_in_p.y != ark_bn254::Fq::ZERO; |
| 126 | if py_is_not_zero { |
| 127 | px = hint_in_p.x; |
| 128 | py = hint_in_p.y; |
| 129 | } |
| 130 | |
| 131 | let (on_curve_scr, on_curve_hint) = G1Affine::hinted_is_on_curve(px, py); |
| 132 | if py_is_not_zero { |
| 133 | hints.extend_from_slice(&on_curve_hint); |
| 134 | } |
| 135 | |
| 136 | let p = ark_bn254::G1Affine::new_unchecked(px, py); |
| 137 | let (eval_xy, eval_hints) = hinted_from_eval_points(p); |
| 138 | |
| 139 | let valid_point = py_is_not_zero && p.is_on_curve(); |
| 140 | let mock_pd = ark_bn254::G1Affine::new_unchecked(ark_bn254::Fq::ONE, ark_bn254::Fq::ONE); |
| 141 | |
| 142 | let pd = if valid_point { |
| 143 | hints.extend_from_slice(&eval_hints); |
| 144 | |
| 145 | let pdy = p.y.inverse().unwrap(); |
| 146 | let pdx = -p.x * pdy; |
| 147 | |
| 148 | ark_bn254::G1Affine::new_unchecked(pdx, pdy) |
| 149 | } else { |
| 150 | mock_pd |
| 151 | }; |
| 152 | |
| 153 | let drop_and_return_scr = script! { |
| 154 | // [px, py] [pdhash, phash] |
| 155 | {G1Affine::push(mock_pd)} // mock values for pd,these values won't be useful as we add {0} <- skip output hash check for invalid input |
| 156 | // [p, pd] [pdhash, phash] |
| 157 | {0} // skip output hash check because input was invalid |
| 158 | }; |
| 159 | let scr = script! { |
| 160 | // [hints, px, py] [pdhash, phash] |
| 161 | |
| 162 | // Validity checks |
| 163 | { Fq::check_validity() } |
| 164 | { Fq::check_validity() } |
| 165 | { Fq::fromaltstack() } { Fq::fromaltstack() } |
| 166 | |
| 167 | // [hints, px, py] [pdhash, phash] |
| 168 | |
| 169 | {Fq::is_zero_keep_element(0)} |
| 170 | OP_IF // PY = 0 |
| 171 | {drop_and_return_scr.clone()} |
| 172 | OP_ELSE // PY != 0 |
| 173 | // [hints, px, py] |
| 174 | {Fq2::copy(0)} |