Skip to content
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

Diverge link methods #346

Merged
merged 5 commits into from
Feb 13, 2024
Merged
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 examples/private_tx_linkedproof/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn main() -> Result<()> {
let mut proof_builder = LogProofBuilder::new(&rt);

println!("Encrypting and sharing transaction...");
let (_ct, tx_msg) = proof_builder.encrypt_and_link(&tx, &public_key)?;
let (_ct, tx_msg) = proof_builder.encrypt_returning_link(&tx, &public_key)?;

println!("Building linkedproof...");
let lp = proof_builder
Expand Down
4 changes: 3 additions & 1 deletion sunscreen/src/linked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@
//! encryption](crate::FheRuntime::encrypt), while also opting to _share_ a message with a linked
//! ZKP program. Under the hood, we'll handle the complicated bits of generating a linear relation
//! for SDLP and sharing the secrets with the [`zkp_program`](crate::zkp_program).
pub use sunscreen_runtime::{LinkedProof, LogProofBuilder, Sdlp};
pub use sunscreen_runtime::{
ExistingMessage, LinkWithZkp, LinkedMessage, LinkedProof, LogProofBuilder, Message, Sdlp,
};
36 changes: 22 additions & 14 deletions sunscreen/tests/linked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ mod linked_tests {
let mut proof_builder = LogProofBuilder::new(&rt);

let (_ct, tx_msg) = proof_builder
.encrypt_and_link(&Signed::from(tx), &public_key)
.encrypt_returning_link(&Signed::from(tx), &public_key)
.unwrap();

println!("Performing linked proof");
Expand Down Expand Up @@ -106,7 +106,7 @@ mod linked_tests {
for tx in [-1, balance + 1] {
let mut proof_builder = LogProofBuilder::new(&rt);
let (_ct, tx_msg) = proof_builder
.encrypt_and_link(&Signed::from(tx), &public_key)
.encrypt_returning_link(&Signed::from(tx), &public_key)
.unwrap();
proof_builder
.zkp_program(valid_transaction_zkp)
Expand Down Expand Up @@ -141,7 +141,7 @@ mod linked_tests {
for val in [3, 0, -3] {
let mut proof_builder = LogProofBuilder::new(&rt);
let (_ct, val_msg) = proof_builder
.encrypt_and_link(&Signed::from(val), &public_key)
.encrypt_returning_link(&Signed::from(val), &public_key)
.unwrap();
proof_builder
.zkp_program(is_eq_zkp)
Expand Down Expand Up @@ -196,7 +196,9 @@ mod linked_tests {
let x_d = rand::random::<i32>().saturating_abs().saturating_add(1) as i64;
let x = Rational::from(Rational64::new_raw(x_n, x_d));
let mut proof_builder = LogProofBuilder::new(&rt);
let (_ct, x_msg) = proof_builder.encrypt_and_link(&x, &public_key).unwrap();
let (_ct, x_msg) = proof_builder
.encrypt_returning_link(&x, &public_key)
.unwrap();
proof_builder
.zkp_program(is_eq_zkp)
.unwrap()
Expand Down Expand Up @@ -240,9 +242,11 @@ mod linked_tests {
let (x, y) = (Signed::from(x.min(y)), Signed::from(x.max(y)));

let mut proof_builder = LogProofBuilder::new(&rt);
let (_ct, x_msg) = proof_builder.encrypt_and_link(&x, &public_key).unwrap();
let (_ct, x_msg) = proof_builder
.encrypt_returning_link(&x, &public_key)
.unwrap();
let (_ct, y_msg) = proof_builder
.encrypt_symmetric_and_link(&y, &private_key)
.encrypt_symmetric_returning_link(&y, &private_key)
.unwrap();
proof_builder
.zkp_program(compare_signed_zkp)
Expand Down Expand Up @@ -293,8 +297,12 @@ mod linked_tests {
let (x, y) = (Rational::from(x.min(y)), Rational::from(x.max(y)));

let mut proof_builder = LogProofBuilder::new(&rt);
let (_ct, x_msg) = proof_builder.encrypt_and_link(&x, &public_key).unwrap();
let (_ct, y_msg) = proof_builder.encrypt_and_link(&y, &public_key).unwrap();
let (_ct, x_msg) = proof_builder
.encrypt_returning_link(&x, &public_key)
.unwrap();
let (_ct, y_msg) = proof_builder
.encrypt_returning_link(&y, &public_key)
.unwrap();
proof_builder
.zkp_program(compare_rational_zkp)
.unwrap()
Expand Down Expand Up @@ -340,13 +348,13 @@ mod linked_tests {
for val in [3, 0, -3] {
let mut proof_builder = LogProofBuilder::new(&rt);
let (_ct_x, x_msg) = proof_builder
.encrypt_and_link(&Signed::from(val), &public_key)
.encrypt_returning_link(&Signed::from(val), &public_key)
.unwrap();
// proves same plaintext within SDLP
let _ct_x1 = proof_builder.encrypt_linked(&x_msg, &public_key).unwrap();
let _ct_x1 = proof_builder.encrypt_msg(&x_msg, &public_key).unwrap();
// proves same value within ZKP
let (_ct_y, y_msg) = proof_builder
.encrypt_symmetric_and_link(&Signed::from(val), &private_key)
.encrypt_symmetric_returning_link(&Signed::from(val), &private_key)
.unwrap();
proof_builder
.zkp_program(is_eq_zkp)
Expand Down Expand Up @@ -414,7 +422,7 @@ mod linked_tests {
proof_builder.zkp_program(is_eq_zkp).unwrap();
for _ in 0..num_linked_inputs {
let (_ct, msg) = proof_builder
.encrypt_and_link(&Signed::from(1), &public_key)
.encrypt_returning_link(&Signed::from(1), &public_key)
.unwrap();
proof_builder.linked_input(msg);
}
Expand Down Expand Up @@ -449,10 +457,10 @@ mod linked_tests {
let mut proof_builder = LogProofBuilder::new(&rt);
proof_builder.zkp_program(compare_signed_zkp).unwrap();
let (_ct, signed_msg) = proof_builder
.encrypt_and_link(&Signed::from(1), &public_key)
.encrypt_returning_link(&Signed::from(1), &public_key)
.unwrap();
let (_ct, unsigned_msg) = proof_builder
.encrypt_and_link(&Unsigned64::from(1), &public_key)
.encrypt_returning_link(&Unsigned64::from(1), &public_key)
.unwrap();
proof_builder
.linked_input(signed_msg)
Expand Down
8 changes: 4 additions & 4 deletions sunscreen/tests/sdlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
mod sdlp_tests {
use lazy_static::lazy_static;
use logproof::rings::SealQ128_1024;
use sunscreen::types::bfv::{Signed, Unsigned64};
use sunscreen::types::bfv::{Fractional, Signed, Unsigned64};
use sunscreen_fhe_program::SchemeType;

use sunscreen_runtime::{FheRuntime, LogProofBuilder, Params};
Expand Down Expand Up @@ -52,13 +52,13 @@ mod sdlp_tests {
let mut logproof_builder = LogProofBuilder::new(&rt);

let (_a1, linked_a) = logproof_builder
.encrypt_and_link(&Signed::from(2), &public_key)
.encrypt_returning_msg(&Fractional::<64>::from(3.23), &public_key)
.unwrap();
let _a2 = logproof_builder
.encrypt_symmetric_linked(&linked_a, &private_key)
.encrypt_symmetric_msg(&linked_a, &private_key)
.unwrap();
let _other = logproof_builder
.encrypt(&Signed::from(3), &public_key)
.encrypt(&Signed::from(2), &public_key)
.unwrap();
let sdlp = logproof_builder.build_logproof().unwrap();
sdlp.verify().unwrap();
Expand Down
Loading
Loading