Skip to content

Commit 3e68ecd

Browse files
committed
feat: add proxy approach
1 parent d1e3098 commit 3e68ecd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+4841
-660
lines changed

Cargo.lock

Lines changed: 130 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,21 @@ tlsn-sdk-core = { path = "crates/sdk-core" }
6565
tlsn-wasm = { path = "crates/wasm" }
6666
tlsn = { path = "crates/tlsn" }
6767

68-
mpz-circuits = { git = "https://github.com/privacy-ethereum/mpz", tag = "v0.1.0-alpha.5" }
69-
mpz-circuits-data = { git = "https://github.com/privacy-ethereum/mpz", tag = "v0.1.0-alpha.5" }
70-
mpz-memory-core = { git = "https://github.com/privacy-ethereum/mpz", tag = "v0.1.0-alpha.5" }
71-
mpz-common = { git = "https://github.com/privacy-ethereum/mpz", tag = "v0.1.0-alpha.5" }
72-
mpz-core = { git = "https://github.com/privacy-ethereum/mpz", tag = "v0.1.0-alpha.5" }
73-
mpz-vm-core = { git = "https://github.com/privacy-ethereum/mpz", tag = "v0.1.0-alpha.5" }
74-
mpz-garble = { git = "https://github.com/privacy-ethereum/mpz", tag = "v0.1.0-alpha.5" }
75-
mpz-garble-core = { git = "https://github.com/privacy-ethereum/mpz", tag = "v0.1.0-alpha.5" }
76-
mpz-ole = { git = "https://github.com/privacy-ethereum/mpz", tag = "v0.1.0-alpha.5" }
77-
mpz-ot = { git = "https://github.com/privacy-ethereum/mpz", tag = "v0.1.0-alpha.5" }
78-
mpz-share-conversion = { git = "https://github.com/privacy-ethereum/mpz", tag = "v0.1.0-alpha.5" }
79-
mpz-fields = { git = "https://github.com/privacy-ethereum/mpz", tag = "v0.1.0-alpha.5" }
80-
mpz-zk = { git = "https://github.com/privacy-ethereum/mpz", tag = "v0.1.0-alpha.5" }
81-
mpz-hash = { git = "https://github.com/privacy-ethereum/mpz", tag = "v0.1.0-alpha.5" }
82-
mpz-ideal-vm = { git = "https://github.com/privacy-ethereum/mpz", tag = "v0.1.0-alpha.5" }
68+
mpz-circuits = { git = "https://github.com/privacy-ethereum/mpz", branch = "fix/zk-ot-alloc" }
69+
mpz-circuits-data = { git = "https://github.com/privacy-ethereum/mpz", branch = "fix/zk-ot-alloc" }
70+
mpz-memory-core = { git = "https://github.com/privacy-ethereum/mpz", branch = "fix/zk-ot-alloc" }
71+
mpz-common = { git = "https://github.com/privacy-ethereum/mpz", branch = "fix/zk-ot-alloc" }
72+
mpz-core = { git = "https://github.com/privacy-ethereum/mpz", branch = "fix/zk-ot-alloc" }
73+
mpz-vm-core = { git = "https://github.com/privacy-ethereum/mpz", branch = "fix/zk-ot-alloc" }
74+
mpz-garble = { git = "https://github.com/privacy-ethereum/mpz", branch = "fix/zk-ot-alloc" }
75+
mpz-garble-core = { git = "https://github.com/privacy-ethereum/mpz", branch = "fix/zk-ot-alloc" }
76+
mpz-ole = { git = "https://github.com/privacy-ethereum/mpz", branch = "fix/zk-ot-alloc" }
77+
mpz-ot = { git = "https://github.com/privacy-ethereum/mpz", branch = "fix/zk-ot-alloc" }
78+
mpz-share-conversion = { git = "https://github.com/privacy-ethereum/mpz", branch = "fix/zk-ot-alloc" }
79+
mpz-fields = { git = "https://github.com/privacy-ethereum/mpz", branch = "fix/zk-ot-alloc" }
80+
mpz-zk = { git = "https://github.com/privacy-ethereum/mpz", branch = "fix/zk-ot-alloc" }
81+
mpz-hash = { git = "https://github.com/privacy-ethereum/mpz", branch = "fix/zk-ot-alloc" }
82+
mpz-ideal-vm = { git = "https://github.com/privacy-ethereum/mpz", branch = "fix/zk-ot-alloc" }
8383

