@@ -11,103 +11,69 @@ open LeanRV64D.Functions BitVec
1111namespace Add
1212
1313variable
14- (Main : Vector (Fin BB) 33 )
14+ (Main : Vector (Fin KB) 34 )
1515 (s : SailState)
1616 (cstrs : (constraints Main).allHold)
17- (h_is_real : Main[32 ] = 1 )
17+ (h_is_real : Main[33 ] = 1 )
1818
1919noncomputable def spec_add (rs2 rs1 rd : regidx) : SailM Unit := do
2020 Sail.writeReg Register.nextPC ((← Sail.readReg Register.PC) + 4 #64 )
2121 _ ← execute_RTYPE rs2 rs1 rd rop.ADD
2222 pure ()
2323
24- def sp1_op_a : BitVec 5 :=
25- by
26- refine BitVec.ofNatLT Main[6 ] ?_
27- simp
28- show Main[6 ] < 32
24+ def sp1_op_a : BitVec 5 := BitVec.ofNat 5 Main[6 ]
2925
30- have reader_cstrs := by
31- simp [SP1ConstraintList.allHold, constraints, SP1Constraint.toProp] at cstrs
32- exact cstrs.2 .2 .1
26+ def sp1_op_b : BitVec 5 := BitVec.ofNat 5 Main[14 ]
3327
34- clear cstrs
35- simp [RTypeReader.constraints, h_is_real, Opcode.ofNat, Nat.ble, Nat.beq, SP1Constraint.toProp] at reader_cstrs
36-
37- exact reader_cstrs.1 .2 .1
38-
39- def sp1_op_b : BitVec 5 :=
40- by
41- refine BitVec.ofNatLT Main[14 ] ?_
42- simp
43- show Main[14 ] < 32
44-
45- have reader_cstrs := by
46- simp [SP1ConstraintList.allHold, constraints, SP1Constraint.toProp] at cstrs
47- exact cstrs.2 .2 .1
48-
49- clear cstrs
50- simp [RTypeReader.constraints, h_is_real, Opcode.ofNat, Nat.ble, Nat.beq, SP1Constraint.toProp] at reader_cstrs
51-
52- exact reader_cstrs.1 .1 .1
53-
54- def sp1_op_c : BitVec 5 :=
55- by
56- refine BitVec.ofNatLT Main[21 ] ?_
57- simp
58- show Main[21 ] < 32
59-
60- have reader_cstrs := by
61- simp [SP1ConstraintList.allHold, constraints, SP1Constraint.toProp] at cstrs
62- exact cstrs.2 .2 .1
63-
64- clear cstrs
65- simp [RTypeReader.constraints, h_is_real, Opcode.ofNat, Nat.ble, Nat.beq, SP1Constraint.toProp] at reader_cstrs
66-
67- exact reader_cstrs.1 .1 .2
28+ def sp1_op_c : BitVec 5 := BitVec.ofNat 5 Main[21 ]
6829
6930def sp1_add : SailM Unit := do
70- let op_a := sp1_op_a Main cstrs h_is_real
31+ let op_a := sp1_op_a Main
7132 Sail.writeReg Register.nextPC (Word.toBitVec64 #v[Main[3 ] + 4 , Main[4 ], Main[5 ], 0 ])
72- Sail.write_reg op_a (Word.toBitVec64 #v[Main[28 ], Main[29 ], Main[30 ], Main[31 ]])
33+ Sail.write_reg op_a (Word.toBitVec64 #v[Main[29 ], Main[30 ], Main[31 ], Main[32 ]])
7334
7435open Sail
7536
7637set_option pp.parens true in
7738theorem correct_add
39+ (Main : Vector (Fin KB) 34 )
40+ (s : SailState)
41+ (cstrs : (constraints Main).allHold)
42+ (h_is_real : Main[33 ] = 1 )
7843 (state_cstrs : (constraints Main).initialState s) :
79- let op_c := sp1_op_c Main cstrs h_is_real
80- let op_b := sp1_op_b Main cstrs h_is_real
81- let op_a := sp1_op_a Main cstrs h_is_real
82- (spec_add (.Regidx op_c) (.Regidx op_b) (.Regidx op_a)).run s = (sp1_add Main cstrs h_is_real ).run s
44+ let op_c := sp1_op_c Main
45+ let op_b := sp1_op_b Main
46+ let op_a := sp1_op_a Main
47+ (spec_add (.Regidx op_c) (.Regidx op_b) (.Regidx op_a)).run s = (sp1_add Main).run s
8348 := by
84- simp [SP1ConstraintList.initialState, constraints, SP1Constraint.toStateProp, List.Forall, AddOperation.constraints, CPUState.constraints, RTypeReader.constraints, h_is_real ] at state_cstrs
49+ simp [SP1ConstraintList.initialState, constraints, SP1Constraint.toStateProp, List.Forall, AddOperation.constraints, CPUState.constraints, RTypeReader.constraints] at state_cstrs
8550 obtain ⟨read_pc, trusted_instr_state, _, read_op_b, read_op_c⟩ := state_cstrs
8651 simp [constraints] at cstrs
8752 obtain ⟨add_op_cstrs, cpu_cstrs, reader_cstrs, rest⟩ := cstrs
8853 rw [CPUState.allHold_constraints_iff_is_real h_is_real] at cpu_cstrs
8954 rw [RTypeReader.allHold_constraints_iff_is_real h_is_real] at reader_cstrs
90- obtain ⟨ trusted_instr_prop, _, _, _, _, _, _, ⟨ ⟨ _, _, ⟨ _, is_U64_b, is_U64_c ⟩ ⟩, _ ⟩⟩ := reader_cstrs
55+ simp [Opcode.ofNat, Nat.ble] at reader_cstrs
56+ obtain ⟨ trusted_instr_prop, _, _, _, _, _, _, _, ⟨ ⟨ _, _, ⟨ _, is_U64_b, is_U64_c ⟩ ⟩, _ ⟩⟩ := reader_cstrs
9157 simp [Opcode.ofNat, Nat.ble] at trusted_instr_state trusted_instr_prop
9258
9359 rw [h_is_real] at *
9460 apply AddOperation.spec is_U64_b is_U64_c at add_op_cstrs
9561 obtain ⟨ is_U64_val, is_add ⟩ := add_op_cstrs
96- simp at *
62+ simp [BitVec.ofNatLT_eq_ofNat] at *
9763
9864 -- Now the monadic manipulation
9965 simp [spec_add, sp1_add, execute, execute_RTYPE']
10066 rw [run_readReg, read_pc]
10167 simp [sp1_op_b, read_op_b (by omega)]
10268 simp [sp1_op_c, read_op_c (by omega)]
10369 simp [sp1_op_a]
104- rw [BabyBear .add4_into_pc_ofNat (by omega)]
70+ rw [KoalaBear .add4_into_pc_ofNat (by omega)]
10571
10672 by_cases h_is_op_a_0 : Main[6 ] = 0 <;> simp_all
10773 . rw [← is_add]
10874 simp [Word.toBitVec64, Word.toNat]
109- . rw [if_neg (by simpa [← BitVec.toNat_inj])]
110- rw [if_neg (by simpa [← BitVec.toNat_inj])]
75+ . rw [if_neg (by simp [← BitVec.toNat_inj]; omega )]
76+ rw [if_neg (by simp [← BitVec.toNat_inj]; omega )]
11177 simp [Word.toBitVec64, Word.toNat]
11278 rfl
11379
0 commit comments