I am checking if an address is a smart contract. Similarly to many articles and example-codes out there, i do this within my function:
uint32 size;
assembly{
size := extcodesize(_to)
}
if(size > 0){}
However, when I do this, as so many others seem to do, I get this error:
security/no-inline-assembly: Avoid using Inline Assembly.
I seem to struggle to find a solution to this. Even in the solidity 0.5.0 documentation they describe inline assembly, so seems weird that it is not allowed. Has anyone else encountered this, and found a solution to it?
Best Answer
If you're using Remix, this should only give you the following warning, not an error. It gives you an idea as to why you should avoid assembly (presumably unless you know what you're doing).
If you're using
solc
directly, then I think you'll need to play around with thesolhint
configuration, specifically under the Security Rules section. (See theno-inline-assembly
rule.) You should be able to set it to 'false'. (Though on your head be it.)For your specific piece of code, you need to be careful - it might not do what you expect it to do. See the Consensys Best Practices for why: