CountersUpgradeable.sol

File @openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol does not anymore exists. Solution? How can we use Counters for upgradable contracts?

The reason for removing Counters can be found here:

The point of Counters was to provide an "object" that was guaranteed to behave in a way that will not overflow, therefore can be safely incremented in an "unchecked" way. It was introduced before Solidity had native checked arithmetic, so it made slightly more sense back then. There are a few issues though. This "guarantee" was always a soft guarantee, because the inner struct members are directly modifiable bypassing the struct interface. Additionally, a Counter being a uint256 value occupies an entire storage slot whereas in most occasions packing a counter in storage with other values will be a far larger optimization than removing overflow checks; the significance of this has also changed since the introduction of Counters due to changes in the EVM gas prices.

So in short, just use your own variable (state or local, depending on your requirements) as a counter.

1 Like