In this track: Advanced security reasoning
advanced · 4 MIN READ

abi.encodePacked collisions

Variable-width concatenation can erase field boundaries.

LET’S PICTURE IT

Removing separators can make two different forms print the same text.

SEE IT FOR YOURSELF
Build a transfer call from typed fieldsStep 1 / 4
Build a transfer call from typed fieldstransfer(address,uint256)Recipient: 0x0000…0001Raw amount: 100Diagram labels abbreviate addresses; the lab shows full bytes4-byte selectora9059cbbEach box is one byte; this prefix is not a 32-byte wordWord 0 · recipient address12 zero bytes20 address bytes000…0001Left padding preserves the lower-order address valueSelector4 bytesa9059cbbAddress32 bytesword 0Amount32 bytesword 1 → 0x644 + 32 + 32 = 68 bytesThe integer does not contain token decimals or market price

The standard transfer interface takes an address and a raw integer amount. This diagram uses address one and amount one hundred.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Construct the ambiguity

Packed string pairs a with bc and ab with c both produce the bytes abc. This equality exists before hashing.

Distinguish from a hash break

Hashing identical byte input gives identical output normally. No attacker needs to defeat Keccak to exploit a protocol that meant those logical records to differ.

Use a reviewed structured encoding

Standard ABI encoding or another unambiguous typed format can preserve boundaries. Ensure the signing, commitment or proof verifier uses the same format.

Test field-boundary changes

Generate distinct logical records that differ in where variable-length fields split. Their intended commitments should differ under a well-specified schema.

Work through the boundary

packed("a","bc") = 0x616263
packed("ab","c") = 0x616263

Specify boundaries before hashing.

A simplified local review scenario. The example establishes a question to test, not a guarantee of production safety.

QUICK CHECK · NO PRESSURE

Is this ambiguity itself a cryptographic collision attack?

Your progress stays in this browser.
Keep exploring the original referenceSolidity documentation ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.