fix: Re-anchor gated-signing counter on uint8 wrap to keep cadence aligned
The gated-signing screen is meant to render every GATED_SIGNING_MAX_COUNT (10) signing operations, gated by a uint8_t counter in N_storage. Because 256 is not a multiple of 10, the natural uint8_t wrap shifts the cadence: a display would land on sign #251, then nothing until sign #257 (gap of 6 instead of 10), then the cycle is permanently out of phase relative to its starting point. Detect the wrap (`counter + 1 == 0` after `uint8_t` promotion) and re-anchor the stored counter to 1, which forces a display on the wrap-spanning signing operation and resumes the every-10th cadence from a known phase. The wrap-adjacent interval is 5 signs instead of 10, accepted as a one-time anomaly; every subsequent cycle is exactly 10. Note: the modulo expression itself (`counter % MAX == 1`) is equivalent to the original `(counter - 1) % MAX == 0` for every uint8_t value, because C integer promotions make `counter - 1` signed (`-1 % 10 == -1`, not 255). The previous form was readable and correct; the fix above addresses the genuine wrap-cadence drift the previous form did not cover. (cherry picked from commit 842d35d00896976263d10e55af20f6649872ea1f)
C
Charles-Edouard de la Vergne committed
4a5417af5d40673c86beea6d98835d76223b8573
Parent: 3b5cf1d
Committed by Alexandre Paillier <alexandre.paillier@ledger.fr>
on 8/25/2026, 3:03:59 PM