February 28, 2024
Why Careful Validation Matters: A Vulnerability Originating in Inline Assembly
Inline assembly in Solidity is often used to make calls more gas-efficient or to make efficient data manipulations. However, it is essential to take extra care, as the Solidity compiler's common safety nets do not apply here.
One of the top Lead Senior Watsons recently uncovered and helped resolve a vulnerability related to the lack of overflow protection in Solidity's inline assembly.
Read on for the details behind the vulnerability that 0x52 detected, allowing the arbitrary call of functions from a vulnerable smart contract.
Context
The function signature is the following:
It is notable that at the usage of this function:
Let's break this down:
Vulnerability
This vulnerability is based on the fact that YUL inline assembly in Solidity has no overflow/underflow protections.
Solution
The project team also implemented this solution.
The Takeaway
This case emphasizes that developers should take extra care when using inline assembly, doing calculations, or manipulating memory, as the common safety nets of Solidity do not apply in these cases.
The outlined finding showcases, once more, the importance of thorough security reviews and testing of smart contract code, especially when using inline assembly.