mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-22 19:49:22 +00:00
Fix serialization
This enabled getting the proof sizes, which are: - ConciseLinear had a proof size of 44607 bytes - CompromiseLinear had a proof size of 48765 bytes - ClassicLinear had a proof size of 56829 bytes - EfficientLinear had a proof size of 65145 byte
This commit is contained in:
parent
c3a0e0375d
commit
4dbf50243b
5 changed files with 26 additions and 10 deletions
|
@ -195,6 +195,7 @@ impl<
|
|||
|
||||
#[cfg(feature = "serialize")]
|
||||
pub(crate) fn serialize<W: Write>(&self, w: &mut W) -> std::io::Result<()> {
|
||||
#[allow(non_snake_case)]
|
||||
match self.Re_0 {
|
||||
Re::R(R0, R1) => {
|
||||
w.write_all(R0.to_bytes().as_ref())?;
|
||||
|
@ -211,6 +212,7 @@ impl<
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[cfg(feature = "serialize")]
|
||||
pub(crate) fn deserialize<R: Read>(r: &mut R, mut Re_0: Re<G0, G1>) -> std::io::Result<Self> {
|
||||
match Re_0 {
|
||||
|
|
|
@ -165,6 +165,11 @@ impl<
|
|||
|
||||
#[cfg(feature = "serialize")]
|
||||
pub(crate) fn deserialize<R: Read>(r: &mut R) -> std::io::Result<Self> {
|
||||
Ok(Bits { commitments: (read_point(r)?, read_point(r)?), signature: Aos::deserialize(r)? })
|
||||
Ok(
|
||||
Bits {
|
||||
commitments: (read_point(r)?, read_point(r)?),
|
||||
signature: Aos::deserialize(r, BitSignature::from(SIGNATURE).aos_form())?
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ pub struct DLEqProof<
|
|||
}
|
||||
|
||||
macro_rules! dleq {
|
||||
($name: ident, $signature: expr, $remainder: expr) => {
|
||||
($name: ident, $signature: expr, $remainder: literal) => {
|
||||
pub type $name<G0, G1> = DLEqProof<
|
||||
G0,
|
||||
G1,
|
||||
|
@ -81,10 +81,12 @@ macro_rules! dleq {
|
|||
// bit and removing a hash while slightly reducing challenge security. This security reduction is
|
||||
// already applied to the scalar being proven for, a result of the requirement it's mutually valid
|
||||
// over both scalar fields, hence its application here as well. This is mainly here as a point of
|
||||
// reference for the following DLEq proofs, all which use merged challenges
|
||||
// reference for the following DLEq proofs, all which use merged challenges, and isn't performant
|
||||
// in comparison to the others
|
||||
dleq!(ClassicLinearDLEq, BitSignature::ClassicLinear, false);
|
||||
|
||||
// Proves for 2-bits at a time to save 3/7 elements of every other bit
|
||||
// <9% smaller than CompromiseLinear, yet ~12% slower
|
||||
dleq!(ConciseLinearDLEq, BitSignature::ConciseLinear, true);
|
||||
|
||||
// Uses AOS signatures of the form R, s, to enable the final step of the ring signature to be
|
||||
|
@ -94,6 +96,7 @@ dleq!(EfficientLinearDLEq, BitSignature::EfficientLinear, false);
|
|||
// Proves for 2-bits at a time while using the R, s form. This saves 3/7 elements of every other
|
||||
// bit, while adding 1 element to every bit, and is more efficient than ConciseLinear yet less
|
||||
// efficient than EfficientLinear due to having more ring signature steps which aren't batched
|
||||
// >25% smaller than EfficientLinear and just 11% slower, making it the recommended option
|
||||
dleq!(CompromiseLinearDLEq, BitSignature::CompromiseLinear, true);
|
||||
|
||||
impl<
|
||||
|
|
|
@ -9,6 +9,7 @@ use crate::{
|
|||
tests::cross_group::{G0, G1, transcript, generators}
|
||||
};
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
#[cfg(feature = "serialize")]
|
||||
fn test_aos_serialization<const RING_LEN: usize>(proof: Aos<G0, G1, RING_LEN>, Re_0: Re<G0, G1>) {
|
||||
let mut buf = vec![];
|
||||
|
|
|
@ -49,7 +49,7 @@ pub(crate) fn generators() -> (Generators<G0>, Generators<G1>) {
|
|||
}
|
||||
|
||||
macro_rules! verify_and_deserialize {
|
||||
($type: ident, $proof: ident, $generators: ident, $keys: ident) => {
|
||||
($type: ty, $proof: ident, $generators: ident, $keys: ident) => {
|
||||
let public_keys = $proof.verify(&mut OsRng, &mut transcript(), $generators).unwrap();
|
||||
assert_eq!($generators.0.primary * $keys.0, public_keys.0);
|
||||
assert_eq!($generators.1.primary * $keys.1, public_keys.1);
|
||||
|
@ -58,14 +58,14 @@ macro_rules! verify_and_deserialize {
|
|||
{
|
||||
let mut buf = vec![];
|
||||
$proof.serialize(&mut buf).unwrap();
|
||||
let deserialized = $type::<G0, G1>::deserialize(&mut std::io::Cursor::new(&buf)).unwrap();
|
||||
assert_eq!(proof, deserialized);
|
||||
let deserialized = <$type>::deserialize(&mut std::io::Cursor::new(&buf)).unwrap();
|
||||
assert_eq!($proof, deserialized);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! test_dleq {
|
||||
($str: expr, $benchmark: ident, $name: ident, $type: ident) => {
|
||||
($str: literal, $benchmark: ident, $name: ident, $type: ident) => {
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn $benchmark() {
|
||||
|
@ -93,7 +93,7 @@ macro_rules! test_dleq {
|
|||
#[cfg(feature = "serialize")]
|
||||
{
|
||||
let mut buf = vec![];
|
||||
proofs[0].serialize(&mut buf);
|
||||
proofs[0].serialize(&mut buf).unwrap();
|
||||
println!("{} had a proof size of {} bytes", $str, buf.len());
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ macro_rules! test_dleq {
|
|||
res
|
||||
};
|
||||
|
||||
verify_and_deserialize!($type, proof, generators, keys);
|
||||
verify_and_deserialize!($type::<G0, G1>, proof, generators, keys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -183,5 +183,10 @@ fn test_remainder() {
|
|||
).unwrap();
|
||||
assert_eq!(keys, res);
|
||||
|
||||
verify_and_deserialize!(ConciseLinearDLEq, proof, generators, keys);
|
||||
verify_and_deserialize!(
|
||||
ConciseLinearDLEq::<ProjectivePoint, ProjectivePoint>,
|
||||
proof,
|
||||
generators,
|
||||
keys
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue