diff --git a/crates/utils/src/rlp.cairo b/crates/utils/src/rlp.cairo index 422797d32..180050982 100644 --- a/crates/utils/src/rlp.cairo +++ b/crates/utils/src/rlp.cairo @@ -158,9 +158,8 @@ impl RLPImpl of RLPTrait { match rlp_type { RLPType::String => { - // checking for default value `0` if (len == 0) { - output.append(RLPItem::String(array![0].span())); + output.append(RLPItem::String(array![].span())); } else { output.append(RLPItem::String(input.slice(offset, len))); } @@ -192,6 +191,10 @@ impl RLPHelpersImpl of RLPHelpersTrait { fn parse_u128_from_string(self: RLPItem) -> Result { match self { RLPItem::String(bytes) => { + // Empty strings means 0 + if bytes.len() == 0 { + return Result::Ok(0); + } let value = U128Impl::from_bytes(bytes).ok_or(RLPHelpersError::FailedParsingU128)?; Result::Ok(value) }, @@ -202,6 +205,10 @@ impl RLPHelpersImpl of RLPHelpersTrait { fn parse_u256_from_string(self: RLPItem) -> Result { match self { RLPItem::String(bytes) => { + // Empty strings means 0 + if bytes.len() == 0 { + return Result::Ok(0); + } let value = U256Impl::from_bytes(bytes).ok_or(RLPHelpersError::FailedParsingU256)?; Result::Ok(value) }, diff --git a/crates/utils/src/tests/test_data.cairo b/crates/utils/src/tests/test_data.cairo index 15f87dbf6..723b2edce 100644 --- a/crates/utils/src/tests/test_data.cairo +++ b/crates/utils/src/tests/test_data.cairo @@ -51,7 +51,7 @@ fn legacy_rlp_encoded_tx() -> Span { 239, 1, 128, - 128 + 128, ] .span() } @@ -110,7 +110,7 @@ fn eip_2930_encoded_tx() -> Span { 171, 205, 239, - 192 + 192, ] .span() } @@ -169,7 +169,7 @@ fn eip_1559_encoded_tx() -> Span { 171, 205, 239, - 192 + 192, ] .span() } diff --git a/crates/utils/src/tests/test_rlp.cairo b/crates/utils/src/tests/test_rlp.cairo index 020fa1f7a..275dd0483 100644 --- a/crates/utils/src/tests/test_rlp.cairo +++ b/crates/utils/src/tests/test_rlp.cairo @@ -381,7 +381,7 @@ fn test_rlp_decode_string_default_value() { let mut arr = array![0x80]; let rlp_item = RLPTrait::decode(arr.span()).unwrap(); - let expected = RLPItem::String(array![0].span()); + let expected = RLPItem::String(array![].span()); assert(rlp_item.len() == 1, 'item length not 1'); assert(*rlp_item[0] == expected, 'default value not 0'); @@ -2121,7 +2121,7 @@ fn test_rlp_decode_long_list() { .span() ); - let mut expected_16 = RLPItem::String(array![0].span()); + let mut expected_16 = RLPItem::String(array![].span()); let mut expected = array![ expected_0,