internals: add track_caller to U256 ops
What changed, and why it matters
This commit only adds Rust's #[track_caller] annotation to internal functions that already could panic in debug builds. It does not change any behavior, fix a bug, or introduce a vulnerability. It merely improves the quality of panic messages by pointing callers to the right location in source code.
No security action needed. Treat as a normal code-quality / diagnostics improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds #[track_caller] to U256 arithmetic operator implementations (Add, Sub, Mul, Div, Rem) and to ArrayVec constructors/extend methods. These functions already documented panic conditions (overflow in debug builds for Add/Sub/Mul, division by zero for Div/Rem, and capacity overflow for ArrayVec). The annotation is a Rust attribute that propagates the caller’s location into panic messages; it has no runtime effect on logic, safety, or security boundaries.
Changed components
internals/src/u256.rsinternals/src/array_vec.rsInspect captured patch +8 / −0
### internals/src/array_vec.rs
@@ -36,6 +36,7 @@ mod safety_boundary {
/// # Panics
///
/// If the slice is longer than `CAP`.
+ #[track_caller]
#[cfg_attr(creusot, check(ghost))]
#[cfg_attr(creusot, requires(slice@.len() <= CAP@))]
#[cfg_attr(creusot, ensures(result@ == slice@))]
@@ -296,6 +297,7 @@ impl<T: Copy, const CAP: usize> ArrayVec<T, CAP> {
/// # Panics
///
/// If the length would increase past CAP.
+ #[track_caller]
#[cfg_attr(creusot, requires(slice@.len() <= CAP@ - self@.len()))]
#[cfg_attr(creusot, ensures((^self)@ == (*self)@.concat(slice@)))]
pub fn extend_from_slice(&mut self, slice: &[T]) {
### internals/src/u256.rs
@@ -128,6 +128,7 @@ impl U256 {
///
/// If `rhs` is zero.
#[allow(clippy::indexing_slicing)]
+ #[track_caller]
fn div_rem(self, rhs: Self) -> (Self, Self) {
let mut sub_copy = self;
let mut shift_copy = rhs;
@@ -400,6 +401,7 @@ impl<T: Into<u128>> From<T> for U256 {
impl Add for U256 {
type Output = Self;
+ #[track_caller]
fn add(self, rhs: Self) -> Self {
let (res, overflow) = self.overflowing_add(rhs);
debug_assert!(!overflow, "addition of U256 values overflowed");
@@ -409,6 +411,7 @@ impl Add for U256 {
impl Sub for U256 {
type Output = Self;
+ #[track_caller]
fn sub(self, rhs: Self) -> Self {
let (res, overflow) = self.overflowing_sub(rhs);
debug_assert!(!overflow, "subtraction of U256 values overflowed");
@@ -418,6 +421,7 @@ impl Sub for U256 {
impl Mul for U256 {
type Output = Self;
+ #[track_caller]
fn mul(self, rhs: Self) -> Self {
let (res, overflow) = self.overflowing_mul(rhs);
debug_assert!(!overflow, "multiplication of U256 values overflowed");
@@ -427,11 +431,13 @@ impl Mul for U256 {
impl Div for U256 {
type Output = Self;
+ #[track_caller]
fn div(self, rhs: Self) -> Self { self.div_rem(rhs).0 }
}
impl Rem for U256 {
type Output = Self;
+ #[track_caller]
fn rem(self, rhs: Self) -> Self { self.div_rem(rhs).1 }
}
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.