Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
a50d179
Add Isabelle/C as expected AFP dependency
DominicPM Feb 23, 2026
e96318d
Add skeleton Micro_C_Parsing_Frontend session
DominicPM Feb 23, 2026
6944f04
Add skeleton Shallow_Micro_C session
DominicPM Feb 23, 2026
55160e3
Add skeleton Micro_C_Interfaces session
DominicPM Feb 23, 2026
d0628ab
Add skeleton Micro_C_Examples session and update umbrella
DominicPM Feb 23, 2026
fdc2881
Verify Isabelle/C parser integration with trivial C file
DominicPM Feb 23, 2026
4432dd6
Define C-specific abort type c_abort
DominicPM Feb 23, 2026
e6fdb45
Define C numeric types with overflow semantics
DominicPM Feb 23, 2026
8867a90
Define C sizeof reasoning connected to byte-level encoding
DominicPM Feb 23, 2026
bf6fda7
Define C pointer types and NULL handling
DominicPM Feb 23, 2026
9cfc580
Set up ML translation infrastructure for C-to-core-monad translation
DominicPM Feb 23, 2026
9c9c498
Translate C variable declarations, assignments, and arithmetic
DominicPM Feb 23, 2026
277e9c8
Translate C if/else conditionals and function parameters
DominicPM Feb 23, 2026
80f4f18
Translate C function calls to core monad funcall expressions
DominicPM Feb 23, 2026
83e954c
Translate bounded C for-loops to raw_for_loop
DominicPM Feb 23, 2026
df0683c
Add stub constants for unsupported C constructs
DominicPM Feb 23, 2026
d12af53
Define pointer arithmetic operation ptr_add
DominicPM Feb 23, 2026
68de134
Define C array access and update operations
DominicPM Feb 23, 2026
89e2288
Translate C pointer operations and array indexing in ML backend
DominicPM Feb 23, 2026
74dbe49
First end-to-end C verification example: swap
DominicPM Feb 23, 2026
ae85af1
Add C verification examples: max and abs
DominicPM Feb 23, 2026
8b7178d
Add WP rules for C arithmetic operations
DominicPM Feb 23, 2026
b7874d4
Wire overflow-checked C arithmetic into ML translation
DominicPM Feb 23, 2026
866e5a9
Update C examples to use fixed-width c_int types
DominicPM Feb 23, 2026
13c81a1
Add struct field access support to C-to-core translation
DominicPM Feb 23, 2026
cd59d6d
Add struct smoke test and end-to-end verification example
DominicPM Feb 23, 2026
f7d4381
Add array indexing support to C-to-core translation
DominicPM Feb 23, 2026
e1e9f8d
Add array verification example: read_at
DominicPM Feb 23, 2026
c1af9ec
Add unsigned arithmetic operations and WP rules
DominicPM Feb 23, 2026
a97471c
Add multi-type support to C-to-core ML translation
DominicPM Feb 23, 2026
060cfa8
Add unsigned int verification examples
DominicPM Feb 23, 2026
8bf647a
Reorganize C examples into thematic files
DominicPM Feb 23, 2026
ce8006d
Add array_fill (memset-style) with loop invariant proof
DominicPM Feb 23, 2026
143267d
Add array_copy (memcpy-style) with loop invariant proof
DominicPM Feb 23, 2026
e6142e3
Add C bitwise and shift operations with UB detection
DominicPM Feb 23, 2026
5af2565
Add C bitwise/shift/complement/negation translation support
DominicPM Feb 23, 2026
8bb4259
Add C bitwise verification examples and fix literal type inference
DominicPM Feb 23, 2026
f49ecc4
Add bounded_while combinator with C while loop translation and verifi…
DominicPM Feb 24, 2026
3db5973
Add #[fuel(n)] while/loop Rust syntax for bounded_while combinator
DominicPM Feb 24, 2026
4953c49
Add while let syntax with general pattern support
DominicPM Feb 24, 2026
d48a5d5
Add comma operator, multi-declarations, and pre/post increment/decrem…
DominicPM Feb 24, 2026
68786ed
Add !=, logical NOT, unary +, ternary, char literals, and compound as…
DominicPM Feb 24, 2026
c5044ba
Add _Bool, casts, do-while, general for-loops, enums, typedefs, and s…
DominicPM Feb 24, 2026
c11a338
Add cast definitions, literal suffixes, compound assignment on non-va…
DominicPM Feb 24, 2026
28f7811
Add sizeof, switch/case, break, continue, fresh variables, and struct…
DominicPM Feb 25, 2026
04d2725
Add address-of, pointer arithmetic, and forward-only goto to C frontend
DominicPM Feb 25, 2026
759de74
Add fixed-width types, void return, struct-array access, and array pa…
DominicPM Feb 25, 2026
c621485
Add function return type tracking, zero-init arrays, and verified mlk…
DominicPM Feb 25, 2026
34d949c
Add verified mlk_poly_sub and sint_minus_no_overflow lemma
DominicPM Feb 25, 2026
a8f127d
Add verified mlk_barrett_reduce and Barrett reduction arithmetic lemmas
DominicPM Feb 25, 2026
bbffcf4
Add micro_c_file command and clean up C frontend theories
DominicPM Feb 26, 2026
0270422
Added Isabelle_C as an explicit dependency
DominicPM Feb 26, 2026
ec6bc08
Improve C frontend type correctness and add truthiness operations
DominicPM Feb 26, 2026
5217695
Tighten C-to-core translation soundness and sync WP proofs
DominicPM Feb 27, 2026
ead5092
Drop wrapper theories and wire sessions to concrete C theories
DominicPM Feb 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ jobs:

