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