CBMC: Improve readability of CBMC specs#1116
Draft
hanno-becker wants to merge 1 commit into
Draft
Conversation
4bda840 to
f52b137
Compare
Contributor
CBMC Results (ML-DSA-87, REDUCE-RAM)Full Results (195 proofs)
|
Contributor
CBMC Results (ML-DSA-44, REDUCE-RAM)Full Results (195 proofs)
|
Contributor
CBMC Results (ML-DSA-87)
Full Results (195 proofs)
|
Contributor
CBMC Results (ML-DSA-65, REDUCE-RAM)
Full Results (195 proofs)
|
Contributor
CBMC Results (ML-DSA-65)Full Results (195 proofs)
|
Contributor
CBMC Results (ML-DSA-44)
Full Results (195 proofs)
|
CBMC contracts in this repo currently require one instance of requires(memory_no_alias(...)) per pointer argument and a parallel set of memory_slice(...) targets in assigns(...). For functions dealing with multiple pointers, this quickly bloats and thereby impedes the readability of the CBMC specs. Introduce two variadic preprocessor macros in mldsa/src/cbmc.h that unfold a list of regions into the corresponding memory_no_alias / memory_slice calls, joined as required by their containing clause: ``` requires(disjoint(arg, ...)) -- AND-joined memory_no_alias checks assigns(..., slices(arg, ...)) -- comma-joined memory_slice targets ``` Each arg is either a bare object x (size sizeof(*x)) or a pair (x, N) where N is an element count (size sizeof(*x) * N). The pair form covers byte buffers like uint8_t seed[CRHBYTES] and typed arrays where the count comes from a parameter rather than the type. Implementation uses the standard C99 variadic-preprocessor toolkit (arg counting, IS_PAIR probe via parenthesis detection, per-arity map/join dispatch) capped at 16 arguments. The macros are defined only inside the existing #ifdef CBMC block, so the C90 build path is unaffected. Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
f52b137 to
2bbe1f0
Compare
Contributor
Author
|
@mkannwischer This is not ready for detailed review as is, but I would like to hear your thoughts on the general direction and what specific argument/macro shape you find the most appealing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CBMC contracts in this repo currently require one instance of
requires(memory_no_alias(...))per pointer argument and aparallel set of
memory_slice(...)targets inassigns(...). For functions dealing with multiple pointers, this quickly bloats and thereby impedes the readability of the CBMC specs.Introduce two variadic preprocessor macros in mldsa/src/cbmc.h that unfold a list of regions into the corresponding memory_no_alias / memory_slice calls, joined as required by their containing clause:
Each arg is either a bare object x (size
sizeof(*x)) or a pair (x, N) where N is an element count (sizesizeof(*x) * N). The pair form covers byte buffers likeuint8_t seed[CRHBYTES]and typed arrays where the count comes from a parameter rather than the type.Implementation relies on some C99 preprocessor magic.