Commit 1f62283
CBMC: Document and enforce 4 GiB limit of forall/exists quantifiers
This commit ports pq-code-package/mlkem-native#1694.
The forall/exists macros in cbmc.h declared the quantified variable as
`unsigned`, which on 64-bit platforms is 32 bits wide. When applied to
a size_t bound, this silently truncated the upper bound: the quantifier
only ranged over indices up to UINT32_MAX rather than the full size_t
range, leaving the predicate unchecked for any larger indices.
mldsa-native does accept arbitrarily large buffers at the
top-level API: the message, context, and pre-string passed into
mld_sign / mld_sign_verify / mld_H / mld_shake256_absorb are bounded
only by MLD_MAX_BUFFER_SIZE = SIZE_MAX >> 12 (~2^52 on 64-bit), and
keccak_absorb walks them in a size_t loop. However, those buffers
never feed into a quantified predicate -- they appear only as
arguments to memory_no_alias / memory_slice and as scalar loop invariants.
Hence, the restricted scope of `forall` has no impact on the
CBMC safety guarantees for mldsa-native's top-level API.
The only size_t-bounded quantifier in the entire tree is mld_ct_memcmp
in ct.h, and it already requires len <= UINT16_MAX.
For now, make the limitation explicit rather than widening the quantifier:
- Explicitly cast the lower and upper bounds to `uint32_t`, so
passing a wider bound triggers CBMC's conversion check rather than
silently truncating.
- Declare the quantified variable as `uint32_t` (was `unsigned`)
as a robustness improvement towards the implementation-defined
size of `unsigned`.
Note: the upstream PR also tightened mlk_ct_cmov_zero's precondition
to UINT32_MAX. mldsa-native has no equivalent function, so no
analogous change is needed.
We may still want to consider widening the quantifier variable
as a follow-up, but this is a more intrusive change that prior
experiments have proved to significantly impact proof performance.
Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>1 parent 1b47ba6 commit 1f62283
1 file changed
Lines changed: 28 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
96 | 108 | | |
97 | 109 | | |
98 | 110 | | |
99 | 111 | | |
100 | 112 | | |
101 | 113 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
107 | 119 | | |
108 | 120 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
114 | 126 | | |
115 | 127 | | |
116 | 128 | | |
| |||
128 | 140 | | |
129 | 141 | | |
130 | 142 | | |
131 | | - | |
132 | | - | |
| 143 | + | |
| 144 | + | |
133 | 145 | | |
134 | 146 | | |
135 | 147 | | |
| |||
141 | 153 | | |
142 | 154 | | |
143 | 155 | | |
144 | | - | |
145 | | - | |
| 156 | + | |
| 157 | + | |
146 | 158 | | |
147 | 159 | | |
148 | 160 | | |
| |||
152 | 164 | | |
153 | 165 | | |
154 | 166 | | |
155 | | - | |
156 | | - | |
| 167 | + | |
| 168 | + | |
157 | 169 | | |
158 | 170 | | |
159 | 171 | | |
| |||
0 commit comments