In the world of blockchain, tokens are considered assets. These assets have to be secured safely. It is the auditor’s responsibility to test a smart contract for vulnerabilities after the developers have created it. Tokens are created using smart contracts that, in turn, use the ERC 20 standard.
So, how do you audit ERC 20 contracts?
Follow the instructions below in this article. But before that, let’s define ERC20.
ERC20(Ethereum Request for Comment) is the standard for fungible tokens created using the Ethereum blockchain. A fungible token is one that is interchangeable with another token — where the well-known non-fungible tokens (NFTs) are not interchangeable.
If some of the below functionalities are implemented in the contract then we can say that the contract is using the ERC20 standard.
When transferring tokens from one account to another, check whether the values are being updated correctly.
Similarly, when transferring ETH, check whether the state changes are happening before the transfer. For example, the balance should be reduced from the sender’s account before transferring it to the receiver. This will stop attacks like reentrancy.
Check all the external calls. Because external functions are the ones that can be called by anyone. If it has any bug then the attacker will drain the balance in the contract.
If the contract is having multiple user roles, then check all the roles, and check whether the access controls are applied properly.
Check whether the parent contracts (ERC20, Ownable) are standard contracts (e.g. written by OpenZeppelin) or are they custom-written contracts by the dev.
During the auditing phase, Auditors will also look for gas optimization issues. It will reduce the cost for the client. Gas optimization can be done for all the contracts, not only for the ERC20 contracts.
After finding all the issues it is important to verify them once again.
Also published here.