Skip to content
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

Update harness for aws_cryptosdk_enc_ctx_clone #611

Merged
merged 10 commits into from
Oct 21, 2020
10 changes: 5 additions & 5 deletions .cbmc-batch/jobs/aws_cryptosdk_enc_ctx_clone/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ include ../Makefile.local_default

#########
# Local vars
MAX_NUM_ELEMS = 4
MAX_TABLE_SIZE ?= 2
# Time on my laptop: 4m50s
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this changes the time? Why was this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before, there was both a MAX_NUM_ELEMS and a MAX_TABLE_SIZE, so I just stuck with MAX_TABLE_SIZE (which was always 2). I've just run it locally, and setting MAX_TABLE_SIZE to 4 is fine. The proof isn't horribly slow so 4 would be fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the time comment still correct?

#########
#if we don't include the hash_table.c, we don't need to remove their function bodies
Expand All @@ -35,13 +35,14 @@ CBMCFLAGS +=

DEFINES += -DHASH_ITER_ELEMENT_GENERATOR=hash_iterator_string_string_generator
DEFINES += -DHASH_TABLE_FIND_ELEMENT_GENERATOR=hash_find_string_string_generator
DEFINES += -DMAX_NUM_ELEMS=$(MAX_NUM_ELEMS)
DEFINES += -DMAX_TABLE_SIZE=$(MAX_TABLE_SIZE)

DEPENDENCIES += $(SRCDIR)/c-common-helper-src/make_common_data_structures.c
DEPENDENCIES += $(SRCDIR)/c-common-helper-src/proof_allocators.c
DEPENDENCIES += $(SRCDIR)/c-common-helper-src/utils.c
DEPENDENCIES += $(SRCDIR)/c-common-src/byte_buf.c
DEPENDENCIES += $(SRCDIR)/c-common-src/common.c
DEPENDENCIES += $(SRCDIR)/c-common-src/hash_table.c
DEPENDENCIES += $(SRCDIR)/c-common-src/math.c
DEPENDENCIES += $(SRCDIR)/c-common-src/string.c
DEPENDENCIES += $(SRCDIR)/c-enc-sdk-src/enc_ctx.c
Expand All @@ -51,8 +52,7 @@ ENTRY = aws_cryptosdk_enc_ctx_clone_harness
REMOVE_FUNCTION_BODIES += --remove-function-body aws_string_destroy
REMOVE_FUNCTION_BODIES += --remove-function-body aws_string_new_from_array

UNWINDSET += aws_cryptosdk_enc_ctx_clone.0:$(shell echo $$(($(MAX_NUM_ELEMS) + 1)))
UNWINDSET += aws_cryptosdk_enc_ctx_clone.1:$(shell echo $$(($(MAX_NUM_ELEMS) + 1)))

UNWINDSET += aws_cryptosdk_enc_ctx_clone.0:$(shell echo $$((1 + $(MAX_TABLE_SIZE))))
UNWINDSET += aws_cryptosdk_enc_ctx_clone.1:$(shell echo $$((1 + $(MAX_TABLE_SIZE))))
###########
include ../Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@
#include <proof_helpers/proof_allocators.h>
#include <proof_helpers/utils.h>

void make_hash_table_with_no_backing_store(struct aws_hash_table *map, size_t max_table_entries);

/**
* The actual proof
*/
void aws_cryptosdk_enc_ctx_clone_harness() {
/* Nondet Input */
struct aws_hash_table dest;
make_hash_table_with_no_backing_store(&dest, MAX_NUM_ELEMS);
struct aws_hash_table src;
Copy link
Contributor

Choose a reason for hiding this comment

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

struct aws_hash_table* src = malloc(sizeof(*src))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!


/* Assumptions */
ensure_allocated_hash_table(&dest, MAX_TABLE_SIZE);
__CPROVER_assume(dest.p_impl != NULL);
__CPROVER_assume(dest.p_impl->entry_count <= MAX_TABLE_SIZE);
Copy link
Contributor

Choose a reason for hiding this comment

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

is there no aws_hash_table_is_bounded function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, I couldn't find anything ensuring this condition which is needed for the loop unwinding. I also haven't come across another proof needing this condition which is why I didn't make an auxiliary function for it.

__CPROVER_assume(aws_hash_table_is_valid(&dest));
ensure_hash_table_has_valid_destroy_functions(&dest);

struct aws_hash_table src;
make_hash_table_with_no_backing_store(&src, MAX_NUM_ELEMS);
ensure_allocated_hash_table(&src, MAX_TABLE_SIZE);
__CPROVER_assume(src.p_impl != NULL);
__CPROVER_assume(src.p_impl->entry_count <= MAX_TABLE_SIZE);
__CPROVER_assume(aws_hash_table_is_valid(&src));
ensure_hash_table_has_valid_destroy_functions(&src);

/* Operation under verification */
int rval = aws_cryptosdk_enc_ctx_clone(can_fail_allocator(), &dest, &src);
}