Skip to content

Hash Collision via abi.encodePacked with Dynamic Types

SAFE-0048 Signatures Checked automatically by the scanner
1

What goes wrong

abi.encodePacked of multiple variable-length arguments can produce identical byte strings for different inputs (e.g. ['a','bc'] vs ['ab','c']), enabling hash collisions in signatures, Merkle leaves, or commitments.

2

How to fix it

the pattern that is safe
bytes32 id = keccak256(abi.encode(name, symbol));        // length-safe
SWC-133. Prefer abi.encode for multi-dynamic hashing.
Check your own contract for this

The SaferICO scanner runs 201 detectors over your Solidity source, SAFE-0048 among them. Paste an address or the source itself — a small per-scan fee, shown before you sign, or unlimited on any plan.

Run the scanner See how it is attacked Read the docs