# AuRa POSDAO genesis
### How make POSDAO genesis
- Nethermind GA `.github/workflows/run-posdao-tests.yml` runs `npm run all-nethermind-no-watcher`
- `all-nethermind-no-watcher` runs `CLIENT=nethermind npm run before-start && npm run start-test-setup-nethermind && npm run after-start-no-watcher`
- `before-start` runs: `npm run compile-posdao-contracts && npm run make-spec`
- `make-spec` runs: `. ./scripts/network-spec && cd ./posdao-contracts && npm i && node ./scripts/make_spec.js && node ../scripts/copy-spec.js`
- `. ./scripts/network-spec` sets ENVs, `INITIAL_VALIDATORS`, `STAKING_ADDRESSES`, etc
- `./posdao-contracts/scripts/make_spec.js`: Deploys governance and staking contracts with the set of `INITIAL_VALIDATORS`, and `STAKING_ADDRESSES`.
- **TODO**: Are this contracts deployed on the “actual” chain?
- How is the deploy-er account funded?
- `./scripts/copy-spec.js`: Sets `authorityRound.params.stepDuratio`, London hard fork parameters and copies the spec file to data
- `start-test-setup-nethermind`: runs `./scripts/start-test-setup ../nethermind/bin/Nethermind.Runner`
- `./script/start-test-setup` runs `--config` step on the client. Then runs `node ./scripts/getReservedPeer.js`
- `./scripts/getReservedPeer.js` gets the node’s enode and sets up bootnodes
- `npm run after-start-no-watcher` runs `npm run checkers && npm run test && npm run stop-test-setup`
- `npm run checkers` runs: `(node scripts/watchOrdinaryNode.js &) && node scripts/deploy-staking-token.js && (node scripts/watchRandomSeed &)`
- Monitors node’s health via their JSON RPC API: block numbers too far apart, block hash disagrees, etc. On fault it writes a file to disk
- `npm run test` runs: `node_modules/.bin/mocha --bail --timeout 1200000`
- Tests POSDAO contract actions: 00_tx_priority, 01_staking, 02_removing_pool, 03_ordinary_node, 04_random_seed
- `npm run stop-test-setup` runs: `bash scripts/stop-test-setup` which kills process with port at 854{0..6}
POSDAO genesis uses a special type of genesis allocation that runs transactions on genesis. [https://github.com/NethermindEth/nethermind/blob/3578975ae10bde4bf8934c0a5cd2abb983d4e7c8/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs#L98](https://github.com/NethermindEth/nethermind/blob/3578975ae10bde4bf8934c0a5cd2abb983d4e7c8/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs#L98)
*NOTE: Not actual C++ code, modified for simplicity*
```cpp
private void Preallocate(Address address, ChainSpecAllocation allocation) {
stateProvider.CreateAccount(address, allocation.Balance, allocation.Nonce);
if (allocation.Code != null) {
Keccak codeHash = _stateProvider.UpdateCode(allocation.Code);
_stateProvider.UpdateCodeHash(address, codeHash, _specProvider.GenesisSpec, true);
}
if (allocation.Storage != null) {
foreach (KeyValuePair<UInt256, byte[]> storage in allocation.Storage) {
_storageProvider.Set(new StorageCell(address, storage.Key),
storage.Value.WithoutLeadingZeros().ToArray());
}
}
if (allocation.Constructor != null) {
Transaction constructorTransaction = new SystemTransaction({
SenderAddress = address,
Data = allocation.Constructor,
GasLimit = genesis.GasLimit
});
_transactionProcessor.Execute(constructorTransaction, genesis.Header, outputTracer);
}
}
```
- TODO: Can I just edit the constructor arguments and inject the addresses I need? Probably yes. Build a cheap ABI encoder in bash. Note an array of addresses is dynamic, and requires length prefix.
### POSDAO constructor format
- `0x1000000000000000000000000000000000000000` - ValidatorSetAuRa impl
- bytecode
- `0x1000000000000000000000000000000000000001` - ValidatorSetAuRa upgrade-able proxy AdminUpgradeabilityProxy
- constructor(`0x1000000000000000000000000000000000000000`, $owner)
- `0x1100000000000000000000000000000000000000` - StakingAuRa impl
- bytecode
- `0x1100000000000000000000000000000000000001` - StakingAuRa AdminUpgradeabilityProxy
- constructor(`0x1100000000000000000000000000000000000000`, $owner)
- `0x2000000000000000000000000000000000000000` - BlockRewardAuRa impl
- bytecode
- `0x2000000000000000000000000000000000000001` - BlockRewardAuRa AdminUpgradeabilityProxy
- constructor(`0x2000000000000000000000000000000000000000`, $owner)
- `0x3000000000000000000000000000000000000000` - RandomAuRa impl
- bytecode
- `0x3000000000000000000000000000000000000001` - RandomAuRa AdminUpgradeabilityProxy
- constructor(`0x3000000000000000000000000000000000000000`, $owner)
- `0x4000000000000000000000000000000000000000` - TxPermission impl
- bytecode
- `0x4000000000000000000000000000000000000001` - TxPermission AdminUpgradeabilityProxy
- constructor(`0x4000000000000000000000000000000000000000`, $owner)
- `0x4100000000000000000000000000000000000000` - TxPriority contract
- constructor($owner)
- `0x5000000000000000000000000000000000000000` - Certifier impl
- bytecode
- `0x5000000000000000000000000000000000000001` - Certifier AdminUpgradeabilityProxy
- constructor(`0x5000000000000000000000000000000000000000`, $owner)
- `0x6100000000000000000000000000000000000000` - Governance impl
- bytecode
- `0x6100000000000000000000000000000000000001` - Governance AdminUpgradeabilityProxy
- constructor(`0x6100000000000000000000000000000000000000`, $owner)
- `0x6000000000000000000000000000000000000000` - Registry contract
- constructor(`0x5000000000000000000000000000000000000001`, $owner) // certifier address
- `0x7000000000000000000000000000000000000000` - InitializerAuRa contract
- constructor(.. see below)
**InitializerAuRa** contract. Constructor args [https://github.com/poanetwork/posdao-contracts/blob/a7f3ee249661acf0471b85da351201d197e54456/contracts/InitializerAuRa.sol#L43](https://github.com/poanetwork/posdao-contracts/blob/a7f3ee249661acf0471b85da351201d197e54456/contracts/InitializerAuRa.sol#L43)
```solidity
/// @param _contracts An array of the contracts:
/// 0 is ValidatorSetAuRa,
/// 1 is BlockRewardAuRa,
/// 2 is RandomAuRa,
/// 3 is StakingAuRa,
/// 4 is TxPermission,
/// 5 is Certifier,
/// 6 is Governance.
/// @param _owner The contracts' owner.
/// @param _miningAddresses The array of initial validators' mining addresses.
/// @param _stakingAddresses The array of initial validators' staking addresses.
constructor(
address[] memory _contracts,
address _owner,
address[] memory _miningAddresses,
address[] memory _stakingAddresses,
bool _firstValidatorIsUnremovable,
uint256 _delegatorMinStake,
uint256 _candidateMinStake,
uint256 _stakingEpochDuration,
uint256 _stakingEpochStartBlock,
uint256 _stakeWithdrawDisallowPeriod,
uint256 _collectRoundLength
) public {
```
An example of a generic constructor args encoded
```solidity
{BYTECODE}
00 0000000000000000000000000000000000000000000000000000000000000160 // address[] memory contracts - offset 352, 11 words
01 000000000000000000000000{OWNER_ADDRESS} // address owner
02 0000000000000000000000000000000000000000000000000000000000000260 // address[] memory miningAddresses - offset 608, 19 words
03 00000000000000000000000000000000000000000000000000000000000002e0 // address[] memory stakingAddresses - offset 736, 23 words
04 0000000000000000000000000000000000000000000000000000000000000001 // bool firstValidatorIsUnremovable
05 00000000000000000000000000000000000000000000003635c9adc5dea00000 // uint256 delegatorMinStake
06 00000000000000000000000000000000000000000000043c33c1937564800000 // uint256 candidateMinStake
07 000000000000000000000000000000000000000000000000000000000000004c // uint256 stakingEpochDuration
08 0000000000000000000000000000000000000000000000000000000000000000 // uint256 stakingEpochStartBlock
09 000000000000000000000000000000000000000000000000000000000000000a // uint256 stakeWithdrawDisallowPeriod
10 0000000000000000000000000000000000000000000000000000000000000026 // uint256 collectRoundLength
11 0000000000000000000000000000000000000000000000000000000000000007 // Actual data for address[] memory contracts
12 0000000000000000000000001000000000000000000000000000000000000001
13 0000000000000000000000002000000000000000000000000000000000000001
14 0000000000000000000000003000000000000000000000000000000000000001
15 0000000000000000000000001100000000000000000000000000000000000001
16 0000000000000000000000004000000000000000000000000000000000000001
17 0000000000000000000000005000000000000000000000000000000000000001
18 0000000000000000000000006100000000000000000000000000000000000001
19 {INITIAL_VALIDATORS_ABI_ENCODED}
23 {STAKING_ADDRESSES_ABI_ENCODED}
```
### Final script
https://github.com/skylenet/ethereum-genesis-generator/blob/master/apps/el-gen/genesis_aura_posdao.py
## On block rewards
-[AuRa block rewards](https://hackmd.io/FsWeN4WfRb6RJdNdOInL9A)
## Misc background
| | AuRa (POSDAO) | Clique |
| --- | --- | --- |
| Validator set
governance | Via smart-contracts POSDAO | Via block headers. Miner and nonce fields are used to propose changes |
| Sync + get VSET | Sync blocks and check TX receipts for changes in the POSDAO contracts | While syncing block-headers compute changes in the validator set |
| Difficulty | ?? | 1 If validator off turn
2 if validator on turn |
- Nethermind guide to run an AuRa validator: [https://github.com/NethermindEth/docs/blob/master/guides-and-helpers/validator-setup/aura-validator.md](https://github.com/NethermindEth/docs/blob/master/guides-and-helpers/validator-setup/aura-validator.md)
- Nethermind AuRa plugin config: [https://docs.nethermind.io/nethermind/ethereum-client/configuration/aura](https://docs.nethermind.io/nethermind/ethereum-client/configuration/aura)
- POSDAO contracts: https://github.com/poanetwork/posdao-contracts
- OpenEthereum AuRa algorithm description: [https://openethereum.github.io/Aura](https://openethereum.github.io/Aura)
- EIP-225: Clique proof-of-authority consensus protocol: [https://eips.ethereum.org/EIPS/eip-225](https://eips.ethereum.org/EIPS/eip-225)