common: Make arith_uint256 trivially copyable
What changed, and why it matters
This commit simplifies the internal copy behavior of a core Bitcoin data type (arith_uint256) by letting the compiler generate default copy routines instead of hand-written loops. The change is framed as a performance/cleanup improvement and includes a compile-time check that the type remains trivially copyable. There is no indication this fixes a security bug or introduces a vulnerability.
No security action required. Treat as a normal code-quality/performance refactor. Standard review for correctness is sufficient.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch removes explicit copy constructor and copy assignment operator implementations in base_uint (the parent of arith_uint256) and replaces them with = default. It also adds a static_assert(std::is_trivially_copyable_v
Changed components
src/arith_uint256.hbase_uintarith_uint256Inspect captured patch +5 / −14
diff --git a/src/arith_uint256.h b/src/arith_uint256.h
index 0cf7aa44..5cefff53 100644
--- a/src/arith_uint256.h
+++ b/src/arith_uint256.h
@@ -37,20 +37,8 @@ public:
pn[i] = 0;
}
- base_uint(const base_uint& b)
- {
- for (int i = 0; i < WIDTH; i++)
- pn[i] = b.pn[i];
- }
-
- base_uint& operator=(const base_uint& b)
- {
- if (this != &b) {
- for (int i = 0; i < WIDTH; i++)
- pn[i] = b.pn[i];
- }
- return *this;
- }
+ base_uint(const base_uint& b) = default;
+ base_uint& operator=(const base_uint& b) = default;
base_uint(uint64_t b)
{
@@ -272,6 +260,9 @@ public:
friend arith_uint256 UintToArith256(const uint256 &);
};
+// Keeping the trivially copyable property is beneficial for performance
+static_assert(std::is_trivially_copyable_v<arith_uint256>);
+
uint256 ArithToUint256(const arith_uint256 &);
arith_uint256 UintToArith256(const uint256 &);
Why this scored 18/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.