Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
run: cargo fmt --all -- --check

- name: Clippy
run: cargo clippy --workspace --all-targets -- -D warnings
run: cargo clippy --workspace --all-targets -- -D warnings -D clippy::unwrap_used -D clippy::expect_used -D clippy::panic -D clippy::float_cmp

- name: Tests
run: cargo test --workspace --all-targets
Expand Down
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/<your-org>/DiscOS"

[workspace.lints.clippy]
unwrap_used = "deny"
expect_used = "deny"
panic = "deny"
float_cmp = "deny"
3 changes: 3 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
allow-unwrap-in-tests = true
allow-expect-in-tests = true
allow-panic-in-tests = true
68 changes: 64 additions & 4 deletions crates/discos-core/src/boundary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,9 @@ pub async fn attacker_ternary_evidenceos(
let a2 = oracles.accuracy_oracle(x2).await?;
q += 2;

if a1.is_none() || a2.is_none() {
let (Some(a1), Some(a2)) = (a1, a2) else {
break;
}
let a1 = a1.unwrap();
let a2 = a2.unwrap();
};

if a1 < a2 {
lo = x1;
Expand Down Expand Up @@ -268,6 +266,7 @@ pub async fn attacker_ternary_evidenceos(
}

#[cfg(test)]
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
mod tests {
use super::*;

Expand Down Expand Up @@ -314,6 +313,67 @@ mod tests {
assert!(accuracy_value_det(dbg.x_submit, b) > 0.999);
}

#[tokio::test]
async fn attacker_ternary_evidenceos_handles_oracle_none_without_panic() -> anyhow::Result<()> {
#[derive(Debug)]
struct NoneAccuracyOracle;

#[async_trait]
impl BudgetedBoundaryOracles for NoneAccuracyOracle {
async fn accuracy_oracle(&mut self, _x: f64) -> anyhow::Result<Option<u32>> {
Ok(None)
}

async fn safety_oracle(&mut self, _x: f64) -> anyhow::Result<Option<u32>> {
Ok(None)
}

fn num_buckets(&self) -> u32 {
256
}

fn bits_per_acc_query(&self) -> f64 {
8.0
}

fn joint_bits_budget(&self) -> f64 {
128.0
}

fn bits_spent(&self) -> f64 {
0.0
}

fn frozen(&self) -> bool {
false
}

fn acc_queries(&self) -> u64 {
0
}

fn safe_queries(&self) -> u64 {
0
}
}

let mut none_acc = NoneAccuracyOracle;
let dbg = attacker_ternary_evidenceos(&mut none_acc, 60, 2e-4, 0.999).await;
assert!(dbg.is_ok());
if let Ok(dbg) = dbg {
assert!(dbg.safety_response.is_none());
}

let mut exhausted = LocalEvidenceOsBoundaryOracles::new(0.42, 256, 0.0)?;
let dbg = attacker_ternary_evidenceos(&mut exhausted, 60, 2e-4, 0.999).await;
assert!(dbg.is_ok());
if let Ok(dbg) = dbg {
assert!(dbg.safety_response.is_none());
assert!(dbg.frozen);
}

Ok(())
}
#[tokio::test]
async fn ternary_evidenceos_runs() {
let b = 0.42;
Expand Down
15 changes: 7 additions & 8 deletions crates/evidenceos-protocol/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
fn main() {
let protoc = protoc_bin_vendored::protoc_bin_path().expect("vendored protoc");
fn main() -> Result<(), Box<dyn std::error::Error>> {
let protoc = protoc_bin_vendored::protoc_bin_path()?;
std::env::set_var("PROTOC", protoc);

let out_dir = std::env::var("OUT_DIR")?;
tonic_build::configure()
.file_descriptor_set_path(
std::path::PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR"))
.join("evidenceos_descriptor.bin"),
)
.compile_protos(&["proto/evidenceos.proto"], &["proto"])
.expect("compile protos");
.file_descriptor_set_path(std::path::PathBuf::from(out_dir).join("evidenceos_descriptor.bin"))
.compile_protos(&["proto/evidenceos.proto"], &["proto"])?;

Ok(())
}
Loading