Skip to content

[DOCS] Add documentation on CBMC Shadow Memory intrinsics #7913

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

Merged
merged 1 commit into from
Sep 29, 2023

Conversation

NlightNFotis
Copy link
Contributor

This PR adds documentation for the 4 CBMC intrinsics that allow a user to interact with the Symbolic Shadow Memory component to the CProver manual.

I would appreciate reviewers to have a closer look at the following two items:

  • The location of the documentation is correct (as in, this is in a place that makes sense semantically, and is discoverable).
  • The Shadow Memory intrinsics types and explanations are correct and lucid, and don't require a lot of mental effort for decoding.

@codecov
Copy link

codecov bot commented Sep 25, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (99c5402) 78.56% compared to head (e68aa9d) 78.99%.
Report is 7 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7913      +/-   ##
===========================================
+ Coverage    78.56%   78.99%   +0.42%     
===========================================
  Files         1699     1701       +2     
  Lines       195804   195932     +128     
===========================================
+ Hits        153833   154769     +936     
+ Misses       41971    41163     -808     

see 56 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 3 to 4
(The original artefact's implementation is outlined in the paper [CBMC-SSM:
Bounded Model Checking of C Programs with Symbolic Shadow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

describes...


## Introduction

CBMC contains a component that supports *Symbolic Shadow Memory*. Shadow memory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CBMC supports Symbolic Shadow Memory.

Comment on lines 11 to 13
analysis program and that shadows the standard memory of the program. In that
memory structure, a user can create fields, for which he can later set and
retrieve values.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the shadow memory a user can set or retrieve values.

memory structure, a user can create fields, for which he can later set and
retrieve values.

By doing so, one can organise his own tracking of metadata related to the code,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

his

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be gender neutral? Also the person who is the object of this sentence is expected to be a user of cbmc. Therefore - "By doing so, a user can organise their own tracking of metadata"...

By doing so, one can organise his own tracking of metadata related to the code,
in a way that is then considered by the backend of CBMC during analysis. This
can be used to implement novel analyses that the CBMC framework itself doesn't
support - for example, the paper above presents as an example a taint analysis
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

" - for example, " -> ". For example,"


A user can interact with the Symbolic Shadow Memory component (from now on
onwards, SSM) through four CBMC primitives, which allow one to declare shadow
memory fields, and retrieve/set their corresponding values:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set/retrieve order consistency


More precisely, their signatures (in pseudo-C, because of some constraints that
we can't express using the type system), along with some small examples of their
usage, look like this:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look like this: -> are described below.

Type constraints:

* `type1`: string literal, such as `"field"`,
* `SSM_value_type`: value of maximum 8 bits, signed or unsigned or `_Bool`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SSM_value_type: any value up to 8 bits in size (signed or unsigned)

analysis program and that shadows the standard memory of the program. In that
memory structure, a user can create fields, for which he can later set and
retrieve values.
CBMC contains a component that implements *Symbolic Shadow Memory*. Symbolic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"contains a component that" -> ""

@NlightNFotis NlightNFotis force-pushed the shadow_mem_docs branch 2 times, most recently from 5e3d405 to a4c9364 Compare September 27, 2023 15:47
Copy link
Contributor

@esteffin esteffin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

memory structure, a user can create fields, for which he can later set and
retrieve values.

By doing so, one can organise his own tracking of metadata related to the code,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be gender neutral? Also the person who is the object of this sentence is expected to be a user of cbmc. Therefore - "By doing so, a user can organise their own tracking of metadata"...

## Usage

A user can interact with the Symbolic Shadow Memory component (from now on
onwards, SSM) through four CBMC primitives, which allow one to declare shadow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion "allow one" -> "support" and splitting into two sentences.
"A user can interact with the Symbolic Shadow Memory component (from now onwards, SSM) through four CBMC primitives. These support the declaration of shadow memory fields, and setting/retrieving their corresponding values:"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed to "allow" without "one".

Split in 2 sentences.


## Usage

A user can interact with the Symbolic Shadow Memory component (from now on
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ Duplication when read across line breaks - "on onwards"


Type constraints:

* `type1`: string literal, such as `"field"`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth emphasising that by string literal we mean that the field name must be compile time constant and may not be the result of runtime string manipulation. That is, if my understanding of what you are trying to say here is correct...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant is that it has to be a string literal such as "this is a string literal".

In the exprt world it has to be a constant_stringt.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. My understanding is correct. I think it is worth making the documentation spell out the exact details of what is and is not allowed as an argument here.


Type constraints:

* `type1`: string literal, such as `"field"`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment of clarifying string literal.

identifier for the field and using the pointer in `p` as the address for the location
of the value to be changed, to the given value, supplied by the third argument
`set_value`. This value needs to be of the same type as the type of the value the
field was originally initialised with.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the shadow memory operates on the byte level. Therefore even if you declare the field as being 16 bits, if you pass in a value of say 300, than value would be truncated to fit in 8 bits. Is my understanding correct/incorrect and does that need to be explained here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, when declaring shadow memory we should use the exact type, so < 8 bits.

The truncation happens only on set_field and it is explained there.

* `type1`: string literal, such as `"field"`,
* `SSM_value_type`: value of maximum 8 bits, signed or unsigned or `_Bool`.

Declares a local (working for variable declared in the current function scope)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user wants to use shadow memory for a value which goes through a function return, should the shadow memory be declared as local or global? It could be local based on it being on the stack or global based on it exceeding the lifetime of the function, so as a user I would be unsure which to declare it as.

Copy link
Contributor

@esteffin esteffin Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is based on the scope, so when you leave it everything is lost.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does that mean the shadow memory would have to be declared as global in that case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, that is unfortunately a shortcoming of the actual implementation.

Global is for global variables and heap-allocated pointers.
Local is for the local function scope.

There may be in the future a way to propagate local shadow memory information to called functions and through return, but it is not implemented yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add the limitation to the documentation then? Do similar limitations apply to function arguments? Do they only apply to stack memory or can the limitations be dodged by heap allocating and passing pointers?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is possible to heap-allocate arguments and return types so they will be tracked on the global SM.

About the documentation I'm not too keen at adding a "limitation" section as it draws attention to the limitation itself.

As the documentation says already local is for local only and is not passed to sub-call, I added that the same applies to returns, so the only way around is having the passed-around values on the global SM.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree on the subject of documenting limitations. If we document them, then it allows users to work around them and allows us to point to the documentation if anyone runs across them. It also adds strength to the argument that removing such limitations is a feature request, rather than a bug fix. However I am happy to leave this to your discretion.

If using global shadow memory enables support for function arguments and returns then doesn't that answer my original question of whether local or global declarations are needed for that use case?


### Working with Compound Type Objects

When using SSM on compound type pointers (e.g. `struct`) the value used for the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this description of shadow memory as it applies to struct types also apply to unions and arrays?

* `__CPROVER_field_decl_local`
* `__CPROVER_field_decl_global`
* `__CPROVER_get_field`
* `__CPROVER_set_field`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth noting that these are only currently supported for the C front end? I am kind of assuming that these are unavailable for the JBMC at the moment.

@esteffin esteffin merged commit 45fa2ca into diffblue:develop Sep 29, 2023
@esteffin esteffin deleted the shadow_mem_docs branch September 29, 2023 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants