Code Monkey home page Code Monkey logo

poa-network-consensus-contracts's Issues

(Fix) there is no event if funds are frozen

Smart-contract layer: EmissionFunds.sol or VotingToManageEmissionFunds.sol
Problem: there is no event is emitted on finalization if validators have voted to freeze funds.
Solution: add method to EmissionFunds.sol which will emit FundsFrozen(uint256 amount) or implement emittance in _finalize method of VotingToManageEmissionFunds.sol

Can't compile PoaNetworkConsensusContract with Remix

When I try to setup my own POA Network, I'm to able to proceed with following step:

Open Remix in your browser, copy-paste code from flat/PoaNetworkConsensus_flat.sol, press "Start to compile".
On "Run" tab select "Javascript VM" as environment, "PoaNetworkConsensus" as your contract, in "Create" field paste MoC's address "0x..." and click "Create"

When I enter my MoC address Remix will never come back with a valid feedback. It just hangs.

Tested with Chrome 63 on MBP

(Fix) Eliminate solhint errors in refactored contracts

Problem: There are a lot of errors from solhint checks in refactored contracts in security-audit branch.

Example:

./contracts/BlockReward.sol
   1:17  warning  Compiler version must be fixed                                       compiler-fixed
   8:1   error    Contract has 17 states declarations but allowed no more than 15      max-states-count
   9:5   warning  Explicitly mark visibility of state                                  state-visibility
  21:5   warning  Explicitly mark visibility of state                                  state-visibility
  22:9   error    Expected indentation of 4 spaces but found 8                         indent
  22:9   warning  Explicitly mark visibility of state                                  state-visibility
  23:9   error    Expected indentation of 4 spaces but found 8                         indent
  23:9   warning  Explicitly mark visibility of state                                  state-visibility
  24:9   error    Expected indentation of 4 spaces but found 8                         indent
  24:9   warning  Explicitly mark visibility of state                                  state-visibility
  25:9   error    Definitions inside contract / library must be separated by one line  separate-by-one-line-in-contract
  25:9   error    Expected indentation of 4 spaces but found 8                         indent
  27:9   error    Definitions inside contract / library must be separated by one line  separate-by-one-line-in-contract
  27:34  error    Expected indentation of 4 spaces but found 33                        indent
  27:9   error    Expected indentation of 4 spaces but found 8                         indent
  27:9   warning  Explicitly mark visibility of state                                  state-visibility
  27:34  warning  Explicitly mark visibility of state                                  state-visibility
  28:9   warning  Explicitly mark visibility of state                                  state-visibility
  28:9   error    Expected indentation of 4 spaces but found 8                         indent
  29:9   error    Expected indentation of 4 spaces but found 8                         indent
  29:38  warning  Explicitly mark visibility of state                                  state-visibility
  29:24  error    Variable name must be in mixedCase                                   var-name-mixedcase
  29:9   warning  Explicitly mark visibility of state                                  state-visibility
  29:38  error    Expected indentation of 4 spaces but found 37                        indent
  30:9   warning  Explicitly mark visibility of state                                  state-visibility
  30:9   error    Expected indentation of 4 spaces but found 8                         indent
  31:9   error    Expected indentation of 4 spaces but found 8                         indent
  31:9   warning  Explicitly mark visibility of state                                  state-visibility
  32:9   warning  Explicitly mark visibility of state                                  state-visibility
  32:9   error    Expected indentation of 4 spaces but found 8                         indent
  33:5   error    Expected indentation of 0 spaces but found 4                         indent
  35:42  error    Expected indentation of 0 spaces but found 41                        indent
  35:57  error    Expected indentation of 0 spaces but found 56                        indent
  35:14  error    Expected indentation of 0 spaces but found 13                        indent
  35:53  error    Expected indentation of 0 spaces but found 52                        indent
  35:51  error    Expected indentation of 0 spaces but found 50                        indent
  35:50  error    Expected indentation of 0 spaces but found 49                        indent
  35:44  error    Expected indentation of 0 spaces but found 43                        indent
  35:20  error    Expected indentation of 0 spaces but found 19                        indent
  35:31  error    Expected indentation of 0 spaces but found 30                        indent
  35:29  error    Expected indentation of 0 spaces but found 28                        indent
  35:28  error    Expected indentation of 0 spaces but found 27                        indent
  35:21  error    Expected indentation of 0 spaces but found 20                        indent
  35:5   error    Expected indentation of 0 spaces but found 4                         indent
  36:9   error    Expected indentation of 0 spaces but found 8                         indent
  37:9   error    Expected indentation of 0 spaces but found 8                         indent
  38:25  error    Expected indentation of 0 spaces but found 24                        indent
  38:18  error    Expected indentation of 0 spaces but found 17                        indent
  38:17  error    Expected indentation of 0 spaces but found 16                        indent
  38:9   error    Expected indentation of 0 spaces but found 8                         indent
  38:38  error    Expected indentation of 0 spaces but found 37                        indent
  38:36  error    Expected indentation of 0 spaces but found 35                        indent
  38:29  error    Expected indentation of 0 spaces but found 28                        indent
  38:37  error    Expected indentation of 0 spaces but found 36                        indent
  38:27  error    Expected indentation of 0 spaces but found 26                        indent
  38:26  error    Expected indentation of 0 spaces but found 25                        indent
  39:5   error    Expected indentation of 0 spaces but found 4                         indent
  40:51  error    Expected indentation of 0 spaces but found 50                        indent
  40:16  error    Expected indentation of 0 spaces but found 15                        indent
  40:9   error    Expected indentation of 0 spaces but found 8                         indent
  40:28  error    Expected indentation of 0 spaces but found 27                        indent
  40:29  error    Expected indentation of 0 spaces but found 28                        indent
  40:17  error    Expected indentation of 0 spaces but found 16                        indent
  40:36  error    Expected indentation of 0 spaces but found 35                        indent
  40:39  error    Expected indentation of 0 spaces but found 38                        indent
  40:43  error    Expected indentation of 0 spaces but found 42                        indent
  40:44  error    Expected indentation of 0 spaces but found 43                        indent
  40:50  error    Expected indentation of 0 spaces but found 49                        indent
  41:9   error    Expected indentation of 0 spaces but found 8                         indent
  41:41  error    Expected indentation of 0 spaces but found 40                        indent
  41:40  error    Expected indentation of 0 spaces but found 39                        indent
  41:39  error    Expected indentation of 0 spaces but found 38                        indent
  41:36  error    Expected indentation of 0 spaces but found 35                        indent
  41:29  error    Expected indentation of 0 spaces but found 28                        indent
  41:28  error    Expected indentation of 0 spaces but found 27                        indent
  41:17  error    Expected indentation of 0 spaces but found 16                        indent
  41:16  error    Expected indentation of 0 spaces but found 15                        indent
  42:30  error    Expected indentation of 0 spaces but found 29                        indent
  42:21  error    Expected indentation of 0 spaces but found 20                        indent
  42:29  error    Expected indentation of 0 spaces but found 28                        indent
  42:28  error    Expected indentation of 0 spaces but found 27                        indent
  42:25  error    Expected indentation of 0 spaces but found 24                        indent
  42:23  error    Expected indentation of 0 spaces but found 22                        indent
  42:22  error    Expected indentation of 0 spaces but found 21                        indent
  42:17  error    Expected indentation of 0 spaces but found 16                        indent
  42:16  error    Expected indentation of 0 spaces but found 15                        indent
  42:9   error    Expected indentation of 0 spaces but found 8                         indent
  44:9   error    Expected indentation of 0 spaces but found 8                         indent
  44:42  error    Expected indentation of 0 spaces but found 41                        indent
  44:43  error    Expected indentation of 0 spaces but found 42                        indent
  44:41  error    Expected indentation of 0 spaces but found 40                        indent
  44:40  error    Expected indentation of 0 spaces but found 39                        indent
  44:27  error    Expected indentation of 0 spaces but found 26                        indent
  44:17  error    Expected indentation of 0 spaces but found 16                        indent
  44:29  error    Expected indentation of 0 spaces but found 28                        indent
  45:29  error    Expected indentation of 0 spaces but found 28                        indent
  45:47  error    Expected indentation of 0 spaces but found 46                        indent
  45:48  error    Expected indentation of 0 spaces but found 47                        indent
  45:57  error    Expected indentation of 0 spaces but found 56                        indent
  45:58  error    Expected indentation of 0 spaces but found 57                        indent
  45:9   error    Expected indentation of 0 spaces but found 8                         indent
  45:17  error    Expected indentation of 0 spaces but found 16                        indent
  45:27  error    Expected indentation of 0 spaces but found 26                        indent
  47:39  error    Expected indentation of 0 spaces but found 38                        indent
  47:37  error    Expected indentation of 0 spaces but found 36                        indent
  47:16  error    Expected indentation of 0 spaces but found 15                        indent
  47:17  error    Expected indentation of 0 spaces but found 16                        indent
  47:27  error    Expected indentation of 0 spaces but found 26                        indent
  47:30  error    Expected indentation of 0 spaces but found 29                        indent
  47:38  error    Expected indentation of 0 spaces but found 37                        indent
  47:9   error    Expected indentation of 0 spaces but found 8                         indent
  47:40  error    Expected indentation of 0 spaces but found 39                        indent
  47:41  error    Expected indentation of 0 spaces but found 40                        indent
  49:9   error    Expected indentation of 0 spaces but found 8                         indent
  49:17  error    Expected indentation of 0 spaces but found 16                        indent
  49:33  error    Expected indentation of 0 spaces but found 32                        indent
  49:36  error    Expected indentation of 0 spaces but found 35                        indent
  49:35  error    Expected indentation of 0 spaces but found 34                        indent
  51:27  error    Expected indentation of 0 spaces but found 26                        indent
  51:13  error    Expected indentation of 0 spaces but found 12                        indent
  51:70  error    Expected indentation of 0 spaces but found 69                        indent
  51:9   error    Expected indentation of 0 spaces but found 8                         indent
  51:68  error    Expected indentation of 0 spaces but found 67                        indent
  51:67  error    Expected indentation of 0 spaces but found 66                        indent
  51:64  error    Expected indentation of 0 spaces but found 63                        indent
  51:44  error    Expected indentation of 0 spaces but found 43                        indent
  51:41  error    Expected indentation of 0 spaces but found 40                        indent
  51:39  error    Expected indentation of 0 spaces but found 38                        indent
  51:38  error    Expected indentation of 0 spaces but found 37                        indent
  51:37  error    Expected indentation of 0 spaces but found 36                        indent
  51:30  error    Expected indentation of 0 spaces but found 29                        indent
  51:12  error    Expected indentation of 0 spaces but found 11                        indent
  52:32  error    Expected indentation of 0 spaces but found 31                        indent
  52:31  error    Expected indentation of 0 spaces but found 30                        indent
  52:29  error    Expected indentation of 0 spaces but found 28                        indent
  52:13  error    Expected indentation of 0 spaces but found 12                        indent
  53:9   error    Expected indentation of 0 spaces but found 8                         indent
  55:67  error    Expected indentation of 0 spaces but found 66                        indent
  55:68  error    Expected indentation of 0 spaces but found 67                        indent
  55:9   error    Expected indentation of 0 spaces but found 8                         indent
  55:16  error    Expected indentation of 0 spaces but found 15                        indent
  55:17  error    Expected indentation of 0 spaces but found 16                        indent
  55:19  error    Expected indentation of 0 spaces but found 18                        indent
  55:26  error    Expected indentation of 0 spaces but found 25                        indent
  55:36  error    Expected indentation of 0 spaces but found 35                        indent
  55:38  error    Expected indentation of 0 spaces but found 37                        indent
  55:42  error    Expected indentation of 0 spaces but found 41                        indent
  55:49  error    Expected indentation of 0 spaces but found 48                        indent
  55:50  error    Expected indentation of 0 spaces but found 49                        indent
  55:51  error    Expected indentation of 0 spaces but found 50                        indent
  55:52  error    Expected indentation of 0 spaces but found 51                        indent
  56:49  error    Expected indentation of 0 spaces but found 48                        indent
  56:9   error    Expected indentation of 0 spaces but found 8                         indent
  56:16  error    Expected indentation of 0 spaces but found 15                        indent
  56:17  error    Expected indentation of 0 spaces but found 16                        indent
  56:19  error    Expected indentation of 0 spaces but found 18                        indent
  56:26  error    Expected indentation of 0 spaces but found 25                        indent
  56:34  error    Expected indentation of 0 spaces but found 33                        indent
  56:36  error    Expected indentation of 0 spaces but found 35                        indent
  56:66  error    Expected indentation of 0 spaces but found 65                        indent
  56:65  error    Expected indentation of 0 spaces but found 64                        indent
  56:50  error    Expected indentation of 0 spaces but found 49                        indent
  56:40  error    Expected indentation of 0 spaces but found 39                        indent
  56:48  error    Expected indentation of 0 spaces but found 47                        indent
  56:47  error    Expected indentation of 0 spaces but found 46                        indent
  58:33  error    Expected indentation of 0 spaces but found 32                        indent
  58:9   error    Expected indentation of 0 spaces but found 8                         indent
  58:18  error    Expected indentation of 0 spaces but found 17                        indent
  58:19  error    Expected indentation of 0 spaces but found 18                        indent
  58:20  error    Expected indentation of 0 spaces but found 19                        indent
  58:22  error    Expected indentation of 0 spaces but found 21                        indent
  58:24  error    Expected indentation of 0 spaces but found 23                        indent
  59:22  error    Expected indentation of 0 spaces but found 21                        indent
  59:20  error    Expected indentation of 0 spaces but found 19                        indent
  59:18  error    Expected indentation of 0 spaces but found 17                        indent
  59:39  error    Expected indentation of 0 spaces but found 38                        indent
  59:17  error    Expected indentation of 0 spaces but found 16                        indent
  59:16  error    Expected indentation of 0 spaces but found 15                        indent
  59:9   error    Expected indentation of 0 spaces but found 8                         indent
  61:9   error    Expected indentation of 0 spaces but found 8                         indent
  61:29  error    Expected indentation of 0 spaces but found 28                        indent
  61:32  error    Expected indentation of 0 spaces but found 31                        indent
  61:33  error    Expected indentation of 0 spaces but found 32                        indent
  61:35  error    Expected indentation of 0 spaces but found 34                        indent
  61:13  error    Expected indentation of 0 spaces but found 12                        indent
  61:12  error    Expected indentation of 0 spaces but found 11                        indent
  62:22  error    Expected indentation of 0 spaces but found 21                        indent
  62:13  error    Expected indentation of 0 spaces but found 12                        indent
  62:41  error    Expected indentation of 0 spaces but found 40                        indent
  62:28  error    Expected indentation of 0 spaces but found 27                        indent
  62:26  error    Expected indentation of 0 spaces but found 25                        indent
  62:24  error    Expected indentation of 0 spaces but found 23                        indent
  62:23  error    Expected indentation of 0 spaces but found 22                        indent
  63:13  error    Expected indentation of 0 spaces but found 12                        indent
  63:45  error    Expected indentation of 0 spaces but found 44                        indent
  63:26  error    Expected indentation of 0 spaces but found 25                        indent
  63:22  error    Expected indentation of 0 spaces but found 21                        indent
  63:21  error    Expected indentation of 0 spaces but found 20                        indent
  63:20  error    Expected indentation of 0 spaces but found 19                        indent
  63:24  error    Expected indentation of 0 spaces but found 23                        indent
  64:9   error    Expected indentation of 0 spaces but found 8                         indent
  66:28  error    Expected indentation of 0 spaces but found 27                        indent
  66:26  error    Expected indentation of 0 spaces but found 25                        indent
  66:17  error    Expected indentation of 0 spaces but found 16                        indent
  66:36  error    Expected indentation of 0 spaces but found 35                        indent
  66:16  error    Expected indentation of 0 spaces but found 15                        indent
  66:9   error    Expected indentation of 0 spaces but found 8                         indent
  66:35  error    Expected indentation of 0 spaces but found 34                        indent
  67:5   error    Expected indentation of 0 spaces but found 4                         indent
  69:51  error    Expected indentation of 0 spaces but found 50                        indent
  69:41  error    Expected indentation of 0 spaces but found 40                        indent
  69:33  error    Expected indentation of 0 spaces but found 32                        indent
  69:32  error    Expected indentation of 0 spaces but found 31                        indent
  69:5   error    Expected indentation of 0 spaces but found 4                         indent
  69:14  error    Expected indentation of 0 spaces but found 13                        indent
  70:6   error    Expected indentation of 0 spaces but found 5                         indent
  70:1   error    Mixed tabs and spaces. Allowed only spaces                           no-mix-tabs-and-spaces
  71:1   error    Mixed tabs and spaces. Allowed only spaces                           no-mix-tabs-and-spaces
  71:6   error    Expected indentation of 0 spaces but found 5                         indent
  72:1   error    Mixed tabs and spaces. Allowed only spaces                           no-mix-tabs-and-spaces
  72:6   error    Expected indentation of 0 spaces but found 5                         indent
  72:14  error    Expected indentation of 0 spaces but found 13                        indent
  72:15  error    Expected indentation of 0 spaces but found 14                        indent
  72:22  error    Expected indentation of 0 spaces but found 21                        indent
  73:5   error    Expected indentation of 0 spaces but found 4                         indent
  74:46  error    Expected indentation of 0 spaces but found 45                        indent
  74:76  error    Expected indentation of 0 spaces but found 75                        indent
  74:75  error    Expected indentation of 0 spaces but found 74                        indent
  74:74  error    Expected indentation of 0 spaces but found 73                        indent
  74:73  error    Expected indentation of 0 spaces but found 72                        indent
  74:59  error    Expected indentation of 0 spaces but found 58                        indent
  74:58  error    Expected indentation of 0 spaces but found 57                        indent
  74:1   error    Mixed tabs and spaces. Allowed only spaces                           no-mix-tabs-and-spaces
  74:45  error    Expected indentation of 0 spaces but found 44                        indent
  74:31  error    Expected indentation of 0 spaces but found 30                        indent
  74:19  error    Expected indentation of 0 spaces but found 18                        indent
  74:6   error    Expected indentation of 0 spaces but found 5                         indent
  74:33  error    Expected indentation of 0 spaces but found 32                        indent
  75:54  error    Expected indentation of 0 spaces but found 53                        indent
  75:6   error    Expected indentation of 0 spaces but found 5                         indent
  75:13  error    Expected indentation of 0 spaces but found 12                        indent
  75:24  error    Expected indentation of 0 spaces but found 23                        indent
  75:25  error    Expected indentation of 0 spaces but found 24                        indent
  75:42  error    Expected indentation of 0 spaces but found 41                        indent
  75:1   error    Mixed tabs and spaces. Allowed only spaces                           no-mix-tabs-and-spaces
  75:43  error    Expected indentation of 0 spaces but found 42                        indent
  75:53  error    Expected indentation of 0 spaces but found 52                        indent
  76:5   error    Expected indentation of 0 spaces but found 4                         indent

โœ– 248 problems (234 errors, 14 warnings)

Solution: let's eliminate them

(Refactor) collapse master and demo branch

Problem: we use master branch for network and demo branch for poa-test-setup. Demo branch differs from master with the limits for ballots.
Solution: consider to use one master branch with the option to configure demo setup.

(Fix) Remove storing of MoC address from `KeysManager`

Smart contract layer: KeysManager.sol

Problem: KeysManager contract stores duplicated masterOfCeremony address which is already stored in PoaNetworkConsensus contract.

Solution: remove storing of MoC address from KeysManager contract and read it from PoaNetworkConsensus contract instead.

License status

Hi! Do you have a license defined for this repository? I want to use these contracts with another project.

(Refactor) Remove currentValidatorsLength from PoaNetworkConsensus contract

We can remove currentValidatorsLength variable from PoaNetworkConsensus.sol because it duplicates .length property of currentValidators array.

getCurrentValidatorsLength() should be:

function getCurrentValidatorsLength() public view returns(uint256) {
    return currentValidators.length;
}

After that we should fix test/keys_manager_test.js and test/poa_network_consensus_test.js to use getCurrentValidatorsLength() instead of currentValidatorsLength().

onlyFirstTime is incorrect

In ValidatorMetadata.sol the modifier onlyFirstTime doesn't use _votingKey parameter. In it's body the getMiningByVotingKey function accepts msg.sender instead of _votingKey:

modifier onlyFirstTime(address _votingKey) {
    address miningKey = getMiningByVotingKey(msg.sender);
    Validator storage validator = validators[miningKey];
    require(validator.createdDate == 0);
    _;
}

The correct code must be:

modifier onlyFirstTime(address _votingKey) {
    address miningKey = getMiningByVotingKey(_votingKey);
    Validator storage validator = validators[miningKey];
    require(validator.createdDate == 0);
    _;
}

(Refactoring) redundant check in calculation of max from 3 numbers

Smart-contract layer: VotingToManageEmissionFunds.sol
Problem: https://github.com/poanetwork/poa-network-consensus-contracts/blob/security-audit/contracts/VotingToManageEmissionFunds.sol#L241-L242 - it seems, the check, that max > 0 is redundant. max can be greater or equal 0.
Solution: suggested implementation:

function _max(uint256 a, uint256 b, uint256 c) private pure returns(uint256) {
    uint256 max = a;
    if (b > max) {
        max = b;
    }
    if (c > max) {
        max = c;
    }
    return max;
}

(Feature) new ballot type: add 3 keys

Problem: The current validators should create 3 ballots to add a completely new validator to consensus: 1 ballot for each key. Validators should make 3 times more actions to create, vote and finalize it instead of doing this stuff in frames of one ballot.

