# Integer overflow and underflow (desbordamiento y subdesbordamiento de enteros)

El desbordamiento ocurre cuando una operación aritmética excede el límite superior del tipo de dato entero, y el subdesbordamiento ocurre cuando la operación cae por debajo del límite inferior.

**Ejemplo**:

```solidity
uint8 a = 255;
a += 1; // Esto causa un desbordamiento, llevando el valor de 'a' a 0.
```

**Mitigación**:

* Usar Solidity 0.8.x o superior, que tiene controles de desbordamiento y subdesbordamiento incorporados.
* Usar bibliotecas de aritmética segura como SafeMath de OpenZeppelin para versiones anteriores.

**Referencia**:

* [OpenZeppelin SafeMath](https://docs.openzeppelin.com/contracts/2.x/api/math)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://edp.ethkipu.org/modulo-5/seguridad-pruebas-y-auditoria/seguridad/principales-vulnerabilidades-en-smart-contracts/integer-overflow-and-underflow-desbordamiento-y-subdesbordamiento-de-enteros.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