8484
futures-plex = { git = "https://github.com/tlsnotary/tlsn-utils", rev = "dd419bf" }
8585
rangeset = { version = "0.4" }
@@ -140,7 +140,7 @@ regex = { version = "1.10" }
140140
ring = { version = "0.17" }
141141
rs_merkle = { git = "https://github.com/tlsnotary/rs-merkle.git", rev = "85f3e82" }
142142
rstest = { version = "0.17" }
143-
rustls = { version = "0.21" }
143+
rustls = { version = "0.23", default-features = false }
144144
rustls-pemfile = { version = "1.0" }
145145
rustls-webpki = { version = "0.103" }
146146
rustls-pki-types = { version = "1.12" }
@@ -152,6 +152,7 @@ sha2 = { version = "0.10" }
152152
signature = { version = "2.2" }
153153
thiserror = { version = "1.0" }
154154
tiny-keccak = { version = "2.0" }
155+
tls-parser = { version = "0.12" }
155156
tokio = { version = "1.38" }
156157
tokio-util = { version = "0.7" }
157158
toml = { version = "0.8" }

crates/core/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ fixtures = [
2525
[dependencies]
2626
tlsn-data-fixtures = { workspace = true, optional = true }
2727
tlsn-tls-core = { workspace = true, features = ["serde"] }
28+
2829
rangeset = { workspace = true, features = ["serde"] }
30+
mpz-memory-core = { workspace = true }
2931

3032
aead = { workspace = true, features = ["alloc"], optional = true }
3133
aes-gcm = { workspace = true, optional = true }

crates/core/src/config/tls_commit.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! TLS commitment configuration.
22
33
pub mod mpc;
4+
pub mod proxy;
45

56
use serde::{Deserialize, Serialize};
67

@@ -61,6 +62,8 @@ impl TlsCommitConfigBuilder {
6162
pub enum TlsCommitProtocolConfig {
6263
/// MPC-TLS configuration.
6364
Mpc(mpc::MpcTlsConfig),
65+
/// Proxy-TLS configuration.
66+
Proxy(proxy::ProxyTlsConfig),
6467
}
6568

6669
impl From<mpc::MpcTlsConfig> for TlsCommitProtocolConfig {
@@ -69,6 +72,12 @@ impl From<mpc::MpcTlsConfig> for TlsCommitProtocolConfig {
6972
}
7073
}
7174

75+
impl From<proxy::ProxyTlsConfig> for TlsCommitProtocolConfig {
76+
fn from(config: proxy::ProxyTlsConfig) -> Self {
77+
Self::Proxy(config)
78+
}
79+
}
80+
7281
/// TLS commitment request.
7382
#[derive(Debug, Clone, Serialize, Deserialize)]
7483
pub struct TlsCommitRequest {
@@ -82,6 +91,21 @@ impl TlsCommitRequest {
8291
}
8392
}
8493

94+
/// Settings for the network environment.
95+
///
96+
/// Provides optimization options to adapt the protocol to different network
97+
/// situations.
98+
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)]
99+
pub enum NetworkSetting {
100+
/// Reduces network round-trips at the expense of consuming more network
101+
/// bandwidth.
102+
Bandwidth,
103+
/// Reduces network bandwidth utilization at the expense of more network
104+
/// round-trips.
105+
#[default]
106+
Latency,
107+
}
108+
85109
/// Error for [`TlsCommitConfig`].
86110
#[derive(Debug, thiserror::Error)]
87111
#[error(transparent)]

crates/core/src/config/tls_commit/mpc.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! MPC-TLS commitment protocol configuration.
22
3+
use crate::config::tls_commit::NetworkSetting;
34
use serde::{Deserialize, Serialize};
45

56
// Default is 32 bytes to decrypt the TLS protocol messages.
@@ -181,21 +182,6 @@ impl MpcTlsConfigBuilder {
181182
}
182183
}
183184

