Skip to content

Latest commit

 

History

History
109 lines (73 loc) · 5.66 KB

CONTRIBUTING.md

File metadata and controls

109 lines (73 loc) · 5.66 KB

Raiden Smart Contracts Development Guide

Code Style

Solidity

For solidity we generally follow the style guide as shown in the solidity documentation with some exceptions:

Variable Names

All variable name should be in snake case, just like in python. Function names on the other hand should be mixedCase. MixedCase is essentially like CamelCase but with the initial letter being a small letter. This helps us to easily determine which function calls are smart contract calls in the python code side.

function iDoSomething(uint awesome_argument) {
    doSomethingElse();
}

Reentrance Problems

Calls into other contracts might call back into our contract. This causes problems when storage accesses and an external call interleave. For example,

   check(storage[address])
   other_contract.method()
   storage[address] = new_value

possibly has a bug, where an attacker can set up other_contract.method() so that it calls back into this piece of code. Then, the check() still sees an old value.

Resources

Python

This repository follows the same guidelines as the Raiden Client, regarding the Python code used in tests and scripts: https://github.com/raiden-network/raiden/blob/master/CONTRIBUTING.md#coding-style.

Making a Pull-Request

  • If you're fixing a bug or adding a feature, add an entry to CHANGELOG.md.
  • If you've changed a Solidity source, run make compile_contracts and add the resulting raiden_contracts/data/contracts.json in the PR.
  • If you're changing documentation only, add [skip ci] in the commit message so Travis does not waste time.
    • But, if you've changed comments in a Solidity source, do not add [skip ci] and let Travis check the hash of the source.
  • Add type annotations (especially on function arguments).

Testing

Read our Test Guide

Adding a New Smart Contract

Location

Currently, our setup is:

  • for core contracts: ./raiden_contracts/data/source/raiden
  • for 3rd party services: ./raiden_contracts/data/source/services
  • libraries: ./raiden_contracts/data/source/lib
  • non-production test contracts: ./raiden_contracts/data/source/test

Constants

Update package constants with the new contract's name, events, gas requirements etc.

Note: gas requirements are currently calculated using ./raiden_contracts/tests/test_print_gas.py, so the contract needs to be added here. This is not optimal: raiden-network#16

Tests

Compilation

We need to add the new contract to the precompiled data. If the new contract is located in one of the existing directories, then it will automatically be added. If a new contracts directory is created, then it must be added to the compilation process: https://github.com/raiden-network/raiden-contracts/blob/810ea24b61221f74939a732e6f20f20184039507/raiden_contracts/contract_manager.py#L250-L267

Deployment

Make sure the new contract's precompiled data and deployment info is included in ./raiden_contracts/data, by adding the contract to the deployment process

Check if the deployment info file path still stands: https://github.com/raiden-network/raiden-contracts/blob/810ea24b61221f74939a732e6f20f20184039507/raiden_contracts/contract_manager.py#L270-L274

Package Release

We need to make sure the contract and related data is part of the release process: