Skip to content

Allow let bindings in function contracts #7201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
feliperodri opened this issue Oct 5, 2022 · 1 comment
Closed

Allow let bindings in function contracts #7201

feliperodri opened this issue Oct 5, 2022 · 1 comment
Assignees
Labels
aws Bugs or features of importance to AWS CBMC users Code Contracts Function and loop contracts feature request

Comments

@feliperodri
Copy link
Collaborator

CBMC version: 5.67.0
Operating system: N/A

For readability by naive readers, and even for hardened pros, we need to allow let bindings in function contract expressions for easy-to-read contracts.

size_t expected_length = (expected != NULL) ? strlen(expected) : 0;
if ( ... S2N_SUCCESS ...) {
     uint8_t *actual = stuffer->blob.data + stuffer->read_cursor - expected_length;
     assert(!memcmp(actual, expected, expected_length));
}

among other things. The ensure clause should be something like

__CPROVER_ensures(!memcmp(actual, expected, expected_length))

Without lets, the best we can do is in-place expansion of both expressions (unreadable: notice that the double nesting of expected_length in this expression) or approximate the lets with preprocessor defines

#define EXPECTED_LENGTH ((expected != NULL) ? strlen(expected) : 0)
#define ACTUAL (stuffer->blob.data + stuffer->read_cursor - EXPECTED_LENGTH)
@feliperodri feliperodri added aws Bugs or features of importance to AWS CBMC users Code Contracts Function and loop contracts feature request labels Oct 5, 2022
@feliperodri feliperodri self-assigned this Oct 5, 2022
@remi-delmas-3000
Copy link
Collaborator

remi-delmas-3000 commented Dec 5, 2022

With the new contract system based on dynamic frames it is now possible to call C functions in requires/ensures/assigns/frees clauses, the called functions are instrumented for side effects checking.

This new PR #7401 adds support for user-defined predicates based on core predicates __CPROVER_is_fresh and __CPROVER_pointer_in_range.

We could say that the inconvenience has been addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws Bugs or features of importance to AWS CBMC users Code Contracts Function and loop contracts feature request
Projects
None yet
Development

No branches or pull requests

2 participants