MCPcopy Create free account
hub / github.com/BitVM/BitVM / chunk_precompute_p

Function chunk_precompute_p

bitvm/src/chunk/taps_ext_miller.rs:18–114  ·  view source on GitHub ↗
(
    hint_in_py: ark_ff::BigInt<4>,
    hint_in_px: ark_ff::BigInt<4>,
)

Source from the content-addressed store, hash-verified

16use super::wrap_hasher::hash_utils::{hash_fp6, hash_g2acc_with_hashed_le};
17
18pub(crate) fn chunk_precompute_p(
19 hint_in_py: ark_ff::BigInt<4>,
20 hint_in_px: ark_ff::BigInt<4>,
21) -> (ark_bn254::G1Affine, bool, Script, Vec<Hint>) {
22 let mut hints = vec![];
23
24 // is py and px less than f_p i.e. are they field elements
25 let mut px: ark_bn254::Fq = ark_bn254::Fq::ONE;
26 let mut py: ark_bn254::Fq = ark_bn254::Fq::ONE;
27
28 let are_valid_field_elems = hint_in_py < ark_bn254::Fq::MODULUS
29 && hint_in_px < ark_bn254::Fq::MODULUS
30 && hint_in_py != ark_ff::BigInt::<4>::zero();
31 if are_valid_field_elems {
32 px = hint_in_px.into();
33 py = hint_in_py.into();
34 }
35
36 let (on_curve_scr, on_curve_hint) = G1Affine::hinted_is_on_curve(px, py);
37 if are_valid_field_elems {
38 hints.extend_from_slice(&on_curve_hint);
39 }
40
41 let p = ark_bn254::G1Affine::new_unchecked(px, py);
42 let (eval_xy, eval_hints) = hinted_from_eval_points(p);
43
44 let valid_point = are_valid_field_elems && py != ark_bn254::Fq::ZERO && p.is_on_curve();
45 let mock_pd = ark_bn254::G1Affine::new_unchecked(ark_bn254::Fq::ONE, ark_bn254::Fq::ONE);
46
47 let pd = if valid_point {
48 hints.extend_from_slice(&eval_hints);
49
50 let pdy = py.inverse().unwrap();
51 let pdx = -px * pdy;
52
53 ark_bn254::G1Affine::new_unchecked(pdx, pdy)
54 } else {
55 mock_pd
56 };
57
58 let drop_and_return_scr = script! {
59 // [px, py] [pdhash]
60 {G1Affine::drop()}
61 // [] [pdhash]
62 {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
63 // [pd] [pdhash]
64 {0} // skip output hash check because input was invalid
65 };
66 let scr = script! {
67 // [hints] [pdhash, py, px]
68 {Fq2::fromaltstack()}
69
70 // [hints, px, py] [pdhash]
71 // {is_field_element}
72 // [hints, px, py, px, py]
73 {Fq2::copy(0)}
74
75 { Fq::is_valid() }

Callers 2

wrap_hints_precompute_pFunction · 0.85
test_tap_precompute_pFunction · 0.85

Calls 2

hinted_from_eval_pointsFunction · 0.85
intoMethod · 0.45

Tested by 1

test_tap_precompute_pFunction · 0.68