Sitelet https://github.com/starkware-libs/cairo/commit/7c0eb5dbe32ad5b0e8e06395f239af6f7f061224
Skip to content

Commit 7c0eb5d

Browse files
committed
Made Encode::size_hint more exact.
1 parent 9899f18 commit 7c0eb5d

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

‎crates/cairo-lang-utils/src/bigint.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ mod impl_parity_scale_codec {
210210
// sign + len packed in the same byte, it allows numbers of byte size up to 63 (2**504),
211211
// data.
212212
let bits = self.value.bits() as usize;
213-
core::mem::size_of::<u8>() + bits.div_ceil(8)
213+
// `encode` always emits at least one data byte (`0` encodes as `[0]`).
214+
core::mem::size_of::<u8>() + bits.div_ceil(8).max(1)
214215
}
215216

216217
/// /!\ Warning this function panics if the number encoded is too big (>= 2**504).

0 commit comments

Comments
 (0)