Skip to main content

compare_normalized

Function compare_normalized 

Source
pub fn compare_normalized(
    onchain: &[u8],
    reference: &[u8],
    impl_addr: Address,
    expected_self_windows: usize,
) -> Result<BytecodeCheck>
Expand description

Compare normalized on-chain bytecode against the binding reference.

Strips the CBOR metadata tail from both, then requires every byte difference to be explained: a difference is only accepted inside a 20-byte window where the on-chain code holds impl_addr and the reference holds zeros. Those windows are the UUPS __self immutable slots (the impl’s own address, baked in at deploy; the binding is compiled with address(this) = 0). Any other difference is a Mismatch, reported with the offset and both values.

Exactly expected_self_windows explained windows are required. This pins the impl address to the immutable slots: substituting it into any other zero region of the reference (e.g. a PUSH32 0 constant) changes the count and fails. Residual: a window misaligned within a 32-byte slot still passes, but a wrong __self value only makes upgradeToAndCall revert (proxiableUUID is notDelegated); it cannot substitute code.

LightClient verification is deferred; bails if the reference contains 0xff*20 library placeholders.