-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add data types for Bctv14 and Groth16 proofs.
This also adds a trait to abstract over them.
- Loading branch information
1 parent
a712806
commit 2f3a7a0
Showing
4 changed files
with
87 additions
and
0 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,22 @@ | ||
//! ZK proofs used in Zcash. | ||
use std::fmt::Debug; | ||
|
||
mod bctv14; | ||
mod groth16; | ||
|
||
pub use bctv14::Bctv14Proof; | ||
pub use groth16::Groth16Proof; | ||
|
||
/// A marker trait used to abstract over BCTV14 or Groth16 proofs. | ||
pub trait ZkSnarkProof: Copy + Clone + Debug + PartialEq + Eq + private::Sealed {} | ||
impl ZkSnarkProof for Bctv14Proof {} | ||
impl ZkSnarkProof for Groth16Proof {} | ||
|
||
mod private { | ||
use super::*; | ||
|
||
pub trait Sealed {} | ||
impl Sealed for Bctv14Proof {} | ||
impl Sealed for Groth16Proof {} | ||
} |
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,32 @@ | ||
use std::fmt; | ||
|
||
/// An encoding of a BCTV14 proof, as used in Zcash. | ||
pub struct Bctv14Proof(pub [u8; 296]); | ||
|
||
impl fmt::Debug for Bctv14Proof { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.debug_tuple("Bctv14Proof") | ||
.field(&hex::encode(&self.0[..])) | ||
.finish() | ||
} | ||
} | ||
|
||
// These impls all only exist because of array length restrictions. | ||
|
||
impl Copy for Bctv14Proof {} | ||
|
||
impl Clone for Bctv14Proof { | ||
fn clone(&self) -> Self { | ||
let mut bytes = [0; 296]; | ||
bytes[..].copy_from_slice(&self.0[..]); | ||
Self(bytes) | ||
} | ||
} | ||
|
||
impl PartialEq for Bctv14Proof { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.0[..] == other.0[..] | ||
} | ||
} | ||
|
||
impl Eq for Bctv14Proof {} |
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,32 @@ | ||
use std::fmt; | ||
|
||
/// An encoding of a Groth16 proof, as used in Zcash. | ||
pub struct Groth16Proof(pub [u8; 192]); | ||
|
||
impl fmt::Debug for Groth16Proof { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.debug_tuple("Groth16Proof") | ||
.field(&hex::encode(&self.0[..])) | ||
.finish() | ||
} | ||
} | ||
|
||
// These impls all only exist because of array length restrictions. | ||
|
||
impl Copy for Groth16Proof {} | ||
|
||
impl Clone for Groth16Proof { | ||
fn clone(&self) -> Self { | ||
let mut bytes = [0; 192]; | ||
bytes[..].copy_from_slice(&self.0[..]); | ||
Self(bytes) | ||
} | ||
} | ||
|
||
impl PartialEq for Groth16Proof { | ||
fn eq(&self, other: &Self) -> bool { | ||
self.0[..] == other.0[..] | ||
} | ||
} | ||
|
||
impl Eq for Groth16Proof {} |