diff --git a/Cargo.lock b/Cargo.lock index 46d68c5df..d55036c36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3176,11 +3176,10 @@ dependencies = [ [[package]] name = "futures-plex" version = "0.1.0" -source = "git+https://github.com/tlsnotary/tlsn-utils?rev=0b46dc0#0b46dc0b11229bd606c6262de0de5ac8f2b76f41" +source = "git+https://github.com/tlsnotary/tlsn-utils?rev=a35cd02#a35cd02c465534f6126941c8b3b695fd78cacf49" dependencies = [ "bytes", - "futures-io", - "futures-util", + "futures", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index d38cbfd13..c04a2787c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,7 +80,7 @@ mpz-zk = { git = "https://github.com/privacy-ethereum/mpz", rev = "bd80826" } mpz-hash = { git = "https://github.com/privacy-ethereum/mpz", rev = "bd80826" } mpz-ideal-vm = { git = "https://github.com/privacy-ethereum/mpz", rev = "bd80826" } -futures-plex = { git = "https://github.com/tlsnotary/tlsn-utils", rev = "0b46dc0" } +futures-plex = { git = "https://github.com/tlsnotary/tlsn-utils", rev = "a35cd02" } rangeset = { version = "0.2" } serio = { version = "0.2" } spansy = { git = "https://github.com/tlsnotary/tlsn-utils", rev = "6168663" } diff --git a/crates/tlsn/src/prover.rs b/crates/tlsn/src/prover.rs index ed36c5574..56048986d 100644 --- a/crates/tlsn/src/prover.rs +++ b/crates/tlsn/src/prover.rs @@ -231,13 +231,14 @@ impl Prover { Ok(prover) } - /// Writes bytes for the verifier into a buffer. - /// - /// # Arguments - /// - /// * `buf` - The buffer. - pub fn write_mpc(&mut self, buf: &mut [u8]) -> std::io::Result { - self.state.mpc_duplex.read(buf) + /// Returns `true` if the prover wants to read data from the verifier. + pub fn wants_read_verifier(&self) -> bool { + self.state.mpc_duplex.remaining_mut() > 0 + } + + /// Returns `true` if the prover wants to write data to the verifier. + pub fn wants_write_verifier(&self) -> bool { + self.state.mpc_duplex.remaining() > 0 } /// Reads bytes for the prover from a buffer. @@ -245,9 +246,18 @@ impl Prover { /// # Arguments /// /// * `buf` - The buffer. - pub fn read_mpc(&mut self, buf: &[u8]) -> std::io::Result { + pub fn read_verifier(&mut self, buf: &[u8]) -> std::io::Result { self.state.mpc_duplex.write(buf) } + + /// Writes bytes for the verifier into a buffer. + /// + /// # Arguments + /// + /// * `buf` - The buffer. + pub fn write_verifier(&mut self, buf: &mut [u8]) -> std::io::Result { + self.state.mpc_duplex.read(buf) + } } impl Prover { @@ -307,13 +317,14 @@ impl Prover { self.state.tls_client.write(buf) } - /// Writes bytes for the verifier into a buffer. - /// - /// # Arguments - /// - /// * `buf` - The buffer. - pub fn write_mpc(&mut self, buf: &mut [u8]) -> std::io::Result { - self.state.mpc_duplex.read(buf) + /// Returns `true` if the prover wants to read data from the verifier. + pub fn wants_read_verifier(&self) -> bool { + self.state.mpc_duplex.remaining_mut() > 0 + } + + /// Returns `true` if the prover wants to write data to the verifier. + pub fn wants_write_verifier(&self) -> bool { + self.state.mpc_duplex.remaining() > 0 } /// Reads bytes for the prover from a buffer. @@ -321,10 +332,19 @@ impl Prover { /// # Arguments /// /// * `buf` - The buffer. - pub fn read_mpc(&mut self, buf: &[u8]) -> std::io::Result { + pub fn read_verifier(&mut self, buf: &[u8]) -> std::io::Result { self.state.mpc_duplex.write(buf) } + /// Writes bytes for the verifier into a buffer. + /// + /// # Arguments + /// + /// * `buf` - The buffer. + pub fn write_verifier(&mut self, buf: &mut [u8]) -> std::io::Result { + self.state.mpc_duplex.read(buf) + } + /// Closes the connection from the client side. pub fn client_close(&mut self) -> Result<(), ProverError> { self.state.tls_client.client_close() @@ -411,13 +431,14 @@ impl Prover { &self.state.transcript } - /// Writes bytes for the verifier into a buffer. - /// - /// # Arguments - /// - /// * `buf` - The buffer. - pub fn write_mpc(&mut self, buf: &mut [u8]) -> std::io::Result { - self.state.mpc_duplex.read(buf) + /// Returns `true` if the prover wants to read data from the verifier. + pub fn wants_read_verifier(&self) -> bool { + self.state.mpc_duplex.remaining_mut() > 0 + } + + /// Returns `true` if the prover wants to write data to the verifier. + pub fn wants_write_verifier(&self) -> bool { + self.state.mpc_duplex.remaining() > 0 } /// Reads bytes for the prover from a buffer. @@ -425,10 +446,19 @@ impl Prover { /// # Arguments /// /// * `buf` - The buffer. - pub fn read_mpc(&mut self, buf: &[u8]) -> std::io::Result { + pub fn read_verifier(&mut self, buf: &[u8]) -> std::io::Result { self.state.mpc_duplex.write(buf) } + /// Writes bytes for the verifier into a buffer. + /// + /// # Arguments + /// + /// * `buf` - The buffer. + pub fn write_verifier(&mut self, buf: &mut [u8]) -> std::io::Result { + self.state.mpc_duplex.read(buf) + } + /// Proves information to the verifier. /// /// # Arguments diff --git a/crates/tlsn/src/verifier.rs b/crates/tlsn/src/verifier.rs index 693302c7a..69c9768f3 100644 --- a/crates/tlsn/src/verifier.rs +++ b/crates/tlsn/src/verifier.rs @@ -186,13 +186,14 @@ impl Verifier { Ok(()) } - /// Writes bytes for the prover into a buffer. - /// - /// # Arguments - /// - /// * `buf` - The buffer. - pub fn write_mpc(&mut self, buf: &mut [u8]) -> std::io::Result { - self.state.mpc_duplex.read(buf) + /// Returns `true` if the verifier wants to read data from the prover. + pub fn wants_read_prover(&self) -> bool { + self.state.mpc_duplex.remaining_mut() > 0 + } + + /// Returns `true` if the verifier wants to write data to the prover. + pub fn wants_write_prover(&self) -> bool { + self.state.mpc_duplex.remaining() > 0 } /// Reads bytes for the verifier from a buffer. @@ -200,9 +201,18 @@ impl Verifier { /// # Arguments /// /// * `buf` - The buffer. - pub fn read_mpc(&mut self, buf: &[u8]) -> std::io::Result { + pub fn read_prover(&mut self, buf: &[u8]) -> std::io::Result { self.state.mpc_duplex.write(buf) } + + /// Writes bytes for the prover into a buffer. + /// + /// # Arguments + /// + /// * `buf` - The buffer. + pub fn write_prover(&mut self, buf: &mut [u8]) -> std::io::Result { + self.state.mpc_duplex.read(buf) + } } impl Verifier { @@ -278,13 +288,14 @@ impl Verifier { }) } - /// Writes bytes for the prover into a buffer. - /// - /// # Arguments - /// - /// * `buf` - The buffer. - pub fn write_mpc(&mut self, buf: &mut [u8]) -> std::io::Result { - self.state.mpc_duplex.read(buf) + /// Returns `true` if the verifier wants to read data from the prover. + pub fn wants_read_prover(&self) -> bool { + self.state.mpc_duplex.remaining_mut() > 0 + } + + /// Returns `true` if the verifier wants to write data to the prover. + pub fn wants_write_prover(&self) -> bool { + self.state.mpc_duplex.remaining() > 0 } /// Reads bytes for the verifier from a buffer. @@ -292,9 +303,18 @@ impl Verifier { /// # Arguments /// /// * `buf` - The buffer. - pub fn read_mpc(&mut self, buf: &[u8]) -> std::io::Result { + pub fn read_prover(&mut self, buf: &[u8]) -> std::io::Result { self.state.mpc_duplex.write(buf) } + + /// Writes bytes for the prover into a buffer. + /// + /// # Arguments + /// + /// * `buf` - The buffer. + pub fn write_prover(&mut self, buf: &mut [u8]) -> std::io::Result { + self.state.mpc_duplex.read(buf) + } } impl Verifier { @@ -342,13 +362,14 @@ impl Verifier { }) } - /// Writes bytes for the prover into a buffer. - /// - /// # Arguments - /// - /// * `buf` - The buffer. - pub fn write_mpc(&mut self, buf: &mut [u8]) -> std::io::Result { - self.state.mpc_duplex.read(buf) + /// Returns `true` if the verifier wants to read data from the prover. + pub fn wants_read_prover(&self) -> bool { + self.state.mpc_duplex.remaining_mut() > 0 + } + + /// Returns `true` if the verifier wants to write data to the prover. + pub fn wants_write_prover(&self) -> bool { + self.state.mpc_duplex.remaining() > 0 } /// Reads bytes for the verifier from a buffer. @@ -356,10 +377,19 @@ impl Verifier { /// # Arguments /// /// * `buf` - The buffer. - pub fn read_mpc(&mut self, buf: &[u8]) -> std::io::Result { + pub fn read_prover(&mut self, buf: &[u8]) -> std::io::Result { self.state.mpc_duplex.write(buf) } + /// Writes bytes for the prover into a buffer. + /// + /// # Arguments + /// + /// * `buf` - The buffer. + pub fn write_prover(&mut self, buf: &mut [u8]) -> std::io::Result { + self.state.mpc_duplex.read(buf) + } + /// Closes the connection with the prover. #[instrument(parent = &self.span, level = "info", skip_all, err)] pub async fn close(self) -> Result<(), VerifierError> { @@ -475,13 +505,14 @@ impl Verifier { }) } - /// Writes bytes for the prover into a buffer. - /// - /// # Arguments - /// - /// * `buf` - The buffer. - pub fn write_mpc(&mut self, buf: &mut [u8]) -> std::io::Result { - self.state.mpc_duplex.read(buf) + /// Returns `true` if the verifier wants to read data from the prover. + pub fn wants_read_prover(&self) -> bool { + self.state.mpc_duplex.remaining_mut() > 0 + } + + /// Returns `true` if the verifier wants to write data to the prover. + pub fn wants_write_prover(&self) -> bool { + self.state.mpc_duplex.remaining() > 0 } /// Reads bytes for the verifier from a buffer. @@ -489,7 +520,16 @@ impl Verifier { /// # Arguments /// /// * `buf` - The buffer. - pub fn read_mpc(&mut self, buf: &[u8]) -> std::io::Result { + pub fn read_prover(&mut self, buf: &[u8]) -> std::io::Result { self.state.mpc_duplex.write(buf) } + + /// Writes bytes for the prover into a buffer. + /// + /// # Arguments + /// + /// * `buf` - The buffer. + pub fn write_prover(&mut self, buf: &mut [u8]) -> std::io::Result { + self.state.mpc_duplex.read(buf) + } }