-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: use RangeSet * bump tlsn-utils commit * add RedactedTranscript * fix return type in TranscriptSlice::data * simplify openings * mark Commitment non_exhaustive * add commitment id, session data builder * move fixtures into tlsn-fixtures * encapsulate more into tlsn-core * fix tlsn-core api test * clean up unused imports * update tlsn-prover * wip * restructuring exports, and documentation * more work on docs * improve substrings errors * implement opaque debug for substringsproof * clean up substringsproof verify * readd merkle test * bump tlsn-utils version * fix dependents * add getter for substrings commitments * fix RedactedTranscript constructor * introduce bimap and info types * clean up error types * add panic if duplicate ids * remove tracing dep * move SubstringsOpeningError * check range bound * remove transcript error * fix panic * flatten commitment types * fix import in example * delete old substrings module * transcript commitment builder * hide constructor for builder * remove dead code * Apply suggestions from code review Co-authored-by: dan <[email protected]> * Update tlsn/tlsn-core/src/proof.rs Co-authored-by: th4s <[email protected]> * Update tlsn/tlsn-core/src/commitment/builder.rs Co-authored-by: dan <[email protected]> * Update tlsn/tlsn-core/src/merkle.rs Co-authored-by: dan <[email protected]> * fix transcript name * update fn name * into -> to * ensure transcript slices are sorted and disjoint --------- Co-authored-by: dan <[email protected]> Co-authored-by: th4s <[email protected]>
- Loading branch information
1 parent
7826e6a
commit 2f0666f
Showing
56 changed files
with
1,207 additions
and
1,532 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
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
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
This file was deleted.
Oops, something went wrong.
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,105 @@ | ||
use crate::commitment::{Commitment, CommitmentOpening}; | ||
use mpz_core::{ | ||
commit::{Decommitment, HashCommit, Nonce}, | ||
hash::Hash, | ||
}; | ||
use mpz_garble_core::{encoding_state, encoding_state::Full, EncodedValue}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// A Blake3 commitment to the encodings of the substrings of a [`Transcript`](crate::Transcript). | ||
#[derive(Clone, Copy, Serialize, Deserialize)] | ||
pub struct Blake3Commitment { | ||
hash: Hash, | ||
nonce: Nonce, | ||
} | ||
|
||
opaque_debug::implement!(Blake3Commitment); | ||
|
||
impl Blake3Commitment { | ||
/// Creates a new Blake3 commitment | ||
pub fn new(encodings: &[EncodedValue<encoding_state::Active>]) -> Self { | ||
let (decommitment, hash) = encodings.hash_commit(); | ||
|
||
Self { | ||
hash, | ||
nonce: *decommitment.nonce(), | ||
} | ||
} | ||
|
||
/// Returns the hash of this commitment | ||
pub fn hash(&self) -> &Hash { | ||
&self.hash | ||
} | ||
|
||
/// Returns the nonce of this commitment | ||
pub fn nonce(&self) -> &Nonce { | ||
&self.nonce | ||
} | ||
|
||
/// Opens this commitment | ||
pub fn open(&self, data: Vec<u8>) -> Blake3Opening { | ||
Blake3Opening::new(data, self.nonce) | ||
} | ||
} | ||
|
||
impl From<Blake3Commitment> for Commitment { | ||
fn from(value: Blake3Commitment) -> Self { | ||
Self::Blake3(value) | ||
} | ||
} | ||
|
||
/// A substring opening using Blake3 | ||
#[derive(Serialize, Deserialize, Clone)] | ||
pub struct Blake3Opening { | ||
data: Vec<u8>, | ||
nonce: Nonce, | ||
} | ||
|
||
impl Blake3Opening { | ||
pub(crate) fn new(data: Vec<u8>, nonce: Nonce) -> Self { | ||
Self { data, nonce } | ||
} | ||
|
||
/// Recovers the expected commitment from this opening. | ||
/// | ||
/// # Panics | ||
/// | ||
/// - If the number of encodings does not match the number of bytes in the opening. | ||
/// - If an encoding is not for a u8. | ||
pub fn recover(&self, encodings: &[EncodedValue<Full>]) -> Blake3Commitment { | ||
assert_eq!( | ||
encodings.len(), | ||
self.data.len(), | ||
"encodings and data must have the same length" | ||
); | ||
|
||
let encodings = encodings | ||
.iter() | ||
.zip(&self.data) | ||
.map(|(encoding, data)| encoding.select(*data).expect("encoding is for a u8")) | ||
.collect::<Vec<_>>(); | ||
|
||
let hash = Decommitment::new_with_nonce(encodings, self.nonce).commit(); | ||
|
||
Blake3Commitment { | ||
hash, | ||
nonce: self.nonce, | ||
} | ||
} | ||
|
||
/// Returns the transcript data corresponding to this opening | ||
pub fn data(&self) -> &[u8] { | ||
&self.data | ||
} | ||
|
||
/// Returns the transcript data corresponding to this opening | ||
pub fn into_data(self) -> Vec<u8> { | ||
self.data | ||
} | ||
} | ||
|
||
impl From<Blake3Opening> for CommitmentOpening { | ||
fn from(value: Blake3Opening) -> Self { | ||
Self::Blake3(value) | ||
} | ||
} |
Oops, something went wrong.