Using safeTransferFrom, is there any benefit of checking allowance before performing the safeTransferFrom?
Just with the safeTransferFrom it would revert is there is not enough allowance, right?
So can I remove the allowance check and save gas? Or is there a good reason to keep it?
If missing allowance, just revert, as stated in the require.
AFAIK safeTransferFrom also would revert if no allowance, since the transferfrom wouldn't succeed. Since there is no specific operation other than revert, is there a point on performing the check of allowance? Or could I just ignore the first line as it doesn't add any value/security?
It will revert even without that require but that line can help logging. You will get Insufficient allowance error message if allowance is not enough. Removing that line you won't see that message.
If your compiler version is >= 0.8.0 the compiled code already includes the under/overflow checks but will revert with a code (you can find a list here)
The require() is there to provide you with a clear error message in cases where a revert() will happen anyway
I don't know if I understand you, but the require here has nothing to do with under/overflow. But rather with checking if there is enough allowance before a safeTransferFrom, and know if it is useful at all.
It does. Not having enough allowance would cause a revertinstead, assuming no other checks. This returns error 0x000...000011, which is kind of cryptic. When using a require, there is a clear error message
correct. In the OZ implementations the common pattern is to find a require and then an unchecked block to optimize for gas. You don't seem to be implementing a token, by your first example. It seems that you are interacting with a token. two different things
I'm interacting with a token.
I'm just asking if there is any advantage on using that line. And I just get that in some tokens, I may get less information if it reverts. But no security risks.
Right?
that's right. if you are calling a token there is no risk in not checking. it just means that you might get an error message or an error code depending on the token implementation instead of a consistent error message