mirror of
https://github.com/tlsnotary/tlsn.git
synced 2026-01-07 22:03:58 -05:00
refactor: decouple ProveConfig from PartialTranscript (#991)
This commit is contained in:
@@ -29,7 +29,7 @@ use crate::{
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ProveConfig {
|
||||
server_identity: bool,
|
||||
transcript: Option<PartialTranscript>,
|
||||
reveal: Option<(RangeSet<usize>, RangeSet<usize>)>,
|
||||
transcript_commit: Option<TranscriptCommitConfig>,
|
||||
}
|
||||
|
||||
@@ -44,9 +44,9 @@ impl ProveConfig {
|
||||
self.server_identity
|
||||
}
|
||||
|
||||
/// Returns the transcript to be proven.
|
||||
pub fn transcript(&self) -> Option<&PartialTranscript> {
|
||||
self.transcript.as_ref()
|
||||
/// Returns the ranges of the transcript to be revealed.
|
||||
pub fn reveal(&self) -> Option<&(RangeSet<usize>, RangeSet<usize>)> {
|
||||
self.reveal.as_ref()
|
||||
}
|
||||
|
||||
/// Returns the transcript commitment configuration.
|
||||
@@ -60,8 +60,7 @@ impl ProveConfig {
|
||||
pub struct ProveConfigBuilder<'a> {
|
||||
transcript: &'a Transcript,
|
||||
server_identity: bool,
|
||||
reveal_sent: RangeSet<usize>,
|
||||
reveal_recv: RangeSet<usize>,
|
||||
reveal: Option<(RangeSet<usize>, RangeSet<usize>)>,
|
||||
transcript_commit: Option<TranscriptCommitConfig>,
|
||||
}
|
||||
|
||||
@@ -71,8 +70,7 @@ impl<'a> ProveConfigBuilder<'a> {
|
||||
Self {
|
||||
transcript,
|
||||
server_identity: false,
|
||||
reveal_sent: RangeSet::default(),
|
||||
reveal_recv: RangeSet::default(),
|
||||
reveal: None,
|
||||
transcript_commit: None,
|
||||
}
|
||||
}
|
||||
@@ -107,10 +105,12 @@ impl<'a> ProveConfigBuilder<'a> {
|
||||
));
|
||||
}
|
||||
|
||||
let (sent, recv) = self.reveal.get_or_insert_default();
|
||||
match direction {
|
||||
Direction::Sent => self.reveal_sent.union_mut(&idx),
|
||||
Direction::Received => self.reveal_recv.union_mut(&idx),
|
||||
Direction::Sent => sent.union_mut(&idx),
|
||||
Direction::Received => recv.union_mut(&idx),
|
||||
}
|
||||
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
@@ -132,18 +132,9 @@ impl<'a> ProveConfigBuilder<'a> {
|
||||
|
||||
/// Builds the configuration.
|
||||
pub fn build(self) -> Result<ProveConfig, ProveConfigBuilderError> {
|
||||
let transcript = if !self.reveal_sent.is_empty() || !self.reveal_recv.is_empty() {
|
||||
Some(
|
||||
self.transcript
|
||||
.to_partial(self.reveal_sent, self.reveal_recv),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(ProveConfig {
|
||||
server_identity: self.server_identity,
|
||||
transcript,
|
||||
reveal: self.reveal,
|
||||
transcript_commit: self.transcript_commit,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -362,6 +362,7 @@ impl Prover<state::Committed> {
|
||||
ctx,
|
||||
vm,
|
||||
tls_transcript,
|
||||
transcript,
|
||||
transcript_refs,
|
||||
..
|
||||
} = &mut self.state;
|
||||
@@ -371,6 +372,14 @@ impl Prover<state::Committed> {
|
||||
transcript_secrets: Vec::new(),
|
||||
};
|
||||
|
||||
let partial_transcript = if let Some((sent, recv)) = config.reveal() {
|
||||
decode_transcript(vm, sent, recv, transcript_refs).map_err(ProverError::zk)?;
|
||||
|
||||
Some(transcript.to_partial(sent.clone(), recv.clone()))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let payload = ProvePayload {
|
||||
handshake: config.server_identity().then(|| {
|
||||
(
|
||||
@@ -388,7 +397,7 @@ impl Prover<state::Committed> {
|
||||
},
|
||||
)
|
||||
}),
|
||||
transcript: config.transcript().cloned(),
|
||||
transcript: partial_transcript,
|
||||
transcript_commit: config.transcript_commit().map(|config| config.to_request()),
|
||||
};
|
||||
|
||||
@@ -397,16 +406,6 @@ impl Prover<state::Committed> {
|
||||
.poll_with(ctx.io_mut().send(payload).map_err(ProverError::from))
|
||||
.await?;
|
||||
|
||||
if let Some(partial_transcript) = config.transcript() {
|
||||
decode_transcript(
|
||||
vm,
|
||||
partial_transcript.sent_authed(),
|
||||
partial_transcript.received_authed(),
|
||||
transcript_refs,
|
||||
)
|
||||
.map_err(ProverError::zk)?;
|
||||
}
|
||||
|
||||
let mut hash_commitments = None;
|
||||
if let Some(commit_config) = config.transcript_commit() {
|
||||
if commit_config.has_encoding() {
|
||||
|
||||
Reference in New Issue
Block a user