Skip to content

energywebfoundation/ewc-system-contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EWC system contracts

Infrastructure contracts for EnergyWeb Chain (EWC) live launch.

Build Status Coverage Status

Maintainers

Primary: Adam Nagy (@ngyam)

Heiko Burkhardt (@hai-ko), Jonas Bentke (@jbentke)

Pre-requisites

  • node 8
  • npm
  • Optional: python 3.6 environment for Slither

Quickstart

npm install -D

and code away. Dependencies are installed locally.

Contracts

Important: all contracts go to the chainspec, deployed at the same time with their addresses known beforehans, so no deployment/migration scripts are written. The contracts are compiled and put into the chainspec by our Genesis/Chainspec generator: https://github.com/energywebfoundation/ewf-genesis-generator

Compiler version: 0.5.8 (reason)

Validator set

# Relay

Implements the Parity's reporting validator set interface. Relays all function calls to a worker "Relayed" contract. This pattern is chosen for upgradeability.

  • Deployment:

    constructor(address _owner, address _relayedSet)
    

    It expects the Relayed address and contract owner address in the constructor.

# Relayed

Implements the actual validator set logic and storage.

  • Deployment:

    constructor(address _owner, address _relaySet, address[] memory _initial)
    

    It expects the Relay address, contract owner and the initial validator addresses in the constructor.

Reward contract

Contains the reward logic. Rewards are issued upon new blocks. The contract implements Parity's BlockReward interface.

Rewarded entities:

  1. Block authors: rewarded for a total of 10 years with ~10 mil tokens based on a discrete S curve distribution. The S curve calculator can be found here.
  2. Community fund: A multisig wallet controlled by the community. Rewarded for a total of 10 years with ~37.9 mil tokens. A constant amount is paid out with each new block.
  • Deployment:

    constructor(address _communityFundAddress, uint256 _communityFundAmount)
    

    Expects the address of the community fund (ideally a mutltisig wallet) and the constant amount that is paid to the fund with each new block in wei.

Holding contract

Holds investor funds, which are available to withdraw after a certain time period has passed.

  • Deployment:

    constructor()
    

    No params needed. The initial holding records are hardcoded into the constructor.

Node control

EWF's node control system contracts. Consists of 3 contracts for upgradeability.

# NodeControlLookUp

Serves as a lookup contract for the node control logic.

  • Deployment:

    constructor(NodeControlDb _nodeControlDb, address _owner)
    

    Constructor expects the address of the db and the owner.

# NodeControlDb

Stores validator node state information.

  • Deployment:

    constructor(NodeControlLookUp _lookUpContract, address _owner)
    

    Constructor expects the address of the lookup contract and the owner.

# NodeControSimple

On-chain node control logic. Can issue update commands to nodes.

  • Deployment:

    constructor(NodeControlDb _nodeControlDb, address _owner)
    

    Constructor expects the address of the db and the owner.

Parity's Name Registry (SimpleRegistry)

This contract is Parity's Registry contract. The minor modification is that the SimpleRegistry was made Ownable and the following functions are only allowed to be called by the owner:

reserve()
confirmReverseAs()
setFee()
drain()

Functionally, this contract is just a placeholer, giving possibilities for future use.

  • Deployment:

    constructor(address _owner)
    

    Constructor expects the address of the owner only.

Other third party contracts used

Compiling the contracts

With the locally installed truffle:

npx truffle compile

Expected warnings:

  • ValidatorSetRelayed.sol:128:9: Warning: Unused function parameter. This function is according to Parity spec. but we are not using tthe _proof param for anything right now.
  • NodeControl contracts -> Warning: Experimental features are turned on. Expected because of ABIEncoderV2.

Running the tests

npm test

The test script starts a ganache instance and stops it afterwards.

Linting

2 linters are set up:

  • Solhint:
    npm run lint:solhint
    
  • Solium
    npm run lint:solium
    

Coverage report

Solidity coverage

npm run coverage

Security analysis

  • Slither by Trail of bits:

    1. Make sure a python 3.6 env is active.

    2. Install

      pip install slither-analyzer
      

      or sometimes

      pip3 install slither-analyzer
      
    3. Then run

    npm run security
    
  • MythX security checker (truffle security plugin by ConsenSys):

    Already installed with the other local deps. Note that for a full check you need to have a registered account (free). Pass in the account params as env vars.

    MYTHX_ETH_ADDRESS=0xYOURADDRESS MYTHX_PASSWORD=yourpass npm run verify
    

Contributing

Please read our CONTRIBUTING guide for our code of conduct and for the process of submitting pull requests to us.

Versioning

We use SemVer for versioning.

License

This project is licensed under the GPLv3 License - see the LICENSE file for details.

FAQ