-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Level checking implementation and proof (WIP) #533
Draft
john-h-kastner-aws
wants to merge
60
commits into
main
Choose a base branch
from
levels-checking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
61a1442
Initial level impl
john-h-kastner-aws ded0e6f
proof for `if` at level `0`
john-h-kastner-aws c7ad783
iwp
john-h-kastner-aws 937fc95
tweak ite
john-h-kastner-aws 4206195
reorg
john-h-kastner-aws cd611a0
wip
john-h-kastner-aws a94d440
wip
john-h-kastner-aws ba9a17c
wip
john-h-kastner-aws e66599b
reorg files
john-h-kastner-aws d5261cc
tidy
john-h-kastner-aws ea104a4
hasattr
john-h-kastner-aws 0b64945
work on reachable_attr_step
john-h-kastner-aws f18e418
comments
john-h-kastner-aws ae34a26
introduce lemma to clean up proof
john-h-kastner-aws 383e6ba
more cases
john-h-kastner-aws a56607b
tidy
john-h-kastner-aws 2c3c037
tidy
john-h-kastner-aws f2158f8
reorg
john-h-kastner-aws 7c52720
use match instead of if
john-h-kastner-aws 8970e0d
tidy: use `symm` a less
john-h-kastner-aws e4a5402
dont need that lemma anymore
john-h-kastner-aws 6b780af
tidy
john-h-kastner-aws f5b05c5
work on not_entities_then_not_slice
john-h-kastner-aws fac2ad4
slightly simplify `lit` case
john-h-kastner-aws 6670bd1
simplify var cae a little
john-h-kastner-aws 2232933
move lit inversion into litvar.lean
john-h-kastner-aws 44ff0df
unary app sound
john-h-kastner-aws 3633668
split checkLevel and checkRoot
john-h-kastner-aws 4b2413a
dead code
john-h-kastner-aws f195a31
rename checkRoot to notEntityLit and adjust lit to accept non-entity
john-h-kastner-aws 27600a4
add most of an inductive definition for level checking
john-h-kastner-aws f1eb7ba
prototype better record handling
john-h-kastner-aws 202a805
rename to `List.unionAll` to match emina's code
john-h-kastner-aws 4904872
nicer termination
john-h-kastner-aws 130813a
fix up proofs
john-h-kastner-aws 1686f02
fill hole in termination proof
john-h-kastner-aws 596bfe1
fill in record case for not_entity_lit_spec
john-h-kastner-aws 758be7d
finish check_level_checked_succ using inductive def
john-h-kastner-aws 49ef4b2
tweak
john-h-kastner-aws ce786bd
Show termination for record in checked_eval_entity_reachable
john-h-kastner-aws ba92360
fill in record details
john-h-kastner-aws 54540ae
nicer match syntax
john-h-kastner-aws e5fb2cd
stronger record inversion lemma
john-h-kastner-aws 83e7891
another record inversion lemma
john-h-kastner-aws a9d158f
fill in more record details
john-h-kastner-aws 4f22ed2
finish proof for equiv of inductive defs
john-h-kastner-aws 234a2d4
notes
john-h-kastner-aws 5fb9211
incorperate emina proof
john-h-kastner-aws cfcee35
split checked_eval_entity_reachable
john-h-kastner-aws d116e43
move lemma
john-h-kastner-aws f388aac
dont need that anymore
john-h-kastner-aws ca78ccb
fill in lemmas
john-h-kastner-aws 8a872f6
rename_inductive
john-h-kastner-aws af8e3ab
simp onlys
john-h-kastner-aws 8044bef
Merge remote-tracking branch 'origin/main' into levels-checking
john-h-kastner-aws 7b732d8
tidy
john-h-kastner-aws 1ce31eb
qualify names
john-h-kastner-aws 8ceece6
use mapUnion
john-h-kastner-aws afdc460
proof for `.and` and `.or`
john-h-kastner-aws 873a178
simplify proof for `or`
john-h-kastner-aws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/- | ||
Copyright Cedar Contributors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
https://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
-/ | ||
|
||
import Cedar.Spec.Value | ||
import Cedar.Spec.Entities | ||
import Cedar.Spec.Request | ||
import Cedar.Data.SizeOf | ||
|
||
/-! | ||
This file defines entity slicing at a level | ||
-/ | ||
|
||
namespace Cedar.Spec | ||
|
||
open Cedar.Data | ||
|
||
def Value.sliceEUIDs : Value → Set EntityUID | ||
| .prim (.entityUID uid) => Set.singleton uid | ||
| .record (Map.mk avs) => avs.attach₃.mapUnion λ e => e.val.snd.sliceEUIDs | ||
| .prim _ | set _ | .ext _ => ∅ | ||
|
||
def EntityData.sliceEUIDs (ed : EntityData) : Set EntityUID := | ||
ed.attrs.values.mapUnion Value.sliceEUIDs ∪ | ||
ed.tags.values.mapUnion Value.sliceEUIDs | ||
|
||
def Request.sliceEUIDs (r : Request) : Set EntityUID := | ||
Set.make [r.principal, r.action, r.resource] ∪ | ||
(Value.record r.context).sliceEUIDs | ||
|
||
def Entities.sliceAtLevel (es : Entities) (r : Request) (level : Nat) : Option Entities := do | ||
let slice ← sliceAtLevel r.sliceEUIDs level | ||
let slice ← slice.elts.mapM λ e => do some (e, ←(es.find? e)) | ||
some (Map.make slice) | ||
where | ||
sliceAtLevel (work : Set EntityUID) : Nat → Option (Set EntityUID) | ||
| 0 => some ∅ | ||
| level + 1 => do | ||
let eds ← work.elts.mapM es.find? | ||
let slice ← List.mapUnion id <$> eds.mapM (λ ed => sliceAtLevel ed.sliceEUIDs level) | ||
some (work ∪ slice) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/- | ||
Copyright Cedar Contributors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
https://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
-/ | ||
|
||
import Cedar.Spec | ||
import Cedar.Data | ||
import Cedar.Validation | ||
import Cedar.Thm.Validation.Typechecker | ||
import Cedar.Thm.Validation.Typechecker.Types | ||
|
||
import Cedar.Thm.Validation.Levels.CheckLevel | ||
import Cedar.Thm.Validation.Levels.IfThenElse | ||
import Cedar.Thm.Validation.Levels.GetAttr | ||
import Cedar.Thm.Validation.Levels.HasAttr | ||
import Cedar.Thm.Validation.Levels.UnaryApp | ||
import Cedar.Thm.Validation.Levels.And | ||
import Cedar.Thm.Validation.Levels.Or | ||
|
||
namespace Cedar.Thm | ||
|
||
open Cedar.Data | ||
open Cedar.Spec | ||
open Cedar.Validation | ||
|
||
theorem level_based_slicing_is_sound {e : Expr} {tx : TypedExpr} {n : Nat} {c c₁ : Capabilities} {env : Environment} {request : Request} {slice entities : Entities} | ||
(hs : slice = entities.sliceAtLevel request n) | ||
(hc : CapabilitiesInvariant c request entities) | ||
(hr : RequestAndEntitiesMatchEnvironment env request entities) | ||
(ht : typeOf e c env = Except.ok (tx, c₁)) | ||
(hl : checkLevel tx n) : | ||
evaluate e request entities = evaluate e request slice | ||
:= by | ||
cases e | ||
case lit => simp [evaluate] | ||
case var v => cases v <;> simp [evaluate] | ||
case ite c t e => | ||
have ihc := @level_based_slicing_is_sound c | ||
have iht := @level_based_slicing_is_sound t | ||
have ihe := @level_based_slicing_is_sound e | ||
exact level_based_slicing_is_sound_if hs hc hr ht hl ihc iht ihe | ||
case and e₁ e₂ => | ||
have ih₁ := @level_based_slicing_is_sound e₁ | ||
have ih₂ := @level_based_slicing_is_sound e₂ | ||
exact level_based_slicing_is_sound_and hs hc hr ht hl ih₁ ih₂ | ||
case or e₁ e₂ => | ||
have ih₁ := @level_based_slicing_is_sound e₁ | ||
have ih₂ := @level_based_slicing_is_sound e₂ | ||
exact level_based_slicing_is_sound_or hs hc hr ht hl ih₁ ih₂ | ||
case unaryApp op e => | ||
have ihe := @level_based_slicing_is_sound e | ||
exact level_based_slicing_is_sound_unary_app hs hc hr ht hl ihe | ||
case binaryApp => sorry -- includes tags cases which should follow the attr cases and `in` case which might be tricky | ||
case getAttr e _ => | ||
have ihe := @level_based_slicing_is_sound e | ||
exact level_based_slicing_is_sound_get_attr hs hc hr ht hl ihe | ||
case hasAttr e _ => | ||
have ihe := @level_based_slicing_is_sound e | ||
exact level_based_slicing_is_sound_has_attr hs hc hr ht hl ihe | ||
case set => sorry -- trivial recursive case maybe a little tricky | ||
case record => sorry -- likely to be tricky. Record cases are always hard, and here there might be an odd interaction with attribute access | ||
case call => sorry -- should be the same as set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
/- | ||
Copyright Cedar Contributors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
https://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
-/ | ||
|
||
import Cedar.Spec | ||
import Cedar.Data | ||
import Cedar.Validation | ||
import Cedar.Thm.Validation.Typechecker | ||
import Cedar.Thm.Validation.Typechecker.Basic | ||
import Cedar.Thm.Validation.Typechecker.IfThenElse | ||
import Cedar.Thm.Validation.Typechecker.Types | ||
import Cedar.Thm.Validation.Levels.Basic | ||
|
||
/-! | ||
This file proves that level checking for `.and` expressions is sound. | ||
-/ | ||
|
||
namespace Cedar.Thm | ||
|
||
open Cedar.Data | ||
open Cedar.Spec | ||
open Cedar.Validation | ||
|
||
theorem level_based_slicing_is_sound_and {e₁ e₂ : Expr} {n : Nat} {c₀ c₁: Capabilities} {env : Environment} {request : Request} {entities slice : Entities} | ||
(hs : slice = entities.sliceAtLevel request n) | ||
(hc : CapabilitiesInvariant c₀ request entities) | ||
(hr : RequestAndEntitiesMatchEnvironment env request entities) | ||
(ht : typeOf (.and e₁ e₂) c₀ env = Except.ok (tx, c₁)) | ||
(hl : checkLevel tx n = true) | ||
(ih₁ : TypedAtLevelIsSound e₁) | ||
(ih₂ : TypedAtLevelIsSound e₂) | ||
: evaluate (.and e₁ e₂) request entities = evaluate (.and e₁ e₂) request slice | ||
:= by | ||
replace ⟨ tx₁, bty, c', htx₁, hty₁, ht ⟩ := type_of_and_inversion ht | ||
have ⟨ hgc, v₁, he₁, hv₁⟩ := type_of_is_sound hc hr htx₁ | ||
rw [hty₁] at hv₁ | ||
split at ht | ||
case isTrue => | ||
replace ⟨ ht, _ ⟩ := ht | ||
subst tx bty | ||
replace hv₁ := instance_of_ff_is_false hv₁ | ||
subst v₁ | ||
unfold EvaluatesTo at he₁ | ||
simp [evaluate] | ||
simp [checkLevel] at hl | ||
specialize ih₁ hs hc hr htx₁ hl | ||
rw [←ih₁] | ||
rcases he₁ with he₁ | he₁ | he₁ | he₁ <;> | ||
simp [he₁, Result.as, Coe.coe, Value.asBool] | ||
case isFalse => | ||
replace ⟨ tx₂, bty₂, c₂, htx₂, hty₂, ht ⟩ := ht | ||
replace ⟨ b₁ , hv₁⟩ := instance_of_bool_is_bool hv₁ | ||
subst v₁ | ||
split at ht | ||
all_goals | ||
replace ⟨ ht, _ ⟩ := ht | ||
subst tx | ||
simp [evaluate] | ||
simp [checkLevel] at hl | ||
specialize ih₁ hs hc hr htx₁ (by simp [hl]) | ||
rw [←ih₁] | ||
rcases he₁ with he₁ | he₁ | he₁ | he₁ <;> | ||
simp [he₁, Result.as, Coe.coe, Value.asBool] | ||
cases b₁ <;> simp | ||
specialize hgc he₁ | ||
specialize ih₂ hs (capability_union_invariant hc hgc) hr htx₂ (by simp [hl]) | ||
simp [ih₂] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/- | ||
Copyright Cedar Contributors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
https://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
-/ | ||
|
||
import Cedar.Thm.Validation.Typechecker.Basic | ||
|
||
namespace Cedar.Thm | ||
|
||
/-! | ||
Basic definitions for levels proof | ||
-/ | ||
|
||
open Cedar.Spec | ||
open Cedar.Validation | ||
|
||
def TypedAtLevelIsSound (e : Expr) : Prop := ∀ {n : Nat} {tx : TypedExpr} {c c₁ : Capabilities} {env :Environment} {request : Request} {entities slice : Entities}, | ||
slice = entities.sliceAtLevel request n → | ||
CapabilitiesInvariant c request entities → | ||
RequestAndEntitiesMatchEnvironment env request entities → | ||
typeOf e c env = Except.ok (tx, c₁) → | ||
checkLevel tx n → | ||
evaluate e request entities = evaluate e request slice |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might also want to have another higher-level theorem (which calls this one) that doesn't mention capabilities. Something along these lines:
cedar-spec/cedar-lean/Cedar/Thm/Typechecking.lean
Line 34 in ead3c16