184-
/// Settings for the network environment.
185-
///
186-
/// Provides optimization options to adapt the protocol to different network
187-
/// situations.
188-
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default)]
189-
pub enum NetworkSetting {
190-
/// Reduces network round-trips at the expense of consuming more network
191-
/// bandwidth.
192-
Bandwidth,
193-
/// Reduces network bandwidth utilization at the expense of more network
194-
/// round-trips.
195-
#[default]
196-
Latency,
197-
}
198-
199185
/// Error for [`MpcTlsConfig`].
200186
#[derive(Debug, thiserror::Error)]
201187
#[error(transparent)]
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//! Proxy-TLS commitment protocol configuration.
2+
3+
use crate::{config::tls_commit::NetworkSetting, connection::DnsName};
4+
use serde::{Deserialize, Serialize};
5+
6+
/// Proxy-TLS commitment protocol configuration.
7+
#[derive(Clone, Debug, Deserialize, Serialize)]
8+
pub struct ProxyTlsConfig {
9+
/// Whether the `deferred decryption` feature is toggled on from the start
10+
/// of the TLS connection.
11+
defer_decryption_from_start: bool,
12+
/// Network settings.
13+
network: NetworkSetting,
14+
/// The server name.
15+
server_name: DnsName,
16+
}
17+
18+
impl ProxyTlsConfig {
19+
/// Creates a new builder.
20+
pub fn builder() -> ProxyTlsConfigBuilder {
21+
ProxyTlsConfigBuilder::default()
22+
}
23+
24+
/// Returns whether the `deferred decryption` feature is toggled on from the
25+
/// start of the TLS connection.
26+
pub fn defer_decryption_from_start(&self) -> bool {
27+
self.defer_decryption_from_start
28+
}
29+
30+
/// Returns the network settings.
31+
pub fn network(&self) -> NetworkSetting {
32+
self.network
33+
}
34+
35+
/// Returns the server name.
36+
pub fn server_name(&self) -> &DnsName {
37+
&self.server_name
38+
}
39+
}
40+
41+
/// Builder for [`ProxyTlsConfig`].
42+
#[derive(Debug, Default)]
43+
pub struct ProxyTlsConfigBuilder {
44+
defer_decryption_from_start: Option<bool>,
45+
network: Option<NetworkSetting>,
46+
server_name: Option<DnsName>,
47+
}
48+
49+
impl ProxyTlsConfigBuilder {
50+
/// Sets whether the `deferred decryption` feature is toggled on from the
51+
/// start of the connection.
52+
pub fn defer_decryption_from_start(mut self, defer_decryption_from_start: bool) -> Self {
53+
self.defer_decryption_from_start = Some(defer_decryption_from_start);
54+
self
55+
}
56+
57+
/// Sets the network settings.
58+
pub fn network(mut self, network: NetworkSetting) -> Self {
59+
self.network = Some(network);
60+
self
61+
}
62+
63+
/// Sets the server name.
64+
pub fn server_name(mut self, server_name: DnsName) -> Self {
65+
self.server_name = Some(server_name);
66+
self
67+
}
68+
69+
/// Builds the configuration.
70+
pub fn build(self) -> Result<ProxyTlsConfig, ProxyTlsConfigError> {
71+
let Self {
72+
defer_decryption_from_start,
73+
network,
74+
server_name,
75+
} = self;
76+
77+
let defer_decryption_from_start = defer_decryption_from_start.unwrap_or(true);
78+
let network = network.unwrap_or_default();
79+
let server_name = server_name.ok_or(ProxyTlsConfigError(ErrorRepr::MissingField {
80+
name: "server_name",
81+
}))?;
82+
83+
let config = ProxyTlsConfig {
84+
defer_decryption_from_start,
85+
network,
86+
server_name,
87+
};
88+
89+
Ok(config)
90+
}
91+
}
92+
93+
/// Error for [`ProxyTlsConfig`].
94+
#[derive(Debug, thiserror::Error)]
95+
#[error(transparent)]
96+
pub struct ProxyTlsConfigError(#[from] ErrorRepr);
97+
98+
#[derive(Debug, thiserror::Error)]
99+
enum ErrorRepr {
100+
#[error("missing field: {name}")]
101+
MissingField { name: &'static str },
102+
}

crates/core/src/config/verifier.rs

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
33
use serde::{Deserialize, Serialize};
44

5-
use crate::webpki::RootCertStore;
5+
use crate::{
6+
config::tls_commit::{TlsCommitProtocolConfig, TlsCommitRequest},
7+
webpki::RootCertStore,
8+
};
69

710
/// Verifier configuration.
811
#[derive(Debug, Clone, Serialize, Deserialize)]
912
pub struct VerifierConfig {
1013
root_store: RootCertStore,
14+
mode: ConnectionMode,
1115
}
1216

1317
impl VerifierConfig {
@@ -20,12 +24,18 @@ impl VerifierConfig {
2024
pub fn root_store(&self) -> &RootCertStore {
2125
&self.root_store
2226
}
27+
28+
/// Returns the accepted mode.
29+
pub fn mode(&self) -> ConnectionMode {
30+
self.mode
31+
}
2332
}
2433

2534
/// Builder for [`VerifierConfig`].
2635
#[derive(Debug, Default)]
2736
pub struct VerifierConfigBuilder {
2837
root_store: Option<RootCertStore>,
38+
mode: ConnectionMode,
2939
}
3040

3141
impl VerifierConfigBuilder {
@@ -35,12 +45,74 @@ impl VerifierConfigBuilder {
3545
self
3646
}
3747

48+
/// Uses multi-party computation for creating commitments.
49+
pub fn mpc(mut self) -> Self {
50+
self.mode = ConnectionMode::Mpc;
51+
self
52+
}
53+
54+
/// Uses proxy mode for creating commitments.
55+
pub fn proxy(mut self) -> Self {
56+
self.mode = ConnectionMode::Proxy;
57+
self
58+
}
59+
60+
/// Allows both modes for creating commitments.
61+
pub fn universal(mut self) -> Self {
62+
self.mode = ConnectionMode::Universal;
63+
self
64+
}
65+
3866
/// Builds the configuration.
3967
pub fn build(self) -> Result<VerifierConfig, VerifierConfigError> {
4068
let root_store = self
4169
.root_store
4270
.ok_or(ErrorRepr::MissingField { name: "root_store" })?;
43-
Ok(VerifierConfig { root_store })
71+
let mode = self.mode;
72+
73+
Ok(VerifierConfig { root_store, mode })
74+
}
75+
}
76+
77+
/// The mode of operation the verifier accepts.
78+
///
79+
/// Sets how the TLS transcript commitments can be created.
80+
#[derive(Default, Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
81+
pub enum ConnectionMode {
82+
/// Only accepts multi-party computation.
83+
#[default]
84+
Mpc,
85+
/// Only accepts proxy mode.
86+
Proxy,
87+
/// Accepts both modes.
88+
Universal,
89+
}
90+
91+
impl ConnectionMode {
92+
/// Checks if the verifier supports the mode of operation requested.
93+
pub fn agrees_with(&self, request: &TlsCommitRequest) -> bool {
94+
let config = request.protocol();
95+
96+
if matches!(self, Self::Universal) {
97+
return true;
98+
}
99+
if matches!(self, Self::Mpc) && matches!(config, TlsCommitProtocolConfig::Mpc(_)) {
100+
return true;
101+
}
102+
if matches!(self, Self::Proxy) && matches!(config, TlsCommitProtocolConfig::Proxy(_)) {
103+
return true;
104+
}
105+
false
106+
}
107+
}
108+
109+
impl std::fmt::Display for ConnectionMode {
110+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
111+
match self {
112+
ConnectionMode::Mpc => write!(f, "MPC mode"),
113+
ConnectionMode::Proxy => write!(f, "Proxy mode"),
114+
ConnectionMode::Universal => write!(f, "Universal mode"),
115+
}
44116
}
45117
}
46118

crates/core/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,30 @@ pub use rangeset;
1515
pub mod config;
1616
pub(crate) mod display;
1717

18+
pub use mpz_memory_core::{binary::U8, Array};
19+
1820
use serde::{Deserialize, Serialize};
1921

2022
use crate::{
2123
connection::ServerName,
2224
transcript::{PartialTranscript, TranscriptCommitment, TranscriptSecret},
2325
};
2426

27+
/// TLS session keys.
28+
#[derive(Debug, Clone)]
29+
pub struct SessionKeys {
30+
/// Client write key.
31+
pub client_write_key: Array<U8, 16>,
32+
/// Client write IV.
33+
pub client_write_iv: Array<U8, 4>,
34+
/// Server write key.
35+
pub server_write_key: Array<U8, 16>,
36+
/// Server write IV.
37+
pub server_write_iv: Array<U8, 4>,
38+
/// Server write MAC key.
39+
pub server_write_mac_key: Array<U8, 16>,
40+
}
41+
2542
/// Prover output.
2643
#[derive(Serialize, Deserialize)]
2744
pub struct ProverOutput {

0 commit comments

Comments
 (0)