Torus-based compression

We implement a torus-based compression method to compress an output of the pairing computation for the BN254 curve (viewed as an element in a degree 12 extension over the base prime field ) to two elements in a degree 2 sub-extension over the same prime field, thus achieving a threefold compression ratio with no information loss. In other words, the decompressed value recovers exactly the pairing value computed without compression.

Recall that the pairing computation follows two steps - the Miller loop and the final exponentiation. The compression method requires only making changes to the final exponentiation step. The compression overhead turns out to be insignificant for applications in Jolt.

Methodology

The pairing output has the form , where is the output from the Miller loop, and is an integer such that the pairing inputs are -torsion points on the BN254 curve defined over some finite extension of - in other words, the power vanishes. We can write

where

is the cyclotomic polynomial and

Let be a sextic non-residue and identify and where and . Through this notation, we emphasise that the sets and form -linear and -linear bases of the fields and viewed as vector spaces, respectively.

It turns out that for each element , the power can be written as

where , , and we can recover from and alone.

Hence we can represent using the pair achieving a compression ratio of three, where the compression takes two steps in which we compress to the field and , respectively.

Compression to

We can compute as

Write , where , we have

where and the second equality follows since the -power map generates the Galois group of the quadratic extension inside , so in particular . Hence

which simplifies to where

Compression to two elements in

We can write , where recall , then we have

so we can drop to only use and to represent .

Compression and decompression

For compressing a pairing value , first compute , then compress to two elements as in the previous section.

For decompression, first compute from two coefficients and in , where as in the previous section. Then, compute
to recover the original pairing value.

Implementation Detail

Basis choice

Different choices of basis vectors for an extension field affect the complexity of field operations within the extension field. In Arkworks, for field arithmetic optimization, the field is represented as an extension , where is an -basis over the sub-extension . (Recall that and , where is a sextic non-residue.)

The -power map no longer maps to , so naively applying the formula in the previous section on the generator will cause problems. Fortunately, we can fix this easily by doing a change of basis before compression and after decompression.

Using the identity , we have

and hence

where , , and all are elements of . To convert between elements in written in -bases and , it suffices to do a multiplication or division by , and we shall see this can be implemented entirely using arithmetics in .

Indeed, write , where , we have

and

The conversion formulae are provided in the following code snippet.


#![allow(unused)]
fn main() {
#[inline]
pub fn fq12_to_compressible_fq12(value: Fq12) -> CompressibleFq12 {
    // Divide by the generator of Fq6
    let new_c1 = Fq6 {
        c0: value.c1.c1,
        c1: value.c1.c2,
        c2: value.c1.c0 * Fq6Config::NONRESIDUE.inverse().unwrap(),
    };

    CompressibleFq12 {
        c0: value.c0,
        c1: new_c1,
    }
}

#[inline]
pub fn compressible_fq12_to_fq12(value: CompressibleFq12) -> Fq12 {
    // Multiply by the generator of Fq6
    let new_c1 = Fq6 {
        c0: value.c1.c2 * Fq6Config::NONRESIDUE,
        c1: value.c1.c0,
        c2: value.c1.c1,
    };

    Fq12 {
        c0: value.c0,
        c1: new_c1,
    }
}
}