فهرست منبع

fix(rtl): close 6400 formal safety properties

root 3 ماه پیش
والد
کامیت
fdef6e1897

+ 33 - 0
src/acquisition/bmc_ascii_snapshot.v

@@ -202,4 +202,37 @@ module bmc_ascii_snapshot #(
             end
         end
     end
+
+`ifdef FORMAL
+    reg formal_past_valid;
+    (* anyconst *) reg [5:0] formal_bank_index;
+    initial formal_past_valid = 0;
+    always @(posedge clk) begin
+        formal_past_valid <= 1;
+        assume(formal_bank_index < 48);
+        if (rst_n && formal_past_valid && $past(rst_n)) begin
+            // P08: writes to the inactive bank cannot alter active-bank bytes.
+            if (active_bank == $past(active_bank)) begin
+                if (active_bank)
+                    assert(bank1[formal_bank_index] == $past(bank1[formal_bank_index]));
+                else
+                    assert(bank0[formal_bank_index] == $past(bank0[formal_bank_index]));
+                if (active_bank)
+                    assert(valid1 == $past(valid1));
+                else
+                    assert(valid0 == $past(valid0));
+            end
+
+            // P09: a bank swap is one pointer flip paired with one epoch step.
+            if (active_bank != $past(active_bank)) begin
+                assert(snapshot_commit);
+                assert(epoch == $past(epoch) + 1'b1);
+            end
+            if (snapshot_commit)
+                assert(active_bank != $past(active_bank));
+            cover(snapshot_commit && active_bank != $past(active_bank));
+            cover(line_active && byte_count != 0);
+        end
+    end
+`endif
 endmodule

+ 40 - 0
src/actuator/pwm_bitmap_engine.v

@@ -90,4 +90,44 @@ module pwm_bitmap_engine #(
             end
         end
     end
+
+`ifdef FORMAL
+    reg formal_past_valid;
+    function [6:0] formal_scan_rank;
+        input [ADDR_WIDTH-1:0] address;
+        input scan_active;
+        input capture_pending;
+        begin
+            if (scan_active)
+                formal_scan_rank = CHANNEL_COUNT[6:0] - address + 1'b1;
+            else if (capture_pending)
+                formal_scan_rank = 7'd1;
+            else
+                formal_scan_rank = 7'd0;
+        end
+    endfunction
+    wire [6:0] formal_scan_remaining = formal_scan_rank(scan_addr, scanning, capture_valid);
+    initial formal_past_valid = 0;
+    always @(posedge clk) begin
+        formal_past_valid <= 1;
+        if (rst_n) begin
+            // P11: the 32-channel scan always completes before the 500-clock deadline.
+            assert(!deadline_miss);
+            assert(phase <= LAST_PHASE);
+            assert(phase_clk <= LAST_SLOT);
+            if (phase_clk < CHANNEL_COUNT + 1)
+                assert(formal_scan_remaining == CHANNEL_COUNT + 1 - phase_clk);
+            else
+                assert(formal_scan_remaining == 0);
+            if (formal_past_valid && $past(rst_n) && logical_bitmap != $past(logical_bitmap))
+                assert(phase_boundary);
+            if (!scanning && !capture_valid)
+                assert(scan_idle);
+            if (formal_past_valid && $past(rst_n))
+                assert(phase_boundary == $past(phase_clk == LAST_SLOT));
+            cover(scan_idle);
+            cover(phase_boundary && !deadline_miss);
+        end
+    end
+`endif
 endmodule

+ 46 - 0
src/common/frame_rx.v

@@ -20,6 +20,10 @@ module frame_rx #(
     output reg        payload_wr_en,
     output reg [7:0]  payload_wr_addr,
     output reg [7:0]  payload_wr_data
+`ifdef FORMAL
+    , output wire formal_crc_accepted_o
+    , output wire formal_bad_crc_event_o
+`endif
 );
     localparam [3:0] ST_WAIT_A5 = 4'd0;
     localparam [3:0] ST_WAIT_5A = 4'd1;
@@ -163,4 +167,46 @@ module frame_rx #(
             end
         end
     end
+
+`ifdef FORMAL
+    reg formal_past_valid;
+    reg formal_crc_accepted;
+    wire formal_good_crc_event = rst_n && accept_enable &&
+        state == ST_CRC_HIGH && byte_valid &&
+        ({byte_data, received_crc_low} == crc_value);
+    wire formal_bad_crc_event = rst_n && accept_enable &&
+        state == ST_CRC_HIGH && byte_valid &&
+        ({byte_data, received_crc_low} != crc_value);
+    assign formal_crc_accepted_o = formal_crc_accepted;
+    assign formal_bad_crc_event_o = formal_bad_crc_event;
+    initial formal_past_valid = 0;
+    initial formal_crc_accepted = 0;
+    always @(posedge clk) begin
+        formal_past_valid <= 1;
+        if (!rst_n) begin
+            formal_crc_accepted <= 0;
+        end else begin
+            if (formal_good_crc_event)
+                formal_crc_accepted <= 1;
+            else if (formal_bad_crc_event || (state == ST_HOLD && frame_ready))
+                formal_crc_accepted <= 0;
+        end
+        if (rst_n && frame_valid && formal_past_valid && !$past(frame_valid)) begin
+            // P06: a wrong CRC can never produce a command-visible frame.
+            assert($past(rst_n));
+            assert($past(state) == ST_CRC_HIGH);
+            assert($past(byte_valid));
+            assert({$past(byte_data), $past(received_crc_low)} == $past(crc_value));
+        end
+        if (rst_n) begin
+            assert(!frame_valid || formal_crc_accepted);
+            if (formal_past_valid && $past(formal_bad_crc_event)) begin
+                assert(!frame_valid);
+                assert(state == ST_WAIT_A5);
+            end
+            cover(formal_bad_crc_event);
+            cover(frame_valid && formal_crc_accepted);
+        end
+    end
+`endif
 endmodule

+ 265 - 10
src/control/thermal_control_core.v

@@ -178,6 +178,18 @@ module thermal_control_core #(
         end
     endfunction
 
+    wire [7:0] apply_ptc_value =
+        (global_fault || control_state == STOPPED ||
+         lane_fault_for_output(work_index) ||
+         lane_invalid(lane_for_channel(work_index)) ||
+         safety_override_mask[work_index]) ? 8'd0 : inactive_request;
+    wire [7:0] apply_fan_value =
+        (global_fault || lane_fault_for_output(work_index) ||
+         lane_invalid(lane_for_output(work_index))) ? 8'd100 : inactive_request;
+    wire [7:0] safe_fill_value = (work_index < 24) ? 8'd0 :
+        ((global_fault || lane_fault_for_output(work_index) ||
+          lane_invalid(lane_for_output(work_index))) ? 8'd100 : safe_fan_target);
+
     always @* begin
         mult_a = 0;
         mult_b = 0;
@@ -268,9 +280,13 @@ module thermal_control_core #(
                 stimulus_running <= 0;
                 work_index <= 0;
                 work_state <= W_SAFE_FILL;
-                safe_fan_target <= (target_celsius == 0) ? 8'd30 : 8'd10;
+                safe_fan_target <= (global_fault || bmc_stale) ? 8'd100 :
+                    ((target_celsius == 0) ? 8'd30 : 8'd10);
+                global_fault <= global_fault || bmc_stale;
                 if (target_celsius == 0)
                     control_state <= STOPPED;
+                else if (global_fault || bmc_stale)
+                    control_state <= SENSOR_DEGRADED;
                 else
                     control_state <= WAIT_CT_VALID;
                 for (i = 0; i < 24; i = i + 1) begin
@@ -280,6 +296,7 @@ module thermal_control_core #(
             end else if (bmc_stale && !global_fault && control_state != STOPPED && control_state != RESET_SAFE) begin
                 global_fault <= 1;
                 control_state <= SENSOR_DEGRADED;
+                stable_epochs <= 0;
                 work_index <= 0;
                 work_state <= W_SAFE_FILL;
                 safe_fan_target <= 100;
@@ -316,7 +333,6 @@ module thermal_control_core #(
                                      !bmc_stale && bmc_epoch != last_bmc_epoch &&
                                      !(snapshot_lock && ((~active_output_bank) == snapshot_lock_bank))) begin
                             last_bmc_epoch <= bmc_epoch;
-                            global_fault <= 0;
                             work_index <= 0;
                             work_state <= W_PREP;
                         end
@@ -347,6 +363,8 @@ module thermal_control_core #(
                         if (!sample_valid) begin
                             if (active_output_bank) begin req0[work_index] <= 0; end else begin req1[work_index] <= 0; end
                             safety_override_mask[work_index] <= 1;
+                            previous_error[work_index] <= 0;
+                            previous_output[work_index] <= 0;
                             epoch_safe <= 0;
                             control_state <= SENSOR_DEGRADED;
                             case (lane_for_channel(work_index))
@@ -358,6 +376,8 @@ module thermal_control_core #(
                         end else if (sample_temperature >= HARD_LIMIT) begin
                             if (active_output_bank) req0[work_index] <= 0; else req1[work_index] <= 0;
                             safety_override_mask[work_index] <= 1;
+                            previous_error[work_index] <= 0;
+                            previous_output[work_index] <= 0;
                             lane_fault_mask[lane_for_channel(work_index)] <= 1;
                             epoch_safe <= 0;
                             control_state <= SENSOR_DEGRADED;
@@ -365,8 +385,18 @@ module thermal_control_core #(
                         end else if (sample_temperature >= PRETRIP_LIMIT) begin
                             if (active_output_bank) req0[work_index] <= 0; else req1[work_index] <= 0;
                             safety_override_mask[work_index] <= 1;
+                            previous_error[work_index] <= 0;
+                            previous_output[work_index] <= 0;
                             epoch_safe <= 0;
                             control_state <= SENSOR_DEGRADED;
