Skip to content

ethlambda-rpc tests fail in debug builds: u8 overflow in ptc.rs test state builder #786

Open

Description

@unbalancedparentheses

Summary

60 ethlambda-rpc unit tests fail in debug builds with attempt to add with overflow. CI does not see it because tests run with the release-fast profile, where overflow checks are off.

Cause

crates/net/rpc/src/beacon/ptc.rs:574, in a test state builder:

for slot in 0..inner.block_roots.len() {
    inner.block_roots[slot] = H256::repeat_byte(slot as u8 + 1);
}

block_roots has more than 255 entries, so at slot == 255 the expression slot as u8 + 1 overflows (255u8 + 1). In release it wraps silently, which also means the "distinct roots per slot" intent breaks after slot 255 (roots repeat).

Reproduce

cargo test -p ethlambda-rpc --lib

(debug profile) → 60 failures at ptc.rs:574. Same result on main c3f5f56 and on #783.

Suggested fix

Use a root that stays distinct for every slot, e.g. H256::from_low_u64_be(slot as u64 + 1), or (slot as u8).wrapping_add(1) if distinctness beyond 255 doesn't matter. Consider running unit tests in debug (or with overflow-checks = true) in CI.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions