mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-08 00:03:09 +00:00
fix: commnets fix cleanup
This commit is contained in:
parent
0e1905ad22
commit
d81fb2665f
@ -1,10 +1,12 @@
|
|||||||
use std::io::{Cursor, Read};
|
use std::io::{Cursor, Read};
|
||||||
|
|
||||||
use nssa_core::{
|
use nssa_core::{
|
||||||
Commitment, Nullifier,
|
Commitment, Nullifier, PrivacyPreservingCircuitOutput,
|
||||||
account::Account,
|
account::Account,
|
||||||
encryption::{Ciphertext, EphemeralPublicKey},
|
encryption::{Ciphertext, EphemeralPublicKey},
|
||||||
};
|
};
|
||||||
|
use program_methods::PRIVACY_PRESERVING_CIRCUIT_ID;
|
||||||
|
use risc0_zkvm::{InnerReceipt, Receipt};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Address, PrivacyPreservingTransaction, PublicKey, Signature,
|
Address, PrivacyPreservingTransaction, PublicKey, Signature,
|
||||||
@ -224,3 +226,40 @@ impl PrivacyPreservingTransaction {
|
|||||||
Ok(PrivacyPreservingTransaction::new(message, witness_set))
|
Ok(PrivacyPreservingTransaction::new(message, witness_set))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Proof {
|
||||||
|
pub(crate) fn is_valid_for(&self, circuit_output: &PrivacyPreservingCircuitOutput) -> bool {
|
||||||
|
let inner: InnerReceipt = borsh::from_slice(&self.0).unwrap();
|
||||||
|
let receipt = Receipt::new(inner, circuit_output.to_bytes());
|
||||||
|
receipt.verify(PRIVACY_PRESERVING_CIRCUIT_ID).is_ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_bytes(&self) -> Vec<u8> {
|
||||||
|
let mut bytes = Vec::new();
|
||||||
|
let proof_len = self.0.len() as u32;
|
||||||
|
bytes.extend_from_slice(&proof_len.to_le_bytes());
|
||||||
|
bytes.extend_from_slice(&self.0);
|
||||||
|
bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_cursor(cursor: &mut Cursor<&[u8]>) -> Result<Self, NssaError> {
|
||||||
|
let proof_len = u32_from_cursor(cursor) as usize;
|
||||||
|
let mut proof = Vec::with_capacity(proof_len);
|
||||||
|
|
||||||
|
for _ in 0..proof_len {
|
||||||
|
let mut one_byte_buf = [0u8];
|
||||||
|
|
||||||
|
cursor.read_exact(&mut one_byte_buf)?;
|
||||||
|
|
||||||
|
proof.push(one_byte_buf[0]);
|
||||||
|
}
|
||||||
|
Ok(Self(proof))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Improve error handling. Remove unwraps.
|
||||||
|
pub fn u32_from_cursor(cursor: &mut Cursor<&[u8]>) -> u32 {
|
||||||
|
let mut word_buf = [0u8; 4];
|
||||||
|
cursor.read_exact(&mut word_buf).unwrap();
|
||||||
|
u32::from_le_bytes(word_buf)
|
||||||
|
}
|
||||||
|
|||||||
@ -1,57 +1,18 @@
|
|||||||
use std::io::{Cursor, Read};
|
|
||||||
|
|
||||||
use nssa_core::{
|
use nssa_core::{
|
||||||
MembershipProof, NullifierPublicKey, NullifierSecretKey, PrivacyPreservingCircuitInput,
|
MembershipProof, NullifierPublicKey, NullifierSecretKey, PrivacyPreservingCircuitInput,
|
||||||
PrivacyPreservingCircuitOutput, SharedSecretKey,
|
PrivacyPreservingCircuitOutput, SharedSecretKey,
|
||||||
account::AccountWithMetadata,
|
account::AccountWithMetadata,
|
||||||
program::{InstructionData, ProgramOutput},
|
program::{InstructionData, ProgramOutput},
|
||||||
};
|
};
|
||||||
use risc0_zkvm::{ExecutorEnv, InnerReceipt, Receipt, default_prover};
|
use risc0_zkvm::{ExecutorEnv, Receipt, default_prover};
|
||||||
|
|
||||||
use crate::{error::NssaError, program::Program};
|
use crate::{error::NssaError, program::Program};
|
||||||
|
|
||||||
use program_methods::{PRIVACY_PRESERVING_CIRCUIT_ELF, PRIVACY_PRESERVING_CIRCUIT_ID};
|
use program_methods::PRIVACY_PRESERVING_CIRCUIT_ELF;
|
||||||
|
|
||||||
/// Proof of the privacy preserving execution circuit
|
/// Proof of the privacy preserving execution circuit
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct Proof(pub(super) Vec<u8>);
|
pub struct Proof(pub(crate) Vec<u8>);
|
||||||
|
|
||||||
impl Proof {
|
|
||||||
pub(crate) fn is_valid_for(&self, circuit_output: &PrivacyPreservingCircuitOutput) -> bool {
|
|
||||||
let inner: InnerReceipt = borsh::from_slice(&self.0).unwrap();
|
|
||||||
let receipt = Receipt::new(inner, circuit_output.to_bytes());
|
|
||||||
receipt.verify(PRIVACY_PRESERVING_CIRCUIT_ID).is_ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_bytes(&self) -> Vec<u8> {
|
|
||||||
let mut bytes = Vec::new();
|
|
||||||
let proof_len = self.0.len() as u32;
|
|
||||||
bytes.extend_from_slice(&proof_len.to_le_bytes());
|
|
||||||
bytes.extend_from_slice(&self.0);
|
|
||||||
bytes
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_cursor(cursor: &mut Cursor<&[u8]>) -> Result<Self, NssaError> {
|
|
||||||
let proof_len = u32_from_cursor(cursor) as usize;
|
|
||||||
let mut proof = Vec::with_capacity(proof_len);
|
|
||||||
|
|
||||||
for _ in 0..proof_len {
|
|
||||||
let mut one_byte_buf = [0u8];
|
|
||||||
|
|
||||||
cursor.read_exact(&mut one_byte_buf)?;
|
|
||||||
|
|
||||||
proof.push(one_byte_buf[0]);
|
|
||||||
}
|
|
||||||
Ok(Self(proof))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Improve error handling. Remove unwraps.
|
|
||||||
pub fn u32_from_cursor(cursor: &mut Cursor<&[u8]>) -> u32 {
|
|
||||||
let mut word_buf = [0u8; 4];
|
|
||||||
cursor.read_exact(&mut word_buf).unwrap();
|
|
||||||
u32::from_le_bytes(word_buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Generates a proof of the execution of a NSSA program inside the privacy preserving execution
|
/// Generates a proof of the execution of a NSSA program inside the privacy preserving execution
|
||||||
/// circuit
|
/// circuit
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user