Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
a6a88a0
add json (de)serialization
Nov 10, 2023
fdcca0b
first pass adding Lean DRT
Nov 10, 2023
015a13c
Compiles and tests start to run but panic
andrewmwells-amazon Nov 13, 2023
499a366
don't build theorems for now
andrewmwells-amazon Nov 13, 2023
9abffa8
fails on Lean side
andrewmwells-amazon Nov 13, 2023
a808fd4
runs, no deserializer
andrewmwells-amazon Nov 14, 2023
4dfce15
deserialization code
andrewmwells-amazon Nov 14, 2023
100750f
lean fails to deserialize
andrewmwells-amazon Nov 15, 2023
89455b4
make stand alone diff test
andrewmwells-amazon Nov 15, 2023
64bca02
smaller test
andrewmwells-amazon Nov 15, 2023
e0466de
checkpoint
andrewmwells-amazon Nov 15, 2023
7034a7b
checkpoint
andrewmwells-amazon Nov 15, 2023
e90ea11
confusing issue
andrewmwells-amazon Nov 15, 2023
5c120c0
fix jsonToContext
andrewmwells-amazon Nov 16, 2023
0ba105e
remove debugging code
andrewmwells-amazon Nov 16, 2023
39f3731
more cleanup
andrewmwells-amazon Nov 16, 2023
cb5624f
failing JSON for 5b
andrewmwells-amazon Nov 16, 2023
ed8dfd8
works on 5b.json standalone
andrewmwells-amazon Nov 16, 2023
4b8f1e3
README instructions
andrewmwells-amazon Nov 16, 2023
311cc80
changes for Rust
andrewmwells-amazon Nov 16, 2023
de88f0d
run Rust integration tests
andrewmwells-amazon Nov 17, 2023
134d783
added back dafny/java code; added test case to DiffTest/Main.lean
Nov 14, 2023
c92b8e0
refactoring in parser
Nov 17, 2023
e959dd2
edits
Nov 17, 2023
b4e0a8f
Dafny and Lean integration tests run
andrewmwells-amazon Nov 17, 2023
7620580
adding more progress
Nov 20, 2023
91eac97
examples for testing
Nov 20, 2023
d05803e
fix some bugs in the validator spec
Nov 21, 2023
cccdacf
rename DiffTestStandAlone -> Cli; add more examples
Nov 21, 2023
7b5d327
forgot to add examples
Nov 21, 2023
3b3e0c8
wip
Nov 21, 2023
9fef0a5
merge w/ main
Nov 21, 2023
3dc359f
update submodule
Nov 21, 2023
78ab68c
fix bad merge
Nov 21, 2023
7f5d0c1
validation tests are working
Nov 21, 2023
60108aa
merge w/ pretty-parser branch
Nov 21, 2023
590859d
cleanup
Nov 21, 2023
655efab
more cleanup
Nov 21, 2023
e547ea3
pulling in Lean changes from main
Nov 29, 2023
51cb310
Merge branch 'main' into lean-drt-javaless
Nov 29, 2023
d41cd85
forgot to add DiffTest file
Dec 5, 2023
0520792
wip
Dec 5, 2023
0a812a5
update cedar submodule
Dec 5, 2023
3b89530
minor fixes
Dec 5, 2023
6d0c6b1
cleanup
Dec 5, 2023
f2cb33b
another attempt at ci
Dec 5, 2023
665b45f
fix CI
andrewmwells-amazon Dec 5, 2023
0f85cb0
upterm
andrewmwells-amazon Dec 5, 2023
54a56fc
fix CI
andrewmwells-amazon Dec 5, 2023
0c91f6a
minor cleanup
Dec 6, 2023
2247432
more nits
Dec 6, 2023
628cbf8
remove mathlib
Dec 6, 2023
17600fd
upterm
Dec 6, 2023
b677417
fix ci?
Dec 6, 2023
28e6ac5
oops
Dec 6, 2023
0bf565b
one more attempt
Dec 6, 2023
1abd248
Update cedar-drt/README.md
khieta Dec 7, 2023
4aebef2
Merge branch 'main' into lean-drt-javaless
Dec 7, 2023
122afc0
merge with main + some cleanup
Dec 7, 2023
0c0bf12
review comments
Dec 7, 2023
c786d25
oops - didn't mean to commit the fuzz target changes
Dec 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 33 additions & 49 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ jobs:
matrix:
toolchain:
- stable