+                        end else if (global_fault || lane_fault_for_output(work_index)) begin
+                            // A global/lane clamp must also clear the hidden PI
+                            // state.  Otherwise recovery could expose duty that
+                            // accumulated while the physical output was forced
+                            // off, violating bumpless limited-duty restart.
+                            if (active_output_bank) req0[work_index] <= 0; else req1[work_index] <= 0;
+                            previous_error[work_index] <= 0;
+                            previous_output[work_index] <= 0;
                         end else begin
                             if (stimulus_running) begin
                                 if (active_output_bank) req0[work_index] <= stimulus_mem[work_index]; else req1[work_index] <= stimulus_mem[work_index];
@@ -394,6 +424,7 @@ module thermal_control_core #(
                                     if (stable_epochs == RECOVERY_EPOCHS - 1'b1) begin
                                         stable_epochs <= 0;
                                         lane_fault_mask <= 0;
+                                        global_fault <= 0;
                                         control_state <= AUTO_BMC;
                                     end else stable_epochs <= stable_epochs + 1'b1;
                                 end else stable_epochs <= 0;
@@ -414,14 +445,14 @@ module thermal_control_core #(
                     W_APPLY: begin
                         if (active_output_bank) begin
                             if (work_index < 24)
-                                app0[work_index] <= (global_fault || lane_fault_for_output(work_index) || lane_invalid(lane_for_channel(work_index)) || safety_override_mask[work_index]) ? 8'd0 : inactive_request;
+                                app0[work_index] <= apply_ptc_value;
                             else
-                                app0[work_index] <= (global_fault || lane_fault_for_output(work_index) || lane_invalid(lane_for_output(work_index))) ? 8'd100 : inactive_request;
+                                app0[work_index] <= apply_fan_value;
                         end else begin
                             if (work_index < 24)
-                                app1[work_index] <= (global_fault || lane_fault_for_output(work_index) || lane_invalid(lane_for_channel(work_index)) || safety_override_mask[work_index]) ? 8'd0 : inactive_request;
+                                app1[work_index] <= apply_ptc_value;
                             else
-                                app1[work_index] <= (global_fault || lane_fault_for_output(work_index) || lane_invalid(lane_for_output(work_index))) ? 8'd100 : inactive_request;
+                                app1[work_index] <= apply_fan_value;
                         end
                         if (work_index == 31) begin
                             active_output_bank <= ~active_output_bank;
@@ -433,11 +464,11 @@ module thermal_control_core #(
                     end
                     W_SAFE_FILL: begin
                         if (active_output_bank) begin
-                            req0[work_index] <= (work_index < 24) ? 8'd0 : safe_fan_target;
-                            app0[work_index] <= (work_index < 24) ? 8'd0 : safe_fan_target;
+                            req0[work_index] <= safe_fill_value;
+                            app0[work_index] <= safe_fill_value;
                         end else begin
-                            req1[work_index] <= (work_index < 24) ? 8'd0 : safe_fan_target;
-                            app1[work_index] <= (work_index < 24) ? 8'd0 : safe_fan_target;
+                            req1[work_index] <= safe_fill_value;
+                            app1[work_index] <= safe_fill_value;
                         end
                         if (work_index == 31) begin
                             active_output_bank <= ~active_output_bank;
@@ -452,4 +483,228 @@ module thermal_control_core #(
             end
         end
     end
+
+`ifdef FORMAL
+    reg formal_past_valid;
+    (* anyconst *) reg [5:0] formal_duty_index;
+    (* anyconst *) reg [4:0] formal_ptc_index;
+
+    wire [7:0] formal_active_applied = active_output_bank ?
+        app1[formal_duty_index] : app0[formal_duty_index];
+    wire [7:0] formal_inactive_applied = active_output_bank ?
+        app0[formal_duty_index] : app1[formal_duty_index];
+    wire [7:0] formal_safe_fill_value = (formal_duty_index < 24) ? 8'd0 :
+        ((global_fault || lane_fault_for_output(formal_duty_index) ||
+          lane_invalid(lane_for_output(formal_duty_index))) ?
+            8'd100 : safe_fan_target);
+    wire formal_stale_preempt = bmc_stale && !global_fault &&
+        control_state != STOPPED && control_state != RESET_SAFE;
+
+    function [7:0] formal_work_rank;
+        input [3:0] state_value;
+        input [4:0] index_value;
+        begin
+            case (state_value)
+                W_PREP:      formal_work_rank = 8'd136 - ({3'd0, index_value} << 2);
+                W_KP:        formal_work_rank = 8'd135 - ({3'd0, index_value} << 2);
+                W_KI:        formal_work_rank = 8'd134 - ({3'd0, index_value} << 2);
+                W_UPDATE:    formal_work_rank = 8'd133 - ({3'd0, index_value} << 2);
+                W_FANS:      formal_work_rank = 8'd64 - index_value;
+                W_APPLY:     formal_work_rank = 8'd32 - index_value;
+                W_SAFE_FILL: formal_work_rank = 8'd64 - index_value;
+                default:     formal_work_rank = 8'd0;
+            endcase
+        end
+    endfunction
+    wire [7:0] formal_scheduler_rank = formal_work_rank(work_state, work_index);
+
+    initial formal_past_valid = 0;
+
+    always @(posedge clk) begin
+        formal_past_valid <= 1;
+        if (stimulus_wr_en) assume(stimulus_wr_data <= 100);
+        if (target_commit)
+            assume(target_celsius == 0 || (target_celsius >= 20 && target_celsius <= 70));
+        assume(formal_duty_index < 32);
+        assume(formal_ptc_index < 24);
+
+        // P01: every requested and applied logical duty remains in 0..100.
+        assert(req0[formal_duty_index] <= 100);
+        assert(req1[formal_duty_index] <= 100);
+        assert(app0[formal_duty_index] <= 100);
+        assert(app1[formal_duty_index] <= 100);
+        assert(stimulus_mem[formal_duty_index] <= 100);
+        assert(safe_fan_target <= 100);
+        assert(control_state <= STOPPED);
+        assert(current_target_celsius == 0 ||
+               (current_target_celsius >= 20 && current_target_celsius <= 70));
+        assert(target_centi <= 16'd7000);
+        if (formal_duty_index < 24) begin
+            assert(previous_output[formal_duty_index] >= 0);
+            assert(previous_output[formal_duty_index] <= 25600);
+        end
+
+        if (!rst_n) begin
+            // P17: reset state is safe and deterministic.
+            assert(control_state == RESET_SAFE);
+            assert(current_target_celsius == 70);
+            assert(safety_override_mask == 0);
+            assert(lane_fault_mask == 0);
+            assert(!global_fault);
+            if (formal_duty_index < 24) begin
+                assert(app0[formal_duty_index] == 0);
+                assert(app1[formal_duty_index] == 0);
+            end else begin
+                assert(app0[formal_duty_index] == 10);
+                assert(app1[formal_duty_index] == 10);
+            end
+        end else begin
+            // P10: an admitted scheduler pass has a finite rank that strictly
+            // decreases every clock unless target/stale safety preempts it.
+            assert(formal_scheduler_rank <= 136);
+            assert(work_state <= W_SAFE_FILL);
+            if (work_state == W_PREP || work_state == W_KP ||
+                work_state == W_KI || work_state == W_UPDATE)
+                assert(work_index < 24);
+            if (work_state == W_FANS)
+                assert(work_index >= 24);
+            // P02/P03/P04/P05/P16: the production apply datapath gives every
+            // hard safety condition priority over an ordinary PTC request.
+            if (work_state == W_APPLY && work_index == formal_ptc_index &&
+                (global_fault || control_state == STOPPED ||
+                 safety_override_mask[formal_ptc_index] ||
+                 lane_fault_mask[lane_for_channel(formal_ptc_index)] ||
+                 lane_invalid(lane_for_channel(formal_ptc_index))))
+                assert(apply_ptc_value == 0);
+
+            // Inductive sweep invariants: every address below work_index has
+            // already been written into the inactive bank by this pass.
+            if (work_state == W_SAFE_FILL &&
+                formal_duty_index < work_index)
+                assert(formal_inactive_applied == formal_safe_fill_value);
+            if (work_state == W_APPLY &&
+                formal_duty_index < work_index) begin
+                if (formal_duty_index < 24 &&
+                    (global_fault || control_state == STOPPED ||
+                     safety_override_mask[formal_duty_index] ||
+                     lane_fault_mask[lane_for_channel(formal_duty_index)] ||
+                     lane_invalid(lane_for_channel(formal_duty_index))))
+                    assert(formal_inactive_applied == 0);
+                if (formal_duty_index >= 24 &&
+                    (global_fault ||
+                     lane_fault_for_output(formal_duty_index) ||
+                     lane_invalid(lane_for_output(formal_duty_index))))
+                    assert(formal_inactive_applied == 100);
+            end
+
+            // Once a safety pass has committed, the active bank itself (not
+            // merely the combinational apply value) is safe.  W_IDLE is the
+            // post-commit quiescent point, so these assertions compose the
+            // detection, fill, bank flip, and externally visible duty state.
+            if (work_state == W_IDLE) begin
+                if (formal_duty_index < 24 &&
+                    (global_fault || control_state == STOPPED ||
+                     safety_override_mask[formal_duty_index] ||
+                     lane_fault_mask[lane_for_channel(formal_duty_index)] ||
+                     lane_invalid(lane_for_channel(formal_duty_index))))
+                    assert(formal_active_applied == 0);
+                if (formal_duty_index >= 24 &&
+                    (global_fault ||
+                     lane_fault_for_output(formal_duty_index) ||
+                     lane_invalid(lane_for_output(formal_duty_index))))
+                    assert(formal_active_applied == 100);
+            end
+            if (formal_past_valid && $past(rst_n)) begin
+                if ($past(formal_scheduler_rank) != 0 &&
+                    !$past(target_commit) && !$past(formal_stale_preempt))
+                    assert(formal_scheduler_rank < $past(formal_scheduler_rank));
+
+                // P03: a newly observed stale source starts the bounded safe
+                // fill at address zero and latches the global fault.  The rank
+                // invariant above forces that fill to reach the safe commit.
+                if ($past(formal_stale_preempt && !target_commit)) begin
+                    assert(global_fault);
+                    assert(control_state == SENSOR_DEGRADED);
+                    assert(work_state == W_SAFE_FILL);
+                    assert(work_index == 0);
+                    assert(safe_fan_target == 100);
+                end
+
+                // P04: an invalid sample records both the zero request and the
+                // channel override before the common apply/commit sequence.
+                if ($past(work_state == W_UPDATE &&
+                          work_index == formal_ptc_index && !sample_valid &&
+                          !target_commit && !formal_stale_preempt)) begin
+                    assert(safety_override_mask[formal_ptc_index]);
+                    if ($past(active_output_bank))
+                        assert(req0[formal_ptc_index] == 0);
+                    else
+                        assert(req1[formal_ptc_index] == 0);
+                end
+
+                // P05: a sampled hard limit latches the lane fault before the
+                // common apply pass zeros every PTC belonging to that lane.
+                if ($past(work_state == W_UPDATE &&
+                          work_index == formal_ptc_index && sample_valid &&
+                          sample_temperature >= HARD_LIMIT &&
+                          !target_commit && !formal_stale_preempt))
+                    assert(lane_fault_mask[lane_for_channel(formal_ptc_index)]);
+
+                // Fault-clamped control passes cannot accumulate hidden PI
+                // state or a nonzero request for later release.
+                if ($past(work_state == W_UPDATE &&
+                          work_index == formal_ptc_index && sample_valid &&
+                          sample_temperature < PRETRIP_LIMIT &&
+                          (global_fault ||
+                           lane_fault_mask[lane_for_channel(formal_ptc_index)]) &&
+                          !target_commit && !formal_stale_preempt)) begin
+                    assert(previous_error[formal_ptc_index] == 0);
+                    assert(previous_output[formal_ptc_index] == 0);
+                    if ($past(active_output_bank))
+                        assert(req0[formal_ptc_index] == 0);
+                    else
+                        assert(req1[formal_ptc_index] == 0);
+                end
+
+                // P12: absence of a Host target commit cannot create STOPPED.
+                if (!$past(target_commit) && $past(control_state) != STOPPED)
+                    assert(control_state != STOPPED);
+
+                // P13: stimulus has a strictly decreasing per-tick rank and
+                // reaches inactive when the remaining rank is one.
+                if ($past(stimulus_running && tick_1s && !stimulus_commit)) begin
+                    if ($past(stimulus_remaining) <= 1)
+                        assert(!stimulus_running);
+                    else if (stimulus_running)
+                        assert(stimulus_remaining == $past(stimulus_remaining) - 1'b1);
+                end
+
+            end
+
+            // Reachability witnesses are discharged by the dedicated cover
+            // tasks; they prevent the safety antecedents from being vacuous.
+            cover(global_fault && work_state == W_IDLE &&
+                  formal_ptc_index < 24 &&
+                  (active_output_bank ? app1[formal_ptc_index] :
+                                        app0[formal_ptc_index]) == 0);
+            cover(safety_override_mask[formal_ptc_index] &&
+                  work_state == W_IDLE &&
+                  (active_output_bank ? app1[formal_ptc_index] :
+                                        app0[formal_ptc_index]) == 0);
+            cover(lane_fault_mask[lane_for_channel(formal_ptc_index)] &&
+                  work_state == W_IDLE &&
+                  (active_output_bank ? app1[formal_ptc_index] :
+                                        app0[formal_ptc_index]) == 0);
+            cover(control_state == STOPPED && work_state == W_IDLE &&
+                  (active_output_bank ? app1[formal_ptc_index] :
+                                        app0[formal_ptc_index]) == 0);
+            cover(stimulus_running && stimulus_remaining != 0);
+            cover(formal_past_valid &&
+                  $past(stimulus_running && tick_1s &&
+                        stimulus_remaining <= 1 && !stimulus_commit) &&
+                  !stimulus_running);
+            cover(control_state == AUTO_BMC && work_state == W_UPDATE);
+        end
+    end
+`endif
 endmodule

+ 31 - 0
src/telemetry/thermal_snapshot_mux.v

@@ -189,4 +189,35 @@ module thermal_snapshot_mux (
         end else if (payload_addr == `FB_SNAPSHOT_LANE_FAULT_MASK_OFFSET) payload_data = {4'd0, lane_fault_latched};
         else if (payload_addr == `FB_SNAPSHOT_GLOBAL_FAULT_OFFSET) payload_data = {7'd0, global_fault_latched};
     end
+
+`ifdef FORMAL
+    reg formal_past_valid;
+    initial formal_past_valid = 0;
+    always @(posedge clk) begin
+        formal_past_valid <= 1;
+        if (rst_n && formal_past_valid && $past(rst_n)) begin
+            // P14: capture locks one coherent set of banks and epochs until unlock.
+            if (locked && !$past(locked)) begin
+                assert($past(capture));
+                assert(bmc_locked_bank == $past(bmc_active_bank));
+                assert(ct_locked_bank == $past(ct_active_bank));
+                assert(output_locked_bank == $past(output_active_bank));
+                assert(bmc_epoch_latched == $past(bmc_epoch));
+                assert(ct_epoch_latched == $past(ct_epoch));
+                assert(control_epoch_latched == $past(control_epoch));
+            end
+            if ($past(locked) && !$past(unlock)) begin
+                assert(locked);
+                assert(bmc_locked_bank == $past(bmc_locked_bank));
+                assert(ct_locked_bank == $past(ct_locked_bank));
+                assert(output_locked_bank == $past(output_locked_bank));
+                assert(bmc_epoch_latched == $past(bmc_epoch_latched));
+                assert(ct_epoch_latched == $past(ct_epoch_latched));
+                assert(control_epoch_latched == $past(control_epoch_latched));
+            end
+            cover(locked && ready);
+            cover(!locked && $past(locked) && $past(unlock));
+        end
+    end
+`endif
 endmodule

+ 24 - 0
src/transport/host_port_selector.v

@@ -74,4 +74,28 @@ module host_port_selector #(
             end
         end
     end
+
+`ifdef FORMAL
+    reg formal_past_valid;
+    initial formal_past_valid = 0;
+    always @(posedge clk) begin
+        formal_past_valid <= 1;
+        if (rst_n) begin
+            // P15: the selected Host port cannot change during one lock interval.
+            if (formal_past_valid && $past(rst_n) && locked && $past(locked))
+                assert(port_sel == $past(port_sel));
+            if (locked && port_sel)
+                assert(rs232_tx);
+            if (locked && !port_sel)
+                assert(ttl_tx);
+            if (!locked) begin
+                assert(rs232_tx);
+                assert(ttl_tx);
+            end
+            cover(locked && !port_sel);
+            cover(locked && port_sel);
+            cover(formal_past_valid && !locked && $past(locked));
+        end
+    end
+`endif
 endmodule

+ 33 - 0
src/transport/thermal_host_command.v

@@ -150,4 +150,37 @@ module thermal_host_command #(
             endcase
         end
     end
+
+`ifdef FORMAL
+    reg formal_past_valid;
+    initial formal_past_valid = 0;
+    always @(posedge clk) begin
+        formal_past_valid <= 1;
+        if (rst_n) begin
+            assert(state <= ST_DROP);
+            // P07: ACK exists only on the same atomic legal target commit.
+            if (tx_start && tx_frame_type == 8'h81) begin
+                assert(target_commit);
+                assert(tx_payload_length == 0);
+            end
+            if (target_commit) begin
+                assert(target_celsius == 0 || (target_celsius >= 20 && target_celsius <= 70));
+                assert(tx_start && tx_frame_type == 8'h81 && tx_payload_length == 0);
+                if (formal_past_valid && $past(rst_n))
+                    assert($past(state) == ST_TARGET);
+            end
+            if (formal_past_valid && $past(rst_n) &&
+                target_celsius != $past(target_celsius))
+                assert(target_commit);
+            if (ENABLE_STIMULUS == 0) begin
+                assert(state != ST_STIM_DURATION);
+                assert(state != ST_STIM_DATA);
+                assert(state != ST_STIM_COMMIT);
+                assert(!stimulus_wr_en);
+                assert(!stimulus_commit);
+            end
+            cover(target_commit && tx_start && tx_frame_type == 8'h81);
+        end
+    end
+`endif
 endmodule

+ 37 - 0
tests/formal/6400-properties.json

@@ -0,0 +1,37 @@
+{
+  "schema": "prod2u-6400-formal-properties-v1",
+  "required_solvers": ["boolector", "z3"],
+  "proof_targets": [
+    {"name": "core", "sby": "6400_core_properties.sby", "tasks": ["boolector", "z3"], "mode": "prove", "depth": 4},
+    {"name": "transport", "sby": "6400_transport_properties.sby", "tasks": ["boolector", "z3"], "mode": "prove", "depth": 8},
+    {"name": "bmc_bank", "sby": "6400_bmc_bank_properties.sby", "tasks": ["boolector", "z3"], "mode": "prove", "depth": 8},
+    {"name": "snapshot", "sby": "6400_snapshot_properties.sby", "tasks": ["boolector", "z3"], "mode": "prove", "depth": 4},
+    {"name": "pwm", "sby": "6400_pwm_properties.sby", "tasks": ["boolector", "z3"], "mode": "prove", "depth": 8}
+  ],
+  "cover_targets": [
+    {"name": "core_reachability", "sby": "6400_core_reachability.sby", "tasks": [], "mode": "cover", "depth": 220, "witnesses": ["P02", "P03", "P04", "P05", "P10", "P12", "P13", "P16"]},
+    {"name": "transport_reachability", "sby": "6400_transport_reachability.sby", "tasks": [], "mode": "cover", "depth": 128, "witnesses": ["P06", "P07", "P15"]},
+    {"name": "bmc_bank_reachability", "sby": "6400_bmc_bank_reachability.sby", "tasks": [], "mode": "cover", "depth": 128, "witnesses": ["P08", "P09"]},
+    {"name": "snapshot_reachability", "sby": "6400_snapshot_reachability.sby", "tasks": [], "mode": "cover", "depth": 8, "witnesses": ["P14"]},
+    {"name": "pwm_reachability", "sby": "6400_pwm_reachability.sby", "tasks": [], "mode": "cover", "depth": 505, "witnesses": ["P11"]}
+  ],
+  "properties": [
+    {"id": "P01", "requirement": "Duty always remains in 0..100", "harness": "6400_core_properties.sby"},
+    {"id": "P02", "requirement": "Hard safety overrides ordinary requests", "harness": "6400_core_properties.sby"},
+    {"id": "P03", "requirement": "BMC stale forces all PTC off", "harness": "6400_core_properties.sby"},
+    {"id": "P04", "requirement": "Invalid channels cannot heat", "harness": "6400_core_properties.sby"},
+    {"id": "P05", "requirement": "77 C lane fault overrides all lane PTC", "harness": "6400_core_properties.sby"},
+    {"id": "P06", "requirement": "Bad CRC cannot change target", "harness": "6400_transport_properties.sby"},
+    {"id": "P07", "requirement": "ACK occurs only after legal atomic commit", "harness": "6400_transport_properties.sby"},
+    {"id": "P08", "requirement": "Inactive bank cannot affect active bank", "harness": "6400_bmc_bank_properties.sby"},
+    {"id": "P09", "requirement": "Bank swap is atomic", "harness": "6400_bmc_bank_properties.sby"},
+    {"id": "P10", "requirement": "Scheduler has no permanent starvation", "harness": "6400_core_properties.sby"},
+    {"id": "P11", "requirement": "PWM scan completes before deadline", "harness": "6400_pwm_properties.sby"},
+    {"id": "P12", "requirement": "Host disconnect does not stop autonomous mode", "harness": "6400_core_properties.sby"},
+    {"id": "P13", "requirement": "Identification stimulus necessarily expires", "harness": "6400_core_properties.sby"},
+    {"id": "P14", "requirement": "Snapshot never mixes epochs or banks", "harness": "6400_snapshot_properties.sby"},
+    {"id": "P15", "requirement": "Host port selection is stable for one lock", "harness": "6400_transport_properties.sby"},
+    {"id": "P16", "requirement": "STOPPED never heats after safe commit", "harness": "6400_core_properties.sby"},
+    {"id": "P17", "requirement": "Reset outputs are safe", "harness": "6400_core_properties.sby"}
+  ]
+}

+ 20 - 0
tests/formal/6400_bmc_bank_properties.sby

@@ -0,0 +1,20 @@
+[tasks]
+boolector
+z3
+
+[options]
+mode prove
+depth 8
+
+[engines]
+boolector: smtbmc boolector
+z3: smtbmc z3 -- --noincr
+
+[script]
+read_verilog -formal -D FORMAL bmc_ascii_snapshot.v
+read_verilog -formal 6400_bmc_bank_properties_formal.v
+prep -top thermal_6400_bmc_bank_properties_formal
+
+[files]
+../../src/acquisition/bmc_ascii_snapshot.v
+6400_bmc_bank_properties_formal.v

+ 30 - 0
tests/formal/6400_bmc_bank_properties_formal.v

@@ -0,0 +1,30 @@
+module thermal_6400_bmc_bank_properties_formal (
+    input wire clk,
+    input wire rst_n
+);
+    (* anyseq *) reg tick_1s;
+    (* anyseq *) reg rx_valid;
+    (* anyseq *) reg [7:0] rx_data;
+    (* anyseq *) reg rx_error;
+    (* anyseq *) reg snapshot_lock;
+    (* anyseq *) reg snapshot_lock_bank;
+
+    bmc_ascii_snapshot #(.STALE_SECONDS(3)) dut (
+        .clk(clk), .rst_n(rst_n), .tick_1s(tick_1s),
+        .rx_valid(rx_valid), .rx_data(rx_data), .rx_framing_error(rx_error),
+        .snapshot_lock(snapshot_lock), .snapshot_lock_bank(snapshot_lock_bank),
+        .snapshot_commit(), .parser_error(), .epoch(), .age_seconds(), .stale(),
+        .active_bank(), .active_valid_mask(), .control_bank(1'b0),
+        .control_index(5'd0), .control_raw(), .control_valid(),
+        .snapshot_bank(1'b0), .snapshot_index(5'd0),
+        .snapshot_raw(), .snapshot_valid()
+    );
+
+    reg [1:0] reset_cycles = 0;
+    always @(posedge clk) begin
+        if (reset_cycles < 2) begin
+            assume(!rst_n);
+            reset_cycles <= reset_cycles + 1'b1;
+        end else assume(rst_n);
+    end
+endmodule

+ 15 - 0
tests/formal/6400_bmc_bank_reachability.sby

@@ -0,0 +1,15 @@
+[options]
+mode cover
+depth 128
+
+[engines]
+smtbmc boolector
+
+[script]
+read_verilog -formal -D FORMAL bmc_ascii_snapshot.v
+read_verilog -formal 6400_bmc_bank_properties_formal.v
+prep -top thermal_6400_bmc_bank_properties_formal
+
+[files]
+../../src/acquisition/bmc_ascii_snapshot.v
+6400_bmc_bank_properties_formal.v

+ 20 - 0
tests/formal/6400_core_properties.sby

@@ -0,0 +1,20 @@
+[tasks]
+boolector
+z3
+
+[options]
+mode prove
+depth 4
+
+[engines]
+boolector: smtbmc boolector
+z3: smtbmc z3 -- --noincr
+
+[script]
+read_verilog -formal -D FORMAL thermal_control_core.v
+read_verilog -formal 6400_core_properties_formal.v
+prep -top thermal_6400_core_properties_formal
+
+[files]
+../../src/control/thermal_control_core.v
+6400_core_properties_formal.v

+ 69 - 0
tests/formal/6400_core_properties_formal.v

@@ -0,0 +1,69 @@
+module thermal_6400_core_properties_formal (
+    input wire clk,
+    input wire rst_n
+);
+    (* anyseq *) reg tick_1s;
+    (* anyseq *) reg target_commit;
+    (* anyseq *) reg [7:0] target_celsius;
+    (* anyseq *) reg stimulus_wr_en;
+    (* anyseq *) reg [4:0] stimulus_wr_addr;
+    (* anyseq *) reg [7:0] stimulus_wr_data;
+    (* anyseq *) reg stimulus_commit;
+    (* anyseq *) reg [7:0] stimulus_duration;
+    (* anyseq *) reg [15:0] bmc_epoch;
+    (* anyseq *) reg bmc_stale;
+    (* anyseq *) reg [23:0] bmc_valid_mask;
+    (* anyseq *) reg [15:0] bmc_rd_raw;
+    (* anyseq *) reg bmc_rd_valid;
+    (* anyseq *) reg [15:0] ct_epoch;
+    (* anyseq *) reg ct_stale;
+    (* anyseq *) reg [26:0] ct_valid_mask;
+    (* anyseq *) reg snapshot_lock;
+    (* anyseq *) reg snapshot_lock_bank;
+    (* anyseq *) reg [4:0] pwm_rd_addr;
+    (* anyseq *) reg snapshot_output_bank;
+    (* anyseq *) reg [4:0] snapshot_rd_addr;
+    wire [4:0] bmc_rd_index;
+    wire [7:0] pwm_rd_data;
+    wire [7:0] snapshot_requested_data;
+    wire [7:0] snapshot_applied_data;
+    wire active_output_bank;
+    wire [2:0] control_state;
+    wire [7:0] current_target;
+    wire host_target_seen;
+    wire [15:0] control_epoch;
+    wire [23:0] safety_override_mask;
+    wire [3:0] lane_fault_mask;
+    wire global_fault;
+    wire output_commit;
+    wire stimulus_active;
+
+    thermal_control_core #(.ENABLE_STIMULUS(1)) dut (
+        .clk(clk), .rst_n(rst_n), .tick_1s(tick_1s),
+        .target_commit(target_commit), .target_celsius(target_celsius),
+        .stimulus_wr_en(stimulus_wr_en), .stimulus_wr_addr(stimulus_wr_addr),
+        .stimulus_wr_data(stimulus_wr_data), .stimulus_commit(stimulus_commit),
+        .stimulus_duration_seconds(stimulus_duration), .bmc_epoch(bmc_epoch),
+        .bmc_stale(bmc_stale), .bmc_valid_mask(bmc_valid_mask),
+        .bmc_rd_index(bmc_rd_index), .bmc_rd_raw(bmc_rd_raw), .bmc_rd_valid(bmc_rd_valid),
+        .ct_epoch(ct_epoch), .ct_stale(ct_stale), .ct_valid_mask(ct_valid_mask),
+        .snapshot_lock(snapshot_lock), .snapshot_lock_bank(snapshot_lock_bank),
+        .pwm_rd_addr(pwm_rd_addr), .pwm_rd_data(pwm_rd_data),
+        .snapshot_output_bank(snapshot_output_bank), .snapshot_rd_addr(snapshot_rd_addr),
+        .snapshot_requested_data(snapshot_requested_data), .snapshot_applied_data(snapshot_applied_data),
+        .active_output_bank(active_output_bank), .control_state(control_state),
+        .current_target_celsius(current_target), .host_target_seen(host_target_seen),
+        .control_epoch(control_epoch), .safety_override_mask(safety_override_mask),
+        .lane_fault_mask(lane_fault_mask), .global_fault(global_fault),
+        .output_commit(output_commit), .stimulus_active(stimulus_active)
+    );
+
+    reg [1:0] reset_cycles = 0;
+    always @(posedge clk) begin
+        if (reset_cycles < 2) begin
+            assume(!rst_n);
+            reset_cycles <= reset_cycles + 1'b1;
+        end else assume(rst_n);
+        assume(stimulus_wr_addr < 32);
+    end
+endmodule

+ 15 - 0
tests/formal/6400_core_reachability.sby

@@ -0,0 +1,15 @@
+[options]
+mode cover
+depth 220
+
+[engines]
+smtbmc boolector
+
+[script]
+read_verilog -formal -D FORMAL thermal_control_core.v
+read_verilog -formal 6400_core_properties_formal.v
+prep -top thermal_6400_core_properties_formal
+
+[files]
+../../src/control/thermal_control_core.v
+6400_core_properties_formal.v

+ 20 - 0
tests/formal/6400_pwm_properties.sby

@@ -0,0 +1,20 @@
+[tasks]
+boolector
+z3
+
+[options]
+mode prove
+depth 8
+
+[engines]
+boolector: smtbmc boolector
+z3: smtbmc z3 -- --noincr
+
+[script]
+read_verilog -formal -D FORMAL pwm_bitmap_engine.v
+read_verilog -formal 6400_pwm_properties_formal.v
+prep -top thermal_6400_pwm_properties_formal
+
+[files]
+../../src/actuator/pwm_bitmap_engine.v
+6400_pwm_properties_formal.v

+ 21 - 0
tests/formal/6400_pwm_properties_formal.v

@@ -0,0 +1,21 @@
+module thermal_6400_pwm_properties_formal (
+    input wire clk,
+    input wire rst_n
+);
+    (* anyseq *) reg [7:0] duty_data;
+
+    pwm_bitmap_engine dut (
+        .clk(clk), .rst_n(rst_n), .duty_rd_addr(), .duty_rd_data(duty_data),
+        .logical_bitmap(), .phase_boundary(), .deadline_miss(),
+        .phase_value(), .scan_idle()
+    );
+
+    reg [1:0] reset_cycles = 0;
+    always @(posedge clk) begin
+        if (reset_cycles < 2) begin
+            assume(!rst_n);
+            reset_cycles <= reset_cycles + 1'b1;
+        end else assume(rst_n);
+        assume(duty_data <= 100);
+    end
+endmodule

+ 15 - 0
tests/formal/6400_pwm_reachability.sby

@@ -0,0 +1,15 @@
+[options]
+mode cover
+depth 505
+
+[engines]
+smtbmc boolector
+
+[script]
+read_verilog -formal -D FORMAL pwm_bitmap_engine.v
+read_verilog -formal 6400_pwm_properties_formal.v
+prep -top thermal_6400_pwm_properties_formal
+
+[files]
+../../src/actuator/pwm_bitmap_engine.v
+6400_pwm_properties_formal.v

+ 21 - 0
tests/formal/6400_snapshot_properties.sby

@@ -0,0 +1,21 @@
+[tasks]
+boolector
+z3
+
+[options]
+mode prove
+depth 4
+
+[engines]
+boolector: smtbmc boolector
+z3: smtbmc z3 -- --noincr
+
+[script]
+read_verilog -formal -D FORMAL -I. thermal_snapshot_mux.v
+read_verilog -formal 6400_snapshot_properties_formal.v
+prep -top thermal_6400_snapshot_properties_formal
+
+[files]
+../../src/telemetry/thermal_snapshot_mux.v
+generated/6400/prod2u_6400_v1_params.vh ../../generated/6400/prod2u_6400_v1_params.vh
+6400_snapshot_properties_formal.v

+ 36 - 0
tests/formal/6400_snapshot_properties_formal.v

@@ -0,0 +1,36 @@
+module thermal_6400_snapshot_properties_formal (
+    input wire clk,
+    input wire rst_n
+);
+    (* anyseq *) reg capture;
+    (* anyseq *) reg unlock;
+    (* anyseq *) reg bmc_active_bank;
+    (* anyseq *) reg ct_active_bank;
+    (* anyseq *) reg output_active_bank;
+    (* anyseq *) reg [15:0] bmc_epoch;
+    (* anyseq *) reg [15:0] ct_epoch;
+    (* anyseq *) reg [15:0] control_epoch;
+
+    thermal_snapshot_mux dut (
+        .clk(clk), .rst_n(rst_n), .capture(capture), .ready(), .locked(),
+        .bmc_active_bank(bmc_active_bank), .ct_active_bank(ct_active_bank),
+        .output_active_bank(output_active_bank), .bmc_locked_bank(),
+        .ct_locked_bank(), .output_locked_bank(), .control_state(3'd0),
+        .fault_flags(16'd0), .current_target(8'd70), .host_target_seen(1'b0),
+        .bmc_epoch(bmc_epoch), .ct_epoch(ct_epoch), .control_epoch(control_epoch),
+        .bmc_age(16'd0), .ct_age(16'd0), .bmc_valid_mask(24'd0),
+        .ct_valid_mask(27'd0), .safety_override_mask(24'd0),
+        .lane_fault_mask(4'd0), .global_fault(1'b0), .unlock(unlock),
+        .payload_addr(8'd0), .payload_data(), .bmc_rd_index(),
+        .bmc_rd_raw(16'd0), .ct_rd_index(), .ct_rd_raw(16'd0),
+        .output_rd_addr(), .requested_data(8'd0), .applied_data(8'd0)
+    );
+
+    reg [1:0] reset_cycles = 0;
+    always @(posedge clk) begin
+        if (reset_cycles < 2) begin
+            assume(!rst_n);
+            reset_cycles <= reset_cycles + 1'b1;
+        end else assume(rst_n);
+    end
+endmodule

+ 16 - 0
tests/formal/6400_snapshot_reachability.sby

@@ -0,0 +1,16 @@
+[options]
+mode cover
+depth 8
+
+[engines]
+smtbmc boolector
+
+[script]
+read_verilog -formal -D FORMAL -I. thermal_snapshot_mux.v
+read_verilog -formal 6400_snapshot_properties_formal.v
+prep -top thermal_6400_snapshot_properties_formal
+
+[files]
+../../src/telemetry/thermal_snapshot_mux.v
+generated/6400/prod2u_6400_v1_params.vh ../../generated/6400/prod2u_6400_v1_params.vh
+6400_snapshot_properties_formal.v

+ 24 - 0
tests/formal/6400_transport_properties.sby

@@ -0,0 +1,24 @@
+[tasks]
+boolector
+z3
+
+[options]
+mode prove
+depth 8
+
+[engines]
+boolector: smtbmc boolector
+z3: smtbmc z3 -- --noincr
+
+[script]
+read_verilog -formal -D FORMAL crc16_serial.v frame_rx.v payload_ram.v thermal_host_command.v host_port_selector.v
+read_verilog -formal 6400_transport_properties_formal.v
+prep -top thermal_6400_transport_properties_formal
+
+[files]
+../../src/common/crc16_serial.v
+../../src/common/frame_rx.v
+../../src/common/payload_ram.v
+../../src/transport/thermal_host_command.v
+../../src/transport/host_port_selector.v
+6400_transport_properties_formal.v

+ 113 - 0
tests/formal/6400_transport_properties_formal.v

@@ -0,0 +1,113 @@
+module thermal_6400_transport_properties_formal (
+    input wire clk,
+    input wire rst_n
+);
+    (* anyseq *) reg byte_valid;
+    (* anyseq *) reg [7:0] byte_data;
+    (* anyseq *) reg snapshot_ready;
+    (* anyseq *) reg tx_done;
+    (* anyseq *) reg rs232_rx;
+    (* anyseq *) reg ttl_rx;
+    (* anyseq *) reg shared_tx;
+    wire frame_valid;
+    wire frame_ready;
+    wire frame_accept_enable;
+    wire [7:0] frame_type;
+    wire [7:0] frame_length;
+    wire [7:0] payload_read_addr;
+    wire [7:0] payload_read_data;
+    wire payload_wr_en;
+    wire [7:0] payload_wr_addr;
+    wire [7:0] payload_wr_data;
+    wire rx_formal_crc_accepted;
+    wire rx_formal_bad_crc_event;
+    wire target_commit;
+    wire [7:0] target_celsius;
+    wire snapshot_capture;
+    wire tx_start;
+    wire [7:0] tx_frame_type;
+    wire [7:0] tx_payload_length;
+    wire transaction_done;
+    wire command_busy;
+    wire selected_rx;
+    wire rs232_tx;
+    wire ttl_tx;
+    wire host_locked;
+    wire host_port_sel;
+
+    frame_rx #(.MAX_PAYLOAD(33), .INTER_BYTE_TIMEOUT_CYCLES(8)) u_frame_rx (
+        .clk(clk), .rst_n(rst_n), .byte_valid(byte_valid), .byte_data(byte_data),
+        .accept_enable(frame_accept_enable), .frame_valid(frame_valid), .frame_ready(frame_ready),
+        .frame_type(frame_type), .frame_length(frame_length),
+        .payload_read_addr(payload_read_addr), .payload_read_data(payload_read_data),
+        .payload_wr_en(payload_wr_en), .payload_wr_addr(payload_wr_addr),
+        .payload_wr_data(payload_wr_data),
+        .formal_crc_accepted_o(rx_formal_crc_accepted),
+        .formal_bad_crc_event_o(rx_formal_bad_crc_event)
+    );
+    payload_ram #(.DEPTH(33), .ADDR_WIDTH(8)) u_payload (
+        .clk(clk), .wr_en(payload_wr_en), .wr_addr(payload_wr_addr), .wr_data(payload_wr_data),
+        .rd_addr(payload_read_addr), .rd_data(payload_read_data)
+    );
+    thermal_host_command #(.ENABLE_STIMULUS(0), .SNAPSHOT_LENGTH(193)) u_command (
+        .clk(clk), .rst_n(rst_n), .frame_valid(frame_valid), .frame_ready(frame_ready),
+        .frame_accept_enable(frame_accept_enable), .frame_type(frame_type), .frame_length(frame_length),
+        .payload_read_addr(payload_read_addr), .payload_read_data(payload_read_data),
+        .target_commit(target_commit), .target_celsius(target_celsius),
+        .stimulus_wr_en(), .stimulus_wr_addr(), .stimulus_wr_data(),
+        .stimulus_commit(), .stimulus_duration_seconds(), .snapshot_capture(snapshot_capture),
+        .snapshot_ready(snapshot_ready), .tx_start(tx_start), .tx_frame_type(tx_frame_type),
+        .tx_payload_length(tx_payload_length), .tx_done(tx_done),
+        .transaction_done(transaction_done), .busy(command_busy)
+    );
+    host_port_selector #(.IDLE_UNLOCK_CLKS(16)) u_selector (
+        .clk(clk), .rst_n(rst_n), .rs232_rx_async(rs232_rx), .ttl_rx_async(ttl_rx),
+        .shared_tx(shared_tx), .transaction_done(transaction_done), .selected_rx(selected_rx),
+        .rs232_tx(rs232_tx), .ttl_tx(ttl_tx), .locked(host_locked), .port_sel(host_port_sel),
+        .rs232_rx_sync(), .ttl_rx_sync()
+    );
+
+    reg [1:0] reset_cycles = 0;
+    reg accepted_crc_good = 0;
+    reg bad_crc_quarantine = 0;
+    reg [7:0] bad_crc_target = 0;
+    always @(posedge clk) begin
+        if (reset_cycles < 2) begin
+            assume(!rst_n);
+            reset_cycles <= reset_cycles + 1'b1;
+        end else assume(rst_n);
+
+        if (!rst_n) begin
+            accepted_crc_good <= 0;
+            bad_crc_quarantine <= 0;
+            bad_crc_target <= target_celsius;
+        end else begin
+            if (rx_formal_bad_crc_event) begin
+                bad_crc_quarantine <= 1;
+                bad_crc_target <= target_celsius;
+            end
+            if (frame_valid && frame_ready) begin
+                assert(rx_formal_crc_accepted);
+                accepted_crc_good <= rx_formal_crc_accepted;
+                bad_crc_quarantine <= 0;
+            end
+            if (transaction_done)
+                accepted_crc_good <= 0;
+
+            // P06 end-to-end: from a rejected CRC through the parser and
+            // command engine, Target is immutable until another CRC-valid
+            // frame is explicitly accepted.
+            if (bad_crc_quarantine && !(frame_valid && frame_ready)) begin
+                assert(!target_commit);
+                assert(target_celsius == bad_crc_target);
+            end
+            if (target_commit)
+                assert(accepted_crc_good);
+
+            cover(bad_crc_quarantine && !target_commit &&
+                  target_celsius == bad_crc_target);
+            cover(target_commit && accepted_crc_good && tx_start &&
+                  tx_frame_type == 8'h81);
+        end
+    end
+endmodule

+ 19 - 0
tests/formal/6400_transport_reachability.sby

@@ -0,0 +1,19 @@
+[options]
+mode cover
+depth 128
+
+[engines]
+smtbmc boolector
+
+[script]
+read_verilog -formal -D FORMAL crc16_serial.v frame_rx.v payload_ram.v thermal_host_command.v host_port_selector.v
+read_verilog -formal 6400_transport_properties_formal.v
+prep -top thermal_6400_transport_properties_formal
+
+[files]
+../../src/common/crc16_serial.v
+../../src/common/frame_rx.v
+../../src/common/payload_ram.v
+../../src/transport/thermal_host_command.v
+../../src/transport/host_port_selector.v
+6400_transport_properties_formal.v

+ 35 - 0
tests/sim/thermal_control_core_tb.v

@@ -119,6 +119,41 @@ module thermal_control_core_tb;
         if (!global_fault) $fatal;
         check_duty(12, 0);
         check_duty(26, 100);
+
+        // A legal target commit must not weaken an already-latched stale
+        // fault or its 100% airflow fallback.
+        i = commits;
+        @(negedge clk); target = 65; target_commit = 1;
+        @(negedge clk); target_commit = 0;
+        wait_commit_after(i);
+        if (!global_fault || state !== 5 || current_target !== 65) $fatal;
+        check_duty(0, 0);
+        check_duty(24, 100);
+        check_duty(28, 100);
+
+        // Recovery holds the global/lane clamps for two complete fresh
+        // epochs and releases them only after the third safe epoch commits.
+        for (i = 0; i < 24; i = i + 1) bmc_raw[i] = {8'd60, 8'd0};
+        bmc_stale = 0;
+        i = commits;
+        next_bmc_epoch();
+        wait_commit_after(i);
+        if (!global_fault || !lane_fault[0] || state !== 5) $fatal;
+        i = commits;
+        next_bmc_epoch();
+        wait_commit_after(i);
+        if (!global_fault || !lane_fault[0] || state !== 5) $fatal;
+        i = commits;
+        next_bmc_epoch();
+        wait_commit_after(i);
+        if (global_fault || lane_fault != 0 || state !== 4) $fatal;
+        // The release commit is still zero-duty: PI state was cleared while
+        // clamped and may only ramp from the next fresh epoch.
+        check_duty(0, 0);
+        i = commits;
+        next_bmc_epoch();
+        wait_commit_after(i);
+        check_duty(0, 4);
         $display("PASS: thermal_control_core_tb");
         $finish;
     end

+ 76 - 0
tests/unit/test_6400_formal_contract.py

@@ -0,0 +1,76 @@
+#!/usr/bin/env python3
+"""Contract checks for the 6400 P01-P17 formal acceptance suite."""
+
+from __future__ import annotations
+
+import json
+from pathlib import Path
+import re
+
+
+ROOT = Path(__file__).resolve().parents[2]
+FORMAL = ROOT / "tests" / "formal"
+
+
+def _manifest() -> dict:
+    return json.loads((FORMAL / "6400-properties.json").read_text(encoding="utf-8"))
+
+
+def test_exact_p01_p17_manifest() -> None:
+    manifest = _manifest()
+    assert [item["id"] for item in manifest["properties"]] == [
+        f"P{index:02d}" for index in range(1, 18)
+    ]
+    assert len({item["id"] for item in manifest["properties"]}) == 17
+
+
+def test_every_proof_runs_boolector_and_z3() -> None:
+    manifest = _manifest()
+    assert manifest["required_solvers"] == ["boolector", "z3"]
+    harnesses = {target["sby"] for target in manifest["proof_targets"]}
+    assert all(target["tasks"] == ["boolector", "z3"] for target in manifest["proof_targets"])
+    assert all(item["harness"] in harnesses for item in manifest["properties"])
+
+
+def test_sby_mode_and_depth_match_manifest() -> None:
+    manifest = _manifest()
+    for target in [*manifest["proof_targets"], *manifest["cover_targets"]]:
+        text = (FORMAL / target["sby"]).read_text(encoding="utf-8")
+        assert re.search(rf"(?m)^mode\s+{re.escape(target['mode'])}\s*$", text)
+        assert re.search(rf"(?m)^depth\s+{target['depth']}\s*$", text)
+
+
+def test_critical_safety_and_crc_properties_have_reachable_witnesses() -> None:
+    witnesses = {
+        property_id
+        for target in _manifest()["cover_targets"]
+        for property_id in target["witnesses"]
+    }
+    assert {"P03", "P04", "P05", "P06"} <= witnesses
+
+
+def test_core_composes_detection_fill_and_active_bank() -> None:
+    source = (ROOT / "src/control/thermal_control_core.v").read_text(encoding="utf-8")
+    assert "formal_stale_preempt" in source
+    assert "formal_inactive_applied" in source
+    assert "formal_active_applied" in source
+    assert "global_fault <= global_fault || bmc_stale" in source
+    assert "safe_fill_value" in source
+
+
+def test_bad_crc_is_composed_through_target_engine() -> None:
+    harness = (FORMAL / "6400_transport_properties_formal.v").read_text(encoding="utf-8")
+    frame = (ROOT / "src/common/frame_rx.v").read_text(encoding="utf-8")
+    command = (ROOT / "src/transport/thermal_host_command.v").read_text(encoding="utf-8")
+    assert "bad_crc_quarantine" in harness
+    assert "formal_bad_crc_event_o" in frame
+    assert "target_celsius != $past(target_celsius)" in command
+    assert "u_frame_rx.formal_" not in harness
+
+
+def test_runner_is_fail_closed_and_commit_bound() -> None:
+    runner = (ROOT / "tools/run_6400_formal.py").read_text(encoding="utf-8")
+    assert "formal acceptance requires a clean worktree" in runner
+    assert "PROD2U_CONTAINER_DIGEST" in runner
+    assert '"source_tree_sha256"' in runner
+    assert '"bitstream_sha256": None' in runner

+ 3 - 0
tools/run-6400-formal.sh

@@ -0,0 +1,3 @@
+#!/bin/sh
+set -eu
+exec python3 "$(dirname "$0")/run_6400_formal.py" "$@"

+ 473 - 0
tools/run_6400_formal.py

@@ -0,0 +1,473 @@
+#!/usr/bin/env python3
+"""Run and bind the complete 6400 P01-P17 formal acceptance suite."""
+
+from __future__ import annotations
+
+import argparse
+from concurrent.futures import ThreadPoolExecutor
+from datetime import datetime, timezone
+import hashlib
+import json
+import os
+from pathlib import Path
+import re
+import shutil
+import subprocess
+import sys
+import time
+from typing import Any, Iterable
+
+
+ROOT = Path(__file__).resolve().parents[1]
+FORMAL_DIR = ROOT / "tests" / "formal"
+MANIFEST = FORMAL_DIR / "6400-properties.json"
+ENVIRONMENT_RECEIPT = ROOT / "receipts" / "environment" / "container-image.json"
+PROJECT_CONTRACT = ROOT / "projects" / "prod2u-6400-front-back" / "project.json"
+PROFILE_CONTRACT = ROOT / "products" / "6400-control" / "project.json"
+SOURCE_MANIFEST = ROOT / "products" / "6400-control" / "source-closure.json"
+DESIGN_LOCK = ROOT / "docs" / "architecture" / "6400-v1-design-lock.md"
+RECEIPT_SCHEMA = "prod2u-6400-formal-receipt-v1"
+
+
+def sha256_file(path: Path) -> str:
+    digest = hashlib.sha256()
+    with path.open("rb") as stream:
+        for block in iter(lambda: stream.read(1024 * 1024), b""):
+            digest.update(block)
+    return digest.hexdigest()
+
+
+def canonical_sha256(value: Any) -> str:
+    data = json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False)
+    return hashlib.sha256(data.encode("utf-8")).hexdigest()
+
+
+def run_text(argv: list[str], *, check: bool = True) -> str:
+    result = subprocess.run(
+        argv,
+        cwd=ROOT,
+        check=check,
+        text=True,
+        stdout=subprocess.PIPE,
+        stderr=subprocess.STDOUT,
+    )
+    return result.stdout.strip()
+
+
+def repository_state() -> dict[str, Any]:
+    commit = run_text(["git", "rev-parse", "HEAD"])
+    branch = run_text(["git", "branch", "--show-current"])
+    status_lines = [
+        line for line in run_text(
+            ["git", "status", "--porcelain=v1", "--untracked-files=all"]
+        ).splitlines()
+        if line
+    ]
+    return {
+        "commit": commit,
+        "branch": branch,
+        "clean": not status_lines,
+        "status_lines": status_lines,
+    }
+
+
+def contract_binding() -> dict[str, Any]:
+    paths = {
+        "project_contract": PROJECT_CONTRACT,
+        "profile_contract": PROFILE_CONTRACT,
+        "source_manifest": SOURCE_MANIFEST,
+        "design_lock": DESIGN_LOCK,
+        "formal_manifest": MANIFEST,
+    }
+    return {
+        name: {"path": path.relative_to(ROOT).as_posix(), "sha256": sha256_file(path)}
+        for name, path in paths.items()
+    }
+
+
+def source_binding() -> dict[str, Any]:
+    manifest = json.loads(SOURCE_MANIFEST.read_text(encoding="utf-8"))
+    entries: list[dict[str, str]] = []
+    for relative in manifest["sources"]:
+        path = ROOT / relative
+        if not path.is_file():
+            raise FileNotFoundError(f"source closure entry is missing: {relative}")
+        entries.append({"path": relative, "sha256": sha256_file(path)})
+    return {
+        "manifest_sha256": sha256_file(SOURCE_MANIFEST),
+        "source_count": len(entries),
+        "sources": entries,
+        "source_tree_sha256": canonical_sha256(entries),
+    }
+
+
+def sby_files(sby_path: Path) -> list[Path]:
+    files: list[Path] = []
+    in_files = False
+    for raw in sby_path.read_text(encoding="utf-8").splitlines():
+        line = raw.strip()
+        if line == "[files]":
+            in_files = True
+            continue
+        if in_files and line.startswith("["):
+            break
+        if not in_files or not line or line.startswith("#"):
+            continue
+        source_token = line.split()[-1]
+        source = (sby_path.parent / source_token).resolve()
+        if not source.is_file():
+            raise FileNotFoundError(f"formal input is missing: {source}")
+        files.append(source)
+    return files
+
+
+def formal_input_binding(targets: Iterable[dict[str, Any]]) -> dict[str, Any]:
+    values: list[dict[str, Any]] = []
+    for target in targets:
+        sby_path = FORMAL_DIR / target["sby"]
+        files = [
+            {"path": path.relative_to(ROOT).as_posix(), "sha256": sha256_file(path)}
+            for path in sby_files(sby_path)
+        ]
+        values.append({
+            "name": target["name"],
+            "mode": target["mode"],
+            "depth": target["depth"],
+            "tasks": target["tasks"],
+            "sby": {
+                "path": sby_path.relative_to(ROOT).as_posix(),
+                "sha256": sha256_file(sby_path),
+            },
+            "files": files,
+            "input_sha256": canonical_sha256({"sby": sha256_file(sby_path), "files": files}),
+        })
+    return {"targets": values, "sha256": canonical_sha256(values)}
+
+
+def executable_evidence(name: str, version_args: list[str], version_override: str = "") -> dict[str, Any]:
+    executable = shutil.which(name)
+    failures: list[str] = []
+    output = ""
+    if executable is None:
+        return {
+            "name": name,
+            "path": "",
+            "sha256": "0" * 64,
+            "version": "",
+            "status": "fail",
+            "failures": [f"tool_missing:{name}"],
+        }
+    result = subprocess.run(
+        [executable, *version_args],
+        cwd=ROOT,
+        check=False,
+        text=True,
+        stdout=subprocess.PIPE,
+        stderr=subprocess.STDOUT,
+    )
+    output = result.stdout.strip()
+    if result.returncode != 0:
+        failures.append(f"tool_version_probe_failed:{name}:{result.returncode}")
+    version = version_override or next((line.strip() for line in output.splitlines() if line.strip()), "")
+    if not version:
+        failures.append(f"tool_version_missing:{name}")
+    return {
+        "name": name,
+        "path": executable,
+        "sha256": sha256_file(Path(executable).resolve()),
+        "version": version,
+        "status": "pass" if not failures else "fail",
+        "failures": failures,
+    }
+
+
+def toolchain_evidence(environment: dict[str, Any]) -> dict[str, Any]:
+    tools = [
+        executable_evidence("sby", ["-h"], f"git:{environment['sby_commit']}"),
+        executable_evidence("yosys", ["-V"]),
+        executable_evidence("boolector", ["--version"]),
+        executable_evidence("z3", ["--version"]),
+    ]
+    failures = [failure for tool in tools for failure in tool["failures"]]
+    return {"status": "pass" if not failures else "fail", "tools": tools, "failures": failures}
+
+
+def compiled_property_ids(workdir: Path) -> tuple[list[str], list[str], str, list[str]]:
+    design_json = workdir / "model" / "design.json"
+    assertions: set[str] = set()
+    covers: set[str] = set()
+    failures: list[str] = []
+    try:
+        payload = json.loads(design_json.read_text(encoding="utf-8"))
+        modules = payload.get("modules", [])
+        for module in modules if isinstance(modules, list) else []:
+            module_name = str(module.get("name", ""))
+            for cell_sort in module.get("cell_sorts", []):
+                for cell in cell_sort.get("cells", []):
+                    name = str(cell.get("name", ""))
+                    flavor = cell.get("parameters", {}).get("FLAVOR")
+                    if not module_name or not name:
+                        continue
+                    identifier = f"{module_name}.{name}"
+                    if flavor == "assert":
+                        assertions.add(identifier)
+                    elif flavor == "cover":
+                        covers.add(identifier)
+    except (OSError, UnicodeError, json.JSONDecodeError, AttributeError, TypeError) as exc:
+        failures.append(f"compiled_properties_unavailable:{type(exc).__name__}")
+    design_hash = sha256_file(design_json) if design_json.is_file() else "0" * 64
+    return sorted(assertions), sorted(covers), design_hash, failures
+
+
+def cover_hit_ids(workdir: Path) -> list[str]:
+    pattern = re.compile(r"(?i)reached cover statement\s+(\S+)\s+at\s+\S+:\d+")
+    hits: set[str] = set()
+    for path in (workdir / "PASS", workdir / "logfile.txt"):
+        if not path.is_file():
+            continue
+        for value in pattern.findall(path.read_text(encoding="utf-8", errors="replace")):
+            if value.casefold() != "in":
+                hits.add(value)
+    return sorted(hits)
+
+
+def relative_artifacts(workdir: Path, pattern: str) -> list[dict[str, str]]:
+    return [
+        {"path": path.relative_to(ROOT).as_posix(), "sha256": sha256_file(path)}
+        for path in sorted(workdir.rglob(pattern))
+        if path.is_file()
+    ]
+
+
+def run_job(job: dict[str, Any], run_root: Path, timeout: int) -> dict[str, Any]:
+    target = job["target"]
+    task = job["task"]
+    suffix = task if task != "default" else "default"
+    workdir = run_root / "work" / target["name"] / suffix
+    workdir.parent.mkdir(parents=True, exist_ok=True)
+    sby_path = FORMAL_DIR / target["sby"]
+    command = [shutil.which("sby") or "sby", "-f", "-d", str(workdir), sby_path.name]
+    if task != "default":
+        command.append(task)
+    started = time.monotonic()
+    timed_out = False
+    try:
+        process = subprocess.run(
+            command,
+            cwd=FORMAL_DIR,
+            check=False,
+            text=True,
+            stdout=subprocess.PIPE,
+            stderr=subprocess.STDOUT,
+            timeout=timeout,
+        )
+        returncode: int | None = process.returncode
+        output = process.stdout
+    except subprocess.TimeoutExpired as exc:
+        timed_out = True
+        returncode = None
+        output = exc.stdout.decode(errors="replace") if isinstance(exc.stdout, bytes) else (exc.stdout or "")
+    duration = time.monotonic() - started
+    process_log = workdir.parent / f"{suffix}.process.log"
+    process_log.write_text(output, encoding="utf-8")
+    status_file = workdir / "status"
+    status_raw = status_file.read_text(encoding="utf-8", errors="replace").strip() if status_file.is_file() else ""
+    status_token = status_raw.split()[0].upper() if status_raw else "MISSING"
+    logfile = workdir / "logfile.txt"
+    log_text = logfile.read_text(encoding="utf-8", errors="replace") if logfile.is_file() else ""
+    assertions, covers, design_hash, failures = compiled_property_ids(workdir)
+    if timed_out:
+        failures.append("timeout")
+    if returncode != 0:
+        failures.append(f"returncode:{returncode}")
+    if status_token != "PASS":
+        failures.append(f"status:{status_token}")
+    if not (workdir / "PASS").is_file() or (workdir / "FAIL").exists():
+        failures.append("pass_fail_marker_mismatch")
+    if "DONE (PASS" not in log_text:
+        failures.append("sby_done_pass_missing")
+    if target["mode"] == "prove":
+        if not assertions:
+            failures.append("compiled_assertions_missing")
+        if "successful proof by k-induction" not in log_text:
+            failures.append("k_induction_evidence_missing")
+        expected_solver = task
+        if not re.search(rf"(?im)Solver:\s*{re.escape(expected_solver)}\b", log_text):
+            failures.append(f"solver_observation_missing:{expected_solver}")
+    else:
+        hits = cover_hit_ids(workdir)
+        if not covers:
+            failures.append("compiled_covers_missing")
+        if set(hits) != set(covers):
+            failures.append(f"cover_hit_set_mismatch:{len(hits)}/{len(covers)}")
+        if not relative_artifacts(workdir, "*.vcd"):
+            failures.append("cover_trace_missing")
+    return {
+        "name": target["name"],
+        "task": task,
+        "mode": target["mode"],
+        "depth": target["depth"],
+        "status": "pass" if not failures else "fail",
+        "returncode": returncode,
+        "timed_out": timed_out,
+        "duration_seconds": round(duration, 3),
+        "command": command,
+        "workdir": workdir.relative_to(ROOT).as_posix(),
+        "process_log": {
+            "path": process_log.relative_to(ROOT).as_posix(),
+            "sha256": sha256_file(process_log),
+        },
+        "sby_log_sha256": sha256_file(logfile) if logfile.is_file() else "0" * 64,
+        "compiled_design_sha256": design_hash,
+        "compiled_assertion_count": len(assertions),
+        "compiled_cover_count": len(covers),
+        "cover_hit_ids": cover_hit_ids(workdir) if target["mode"] == "cover" else [],
+        "traces": relative_artifacts(workdir, "*.vcd") if target["mode"] == "cover" else [],
+        "evidence_failures": failures,
+    }
+
+
+def validate_manifest(manifest: dict[str, Any]) -> None:
+    properties = manifest.get("properties", [])
+    ids = [entry.get("id") for entry in properties]
+    expected = [f"P{index:02d}" for index in range(1, 18)]
+    if ids != expected:
+        raise ValueError(f"formal property IDs must be exactly {expected}, got {ids}")
+    proof_targets = manifest.get("proof_targets", [])
+    if not proof_targets:
+        raise ValueError("proof_targets is empty")
+    harnesses = {entry["sby"] for entry in proof_targets}
+    if any(entry.get("harness") not in harnesses for entry in properties):
+        raise ValueError("a P01-P17 property references a non-proof harness")
+    for target in [*proof_targets, *manifest.get("cover_targets", [])]:
+        sby_path = FORMAL_DIR / target["sby"]
+        if not sby_path.is_file():
+            raise FileNotFoundError(sby_path)
+        text = sby_path.read_text(encoding="utf-8")
+        if not re.search(rf"(?m)^mode\s+{re.escape(target['mode'])}\s*$", text):
+            raise ValueError(f"mode mismatch in {sby_path.name}")
+        if not re.search(rf"(?m)^depth\s+{target['depth']}\s*$", text):
+            raise ValueError(f"depth mismatch in {sby_path.name}")
+
+
+def main(argv: list[str] | None = None) -> int:
+    parser = argparse.ArgumentParser()
+    parser.add_argument("--run-id")
+    parser.add_argument("--jobs", type=int, default=4)
+    parser.add_argument("--timeout-seconds", type=int, default=600)
+    args = parser.parse_args(argv)
+    timestamp = datetime.now(timezone.utc)
+    run_id = args.run_id or timestamp.strftime("6400-formal-%Y%m%dT%H%M%SZ")
+    if not re.fullmatch(r"[A-Za-z0-9._-]+", run_id):
+        parser.error("run ID may contain only letters, digits, dot, underscore, and hyphen")
+    run_root = ROOT / "receipts" / "6400-formal" / run_id
+    if run_root.exists():
+        parser.error(f"run directory already exists: {run_root}")
+    run_root.mkdir(parents=True)
+
+    manifest = json.loads(MANIFEST.read_text(encoding="utf-8"))
+    validate_manifest(manifest)
+    repository = repository_state()
+    if not repository["clean"]:
+        raise RuntimeError("formal acceptance requires a clean worktree")
+    environment = json.loads(ENVIRONMENT_RECEIPT.read_text(encoding="utf-8"))
+    observed_digest = os.environ.get("PROD2U_CONTAINER_DIGEST", "")
+    observed_image_id = os.environ.get("PROD2U_CONTAINER_IMAGE_ID", "")
+    if observed_digest != environment.get("digest") or observed_image_id != environment.get("image_id"):
+        raise RuntimeError("container identity environment does not match the pinned image receipt")
+    tools = toolchain_evidence(environment)
+    if tools["status"] != "pass":
+        raise RuntimeError(f"formal toolchain evidence failed: {tools['failures']}")
+
+    targets = [*manifest["proof_targets"], *manifest["cover_targets"]]
+    formal_inputs = formal_input_binding(targets)
+    jobs = [
+        {"target": target, "task": task}
+        for target in targets
+        for task in (target["tasks"] or ["default"])
+    ]
+    with ThreadPoolExecutor(max_workers=max(1, min(args.jobs, len(jobs)))) as executor:
+        results = list(executor.map(lambda job: run_job(job, run_root, args.timeout_seconds), jobs))
+
+    result_by_target: dict[str, list[dict[str, Any]]] = {}
+    for result in results:
+        result_by_target.setdefault(result["name"], []).append(result)
+    target_results = [
+        {
+            "name": target["name"],
+            "sby": target["sby"],
+            "mode": target["mode"],
+            "depth": target["depth"],
+            "status": "pass" if all(item["status"] == "pass" for item in result_by_target[target["name"]]) else "fail",
+            "tasks": result_by_target[target["name"]],
+        }
+        for target in targets
+    ]
+    target_status = {entry["sby"]: entry["status"] for entry in target_results}
+    result_status_by_name = {entry["name"]: entry["status"] for entry in target_results}
+    witness_status = {
+        property_id: result_status_by_name.get(target["name"], "fail")
+        for target in manifest["cover_targets"]
+        for property_id in target.get("witnesses", [])
+    }
+    properties = []
+    for entry in manifest["properties"]:
+        proof_status = target_status.get(entry["harness"], "fail")
+        witness = witness_status.get(entry["id"], "not_required")
+        properties.append({
+            **entry,
+            "proof_status": proof_status,
+            "witness_status": witness,
+            "status": "pass" if proof_status == "pass" and witness in {"pass", "not_required"} else "fail",
+        })
+    passed = all(entry["status"] == "pass" for entry in target_results)
+    receipt = {
+        "schema": RECEIPT_SCHEMA,
+        "status": "pass" if passed else "fail",
+        "verification_layer": "formal",
+        "run_id": run_id,
+        "started_utc": timestamp.isoformat(),
+        "finished_utc": datetime.now(timezone.utc).isoformat(),
+        "command": [sys.executable, str(Path(__file__).relative_to(ROOT)), *sys.argv[1:]],
+        "repository": repository,
+        "contracts": contract_binding(),
+        "source_binding": source_binding(),
+        "formal_inputs": formal_inputs,
+        "container": {
+            "image": environment["image"],
+            "digest": observed_digest,
+            "image_id": observed_image_id,
+            "receipt_sha256": sha256_file(ENVIRONMENT_RECEIPT),
+            "sby_commit": environment["sby_commit"],
+        },
+        "toolchain": tools,
+        "properties": properties,
+        "targets": target_results,
+        "applicable_bitstream": False,
+        "bitstream_sha256": None,
+        "physical_evidence": {
+            "hardware": "not_run",
+            "jtag": "not_run",
+            "com": "not_run",
+            "real_bmc": "not_run",
+            "real_rs232": "not_run",
+            "real_ttl_uart": "not_run",
+            "real_thermal_performance": "not_run",
+        },
+        "authority_boundary": "Formal proves RTL properties and reachable witnesses only; it is not TD, bitstream, hardware, or thermal evidence.",
+    }
+    receipt_path = run_root / "formal-receipt.json"
+    receipt_path.write_text(json.dumps(receipt, indent=2, sort_keys=True) + "\n", encoding="utf-8")
+    print(json.dumps({
+        "status": receipt["status"],
+        "run_id": run_id,
+        "receipt": receipt_path.relative_to(ROOT).as_posix(),
+        "receipt_sha256": sha256_file(receipt_path),
+        "target_count": len(target_results),
+        "task_count": len(results),
+    }, indent=2, sort_keys=True))
+    return 0 if passed else 1
+
+
+if __name__ == "__main__":
+    raise SystemExit(main())