Solution: Create new ballot type to add 3 keys in /VotingToChangeKeys.sol

VOTING_START_DATE issue in test/voting_to_change_*.js

VOTING_START_DATE must be equal to the current timestamp plus more than 2 seconds. Let's make the offset equal to 20 seconds:

VOTING_START_DATE = moment.utc().add(20, 'seconds').unix();

instead of

VOTING_START_DATE = moment.utc().add(2, 'seconds').unix();

Two seconds is a very small amount. This can cause revert on the next line in voting contracts:

require(_endTime > _startTime && _startTime > getTime());

I ran into this problem when running tests on a weak machine. Some tests did not have time to start before 2 seconds have elapsed since VOTING_START_DATE was initialized.

Here is the corresponding commit in my repo: varasev@8ae8b59

I will make a pull request later.

(Fix) Handle MoC miningKey removing/swapping

The current smart contracts implementations don't handle the case when MoC miningKey can be removed or swapped. It's necessary to add such handling.

Note, that MoC may only be removed after all of the 12 initial keys are activated.

getProxyThreshold and getBallotLimitPerValidator methods of BallotsStorage contract must take into account that MoC may be removed. The same applies to vote method of VotingToManageEmissionFunds contract.

swapValidatorKey method of PoaNetworkConsensus contract must change the value of masterOfCeremony variable in case of MoC's key is changing.

