wrong sign handling when x == 0 produces non-canonical / out-of-range x = p
The Ed25519 decompression code unconditionally flips the x-coordinate when the sign bit is set, so if x is zero it becomes p, which is out of range and non-canonical. An attacker could supply a malformed compressed point that is accepted as valid, causing malleability or breaking equality checks.
Source: https://github.com/sherlock-audit/2025-08-pico-judging/issues/78
Found by
0xpetern
Summary
During Ed25519 decompression, the implementation flips the recovered x-coordinate with:
if sign { x = modulus - x; }
If x == 0 and the compressed sign bit is 1, this sets x = p (not reduced), violating both (a) the canonical field range 0 ≤ x < p and (b) the Ed25519 spec rule that the sign bit MUST be 0 when x = 0. The routine may therefore accept non-canonical encodings and yield an out-of-range coordinate. Beyond the x==0 case, the unconditional flip can also select the wrong square root when the returned root already matches the requested parity.
Root Cause
The code unconditionally applies x ← p − x when sign == 1, without guarding x == 0 or enforcing canonical reduction. This can set x = p (out of range) and accepts an encoding that the spec forbids.
https://github.com/sherlock-audit/2025-08-pico/blob/main/pico/vm/src/chips/gadgets/curves/edwards/ed25519.rs#L124 https://github.com/sherlock-audit/2025-08-pico/blob/main/pico/vm/src/chips/gadgets/curves/edwards/ed25519.rs#L144
In Ed25519 compression, you store: y as 255 little-endian bits, and the top bit of the last byte as the sign of x (specifically, the LSB parity of x). When x == 0, the sign bit MUST be 0. (RFC 8032 / edwards25519 rule)
If x == 0 and sign == 1, this sets x = modulus (since it’s not reduced), which is out of range (x must be < p) and violates the spec that the sign bit must be 0 for x=0.
Even beyond x == 0: the flip rule itself is off
There are two square roots: 𝑥 and −x.
The spec requires you to choose the one whose parity (LSB in little-endian) matches the sign bit.
The code flips unconditionally when sign==1. That’s only correct if your sqrt routine always returns the root with parity 0. If the routine already returned a root with parity matching the sign, flipping will pick the wrong root.
Internal Pre-conditions
-
Decompression computed a root x with x == 0 (this happens for valid points like the identity (x=0, y=1) or other cases where the sqrt ratio yields zero).
-
Code performs if sign { x = modulus - x; } without a guard for x == 0 and without a % p canonical reduction.
External Pre-conditions
-
An attacker (or malformed input) supplies a compressed point with sign bit = 1 that decompresses to x == 0 (e.g., identity encoded with sign=1, or another input yielding x=0).
-
Downstream code accepts the decompressed point as valid (i.e., there’s no independent canonicality check that rejects x=p or x==0 && sign==1).
Attack Path
-
Adversary crafts compressed bytes with sign=1 that lead the decompressor to compute x = 0.
-
The routine executes x ← p − x ⇒ x = p (out of range).
-
The decompressor returns this point as valid:
Canonicality breach / malleability: multiple encodings represent the same point. Range breach: x is not < p. If later code assumes canonical limbs or compares serialized encodings, behavior diverges (logic bugs, equality bypass).
- If other modules treat the returned x as canonical or rely on byte-level equality (rather than mod-p equivalence), this can cause constraint gaps or protocol malleability.
Impact
- Enables malleability and can break equality checks or downstream constraints that assume x < p.
PoC
No response
Mitigation
Enforce the x == 0 rule:
If x.is_zero() and sign == 1 ⇒ reject (return error/None).
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/brevis-network/pico/pull/61
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The code unconditionally applies x ← p − x when sign == 1, without guarding x == 0 or enforcing canonical reduction.
Impact
Enables malleability and can break equality checks or downstream constraints that assume x < p.
What the attacker needed
Attacker supplies malformed compressed point; downstream code accepts decompressed point as valid
The fix
The protocol team fixed this issue in a pull request.
How it was found
- Adversary crafts compressed bytes with sign=1 that lead the decompressor to compute x = 0.
- The routine executes x ← p − x ⇒ x = p (out of range).
- The decompressor returns this point as valid.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Ed25519 is a digital signature system. When it stores a point, it saves the y-coordinate and one bit that says which of two possible x-coordinates to use. The code here flips x whenever that bit is 1, but if x is zero, flipping gives a number that is too large and not allowed. This means a crafted input can be accepted even though it breaks the rules.
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.