Skip to content
This repository has been archived by the owner on Mar 12, 2021. It is now read-only.

Latest commit

 

History

History
54 lines (36 loc) · 1.95 KB

CodeStyle.md

File metadata and controls

54 lines (36 loc) · 1.95 KB

Code style

Order within contracts:

  1. Type declarations
  2. Constants
  3. Immutable state variables (Set only in constructor)
  4. State variables
  5. Events
  6. Modifiers
  7. Constructor
  8. Fallback function
  9. External functions (constant functions last)
  10. Public funcions (constant functions last)
  11. Internal functions (constant functions last)
  12. Private functions (constant functions last)

Order of operations within an external or public function:

  1. pure Validate input (require)
  2. constant Read state, compute and validate more (require and assert)
  3. Write state (from here only pure operations allowed) (no require or assert)
  4. Call external functions (assert allowed again)
  5. Write logs
  6. Return

The critical section is between the first read and the last write. In this region the control flow needs to be extremely reliable.

Abstract internal functions are used through a Mixin interface; a constract with an M prefix containing only abstract internal functions.

Constants and immutable state variables are ALL_CAPS. Internal constants go before private ones. All constants are either internal or private.

Mutable state variables are _camelCase with a _ prefix. State variables should always be private or, when intended to be access by a subclass, internal. This is to avoid uncessary public functions cluthering the ABI, or accidental collision/overriding a state variable in a subclass.

Don't use uint, always be explicit and use uint256.

Only mutable state variables can start with _. In particular functions, arguments and variables do not.

Log events start with Log.

References

TODO

Mark contracts Trusted or Untrusted.

[]: https://github.com/ConsenSys/smart-contract-best-practices#mark-untrusted-contracts