Skip to content

Validation soundness - Complete#383

Merged
khieta merged 35 commits intocedar-policy:mainfrom
bhaktishh:main
Jul 16, 2024
Merged

Validation soundness - Complete#383
khieta merged 35 commits intocedar-policy:mainfrom
bhaktishh:main

Conversation

@bhaktishh
Copy link
Copy Markdown
Contributor

@bhaktishh bhaktishh commented Jul 2, 2024

Description of changes:

This PR contains the proof of soundness of the Cedar validator.

@bhaktishh bhaktishh marked this pull request as draft July 2, 2024 20:23
@bhaktishh bhaktishh marked this pull request as ready for review July 2, 2024 20:23
Copy link
Copy Markdown
Contributor

@khieta khieta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start Bhakti! Thanks for the PR 🙂

It occurred to me that the partial evaluation proofs also have to reason about a substitution function (see Partial.Value.subst), so maybe you can look there for inspiration about how to verify substituteAction. Would also be great to unify these definitions, if at all possible.

Comment thread .gitignore Outdated
# We expect a copy of `cedar-policy/cedar` present in this directory, but do
# not track it in version control.
cedar/
/cedar-policy/cedar
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably don't want to change this since CI expects the cedar/ path

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so this line messes up stuff on macos because of case sensitivity; i can restore it but it just means the entire cedar-lean/cedar directory is ignored when i commit. i can just manually change it back and forth for now but it could be worth resolving

Comment thread cedar-lean/Cedar/Thm/Validation/Validator.lean Outdated
Comment thread cedar-lean/Cedar/Thm/Validation.lean Outdated
Comment thread cedar-lean/Cedar/Thm/Validation.lean Outdated
Comment thread cedar-lean/Cedar/Thm/Validation/Validator.lean Outdated
@khieta khieta requested review from cdisselkoen and emina July 3, 2024 17:14
Copy link
Copy Markdown
Contributor

@emina emina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR; very nice progress! :)

Some small comments included.


-- forM and mapM

theorem forM_mapM {α β : Type} (f : α → Except β PUnit) (xs : List α) (ys : List PUnit) :
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting nit: see here for a guide on indentation and formatting.

We would usually format this theorem statement so that the name of the theorem and arguments are on one line, the hypotheses and conclusion are indented and on separate lines, := by is on its own line and not indented, and the proof body is indented. For example:

theorem forM_mapM {α β : Type} (f : α → Except β PUnit) (xs : List α) (ys : List PUnit) :
  xs.mapM f = Except.ok ys → xs.forM f = Except.ok () 
:= by
  intro h₀
  rw [List.mapM_ok_iff_forall₂] at h₀
  sorry

Comment thread cedar-lean/Cedar/Thm/Validation.lean Outdated
Comment thread cedar-lean/Cedar/Thm/Validation/Validator.lean Outdated
complete proof of the soundness of the cedar validator
@bhaktishh bhaktishh changed the title Validation soundness - WIP Validation soundness - Complete Jul 11, 2024
@bhaktishh
Copy link
Copy Markdown
Contributor Author

This PR is now complete with the proof of soundness of the Cedar validator.

@bhaktishh bhaktishh requested review from emina and khieta July 11, 2024 21:53
Copy link
Copy Markdown
Contributor

@emina emina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice PR, thank you!

Left some minor comments on formatting but approving the PR otherwise.

Comment thread cedar-lean/Cedar/Thm/Data/List/Lemmas.lean Outdated
Comment thread cedar-lean/Cedar/Thm/Validation.lean Outdated
Comment thread cedar-lean/Cedar/Thm/Validation.lean Outdated
Comment thread cedar-lean/Cedar/Thm/Validation.lean Outdated
Comment thread cedar-lean/Cedar/Thm/Validation.lean Outdated
Comment thread cedar-lean/Cedar/Thm/Validation/Validator.lean Outdated
Comment thread cedar-lean/Cedar/Thm/Validation/Validator.lean Outdated
Comment thread cedar-lean/Cedar/Thm/Validation/Validator.lean Outdated
Comment thread cedar-lean/Cedar/Thm/Validation/Validator.lean Outdated
Comment thread cedar-lean/Cedar/Thm/Validation/Validator.lean Outdated
Copy link
Copy Markdown
Contributor

@emina emina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Copy link
Copy Markdown
Contributor

@khieta khieta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the hard work 🙂 Left a couple minor comments on naming

Comment thread cedar-lean/Cedar/Thm/Validation/Validator.lean Outdated
Comment thread cedar-lean/Cedar/Thm/Validation/Validator.lean Outdated
Comment thread cedar-lean/Cedar/Thm/Validation/Validator.lean Outdated
Comment on lines +45 to +50
theorem evaluates_subst_ite {i t e : Expr} {request : Request} {entities : Entities}
(ih₁ : EvaluatesSubst i request entities)
(ih₂ : EvaluatesSubst t request entities)
(ih₃ : EvaluatesSubst e request entities) :
evaluate (substituteAction request.action (Expr.ite i t e)) request entities =
evaluate (Expr.ite i t e) request entities
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a little cleaner to move these proofs about substituteAction to their own file (e.g., Thm/Validation/SubstituteAction.lean)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emina said keeping things in one file < 1000 lines was ideal for like easy access -- any thoughts here? I would probably opt for a different file too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I should have clarify: we normally keep the main theorem in a separate (small) file, and all the auxiliary ones in separate (usually) big files. An example of the main theorem: https://github.com/cedar-policy/cedar-spec/blob/main/cedar-lean/Cedar/Thm/Typechecking.lean

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly, so fine either way

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd personally prefer if files were capped at something more like 500 lines, not 1000 lines -- for larger files, there's probably a sensible way to split it up. But our current codebase definitely has a bunch of large files. Not merge blocking for sure

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I separated it out

Comment thread cedar-lean/Cedar/Thm/Validation.lean Outdated
Comment thread cedar-lean/Cedar/Thm/Validation/Validator.lean Outdated
Comment on lines +41 to +42
def SubstituteActionPreservesEvaluation (expr : Expr) (request : Request) (entities : Entities) : Prop :=
evaluate (substituteAction request.action expr) request entities = evaluate expr request entities
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed that you're only using this predicate in hypotheses below. Is there a reason you don't use it in the main lemma statement?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just following the structure of the typechecker proofs -- no real reason to do it this way, I guess.

Copy link
Copy Markdown
Contributor

@cdisselkoen cdisselkoen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Minor naming suggestion for the generic (List) lemma, for consistency with other mapM lemmas

Comment thread cedar-lean/Cedar/Thm/Data/List/Lemmas.lean Outdated
@khieta khieta merged commit c6bc61c into cedar-policy:main Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants