Non-unified Curve Addition May Leak Information about Addends
Description
The ch-add gate defined in the affine arm branches on whether the provided points are equal up to negation or one of the points is the identity. Depending on these conditions, the gate will either add the points using the usual addition formula, double a point using a doubling formula, or return the identity point. This logic also exists in ch-add in the projective and jacobian arms, and ch-double in the affine, projective, and jacobian arms.
Impact
If addition, doubling, and returning the identity take a different number of cycles in the zkVM, then the length of the trace resulting from a ch-add call may leak information about which branch was taken, and thus leak information about the addends. If these addends are secret, then this can lead to vulnerabilities.
We note that this, as well as every other constant-time-related finding in this document, is a non-issue if none of the inputs are secret. Since it appears these functions may only used for Schnorr verification of public values in practice, this may indeed be the case.
Recommendation
If indeed these functions operate over secret values, mitigations must be taken. We provide options for mitigations, with tradeoffs:
- Perform both addition and doubling, and perform a constant-time selection operation to pick the correct result (between the sum, doubling, and identity). As a point of reference, this is performed in the
arkworksZK framework using theCondSelectGadgettrait. The caveat to this solution is that the newch-addcycle count is the sum of the cycle counts of the addition and doubling formulas. - Pad the cycle count to a fixed number, regardless of the branch taken. So long as all cycles appear the same to a verifier, the prover can simply pad out each branch with the correct number of no-op cycles to make the total cycle count invariant under different inputs. The caveat to this method is that this adds a constant that depends on the specific zkVM implementation, and must be kept up to date with the implementation, else a severe privacy lapse can occur.
- Use a different curve over the same base field. The ecGFp5 curve was designed for the same setting as Cheetah, and comes with complete formulas. The downside to this recommendation is that it requires an entirely new curve implementation.
We note that it is not obvious whether unified (i.e., handling addition when ) formulas for Cheetah exist, let alone complete (handling and ) ones. We note that the Cheetah Rust implementation claims to use complete formulas, but in fact does not. The formulas they use, from RCB15, do not produce the correct result when is a point of exact order 2.