PoaNetworkConsensus contract should store isMasterOfCeremonyRemoved boolean flag.

Also, it's necessary to cover these changes with unit tests.

(Refactor) define hardcoded names of Registry properties pointers only once

Problem: For example, keccak256("initDisabled") is utilized in BallotsStorage.sol twice: here https://github.com/poanetwork/poa-network-consensus-contracts/blob/security-audit/contracts/BallotsStorage.sol#L30 and here https://github.com/poanetwork/poa-network-consensus-contracts/blob/security-audit/contracts/BallotsStorage.sol#L101

Solution: suggestion is to define it once in constant and then reuse this constant: bytes32 internal constant INIT_DISABLED = keccak256("initDisabled");

(Refactor) validators && pendingChanges functions could use the same subfunction inside

Problem:
implementation of
validators function: https://github.com/poanetwork/poa-network-consensus-contracts/blob/security-audit/contracts/ValidatorMetadata.sol#L46
and
pendingChanges function: https://github.com/poanetwork/poa-network-consensus-contracts/blob/security-audit/contracts/ValidatorMetadata.sol#L70

have repeated content

Solution: create internal subfunction _validators(bool _pending, address _miningKey) instead

(Update) Steps to deploy and migrate all upgradable contracts to the network

The next steps need to be taken to update all contracts on the network after we finish making them upgradable and after security audit is done.

