Skip to content

Latest commit

 

History

History
114 lines (97 loc) · 7.93 KB

README.md

File metadata and controls

114 lines (97 loc) · 7.93 KB

Auditing reference

What exactly is a Smart Contract audit?

A Smart Contract audit is the process investigating carefully a piece of code, in this case a Solidity contract to find bugs, vulnerabilities and risks before the code is deployed and used in the main Ethereum’s network where it won’t be modifiable. It’s just for discussion purposes.

Be aware of feature of blockchain and EVM limits

Solidity Code

Write simple and modular code and order your function code: conditions, actions, interactions

config

  • Using pragma version latest

variable

  • Consider variable size (i.e uint8, uint16, ..., uint256)
  • Consider solidity automatically creates getter functions for state variable
  • Delete unused variables
  • Delete variables that have the same information
  • If you can infer a variable value through another variable, delete that variable
  • Do not use unnecessary temp variables
  • MAGIC NUMBER uses a constant
  • A constant of the same name must not have a different value in another contract
  • If you can infer true / false as an integer value, use bool
  • If the values ​​of the various state variables must maintain the relationship, consider implementing a mechanism to assert the integrity of invariants
  • Consider difference between string and byte

function

  • Validate the paramter
  • Multiple functions in the same logic make one function.
  • Delete unused function
  • If the return value is not used, remove the return parameter.
  • Use view if the function doesn't change state.
  • Use pure if the function doesn't even read state.
  • If you expect that the function will only ever be called externally, use external

modifier

  • If the modifier is used only once, it is confusing rather than useful
  • Consider whether logic such as the modifier's logic is in the function
  • Consider using modifiers when using common logic in multiple functions

control statements

  • for loop
    • Consider reviewing all for-loops and ensure that array maximum lengths are checked on iteration.
    • Consider the situation where loop exits out of gas.
    • Make sure that increment variable does not overflow.

naming

  • Naming with clear meaning
  • It is recommended that the name of the event and the name of the function be different.

etc

  • Consider using scientific notation to declare numeric constants to avoid typos

for ERC20

for crowdsale

  • Implement claimTokens function to prevent ERC20 tokens from being sent inadvertently.

Attack scenario

Write tests

Reference