-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a garbled circuit based soritng algorithm (#252)
- Loading branch information
Showing
6 changed files
with
455 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//! Gadgets | ||
//! | ||
//! This module contains some commonly used gadgets for the Rep3 protocol. | ||
pub mod sort; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//! Sort | ||
//! | ||
//! This module contains some oblivious sorting algorithms for the Rep3 protocol. | ||
use crate::protocols::rep3::{ | ||
arithmetic::FieldShare, | ||
network::{IoContext, Rep3Network}, | ||
yao::{self, circuits::GarbledCircuits}, | ||
IoResult, | ||
}; | ||
use ark_ff::PrimeField; | ||
|
||
/// Sorts the inputs using the Batcher's odd-even merge sort algorithm. Thereby, only the lowest `bitsize` bits are considered. The final results also only have bitsize bits each. | ||
pub fn batcher_odd_even_merge_sort_yao<F: PrimeField, N: Rep3Network>( | ||
inputs: &[FieldShare<F>], | ||
io_context: &mut IoContext<N>, | ||
bitsize: usize, | ||
) -> IoResult<Vec<FieldShare<F>>> { | ||
if bitsize > F::MODULUS_BIT_SIZE as usize { | ||
Err(std::io::Error::new( | ||
std::io::ErrorKind::InvalidInput, | ||
"Bit size is larger than field size", | ||
))?; | ||
} | ||
let num_inputs = inputs.len(); | ||
|
||
yao::decompose_circuit_compose_blueprint!( | ||
inputs, | ||
io_context, | ||
num_inputs, | ||
GarbledCircuits::batcher_odd_even_merge_sort::<_, F>, | ||
(bitsize) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.