Skip to content

unexpected behaviour of get_representative_least_absolute_residue() #68

Closed

Description

@jvdheyden

Describe the bug

According to the documentation, get_representative_least_absolute_residue should do the following:

Returns the Z value of the Zq element with the representatives close to 0.

The output value is in the range of [-modulus/2, modulus/2]. For even moduli, the positive representative is chosen for the element modulus / 2. Use Zq::get_representative_least_nonnegative_residue if they should be in the range [0, modulus).

So for a value >= modulus / 2 it should output value - modulus. In reality it outputs modulus - value.

To Reproduce

use qfall_math::{integer::Z, integer_mod_q::Zq};

let x = Zq::from((256, 257));
let actual = x.get_representative_least_absolute_residue();

// 256 ≡ -1 (mod 257).
assert_eq!(actual, Z::from(-1));

Expected behavior

actual should be -1.

  • Version of qFALL-tools: 0.11

Additional context

Solution

Activity

  1. self-assigned this
    on Oct 20, 2026
  2. added theissue type on Oct 20, 2026
  3. jnsiemer commented on Oct 20, 2026

    @jnsiemer
    Member

    Dear Jonas,

    Thanks for making us aware of this issue.

    Fortunately, I encountered this issue myself whilst implementing qfall/schemes#10 (ML-DSA / Dilithium) and fixed it in qfall/math#531 (as it was an issue of qfall-math).

    I took this issue as reason to specify the doc-comments further and include additional tests for this edge case in qfall/math#538.

    The new release of qfall-math and qfall-tools (and qfall-schemes) in version 0.2 resolves the described issue.
    Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug🐛Something isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions