Smart Contracts Security

ShellBoxes
3 min readAug 19, 2021

riting unit tests for your smart contracts is important, just like it is for every other software project. Unit research, on the other hand, is often ignored and undervalued in blockchain-based solutions. I audited over 200 smart contracts last year, mainly for Ethereum but also for the Neo, Eos, Tron, and Bitcoin blockchains. Nearly half of these projects, based on my experience, did not compose unit tests. Bad contract efficiency and numerous protection problems were found through investigations were often the product of such monitoring.

Unit checks for ERC-20 Ethereum Smart Contracts: How to Write Them
Writing unit tests for your smart contracts is important, just like it is for every other software project. Unit research, on the other hand, is often ignored and undervalued in blockchain-based solutions. I audited over 200 smart contracts last year, mainly for Ethereum but also for the Neo, Eos, Tron, and Bitcoin blockchains. Nearly half of these projects, based on my observations, did not compose unit tests. Bad contract efficiency and numerous protection problems discovered through audits were often the product of such oversight.

Tests that are needed

The constructor, final supply, functions for transition to and from, consent, and often a feature for burning extra tokens are all common parts of every smart contract. As a consequence, it’s crucial to double-check the smart contract for proper parameter initialization and reverts when complete supply or other uint values are overflowing or underflowing. You can also double-check modifiers and privileges use.

We’ll just look at Ethereum smart contracts here, but the same rules extend to other networks when contracts have the same framework. Let’s start with a test of the token’s proper initialization and pass to a specific address.

The checks for proper initialization are clear. All you have to do now is build a sample contract and double-check if all of the variables that must be initialized are accurate.

It is important to check the transfer feature and there could be problems that result in inaccurate transfers. You must guarantee that the recipient’s and sender’s balances will adjust upon conversion, and you must seek to gain reverts in the event that the feature receives inaccurate criteria, such as whether the sum being received reaches the sender’s balance, when the contract address or null address is sent instead of the recipient address, and so on. Finally, double-check that the logs from the transition case are right.

The transferFrom role is identical to move, except you must still guarantee that the spender has ample allowed balance to submit. Here are several instances of tests where the spender has less money than is needed for the move.

The ERC20 standard’s approve feature is the most basic. It is not necessary to search for a zero address; it is sufficient to ensure that the allowance list is appropriately filled. Additionally, whether you don’t have the increaseApproval or decreaseApproval functions, the accept feature would overwrite all previous values. As a consequence, we consider utilizing these features to prevent needless overwrites. It’s often vital to double-check that the logs from the Acceptance case are accurate.

Most smart contracts provide a feature for burning tokens that have been left over from the main selling. Many of them have a specific token holder account, which is often referred to as an owner account. As a result, the following is the ideal option for burning unsold tokens: Get the number of tokens on the holders’ address, deduct it from the overall stock, and set the number of tokens on the holders’ address to nil. This would mean that you don’t destroy any of the tokens, so make a white paper outlining your token burn plan.

To arrange for an audit of your smart contract, please contact us .

--

--

ShellBoxes

Innovating for a safer, more secure decentralized future