steps:
- name: Checkout cedar-spec
uses: actions/checkout@v3
Expand Down Expand Up @@ -44,33 +43,55 @@ jobs:
dotnet tool restore
dotnet tool run dafny-reportgenerator summarize-csv-results --max-resource-count 10000000 . || true

build_and_test_lean:
name: Build and Test Lean
runs-on: ubuntu-latest
strategy:
matrix:
toolchain:
- stable
steps:
- name: Checkout cedar-spec
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Lean
shell: bash
run: |
wget https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh
bash elan-init.sh -y
- name: Build
working-directory: ./cedar-lean
shell: bash
run: source ~/.profile && lake build Cedar
- name: Test
working-directory: ./cedar-lean
shell: bash
run: source ~/.profile && lake exe CedarUnitTests

build_and_test_drt:
name: Build and Test DRT
runs-on: ubuntu-latest
strategy:
matrix:
toolchain:
- stable

steps:
- name: Checkout cedar-spec
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Lean
shell: bash
run: |
wget https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh
bash elan-init.sh -y
- name: Get Java 17
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '17'
cache: 'gradle'
- name: Build Dafny def engine
working-directory: ./cedar-dafny
shell: bash
run: make compile-difftest
- name: Build cedar-dafny-java-wrapper
working-directory: ./cedar-dafny-java-wrapper
shell: bash
run: ./gradlew build dumpClasspath
Comment thread
cdisselkoen marked this conversation as resolved.
- name: rustup
run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- name: cargo fmt (cedar-policy-generators)
Expand All @@ -85,46 +106,9 @@ jobs:
- name: cargo rustc (cedar-policy-generators)
working-directory: ./cedar-policy-generators
run: RUSTFLAGS="-D warnings -F unsafe-code" cargo build --verbose
- name: cargo rustc (cedar-drt)
working-directory: ./cedar-drt
run: RUSTFLAGS="-D warnings -F unsafe-code" cargo build --verbose
- name: cargo rustc (cedar-drt/fuzz/)
working-directory: ./cedar-drt/fuzz
run: RUSTFLAGS="-D warnings -F unsafe-code" cargo build --verbose
- name: cargo test (cedar-policy-generators)
working-directory: ./cedar-policy-generators
run: cargo test --verbose
- name: cargo test (cedar-drt)
working-directory: ./cedar-drt
shell: bash
run: |
source ./set_env_vars.sh
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH+$LD_LIBRARY_PATH:}$JAVA_HOME/lib/server
cargo test --verbose

build_cedar_lean:
name: Build cedar-lean
runs-on: ubuntu-latest
strategy:
matrix:
toolchain:
- stable

steps:
- name: Checkout cedar-spec
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Lean
shell: bash
run: |
wget https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh
bash elan-init.sh -y
- name: Build
working-directory: ./cedar-lean
shell: bash
run: source ~/.profile && lake build Cedar
- name: Test
working-directory: ./cedar-lean
- name: build.sh
shell: bash
run: source ~/.profile && lake exe CedarUnitTests
run: source ~/.profile && ./build.sh
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ This repository contains the Dafny formalization of Cedar and infrastructure for

To build the Dafny formalization and proofs:

* Install Dafny 4.0, following the instructions [here](https://github.com/dafny-lang/dafny/wiki/INSTALL). Our proofs expect Z3 version 4.12.1, so if you have another copy of Z3 installed locally, you may need to adjust your PATH.
* Install Dafny, following the instructions [here](https://github.com/dafny-lang/dafny/wiki/INSTALL). Our proofs expect Z3 version 4.12.1, so if you have another copy of Z3 installed locally, you may need to adjust your PATH.
* `cd cedar-dafny && make verify test`

To build the Lean formalization and proofs:

* Install Lean, following the instructions [here](https://leanprover.github.io/lean4/doc/setup.html).
* `cd cedar-lean && lake build Cedar`

To build the DRT framework:

* Install Dafny, following the instructions above
* Install Dafny and Lean, following the instructions above.
* `./build.sh`

Note that the build for DRT has only been tested on **Amazon Linux 2**.

## Run

To run DRT:
Expand Down
28 changes: 21 additions & 7 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,33 @@
git submodule update --init

# Set environment variables
cd cedar-drt && source ./set_env_vars.sh
cd cedar-drt
source set_env_vars.sh
cd ..

# Build the Dafny formalization and extract to Java code
Comment thread
shaobo-he-aws marked this conversation as resolved.
cd cedar-dafny
make compile-difftest
cd ..

# Build the formalization and extract Java code
cd cedar-dafny && make compile-difftest
# Build the Dafny Java wrapper
cd cedar-dafny-java-wrapper
./gradlew build dumpClasspath
cd ..

# Build the Java wrapper for DRT
cd cedar-dafny-java-wrapper && ./gradlew build dumpClasspath
# Build the Lean formalization and extract to static C libraries
cd cedar-lean
lake build Cedar:static DiffTest:static Std:static
cd ..

# Build DRT
cd cedar-drt
cargo build
cargo test
cd fuzz && RUSTFLAGS="--cfg=fuzzing" cargo build

# Run integration tests
source set_env_vars.sh
cargo test -- --nocapture

# Build inner fuzz crate
cd fuzz && RUSTFLAGS="--cfg=fuzzing" cargo build
cargo test
1 change: 1 addition & 0 deletions cedar-drt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ cedar-policy-core = { path = "../cedar/cedar-policy-core", version = "3.*", feat
cedar-policy-validator = { path = "../cedar/cedar-policy-validator", version = "3.*", features = ["arbitrary"] }
cedar-policy-formatter = { path = "../cedar/cedar-policy-formatter", version = "3.*" }
jni = { version = "0.19.0", features = ["invocation"] }
lean-sys = { version = "0.0.5", features = ["small_allocator"], default-features = false }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
lazy_static = "1.4"
Expand Down
12 changes: 11 additions & 1 deletion cedar-drt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,15 @@ The table below lists all available fuzz targets, including which component of t

## Logging

If the fuzz targets are compiled with the `log` features, then they will log their entire corpus to the file pointed at in the `LOGFILE` environment variable.
If the fuzz targets are compiled with the `log` features, then they will log their entire corpus to the file pointed at in the `LOGFILE` environment variable.
The sampling rate can be controlled by the `RATE` environment variable, which defaults to 100% if not set.


## Debugging build failures

If you run into weird build issues,
1. Make sure you have run `source set_env_vars.sh`, which sets all the environment variables needed to run the Dafny and Lean definitional code.
2. Try a `cargo clean` and rebuild.
3. If the steps above don't help, then file [an issue](https://github.com/cedar-policy/cedar-spec/issues).

If everything builds, but the integration tests are failing, then it may be helpful to set `RUST_BACKTRACE=1` and run `cargo test -- --nocapture` to print additional test information.
7 changes: 7 additions & 0 deletions cedar-drt/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std::env;
fn main() {
let lean_dir = env::var("LEAN_LIB_DIR").unwrap();
println!("cargo:rustc-link-search=native=../cedar-lean/build/lib");
println!("cargo:rustc-link-search=native={lean_dir}");
println!("cargo:rustc-link-search=native=../cedar-lean/lake-packages/std/build/lib");
}
7 changes: 7 additions & 0 deletions cedar-drt/fuzz/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use std::env;
fn main() {
let lean_dir = env::var("LEAN_LIB_DIR").unwrap();
println!("cargo:rustc-link-search=native=../../cedar-lean/build/lib");
println!("cargo:rustc-link-search=native={lean_dir}");
println!("cargo:rustc-link-search=native=../../cedar-lean/lake-packages/std/build/lib");
}
1 change: 1 addition & 0 deletions cedar-drt/lean-toolchain
6 changes: 6 additions & 0 deletions cedar-drt/set_env_vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ unset -f add_lib_to_path
if [ -f "$(pwd)/../cedar-dafny-java-wrapper/build/libs/cedar-dafny-java-wrapper.jar" ]; then
export CLASSPATH="$(< ../cedar-dafny-java-wrapper/build/runtimeClasspath.txt):$(pwd)/../cedar-dafny-java-wrapper/build/libs/cedar-dafny-java-wrapper.jar"
fi

# Set environment variables for Lean
export LEAN_LIB_DIR=$(lean --print-libdir)
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH+$LD_LIBRARY_PATH:}$(lean --print-libdir)
export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH+$DYLD_LIBRARY_PATH:}$(lean --print-libdir)
export LD_PRELOAD=${LD_PRELOAD+$LD_PRELOAD:}$(lean --print-prefix)/lib/glibc/libm.so
49 changes: 2 additions & 47 deletions cedar-drt/src/dafny_java_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@
//! implementation extracted from the Dafny specification.

use crate::cedar_test_impl::*;
use crate::definitional_request_types::*;
use crate::logger::*;
use cedar_policy::frontend::is_authorized::InterfaceResponse;
use cedar_policy::integration_testing::{CustomCedarImpl, IntegrationTestValidationResult};
pub use cedar_policy::Response;
use cedar_policy_core::ast::{Expr, Value};
pub use cedar_policy_core::*;
pub use cedar_policy_validator::{ValidationMode, ValidationResult, ValidatorSchema};
pub use cedar_policy_validator::{ValidationMode, ValidatorSchema};
pub use entities::Entities;
use jni::objects::{JObject, JString, JValue};
use jni::{JNIVersion, JavaVM};
use lazy_static::lazy_static;
use log::info;
use serde::{Deserialize, Serialize};

/// Times to (de)serialize JSON content sent to / received from the Dafny-Java
/// implementation.
Expand Down Expand Up @@ -67,50 +66,6 @@ lazy_static! {
};
}

#[derive(Debug, Serialize)]
struct RequestForDefEngine<'a> {
request: &'a ast::Request,
policies: &'a ast::PolicySet,
entities: &'a Entities,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct DefinitionalAuthResponse {
serialization_nanos: i64,
deserialization_nanos: i64,
auth_nanos: i64,
response: InterfaceResponse,
}