These steps are implemented inside scripts/migrate/migrateAll.js: https://github.com/varasev/poa-network-consensus-contracts/blob/master/scripts/migrate/migrateAll.js

  1. Deploy PoaNetworkConsensus contract with the current MoC and the current mining keys list in constructor.

  2. Deploy ProxyStorage contract and call its init method with PoaNetworkConsensus address as a parameter.

  3. Call PoaNetworkConsensus.setProxyStorage with the address of ProxyStorage as a parameter.

  4. Run scripts/migrate/migrateKeys.js. It will deploy and initialize KeysManager contract and migrate all keys from an old KeysManager contract.

  5. Run scripts/migrate/migrateVotings.js. It will deploy and initialize BallotsStorage, VotingToChangeKeys, VotingToChangeMinThreshold and VotingToChangeProxyAddress contracts and migrate all thresholds and ballots from old contracts.

  6. Deploy ValidatorMetadata.

  7. Call ProxyStorage.initializeAddresses method.

  8. Run scripts/migrate/migrateMetadataNew.js.

Hardcoded MoC in PoaNetworkConsensus contract

Hi! Im playing with your PoaNetworkConsensus contract and I don't understand one step.
Also Parity gets stuck in the process. If I change the constructor from:

function PoaNetworkConsensus(address _masterOfCeremony, address[] validators) public {
        // TODO: When you deploy this contract, make sure you hardcode items below
        // Make sure you have those addresses defined in spec.json
        require(_masterOfCeremony != address(0));
        masterOfCeremony = _masterOfCeremony;
        currentValidators = [masterOfCeremony];
        .... 
}

