<!-- canonical: https://0xsimao.com/findings/vertex-downcasting-silent-overflow -->

# Downcasting Leads to Silent Overflow

Low/Info · Three Sigma · Hybrid orderbook DEX · 3rd April 2024

Finding 3S-Vertex-L02 of the Vertex security review.

- Report: /reports/vertex
- Source: https://github.com/0xsimao/audits/blob/main/Three%20Sigma/2024-04-03-vertex.pdf

---

### Description

Variables of type int128 are being upcasted to int256 and then downcasted again in the
burnLp function in [PerpEngineLp.sol](https://github.com/vertex-protocol/vertex-contracts-3sigma-audit/blob/4286c37cf4ee59d7e3231ac4683859f54d0d8e96/contracts/PerpEngineLp.sol#L91-L98) and [SpotEngineLP.sol](https://github.com/vertex-protocol/vertex-contracts-3sigma-audit/blob/4286c37cf4ee59d7e3231ac4683859f54d0d8e96/contracts/SpotEngineLP.sol#L92-L97), leading to silent overflow.

### Recommendation

Consider using a solution like [OpenZeppelin's SafeCast Library](https://docs.openzeppelin.com/contracts/3.x/api/utils#SafeCast).

### Status

Acknowledged

Disclosed by 0xSimao (https://0xsimao.com/).