#[derive(Debug, Serialize)]
struct EvalRequestForDefEngine<'a> {
request: &'a ast::Request,
entities: &'a Entities,
expr: &'a ast::Expr,
expected: Option<&'a ast::Expr>,
}

#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
#[repr(transparent)]
struct DefinitionalEvalResponse {
matches: bool,
}

#[derive(Debug, Serialize)]
struct RequestForDefValidator<'a> {
schema: &'a ValidatorSchema,
policies: &'a ast::PolicySet,
mode: ValidationMode,
}

#[derive(Debug, Deserialize)]
pub struct DefinitionalValResponse {
serialization_nanos: i64,
deserialization_nanos: i64,
validation_nanos: i64,
response: ValidationInterfaceResponse,
}

/// The lifetime parameter 'j is the lifetime of the JVM instance
pub struct JavaDefinitionalEngine<'j> {
/// Thread attached to the JVM
Expand Down
66 changes: 66 additions & 0 deletions cedar-drt/src/definitional_request_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2022-2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* 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.
*/

use crate::cedar_test_impl::*;
use cedar_policy::frontend::is_authorized::InterfaceResponse;
pub use cedar_policy_core::*;
pub use cedar_policy_validator::{ValidationMode, ValidatorSchema};
pub use entities::Entities;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize)]
pub struct RequestForDefEngine<'a> {
pub request: &'a ast::Request,
pub policies: &'a ast::PolicySet,
pub entities: &'a Entities,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct DefinitionalAuthResponse {
pub serialization_nanos: i64,
pub deserialization_nanos: i64,
pub auth_nanos: i64,
pub response: InterfaceResponse,
}

#[derive(Debug, Serialize)]
pub struct EvalRequestForDefEngine<'a> {
pub request: &'a ast::Request,
pub entities: &'a Entities,
pub expr: &'a ast::Expr,
pub expected: Option<&'a ast::Expr>,
}

#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
#[repr(transparent)]
pub struct DefinitionalEvalResponse {
pub matches: bool,
}

#[derive(Debug, Serialize)]
pub struct RequestForDefValidator<'a> {
pub schema: &'a ValidatorSchema,
pub policies: &'a ast::PolicySet,
pub mode: ValidationMode,
}

#[derive(Debug, Deserialize)]
pub struct DefinitionalValResponse {
pub serialization_nanos: i64,
pub deserialization_nanos: i64,
pub validation_nanos: i64,
pub response: ValidationInterfaceResponse,
}
Loading