- name: Build AutoCorrode
run: |
$ISABELLE_HOME/bin/isabelle build -v -b -d . -o browser_info -d $AFP_COMPONENT_BASE/Word_Lib AutoCorrode
$ISABELLE_HOME/bin/isabelle build -v -b -d . -o browser_info \
-d $AFP_COMPONENT_BASE/Word_Lib \
-d $AFP_COMPONENT_BASE/Isabelle_C \
AutoCorrode

- name: Upload documentation as pages artifact
uses: actions/upload-pages-artifact@v3
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ jobs:
# Build with HTML documentation, to make sure we can deploy to pages on merge
- name: Build AutoCorrode
run: |
$ISABELLE_HOME/bin/isabelle build -v -b -d . -o browser_info -d $AFP_COMPONENT_BASE/Word_Lib AutoCorrode
$ISABELLE_HOME/bin/isabelle build -v -b -d . -o browser_info \
-d $AFP_COMPONENT_BASE/Word_Lib \
-d $AFP_COMPONENT_BASE/Isabelle_C \
AutoCorrode

iq-build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -134,6 +137,7 @@ jobs:
- name: Build HOL heap (local)
run: |
$ISABELLE components -u $AFP_COMPONENT_BASE/Word_Lib
$ISABELLE components -u $AFP_COMPONENT_BASE/Isabelle_C
$ISABELLE build -b HOL

- name: Configure I/P remote (localhost, fresh install + push heaps)
Expand Down
8 changes: 8 additions & 0 deletions AutoCorrode.thy
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ theory AutoCorrode
"Micro_Rust_Parsing_Frontend.Micro_Rust_Parsing_Frontend"
"Micro_Rust_Runtime.Micro_Rust_Runtime"
"Micro_Rust_Std_Lib.Micro_Rust_Std_Lib"
"Micro_C_Parsing_Frontend.C_To_Core_Translation"
"Shallow_Micro_C.C_Arithmetic_Rules"
"Micro_C_Examples.Simple_C_Functions"
"Micro_C_Examples.C_Struct_Examples"
"Micro_C_Examples.C_Array_Examples"
"Micro_C_Examples.C_Bitwise_Examples"
"Micro_C_Examples.C_While_Examples"
"Micro_C_Examples.Mlkem_Native_Examples"
"Misc.Misc"
"Lenses_And_Other_Optics.Lenses_And_Other_Optics"
"Separation_Lenses.Separation_Lenses"
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jedit: register-afp-components

