consensus_encoding: add track_caller to panic-able sites
What changed, and why it matters
This commit adds Rust's #[track_caller] attribute to two methods in a decoding trait. This is a diagnostic improvement: if the code ever panics, the error message will point to the caller's location instead of deep inside the library. It does not change what the code does, what data it accepts, or whether it panics. There is no security fix here.
No security action required. Treat as a normal code-quality/diagnostics improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change annotates Decoder::push_bytes and Decoder::end with #[track_caller]. This attribute instructs the Rust compiler to preserve the caller’s source location for panic messages and backtraces. It is purely additive for debugging/diagnostics and has no effect on runtime behavior, input validation, error handling, or exploitability. The commit message explicitly frames it as a defensive, low-impact addition.
Changed components
consensus_encoding/src/decode/mod.rsDecoder traitInspect captured patch +2 / −0
diff --git a/consensus_encoding/src/decode/mod.rs b/consensus_encoding/src/decode/mod.rs
index e1d3e705..ed48e829 100644
--- a/consensus_encoding/src/decode/mod.rs
+++ b/consensus_encoding/src/decode/mod.rs
@@ -40,6 +40,7 @@ pub trait Decoder: Sized {
///
/// May panic if called after a previous call to [`Self::push_bytes`] errored.
#[must_use = "must check result to avoid panics on subsequent calls"]
+ #[track_caller]
fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error>;
/// Complete the decoding process and return the final result.
@@ -57,6 +58,7 @@ pub trait Decoder: Sized {
///
/// May panic if called after a previous call to [`Self::push_bytes`] errored.
#[must_use = "must check result to avoid panics on subsequent calls"]
+ #[track_caller]
fn end(self) -> Result<Self::Output, Self::Error>;
/// Returns the maximum number of bytes this decoder can consume without over-reading.
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.