To:

function PoaNetworkConsensus(address[] validators) public {
        // TODO: When you deploy this contract, make sure you hardcode items below
        // Make sure you have those addresses defined in spec.json
        masterOfCeremony = 0x....;
        require(masterOfCeremony != address(0));
        currentValidators = [masterOfCeremony];
        .... 
}

It compiles well and I'm able to put the bytecode in the spec.json as a precompiled contract.
Then I start the network with: parity --config basictoml.toml
When I execute this command parity is loading the .toml file forever with 99% of CPU usage.
The rest of the contract is the same.

I don't know what happens because every time I set up a PoA, if the precompiled contract works bad, parity throws an exception. Possibly I made a mistake with the code mentioned before but im not sure.
Thank you in advance and forgive me if I did not understand well the solidity code.

ValidatorMetadata and it's storage address in contracts.json

@rstormsf @vbaranov

migrations/2_deploy_contract.js saves contracts addresses into contracts.json.

Now we have ValidatorMetadata contract address and EternalStorageProxy address: varasev@d9aa31e

Is it OK? Or we have to save only EternalStorageProxy address?

For example:

let contracts = {
  ...
  "METADATA_ADDRESS": EternalStorageProxy.address,
  ...
}

instead of

let contracts = {
  ...
  "METADATA_ADDRESS": ValidatorMetadata.address,
  "ETERNAL_STORAGE_PROXY": EternalStorageProxy.address,
  ...
}

I think the former is better because we need to know only the storage address to use ValidatorMetadata.

(Feature) Make ValidatorMetadata upgradable

ValidatorMetadata contract made upgradable. The changes are in my repo: https://github.com/varasev/poa-network-consensus-contracts/blob/master/contracts/ValidatorMetadata.sol

All the current tests are passing.

The next solution from zeppelinos (thanks!) was used: https://github.com/zeppelinos/labs/tree/master/upgradeability_using_generic_eternal_storage

It is an awesome solution to separate an implementation from a storage! Now we can change contract's implementation and keep it's storage.

We need only two additional contracts for this: https://github.com/varasev/poa-network-consensus-contracts/tree/master/contracts/eternal-storage

