Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
point check\ g1/g2 push and read from stack
  • Loading branch information
Ubuntu
Ubuntu committed Sep 22, 2025
commit 38b81c3f13e7cb10487bd98c13b64d9376bf2c70
15 changes: 13 additions & 2 deletions bitvm/src/bn254/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,16 @@ impl G1Affine {
}
}

pub fn check(element: &ark_bn254::G1Affine) {
assert!(
(element.is_on_curve() && element.is_in_correct_subgroup_assuming_on_curve())
|| (element.x == ark_bn254::Fq::ZERO && element.y == ark_bn254::Fq::ZERO)
|| (element.x == ark_bn254::Fq::ONE && element.y == ark_bn254::Fq::ONE)
)
}

pub fn push(element: ark_bn254::G1Affine) -> Script {
Self::check(&element);
script! {
{ Fq::push_u32_le(&BigUint::from(element.x).to_u32_digits()) }
{ Fq::push_u32_le(&BigUint::from(element.y).to_u32_digits()) }
Expand All @@ -150,11 +159,13 @@ impl G1Affine {
assert_eq!(witness.len() as u32, Fq::N_LIMBS * 2);
let x = Fq::read_u32_le(witness[0..Fq::N_LIMBS as usize].to_vec());
let y = Fq::read_u32_le(witness[Fq::N_LIMBS as usize..2 * Fq::N_LIMBS as usize].to_vec());
ark_bn254::G1Affine {
let element = ark_bn254::G1Affine {
x: BigUint::from_slice(&x).into(),
y: BigUint::from_slice(&y).into(),
infinity: false,
}
};
Self::check(&element);
element
}

pub fn hinted_check_add(t: ark_bn254::G1Affine, q: ark_bn254::G1Affine) -> (Script, Vec<Hint>) {
Expand Down
15 changes: 13 additions & 2 deletions bitvm/src/bn254/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,16 @@ impl G2Affine {
(scr, hints)
}

pub fn check(element: &ark_bn254::G2Affine) {
assert!(
(element.is_on_curve() && element.is_in_correct_subgroup_assuming_on_curve())
|| (element.x == ark_bn254::Fq2::ZERO && element.y == ark_bn254::Fq2::ZERO)
|| (element.x == ark_bn254::Fq2::ONE && element.y == ark_bn254::Fq2::ONE)
)
}

pub fn push(element: ark_bn254::G2Affine) -> Script {
Self::check(&element);
script! {
{ Fq2::push(element.x) }
{ Fq2::push(element.y) }
Expand All @@ -122,11 +131,13 @@ impl G2Affine {
let y = Fq2::read_from_stack(
witness[2 * Fq::N_LIMBS as usize..4 * Fq::N_LIMBS as usize].to_vec(),
);
ark_bn254::G2Affine {
let element = ark_bn254::G2Affine {
x,
y,
infinity: false,
}
};
Self::check(&element);
element
}
}

Expand Down
5 changes: 3 additions & 2 deletions bitvm/src/chunk/taps_point_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ pub(crate) fn chunk_init_t4(ts: [ark_ff::BigInt<4>; 4]) -> (ElemG2Eval, bool, Sc
ark_bn254::Fq2::new(ts[0].into(), ts[1].into()),
ark_bn254::Fq2::new(ts[2].into(), ts[3].into()),
);
G2Affine::check(&t4.t);
}

let (on_curve_scr, on_curve_hints) = G2Affine::hinted_is_on_curve(t4.t.x, t4.t.y);
Expand Down Expand Up @@ -1110,9 +1111,9 @@ mod test {
ark_ff::BigInt::<4>::one() << 255,
];
let q4 = [
ark_ff::BigInt::<4>::one(),
ark_ff::BigInt::<4>::one(),
ark_ff::BigInt::<4>::zero(),
ark_ff::BigInt::<4>::one(),
ark_ff::BigInt::<4>::zero(),
];

Expand Down Expand Up @@ -1286,7 +1287,7 @@ mod test {

let t3 = t4; // ark_bn254::G2Affine::rand(&mut prng);
let q3 = q4; //ark_bn254::G2Affine::rand(&mut prng);
let p3 = ark_bn254::G1Affine::new_unchecked(-p4.x, -p4.y); //ark_bn254::G1Affine::rand(&mut prng);
let p3 = ark_bn254::G1Affine::new_unchecked(p4.x, -p4.y); //ark_bn254::G1Affine::rand(&mut prng);

let t2 = ark_bn254::G2Affine::rand(&mut prng);
let q2 = ark_bn254::G2Affine::rand(&mut prng);
Expand Down