Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions g16ckt/src/gadgets/bn254/fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ impl WiresObject for Fq {

impl FromWires for Fq {
fn from_wires(wires: &[WireId]) -> Option<Self> {
Some(Self(crate::gadgets::bigint::BigIntWires::from_bits(
wires.iter().copied(),
)))
if wires.len() == Fq::N_BITS {
Some(Self(crate::gadgets::bigint::BigIntWires::from_bits(
wires.iter().copied(),
)))
} else {
None
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion g16ckt/src/gadgets/bn254/fq12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl WiresObject for Fq12 {

impl FromWires for Fq12 {
fn from_wires(wires: &[WireId]) -> Option<Self> {
if wires.len() >= 1524 {
if wires.len() == Fq12::N_BITS {
// 2 * 3 * 2 * 254 = 3048/2 = 1524 wires per Fq6
let mid = wires.len() / 2;
let fq6_1 = Fq6::from_wires(&wires[..mid])?;
Expand Down
4 changes: 2 additions & 2 deletions g16ckt/src/gadgets/bn254/fq2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ impl WiresObject for Fq2 {

impl crate::circuit::FromWires for Fq2 {
fn from_wires(wires: &[WireId]) -> Option<Self> {
if wires.len() >= 508 {
if wires.len() == Fq2::N_BITS {
// 2 * 254 bits
let (fq1_wires, fq2_wires) = wires.split_at(254);
let (fq1_wires, fq2_wires) = wires.split_at(wires.len() / 2);
let fq1 = Fq::from_wires(fq1_wires)?;
let fq2 = Fq::from_wires(fq2_wires)?;
Some(Self([fq1, fq2]))
Expand Down
18 changes: 11 additions & 7 deletions g16ckt/src/gadgets/bn254/fq6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ impl WiresObject for Fq6 {

impl FromWires for Fq6 {
fn from_wires(wires: &[WireId]) -> Option<Self> {
let len = wires.len() / 3;
let mut chunks = wires.chunks(len);
Some(Self([
Fq2::from_wires(chunks.next()?)?,
Fq2::from_wires(chunks.next()?)?,
Fq2::from_wires(chunks.next()?)?,
]))
if wires.len() == Fq6::N_BITS {
let len = wires.len() / 3;
let mut chunks = wires.chunks(len);
Some(Self([
Fq2::from_wires(chunks.next()?)?,
Fq2::from_wires(chunks.next()?)?,
Fq2::from_wires(chunks.next()?)?,
]))
} else {
None
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions g16ckt/src/gadgets/bn254/fr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ impl WiresObject for Fr {

impl crate::circuit::FromWires for Fr {
fn from_wires(wires: &[WireId]) -> Option<Self> {
Some(Self(crate::gadgets::bigint::BigIntWires::from_bits(
wires.iter().copied(),
)))
if wires.len() == Fr::N_BITS {
Some(Self(crate::gadgets::bigint::BigIntWires::from_bits(
wires.iter().copied(),
)))
} else {
None
}
}
}

Expand Down
18 changes: 11 additions & 7 deletions g16ckt/src/gadgets/bn254/g1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ impl WiresObject for G1Projective {

impl FromWires for G1Projective {
fn from_wires(wires: &[WireId]) -> Option<Self> {
let len = wires.len() / 3;
let mut chunks = wires.chunks(len);
Some(Self {
x: Fq::from_wires(chunks.next()?)?,
y: Fq::from_wires(chunks.next()?)?,
z: Fq::from_wires(chunks.next()?)?,
})
if wires.len() == G1Projective::N_BITS {
let len = wires.len() / 3;
let mut chunks = wires.chunks(len);
Some(Self {
x: Fq::from_wires(chunks.next()?)?,
y: Fq::from_wires(chunks.next()?)?,
z: Fq::from_wires(chunks.next()?)?,
})
} else {
None
}
}
}

Expand Down
18 changes: 11 additions & 7 deletions g16ckt/src/gadgets/bn254/g2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ impl WiresObject for G2Projective {

impl FromWires for G2Projective {
fn from_wires(wires: &[WireId]) -> Option<Self> {
let len = wires.len() / 3;
let mut chunks = wires.chunks(len);
Some(Self {
x: Fq2::from_wires(chunks.next()?)?,
y: Fq2::from_wires(chunks.next()?)?,
z: Fq2::from_wires(chunks.next()?)?,
})
if wires.len() == G2Projective::N_BITS {
let len = wires.len() / 3;
let mut chunks = wires.chunks(len);
Some(Self {
x: Fq2::from_wires(chunks.next()?)?,
y: Fq2::from_wires(chunks.next()?)?,
z: Fq2::from_wires(chunks.next()?)?,
})
} else {
None
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions g16ckt/src/gadgets/bn254/pairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,13 @@ fn g2_line_coeffs_add<C: CircuitContext>(

impl FromWires for (G2Projective, Fq6) {
fn from_wires(wires: &[crate::WireId]) -> Option<Self> {
let (g2, fq6) = wires.split_at(G2Projective::ARITY);
if wires.len() == G2Projective::N_BITS + Fq6::N_BITS {
let (g2, fq6) = wires.split_at(G2Projective::ARITY);

Some((G2Projective::from_wires(g2)?, Fq6::from_wires(fq6)?))
Some((G2Projective::from_wires(g2)?, Fq6::from_wires(fq6)?))
} else {
None
}
}
}

Expand Down
Loading