kadenzipfel / smart-contract-vulnerabilities

A collection of smart contract vulnerabilities along with prevention methods
https://kadenzipfel.github.io/smart-contract-vulnerabilities/
1.83k stars 256 forks source link

Potential hash collision when using abi.encodePacked() with multiple variable-length arguments #57

Closed indeqs closed 3 months ago

indeqs commented 4 months ago

Checklist

Type of Issue

Description

Using abi.encodePacked() with multiple variable-length arguments can, in certain situations, lead to a hash collision. Since abi.encodePacked() packs all elements in order regardless of whether they're part of an array, you can move elements between arrays and, so long as all elements are in the same order, it will return the same encoding. In a signature verification situation, an attacker could exploit this by modifying the position of elements in a previous function call to effectively bypass authorization.

Sources