From 9f849e7c185bbf929b921beed43a11b95667157a Mon Sep 17 00:00:00 2001 From: th4s Date: Wed, 13 Aug 2025 09:57:00 +0200 Subject: [PATCH] fix(encoding): set correct frame limit (#963) * fix(encoding): set correct frame limit * bugfix for `TranscriptRefs::len` * use current frame limit as cushion room --- crates/tlsn/src/commit/transcript.rs | 8 ++++++++ crates/tlsn/src/encoding.rs | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/crates/tlsn/src/commit/transcript.rs b/crates/tlsn/src/commit/transcript.rs index e4d0b77f2..db30b36cc 100644 --- a/crates/tlsn/src/commit/transcript.rs +++ b/crates/tlsn/src/commit/transcript.rs @@ -28,6 +28,14 @@ impl TranscriptRefs { &self.recv } + /// Returns the transcript lengths. + pub(crate) fn len(&self) -> (usize, usize) { + let sent = self.sent.iter().map(|v| v.len()).sum(); + let recv = self.recv.iter().map(|v| v.len()).sum(); + + (sent, recv) + } + /// Returns VM references for the given direction and index, otherwise /// `None` if the index is out of bounds. pub(crate) fn get(&self, direction: Direction, idx: &Idx) -> Option>> { diff --git a/crates/tlsn/src/encoding.rs b/crates/tlsn/src/encoding.rs index 7ab71655d..302a8fa0e 100644 --- a/crates/tlsn/src/encoding.rs +++ b/crates/tlsn/src/encoding.rs @@ -88,7 +88,12 @@ pub(crate) async fn transfer<'a>( .zip(recv_keys) .for_each(|(enc, key)| *enc ^= key); + // Set frame limit and add some extra bytes cushion room. + let (sent, recv) = refs.len(); + let frame_limit = ENCODING_SIZE * (sent + recv) + ctx.io().limit(); + ctx.io_mut() + .with_limit(frame_limit) .send(Encodings { sent: sent_encoding, recv: recv_encoding, @@ -114,7 +119,12 @@ pub(crate) async fn receive<'a>( f: impl Fn(Vector) -> &'a [Mac], idxs: impl IntoIterator, ) -> Result<(EncodingCommitment, EncodingTree), EncodingError> { - let Encodings { mut sent, mut recv } = ctx.io_mut().expect_next().await?; + // Set frame limit and add some extra bytes cushion room. + let (sent, recv) = refs.len(); + let frame_limit = ENCODING_SIZE * (sent + recv) + ctx.io().limit(); + + let Encodings { mut sent, mut recv } = + ctx.io_mut().with_limit(frame_limit).expect_next().await?; let sent_macs: Vec = refs .sent()