Skip to content

Latest commit

 

History

History
49 lines (40 loc) · 1.54 KB

hacker-proof-practices.md

File metadata and controls

49 lines (40 loc) · 1.54 KB

Hacker proof practices

State Changes

Contract state modifying statements

  • Setting the value in storage variable
  • Emitting of events from the function
  • Creating a new contract instance
  • Sending Ethers
  • Using low level calls OR EVM assembly
  • Using selfdestruct
  • Calling functions that modify the state with any of the above

View (Hacker proof practices)

View statements e.g. function getSomethingFixed() public view returns (uint)

  • Allowed to read the
  • NOT allowed to use any state change statement

Pure (Hacker proof practices)

Pure statements e.g. function returnConstantFixed() public pure returns (uint)

  • NOT allowed to read the storage
  • NOT allowed to use any state change statement

Examples of good and bad coding practices

GET function

Bad function getSomething() public returns(uint) { someValue = 10 // Shouldn't change the state of storage in GET function return someValue; }

Good function getSomethingFixed() public view returns(uint) { someValue = 10 // With view modifier, a state change in the function will cause compilation error, forcing developer to fix the error return someValue; }

RETURN a constant

Bad function returnConstant() public returns(uint) { return someValue + 100 // This is not a constant }

Good function returnConstantFixed() public pure returns(uint) { return someValue + 100 // With pure modifier, a state change in the function will cause compilation error, forcing developer to fix the error

return 100 // This will return constant }