Skip to content

Latest commit

 

History

History
60 lines (43 loc) · 1.96 KB

CodeStyle.md

File metadata and controls

60 lines (43 loc) · 1.96 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 beprivateor, 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