Skip to content

Commit

Permalink
Skip the unverified multiplies check if we're already unwinding (#1334)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyleiserson authored Oct 4, 2024
1 parent 1d0a24a commit 27de807
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion ipa-core/src/protocol/context/dzkp_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,15 @@ impl<'a, B: ShardBinding> MaliciousDZKPValidator<'a, B> {

impl<'a, B: ShardBinding> Drop for MaliciousDZKPValidator<'a, B> {
fn drop(&mut self) {
if self.inner_ref.is_some() {
// If `validate` has not been called, and we are not unwinding, check that the
// validator is not holding unverified multiplies.
// * If `validate` has been called (i.e. the validator was used in the
// non-`validate_record` mode of operation), then `self.inner_ref` is `None`,
// because validation consumed the batcher via `self.inner_ref`.
// * Unwinding can happen at any time, so complaining about incomplete
// validation is likely just extra noise, and the additional panic
// during unwinding could be confusing.
if self.inner_ref.is_some() && !std::thread::panicking() {
self.is_verified().unwrap();
}
}
Expand Down Expand Up @@ -1249,6 +1257,47 @@ mod tests {
}
}

#[tokio::test]
#[should_panic(expected = "ContextUnsafe(\"DZKPMaliciousContext\")")]
async fn missing_validate() {
let mut rng = thread_rng();

let a = rng.gen::<Boolean>();
let b = rng.gen::<Boolean>();

TestWorld::default()
.malicious((a, b), |ctx, (a, b)| async move {
let v = ctx.dzkp_validator(TEST_DZKP_STEPS, 1);
let m_ctx = v.context().set_total_records(1);

a.multiply(&b, m_ctx, RecordId::FIRST).await.unwrap()

// `validate` should appear here.
})
.await;
}

#[tokio::test]
#[should_panic(expected = "panicking before validate")]
#[allow(unreachable_code)]
async fn missing_validate_panic() {
let mut rng = thread_rng();

let a = rng.gen::<Boolean>();
let b = rng.gen::<Boolean>();

TestWorld::default()
.malicious((a, b), |ctx, (a, b)| async move {
let v = ctx.dzkp_validator(TEST_DZKP_STEPS, 1);
let m_ctx = v.context().set_total_records(1);

let _result = a.multiply(&b, m_ctx, RecordId::FIRST).await.unwrap();

panic!("panicking before validate");
})
.await;
}

#[test]
fn batch_allocation_small() {
const SIZE: usize = 1;
Expand Down

0 comments on commit 27de807

Please sign in to comment.