Skip to content

Commit b013b52

Browse files
committed
migrate proof data types
1 parent 3a73ac3 commit b013b52

35 files changed

+771
-409
lines changed

zk-sdk-pod/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
pub mod encryption;
22
pub mod errors;
33
pub mod macros;
4+
pub mod num;
5+
pub mod proof_data;
46
pub mod range_proof;
57
pub mod sigma_proofs;
68

zk-sdk-pod/src/num.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use bytemuck_derive::{Pod, Zeroable};
2+
3+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Pod, Zeroable)]
4+
#[repr(transparent)]
5+
pub struct PodU16([u8; 2]);
6+
impl From<u16> for PodU16 {
7+
fn from(n: u16) -> Self {
8+
Self(n.to_le_bytes())
9+
}
10+
}
11+
impl From<PodU16> for u16 {
12+
fn from(pod: PodU16) -> Self {
13+
Self::from_le_bytes(pod.0)
14+
}
15+
}
16+
17+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Pod, Zeroable)]
18+
#[repr(transparent)]
19+
pub struct PodU64([u8; 8]);
20+
impl From<u64> for PodU64 {
21+
fn from(n: u64) -> Self {
22+
Self(n.to_le_bytes())
23+
}
24+
}
25+
impl From<PodU64> for u64 {
26+
fn from(pod: PodU64) -> Self {
27+
Self::from_le_bytes(pod.0)
28+
}
29+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use {
2+
crate::{
3+
encryption::{
4+
elgamal::PodElGamalPubkey, grouped_elgamal::PodGroupedElGamalCiphertext2Handles,
5+
},
6+
sigma_proofs::PodBatchedGroupedCiphertext2HandlesValidityProof,
7+
},
8+
bytemuck_derive::{Pod, Zeroable},
9+
};
10+
11+
/// The instruction data that is needed for the
12+
/// `ProofInstruction::VerifyBatchedGroupedCiphertextValidity` instruction.
13+
///
14+
/// It includes the cryptographic proof as well as the context data information needed to verify
15+
/// the proof.
16+
#[derive(Clone, Copy, Pod, Zeroable)]
17+
#[repr(C)]
18+
pub struct BatchedGroupedCiphertext2HandlesValidityProofData {
19+
pub context: BatchedGroupedCiphertext2HandlesValidityProofContext,
20+
21+
pub proof: PodBatchedGroupedCiphertext2HandlesValidityProof,
22+
}
23+
24+
#[derive(Clone, Copy, Pod, Zeroable)]
25+
#[repr(C)]
26+
pub struct BatchedGroupedCiphertext2HandlesValidityProofContext {
27+
pub first_pubkey: PodElGamalPubkey, // 32 bytes
28+
29+
pub second_pubkey: PodElGamalPubkey, // 32 bytes
30+
31+
pub grouped_ciphertext_lo: PodGroupedElGamalCiphertext2Handles, // 96 bytes
32+
33+
pub grouped_ciphertext_hi: PodGroupedElGamalCiphertext2Handles, // 96 bytes
34+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use {
2+
crate::{
3+
encryption::{
4+
elgamal::PodElGamalPubkey, grouped_elgamal::PodGroupedElGamalCiphertext3Handles,
5+
},
6+
sigma_proofs::PodBatchedGroupedCiphertext3HandlesValidityProof,
7+
},
8+
bytemuck_derive::{Pod, Zeroable},
9+
};
10+
11+
/// The instruction data that is needed for the
12+
/// `ProofInstruction::VerifyBatchedGroupedCiphertext3HandlesValidity` instruction.
13+
///
14+
/// It includes the cryptographic proof as well as the context data information needed to verify
15+
/// the proof.
16+
#[derive(Clone, Copy, Pod, Zeroable)]
17+
#[repr(C)]
18+
pub struct BatchedGroupedCiphertext3HandlesValidityProofData {
19+
pub context: BatchedGroupedCiphertext3HandlesValidityProofContext,
20+
21+
pub proof: PodBatchedGroupedCiphertext3HandlesValidityProof,
22+
}
23+
24+
#[derive(Clone, Copy, Pod, Zeroable)]
25+
#[repr(C)]
26+
pub struct BatchedGroupedCiphertext3HandlesValidityProofContext {
27+
pub first_pubkey: PodElGamalPubkey, // 32 bytes
28+
29+
pub second_pubkey: PodElGamalPubkey, // 32 bytes
30+
31+
pub third_pubkey: PodElGamalPubkey, // 32 bytes
32+
33+
pub grouped_ciphertext_lo: PodGroupedElGamalCiphertext3Handles, // 128 bytes
34+
35+
pub grouped_ciphertext_hi: PodGroupedElGamalCiphertext3Handles, // 128 bytes
36+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
mod handles_2;
2+
mod handles_3;
3+
4+
pub use {
5+
handles_2::{
6+
BatchedGroupedCiphertext2HandlesValidityProofContext,
7+
BatchedGroupedCiphertext2HandlesValidityProofData,
8+
},
9+
handles_3::{
10+
BatchedGroupedCiphertext3HandlesValidityProofContext,
11+
BatchedGroupedCiphertext3HandlesValidityProofData,
12+
},
13+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use {
2+
crate::{
3+
proof_data::batched_range_proof::BatchedRangeProofContext, range_proof::PodRangeProofU128,
4+
},
5+
bytemuck_derive::{Pod, Zeroable},
6+
};
7+
8+
/// The instruction data that is needed for the
9+
/// `ProofInstruction::VerifyBatchedRangeProofU128` instruction.
10+
///
11+
/// It includes the cryptographic proof as well as the context data information needed to verify
12+
/// the proof.
13+
#[derive(Clone, Copy, Pod, Zeroable)]
14+
#[repr(C)]
15+
pub struct BatchedRangeProofU128Data {
16+
/// The context data for a batched range proof
17+
pub context: BatchedRangeProofContext,
18+
19+
/// The batched range proof
20+
pub proof: PodRangeProofU128,
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use {
2+
crate::{
3+
proof_data::batched_range_proof::BatchedRangeProofContext, range_proof::PodRangeProofU256,
4+
},
5+
bytemuck_derive::{Pod, Zeroable},
6+
};
7+
8+
/// The instruction data that is needed for the
9+
/// `ProofInstruction::BatchedRangeProofU256Data` instruction.
10+
///
11+
/// It includes the cryptographic proof as well as the context data information needed to verify
12+
/// the proof.
13+
#[derive(Clone, Copy, Pod, Zeroable)]
14+
#[repr(C)]
15+
pub struct BatchedRangeProofU256Data {
16+
/// The context data for a batched range proof
17+
pub context: BatchedRangeProofContext,
18+
19+
/// The batched range proof
20+
pub proof: PodRangeProofU256,
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use {
2+
crate::{
3+
proof_data::batched_range_proof::BatchedRangeProofContext, range_proof::PodRangeProofU64,
4+
},
5+
bytemuck_derive::{Pod, Zeroable},
6+
};
7+
8+
/// The instruction data that is needed for the
9+
/// `ProofInstruction::VerifyBatchedRangeProofU64` instruction.
10+
///
11+
/// It includes the cryptographic proof as well as the context data information needed to verify
12+
/// the proof.
13+
#[derive(Clone, Copy, Pod, Zeroable)]
14+
#[repr(C)]
15+
pub struct BatchedRangeProofU64Data {
16+
/// The context data for a batched range proof
17+
pub context: BatchedRangeProofContext,
18+
19+
/// The batched range proof
20+
pub proof: PodRangeProofU64,
21+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use {
2+
crate::encryption::pedersen::PodPedersenCommitment,
3+
bytemuck_derive::{Pod, Zeroable},
4+
};
5+
6+
pub mod batched_range_proof_u128;
7+
pub mod batched_range_proof_u256;
8+
pub mod batched_range_proof_u64;
9+
10+
pub use {
11+
batched_range_proof_u128::BatchedRangeProofU128Data,
12+
batched_range_proof_u256::BatchedRangeProofU256Data,
13+
batched_range_proof_u64::BatchedRangeProofU64Data,
14+
};
15+
16+
/// The maximum number of Pedersen commitments that can be processed in a single batched range proof.
17+
const MAX_COMMITMENTS: usize = 8;
18+
19+
/// The context data needed to verify a range-proof for a Pedersen committed value.
20+
///
21+
/// This struct holds the public information that a batched range proof certifies. It includes the
22+
/// Pedersen commitments and their corresponding bit lengths. This context is shared by all
23+
/// `VerifyBatchedRangeProof{N}` instructions.
24+
#[derive(Clone, Copy, Pod, Zeroable)]
25+
#[repr(C)]
26+
pub struct BatchedRangeProofContext {
27+
pub commitments: [PodPedersenCommitment; MAX_COMMITMENTS],
28+
pub bit_lengths: [u8; MAX_COMMITMENTS],
29+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use {
2+
crate::{
3+
encryption::elgamal::{PodElGamalCiphertext, PodElGamalPubkey},
4+
sigma_proofs::PodCiphertextCiphertextEqualityProof,
5+
},
6+
bytemuck_derive::{Pod, Zeroable},
7+
};
8+
9+
/// The instruction data that is needed for the
10+
/// `ProofInstruction::VerifyCiphertextCiphertextEquality` instruction.
11+
///
12+
/// It includes the cryptographic proof as well as the context data information needed to verify
13+
/// the proof.
14+
#[derive(Clone, Copy, Pod, Zeroable)]
15+
#[repr(C)]
16+
pub struct CiphertextCiphertextEqualityProofData {
17+
pub context: CiphertextCiphertextEqualityProofContext,
18+
19+
pub proof: PodCiphertextCiphertextEqualityProof,
20+
}
21+
22+
/// The context data needed to verify a ciphertext-ciphertext equality proof.
23+
#[derive(Clone, Copy, Pod, Zeroable)]
24+
#[repr(C)]
25+
pub struct CiphertextCiphertextEqualityProofContext {
26+
pub first_pubkey: PodElGamalPubkey, // 32 bytes
27+
28+
pub second_pubkey: PodElGamalPubkey, // 32 bytes
29+
30+
pub first_ciphertext: PodElGamalCiphertext, // 64 bytes
31+
32+
pub second_ciphertext: PodElGamalCiphertext, // 64 bytes
33+
}

0 commit comments

Comments
 (0)