register-afp-components:
$(ISABELLE_HOME)/isabelle components -u $(AFP_COMPONENT_BASE)/Word_Lib
$(ISABELLE_HOME)/isabelle components -u $(AFP_COMPONENT_BASE)/Isabelle_C

build: register-afp-components
$(ISABELLE_HOME)/isabelle build $(ISABELLE_FLAGS) -d . AutoCorrode
215 changes: 215 additions & 0 deletions Micro_C_Examples/C_Array_Examples.thy
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
theory C_Array_Examples
imports
Simple_C_Functions
begin

section \<open>C array verification\<close>

text \<open>
This theory demonstrates verification of C array indexing operations.
Arrays are modeled as references to @{typ \<open>c_int list\<close>}.
Array indexing uses @{const focus_nth} (focus-based access).
\<close>

subsection \<open>Helper Definitions for Array Loop Proofs\<close>

definition list_fill_prefix :: \<open>nat \<Rightarrow> 'a \<Rightarrow> 'a list \<Rightarrow> 'a list\<close> where
\<open>list_fill_prefix k v xs \<equiv> replicate k v @ drop k xs\<close>

lemma list_fill_prefix_length [simp]:
assumes \<open>k \<le> length xs\<close>
shows \<open>length (list_fill_prefix k v xs) = length xs\<close>
using assms by (simp add: list_fill_prefix_def)

lemma list_fill_prefix_zero [simp]:
shows \<open>list_fill_prefix 0 v xs = xs\<close>
by (simp add: list_fill_prefix_def)

lemma list_fill_prefix_step:
assumes \<open>k < length xs\<close>
shows \<open>(list_fill_prefix k v xs)[k := v] = list_fill_prefix (Suc k) v xs\<close>
proof -
have \<open>drop k xs = xs ! k # drop (Suc k) xs\<close>
using assms by (simp add: Cons_nth_drop_Suc)
then have \<open>(list_fill_prefix k v xs)[k := v] = replicate k v @ v # drop (Suc k) xs\<close>
by (simp add: list_fill_prefix_def list_update_append)
also have \<open>\<dots> = replicate (Suc k) v @ drop (Suc k) xs\<close>
by (simp add: replicate_app_Cons_same)
finally show ?thesis
by (simp add: list_fill_prefix_def)
qed

definition list_copy_prefix :: \<open>nat \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list\<close> where
\<open>list_copy_prefix k src dst \<equiv> take k src @ drop k dst\<close>

lemma list_copy_prefix_length [simp]:
assumes \<open>k \<le> length src\<close>
and \<open>k \<le> length dst\<close>
shows \<open>length (list_copy_prefix k src dst) = length dst\<close>
using assms by (simp add: list_copy_prefix_def)

lemma list_copy_prefix_zero [simp]:
shows \<open>list_copy_prefix 0 src dst = dst\<close>
by (simp add: list_copy_prefix_def)

lemma list_copy_prefix_step:
assumes \<open>k < length src\<close> \<open>k < length dst\<close>
shows \<open>(list_copy_prefix k src dst)[k := src ! k] = list_copy_prefix (Suc k) src dst\<close>
proof -
have drop_eq: \<open>drop k dst = dst ! k # drop (Suc k) dst\<close>
using assms by (simp add: Cons_nth_drop_Suc)
have \<open>(list_copy_prefix k src dst)[k := src ! k] = take k src @ src ! k # drop (Suc k) dst\<close>
using assms by (simp add: list_copy_prefix_def list_update_append drop_eq)
also have \<open>\<dots> = take (Suc k) src @ drop (Suc k) dst\<close>
using assms by (simp add: take_Suc_conv_app_nth)
finally show ?thesis
by (simp add: list_copy_prefix_def)
qed


lemma sint_word_of_nat_Suc_ge_zero:
assumes \<open>i < n\<close>
and \<open>n < 2147483648\<close>
shows \<open>sint (1 + word_of_nat i :: 32 sword) \<ge> 0\<close>
apply (simp only: add.commute[of 1] word_succ_p1[symmetric] Abs_fnat_hom_Suc)
apply (rule More_Word.sint_of_nat_ge_zero)
using assms apply simp
done

context c_verification_ctx begin

subsection \<open>C Array Functions\<close>

micro_c_translate \<open>
int read_at(int *arr, int idx) {
return arr[idx];
}
\<close>

thm c_read_at_def

micro_c_translate \<open>
void write_at(int *arr, int idx, int val) {
arr[idx] = val;
}
\<close>

thm c_write_at_def

subsection \<open>Read-at Contract and Proof\<close>

text \<open>
The contract for @{text read_at}: given a reference to a @{typ \<open>c_int list\<close>}
and a valid index, the function returns the element at that index.
The @{const c_idx_to_nat} function converts the C integer index to a natural number.
\<close>

definition c_read_at_contract :: \<open>('addr, 'gv, c_int list) Global_Store.ref \<Rightarrow> c_int \<Rightarrow>
'gv \<Rightarrow> c_int list \<Rightarrow> ('s, c_int, 'b) function_contract\<close> where
[crush_contracts]: \<open>c_read_at_contract arr idx g vs \<equiv>
let pre = arr \<mapsto>\<langle>\<top>\<rangle> g\<down>vs \<star> \<langle>\<not> (sint idx < 0)\<rangle> \<star> \<langle>c_idx_to_nat idx < length vs\<rangle>;
post = \<lambda>r. arr \<mapsto>\<langle>\<top>\<rangle> g\<down>vs \<star> \<langle>r = vs ! (c_idx_to_nat idx)\<rangle>
in make_function_contract pre post\<close>
ucincl_auto c_read_at_contract

lemma c_read_at_spec:
shows \<open>\<Gamma>; c_read_at arr idx \<Turnstile>\<^sub>F c_read_at_contract arr idx g vs\<close>
by (crush_boot f: c_read_at_def contract: c_read_at_contract_def) crush_base

subsection \<open>Array Fill (memset-style)\<close>

text \<open>
A loop-based function that fills the first @{text n} elements of an array
with a given value. This is the first C loop verification example.
\<close>

micro_c_translate \<open>
void array_fill(int *arr, int val, unsigned int n) {
for (unsigned int i = 0; i < n; i++) {
arr[i] = val;
}
}
\<close>

thm c_array_fill_def

definition c_array_fill_contract :: \<open>('addr, 'gv, c_int list) Global_Store.ref \<Rightarrow> c_int \<Rightarrow> c_uint \<Rightarrow>
'gv \<Rightarrow> c_int list \<Rightarrow> ('s, 'a, 'b) function_contract\<close> where
\<open>c_array_fill_contract arr val n g vs \<equiv>
let pre = arr \<mapsto>\<langle>\<top>\<rangle> g\<down>vs \<star>
\<langle>c_idx_to_nat n \<le> size arr\<rangle> \<star>
\<langle>c_idx_to_nat n \<le> length vs\<rangle> \<star>
\<langle>c_idx_to_nat n < 2147483648\<rangle> \<star>
can_alloc_reference;
post = \<lambda>_. (\<Squnion>g'. arr \<mapsto>\<langle>\<top>\<rangle> g'\<down>(list_fill_prefix (c_idx_to_nat n) val vs)) \<star>
can_alloc_reference
in make_function_contract pre post\<close>
ucincl_auto c_array_fill_contract

lemma c_array_fill_spec:
shows \<open>\<Gamma>; c_array_fill arr val n \<Turnstile>\<^sub>F c_array_fill_contract arr val n g vs\<close>
apply (crush_boot f: c_array_fill_def contract: c_array_fill_contract_def)
apply crush_base
apply (ucincl_discharge\<open>
rule_tac
INV=\<open>\<lambda>_ i. (\<Squnion> g. arr \<mapsto>\<langle>\<top>\<rangle> g\<down>(list_fill_prefix i val vs))
\<star> \<langle>\<not> sint (word_of_nat i :: c_int) < 0\<rangle>\<close>
and \<tau>=\<open>\<lambda>_. \<langle>False\<rangle>\<close>
and \<theta>=\<open>\<lambda>_. \<langle>False\<rangle>\<close>
in wp_raw_for_loop_framedI'\<close>)
using unat_lt2p[of n] apply (crush_base simp add: list_fill_prefix_step unat_of_nat_eq More_Word.sint_of_nat_ge_zero)
apply (metis sint_word_of_nat_Suc_ge_zero not_le)
done

subsection \<open>Array Copy (memcpy-style)\<close>

text \<open>
A loop-based function that copies the first @{text n} elements from
@{text src} to @{text dst}. The source array is read-only.
\<close>

micro_c_translate \<open>
void array_copy(int *dst, int *src, unsigned int n) {
for (unsigned int i = 0; i < n; i++) {
dst[i] = src[i];
}
}
\<close>

thm c_array_copy_def

definition c_array_copy_contract :: \<open>('addr, 'gv, c_int list) Global_Store.ref \<Rightarrow>
('addr, 'gv, c_int list) Global_Store.ref \<Rightarrow> c_uint \<Rightarrow> 'gv \<Rightarrow> c_int list \<Rightarrow> 'gv \<Rightarrow>
c_int list \<Rightarrow> ('s, 'a, 'b) function_contract\<close> where
\<open>c_array_copy_contract dst src n gd vd gs vs \<equiv>
let pre = dst \<mapsto>\<langle>\<top>\<rangle> gd\<down>vd \<star> src \<mapsto>\<langle>\<top>\<rangle> gs\<down>vs \<star>
\<langle>c_idx_to_nat n \<le> size dst\<rangle> \<star>
\<langle>c_idx_to_nat n \<le> size src\<rangle> \<star>
\<langle>c_idx_to_nat n \<le> length vd\<rangle> \<star>
\<langle>c_idx_to_nat n \<le> length vs\<rangle> \<star>
\<langle>c_idx_to_nat n < 2147483648\<rangle> \<star>
can_alloc_reference;
post = \<lambda>_. (\<Squnion> g'. dst \<mapsto>\<langle>\<top>\<rangle> g'\<down>(list_copy_prefix (c_idx_to_nat n) vs vd)) \<star>
src \<mapsto>\<langle>\<top>\<rangle> gs\<down>vs \<star>
can_alloc_reference
in make_function_contract pre post\<close>
ucincl_auto c_array_copy_contract

lemma c_array_copy_spec:
shows \<open>\<Gamma>; c_array_copy dst src n \<Turnstile>\<^sub>F c_array_copy_contract dst src n gd vd gs vs\<close>
apply (crush_boot f: c_array_copy_def contract: c_array_copy_contract_def)
apply crush_base
apply (ucincl_discharge\<open>
rule_tac
INV=\<open>\<lambda>_ i. ((\<Squnion> g. dst \<mapsto>\<langle>\<top>\<rangle> g\<down>(list_copy_prefix i vs vd)) \<star> src \<mapsto>\<langle>\<top>\<rangle> gs\<down>vs)
\<star> \<langle>\<not> sint (word_of_nat i :: c_int) < 0\<rangle>\<close>
and \<tau>=\<open>\<lambda>_. \<langle>False\<rangle>\<close>
and \<theta>=\<open>\<lambda>_. \<langle>False\<rangle>\<close>
in wp_raw_for_loop_framedI'\<close>)
using unat_lt2p[of n] apply (crush_base simp add: list_copy_prefix_step unat_of_nat_eq More_Word.sint_of_nat_ge_zero)
apply (metis sint_word_of_nat_Suc_ge_zero not_le)
done

end

end
Loading