From d6b68d3dc1df3b999280a71bc0623025644e10ef Mon Sep 17 00:00:00 2001 From: baku-ccron Date: Wed, 16 Sep 2026 11:43:49 +0000 Subject: [PATCH] docs: put the cross-type counterexample back beside the claim #113 cut the README's copy of the abi.encode argument and, with it, the one concrete thing in that copy: abi.encode of uint8(1), uint256(1), true and address(1) is the same 32 bytes in every case. The claim it illustrates, that abi.encode is not injective across types, survived in the LibHashNoAlloc title block without it, where the claim reads as an assertion rather than a demonstration. The four encodings are re-verified with cast abi-encode at foundry 1.7.2: each is 0x00...01, one word. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01V8ViHcKLVk2YoS2joH4HdN --- src/lib/LibHashNoAlloc.sol | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/LibHashNoAlloc.sol b/src/lib/LibHashNoAlloc.sol index 91e740f..46ebf76 100644 --- a/src/lib/LibHashNoAlloc.sol +++ b/src/lib/LibHashNoAlloc.sol @@ -20,8 +20,11 @@ bytes32 constant HASH_NIL = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7b /// to use abi.encode, which includes the lengths disambiguating dynamic data. /// Something like `3"abc" + 3"def"` with the length prefixes won't collide with /// `2"ab" + 4"cdef"`: within one type tuple `abi.encode` is injective because -/// `abi.decode` recovers the value. It is not injective across types, which is -/// the same restriction the composition below carries, and it is not efficient. +/// `abi.decode` recovers the value. It is not injective across types: +/// `abi.encode(uint8(1))`, `abi.encode(uint256(1))`, `abi.encode(true)` and +/// `abi.encode(address(1))` are all the same 32 bytes. That is the same +/// restriction the composition below carries, and abi encoding is not efficient +/// either. /// /// - Abi encoding is a complex algorithm that costs several hundred gas for a /// struct with one or two dynamic typed fields even when those fields are