alloy-rs / alloy-rs/ruint

Trailing characters on zero values are accepted

Đang mở
#389 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Rust
Star
225
Fork
70
Merge trung bình
16 giờ 54 phút
Pull request đã merge (30 ngày)
8

Mô tả

**Version**
```
1.12.3
```

**Platform**
```
Darwin Dans-MacBook-Pro-4.local 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:44 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6000 arm64
```

**Description**
I was noticing that reth was succeeding when it got `eth_getStorageAt` calls that had a 67-character "zero" slot:
`0x00000000000000000000000000000000000000000000000000000000000000000`

I wrote a crude test to check this:
```rust
#[test]
fn test_serde_invalid_size_error_zero() {
// Test that if we add a character to a zero value for the given number of bits, we get an
// error.
const_for!(BITS in SIZES {
const LIMBS: usize = nlimbs(BITS);

// repeated pattern of 0
let mut zero_bytes = BITS / 8;
if BITS % 8 != 0 {
zero_bytes += 1;
}

let mut serialized = String::from("\"0x");

// push zero bytes
for _ in 0..zero_bytes {
serialized.push('0');
serialized.push('0');
}
// add one zero
serialized.push('0');

// edge case: zero bits, we should only be able to deser `0x0` for the zero bit Uint
if BITS == 0 {
serialized.push('0');
}

serialized.push('\"');

// ensure format of serialized value is correct ("0x...")
assert_eq!(&serialized[..3], "\"0x");
// last character should be a quote
assert_eq!(&serialized[serialized.len() - 1..], "\"");

let deserialized = serde_json::from_str::>(&serialized);
assert!(deserialized.is_err(), "{BITS} {serialized}");
});
}
```

To be compliant with QUANTITY, these should be rejected.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.