Skip to content

Commit d1a3bac

Browse files
Repair batched evaluation proof (#833)
Signed-off-by: John Kastner <jkastner@amazon.com>
1 parent 9e7be7e commit d1a3bac

File tree

8 files changed

+52
-23
lines changed

8 files changed

+52
-23
lines changed

cedar-lean/Cedar/Thm.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ import Cedar.Thm.Typechecking
2222
import Cedar.Thm.Validation
2323
import Cedar.Thm.WellTyped
2424
import Cedar.Thm.TPE
25+
import Cedar.Thm.BatchedEvaluator
2526
import Cedar.Thm.WellTypedVerification

cedar-lean/Cedar/Thm/Authorization.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
import Cedar.Spec
1818
import Cedar.Thm.Authorization.Authorizer
19+
import Cedar.Thm.Authorization.PolicySlice
20+
import Cedar.Thm.Authorization.Evaluator
1921

2022
/-! This file contains basic theorems about Cedar's authorizer. -/
2123

cedar-lean/Cedar/Thm/TPE/BatchedEvaluator.lean renamed to cedar-lean/Cedar/Thm/BatchedEvaluator.lean

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ in the code base at the moment.
2929
-/
3030
abbrev EntityLoader.WellBehaved (store: Entities) (loader: EntityLoader) : Prop :=
3131
∀ s, s ⊆ (loader s).keys ∧
32-
EntitiesRefine store ((loader s).mapOnValues EntityDataOption.asPartial)
32+
EntitiesRefine store ((loader s).mapOnValues MaybeEntityData.asPartial)
3333

3434
theorem as_partial_request_refines {req : Request} :
3535
RequestRefines req req.asPartialRequest := by
@@ -51,12 +51,12 @@ theorem any_refines_empty_entities :
5151
intro a e₂ h₁
5252
contradiction
5353

54-
-- Helper lemma for map append refinementSlicedEntities
54+
-- Helper lemma for map append refinement
5555
theorem entities_refine_append (es : Entities) (m1 m2 : PartialEntities) :
5656
EntitiesRefine es m1 → EntitiesRefine es m2 → EntitiesRefine es (m2 ++ m1) := by
5757
intro h1 h2
5858
unfold EntitiesRefine
59-
intro a e₂ h_findSlicedEntities
59+
intro a e₂ h_find
6060
rw [Map.find?_append] at h_find
6161
cases h_case : m2.find? a with
6262
| some e₂' =>
@@ -67,21 +67,21 @@ theorem entities_refine_append (es : Entities) (m1 m2 : PartialEntities) :
6767
rw [h_eq]
6868
exact h2 a e₂' h_case
6969
| none =>
70-
have h_find1 : m1.find? a = some e₂ := byMaybeEntityData.asPartial
70+
have h_find1 : m1.find? a = some e₂ := by
7171
rw [h_case] at h_find
72-
simp only [Option.none_or] at h_fMaybeEntityData.asPartial
73-
rw [h_find]MaybeEntityData.asPartial
72+
simp only [Option.none_or] at h_find
73+
rw [h_find]
7474
exact h1 a e₂ h_find1
7575

7676

7777
theorem direct_request_and_entities_refine (req : Request) (es : Entities) :
7878
RequestAndEntitiesRefine req es req.asPartialRequest es.asPartial := by
7979
constructor
80-
· exact as_partiaMaybeEntityData.asPartial_refines
80+
· exact as_partial_request_refines
8181
· unfold EntitiesRefine Entities.asPartial
8282
intro uid data₂ h_find
8383
have h_mapOnValues := Map.find?_mapOnValues_some' EntityData.asPartial h_find
84-
obtain ⟨data₁, h_find₁, h_eq⟩ := h_MaybeEntityData.asPartial
84+
obtain ⟨data₁, h_find₁, h_eq⟩ := h_mapOnValues
8585
exists data₁
8686
exact ⟨h_find₁,
8787
by rw [h_eq]; apply PartialIsValid.some; rfl,
@@ -105,8 +105,8 @@ theorem batched_eval_loop_eq_evaluate
105105
case h_1 => simp only
106106
case h_2 iters n=>
107107
let toLoad := (Set.filter (fun uid => (Map.find? current_store uid).isNone) x.allLiteralUIDs)
108-
let newEntities := ((loader toLoad).mapOnValues EntityDataOption.asPartial)
109-
let newStore :=SlicedEntitiesrent_store
108+
let newEntities := ((loader toLoad).mapOnValues MaybeEntityData.asPartial)
109+
let newStore := newEntities ++ current_store
110110

111111
have h₀₂ := h₀
112112
specialize h₀₂ toLoad
@@ -120,7 +120,7 @@ theorem batched_eval_loop_eq_evaluate
120120
· unfold RequestAndEntitiesRefine at h₂
121121
exact h₂.right
122122
· apply h₅
123-
let newRes := SlicedEntitiesasPartialRequest newStore
123+
let newRes := TPE.evaluate x req.asPartialRequest newStore
124124
have h₇ : (Residual.evaluate newRes req es).toOption = (Residual.evaluate x req es).toOption := by
125125
subst newRes
126126
rw [← partial_evaluate_is_sound h₁ h₃ h₆]

cedar-lean/Cedar/Thm/Data.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
limitations under the License.
1515
-/
1616

17+
import Cedar.Thm.Data.Applicative
18+
import Cedar.Thm.Data.Option
1719
import Cedar.Thm.Data.Control
1820
import Cedar.Thm.Data.List
1921
import Cedar.Thm.Data.LT

cedar-lean/Cedar/Thm/TPE.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import Cedar.Thm.TPE.PreservesTypeOf
2525
import Cedar.Thm.TPE.Policy
2626
import Cedar.Thm.TPE.Authorizer
2727
import Cedar.Thm.TPE.WellTyped
28+
import Cedar.Thm.TPE.WellTypedCases
29+
import Cedar.Thm.TPE.ErrorFree
2830
import Cedar.Thm.Validation
2931
import Cedar.Thm.Authorization
3032

cedar-lean/Cedar/Thm/Validation.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import Cedar.Thm.Validation.Validator
2323
import Cedar.Thm.Validation.RequestEntityValidation
2424
import Cedar.Thm.Validation.EnvironmentValidation
2525
import Cedar.Thm.Validation.Levels
26+
import Cedar.Thm.Validation.SubstituteAction
27+
import Cedar.Thm.Validation.Typechecker
2628

2729
/-!
2830
This file contains the top-level correctness properties for the Cedar validator.

cedar-lean/Cedar/Thm/Validation/Typechecker.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ import Cedar.Thm.Validation.Typechecker.Record
2525
import Cedar.Thm.Validation.Typechecker.Set
2626
import Cedar.Thm.Validation.Typechecker.Or
2727
import Cedar.Thm.Validation.Typechecker.UnaryApp
28+
import Cedar.Thm.Validation.Typechecker.LUB
29+
import Cedar.Thm.Validation.Typechecker.WF
30+
import Cedar.Thm.Validation.Typechecker.Basic
31+
import Cedar.Thm.Validation.Typechecker.Types
2832

2933
/-!
3034
This file contains useful definitions and lemmas about the `Typechecker` functions.

cedar-lean/lakefile.lean

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,39 @@ lean_exe CedarSymTests where
6262
lean_exe Cli where
6363
root := `Cli.Main
6464

65+
-- Check that a .lean file imports all files in its corresponding directory
66+
partial def checkThmFile (module : String) (paths : List System.FilePath) : IO Nat := do
67+
let path := paths.head!
68+
let dir := path.withExtension ""
69+
if ← dir.isDir then
70+
let contents ← paths.mapM IO.FS.readFile
71+
let mod_files ← dir.readDir
72+
let mut exitCode := 0
73+
74+
for file in mod_files.toList do
75+
let file_name := file.fileName
76+
if file_name.endsWith ".lean" then
77+
let subModule := s!"{module}.{file_name.dropRight 5}"
78+
let expectedImport := s!"import {subModule}\n"
79+
if contents.all λ content => (content.replace expectedImport "" == content) then
80+
IO.println s!"{path} missing import: {expectedImport}"
81+
exitCode := 1
82+
let subExitCode ← checkThmFile subModule [dir / file_name]
83+
if subExitCode != 0 then
84+
exitCode := subExitCode
85+
86+
return exitCode
87+
else
88+
return 0
89+
6590
/--
66-
Check that Cedar.Thm imports all top level proofs.
91+
Check that Cedar.Thm imports all top level proofs recursively.
6792
6893
USAGE:
6994
lake run checkThm
7095
lake lint
7196
-/
7297
@[lint_driver]
7398
script checkThm do
74-
let thm ← IO.FS.readFile ⟨"Cedar/Thm.lean"
75-
let symcc ← IO.FS.readFile ⟨"SymCC.lean"
76-
let dir ← System.FilePath.readDir ⟨"Cedar/Thm/"
77-
for entry in dir.toList do
78-
let fn := entry.fileName
79-
if fn.endsWith ".lean" then
80-
let ln := s!"import Cedar.Thm.{fn.dropRight 5}\n"
81-
if thm.replace ln "" == thm && symcc.replace ln "" == symcc then
82-
IO.println s!"Neither Cedar.Thm nor SymCC imports Cedar/Thm/{fn}"
83-
return 1
84-
return 0
99+
let exitCode ← checkThmFile "Cedar.Thm" [⟨"Cedar/Thm.lean"⟩, ⟨"SymCC.lean"⟩]
100+
return ⟨exitCode⟩

0 commit comments

Comments
 (0)