Skip to content

Cross-platform instability arising from default signedness of char in contracts library #8991

Description

@rod-chapman

In GOTO arising from the mlkem-native codebase, we're still seeing some cross-platform differences (i.e. between macOS and Linux) regarding casts to/from "char *" where the default signedness of "char" is implementation-defined, using CBMC 6.9.0

A small isolated example: the function scalar_signed_to_unsigned_q() in mlkem/src/poly.c, the GOTO generated by goto-instrument on Mac vs Linux contains the following single difference:

$ diff mac2/f.txt lnx2/f.txt 
140c140
<         ASSIGN __CPROVER_contracts_write_set_check_assignment::1::ub := cast(cast(__CPROVER_contracts_write_set_check_assignment::ptr, signedbv[8]*) + cast(__CPROVER_contracts_write_set_check_assignment::size, signedbv[64]), empty*)
---
>         ASSIGN __CPROVER_contracts_write_set_check_assignment::1::ub := cast(cast(__CPROVER_contracts_write_set_check_assignment::ptr, unsignedbv[8]*) + cast(__CPROVER_contracts_write_set_check_assignment::size, signedbv[64]), empty*)

This difference knocks-on to cause instability in the generated SMT, and unstable behaviour of Z3.

I think the solution is still to fix the signedness of "char" in a few places in cprover_contract.c, such as

.is_writable = ptr != 0, .size = size, .lb = ptr, .ub = (char *)ptr + size};

To be confirmed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C Front EndCode ContractsFunction and loop contractsawsBugs or features of importance to AWS CBMC users

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions