If Barreto-Naehrig Curves are suitable for pairing-based cryptography, can I use the library available at Optimal ATE Pairing?
According to Trevor Perrin's post from 2016, Barreto-Naehrig curves are not secure enough:
The attack is relevant to pairing-friendly curves (like BN) that support a "pairing" operation. A pairing maps points on the elliptic curve to values in some "extension field". Security depends on both the EC-DLP for the elliptic curve, and also DLP on the extension field.
256-bit BN curves have a field prime p of 256 bits and an "embedding degree" of 12, so the extension field is mod p^12, where p^12 has 3072 bits. The hope was that 256-bit EC-DLP and 3072-bit DLP would both have security ~128 bits, so this would be nicely matched.
However, Kim and Barbulescu showed that DLP where the modulus is a 3072-bit (prime^12) is easier than DLP for a 3072-bit prime. How much easier isn't clear, though by a "crude and naive estimation" they suggest increasing the size of relevant curves by a third (Section 6). Mehdi Tibouchi has a similar estimate : "after this attack, 256-bit Barreto-Naehrig curves no longer offer 128 bits of security, but perhaps closer to 96 or so".
You can, with the right parameter sizes (384-bit prime instead of the older 256-bit).
Pairings can be attacked in two fronts: the elliptic curve or the extension finite field. The security of the pairing will be the the one that is easiest to break.
Previously, a BN curve using an elliptic curve over a 256-bit prime provided 128 bits of security; it was the "perfect" case since the elliptic curve provided 128 bits and the extension field also provided 128 bits.
After Extended Tower Number Field Sieve: A New Complexity for the Medium Prime Case, things changed in the extension field case, and it's hard to give a concrete estimate since the paper handles asymptotics and we'd need to have concrete implementations to have more accuracy. But the paper estimates that the prime size must be doubled (i.e. from 256 bits to 512 for 128 bits of security). Aurore Guillevic estimates that it should be changed to 448 or 512 bits. However, further analysis in Challenges with Assessing the Impact of NFS Advances on the Security of Pairing-based Cryptography, indicate that 384 bits should be enough.
So, if you use $p$ with 384 bits, you should be fine, but the performance won't be very good. In this case, the elliptic curve provides 192 bits of security while the extension field provides 128 bits, and we're stuck with the smaller value.
As an example, Zcash chooses the BLS12 pairing for the 128-bit security level since, due its structure, it is a 256-bit group (instead of a 384-bit group in BN) which makes some things faster. The underlying prime is the same size, though (384 bits).