It is planned that EternalStorageProxy.upgradeTo function will be called from ProxyStorage contract when the voters agree with implementation changing in VotingToChangeProxyAddress contract.

We can also do this with other contracts soon.

(Refactor) initMetadata, createMetadata, changeRequestForValidator use common patterns

Problem:
initMetadata, createMetadata, changeRequestForValidator functions use common pattern:

_setFirstName(true, _miningKey, _firstName);
_setLastName(true, _miningKey, _lastName);
_setLicenseId(true, _miningKey, _licenseId);
_setState(true, _miningKey, _state);
_setFullAddress(true, _miningKey, _fullAddress);
_setZipcode(true, _miningKey, _zipcode);
_setExpirationDate(true, _miningKey, _expirationDate);

Solution: could be combined to one subfunction

(Fix) make BallotTypes enum global for all ballot types

Problem: ballot types for changing threshold and proxy are defined as numbers: https://github.com/poanetwork/poa-network-consensus-contracts/blob/security-audit/contracts/VotingToChangeMinThreshold.sol#L22 and https://github.com/poanetwork/poa-network-consensus-contracts/blob/security-audit/contracts/VotingToChangeProxyAddress.sol#L18

Solution: let's define BallotTypes enum from https://github.com/poanetwork/poa-network-consensus-contracts/blob/security-audit/contracts/VotingToChangeKeys.sol#L9 globally (for example, in VotingToChange abstract) for all types of ballots and use named ballot types instead of numbers.

changeRequest and changeRequestForValidator functions should check zipcode

In ValidatorMetadata.sol these functions should check _zipcode for zero because we see the same condition in onlyIfChangeExist function:

function onlyIfChangeExist(address _miningKey) public view returns(bool) {
    return pendingChanges[_miningKey].zipcode > 0;
}

I suggest to use

require(_zipcode > 0);

at the beginning of changeRequest and changeRequestForValidator.

(Feature) Make ProxyStorage upgradable

We must make the ProxyStorage contract upgradable because it is a crucial contract that connects all other contracts and we may want to change its implementation in the future.

I made a related commit in my repository today: varasev@e115d03

All tests are successful: https://travis-ci.org/varasev/poa-network-consensus-contracts/builds/373019590

The ability to change ProxyStorage implementation address was added in ProxyStorage's setContractAddress method. Note that we use this keyword to call upgradeTo method inside the contract: https://github.com/varasev/poa-network-consensus-contracts/blob/e115d03d3e59a697ce127422acfb4f8b9643d765/contracts/ProxyStorage.sol#L136

The upgradeTo method may be called only by ProxyStorage contract itself: https://github.com/varasev/poa-network-consensus-contracts/blob/e115d03d3e59a697ce127422acfb4f8b9643d765/contracts/eternal-storage/EternalStorageProxy.sol#L66

We can achieve this approach with the same this keyword in EternalStorageProxy constructor: https://github.com/varasev/poa-network-consensus-contracts/blob/e115d03d3e59a697ce127422acfb4f8b9643d765/contracts/eternal-storage/EternalStorageProxy.sol#L34

When we deploy EternalStorageProxy, we can set _proxyStorage constructor's parameter equal to zero. That means that we want EternalStorageProxy to use its own address to filter msg.sender in upgradeTo method.

So, no one can call ProxyStorage's upgradeTo method - it can be called only by ProxyStorage inside it as I shown above: https://github.com/varasev/poa-network-consensus-contracts/blob/e115d03d3e59a697ce127422acfb4f8b9643d765/contracts/ProxyStorage.sol#L136

In this way, ProxyStorage implementation may be changed only by voting because setContractAddress method may be called only by VotingToChangeProxy contract: https://github.com/varasev/poa-network-consensus-contracts/blob/e115d03d3e59a697ce127422acfb4f8b9643d765/contracts/ProxyStorage.sol#L118

(Refactoring) make getTotalNumberOfValidators private

Smart-contract layer: BallotsStorage.sol
Problem: getTotalNumberOfValidators() is public. It is only used internal. We already have public function getCurrentValidatorsLength() in PoaNetworkConsensus.sol, which returns the number of validators.
Solution: let' make getTotalNumberOfValidators() private.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.