POSDAO Smart Contracts – POSDAO智能合约区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,POSDAO Smart Contracts – POSDAO智能合约区块链毕设代写 是一篇很好的国外资料

POSDAO Smart Contracts

Implementation of the POSDAO consensus algorithm in Solidity.

About

POSDAO is a Proof-of-Stake (POS) algorithm implemented as a decentralized autonomous organization (DAO). It is designed to provide a decentralized, fair, and energy efficient consensus for public chains. The algorithm works as a set of smart contracts written in Solidity. POSDAO is implemented with a general purpose BFT consensus protocol such as AuthorityRound (AuRa) with a leader and probabilistic finality, or Honeybadger BFT (HBBFT), leaderless and with instant finality. It incentivizes actors to behave in the best interests of a network.

The algorithm provides a Sybil control mechanism for reporting malicious validators and adjusting their stake, distributing a block reward, and managing a set of validators. The authors implement the POSDAO for a sidechain based on Ethereum 1.0 protocol.

POSDAO Repositories and Resources

  • White paper https://forum.poa.network/t/posdao-white-paper/2208
  • Backported OpenEthereum client with all POSDAO features https://github.com/poanetwork/open-ethereum/tree/posdao-backport
  • Original OpenEthereum client supporting all POSDAO features https://github.com/openethereum/openethereum starting from v3.0.0
  • Integration tests setup for a POSDAO network https://github.com/poanetwork/posdao-test-setup
  • Discussion forum https://forum.poa.network/c/posdao

Smart Contract Summaries

Note: The following descriptions are for AuRa contracts only. HBBFT contract implementations are not started yet and are not listed nor described here. All contracts are located in the contracts directory.

  • BlockRewardAuRa: generates and distributes rewards according to the logic and formulas described in the white paper. Main features include:

    • distributes the entrance/exit fees from the erc-to-erc, native-to-erc, and/or erc-to-native bridges among validators pools;
    • mints native coins needed for the erc-to-native bridge;
    • makes a snapshot of the validators stakes at the beginning of each staking epoch. That snapshot is used by the StakingAuRa.claimReward function to transfer rewards to validators and their delegators.
  • Certifier: allows validators to use a zero gas price for their service transactions (see OpenEthereum Wiki for more info). The following functions are considered service transactions:

    • ValidatorSetAuRa.emitInitiateChange
    • ValidatorSetAuRa.reportMalicious
    • RandomAura.commitHash
    • RandomAura.revealNumber
  • InitializerAuRa: used once on network startup and then destroyed. This contract is needed for initializing upgradable contracts since an upgradable contract can’t have the constructor. The bytecode of this contract is written by the scripts/make_spec.js into spec.json along with other contracts when initializing on genesis block.

  • RandomAuRa: generates and stores random numbers in a RANDAO manner (and controls when they are revealed by AuRa validators). Random numbers are used to form a new validator set at the beginning of each staking epoch by the ValidatorSet contract. Key functions include:

    • commitHash and revealNumber. Can only be called by the validator’s node when generating and revealing their secret number (see RANDAO to understand principle). Each validator node must call these functions once per collection round. This creates a random seed which is used by ValidatorSetAuRa contract. See the white paper for more details;

    • onFinishCollectRound. This function is automatically called by the BlockRewardAuRa contract at the end of each collection round. It controls the reveal phase for validator nodes and punishes validators when they don’t reveal (see the white paper for more details on the banning protocol);

    • currentSeed. This public getter is used by the ValidatorSetAuRa contract at the latest block of each staking epoch to get the accumulated random seed for randomly choosing new validators among active pools. It can also be used by anyone who wants to use the network’s random seed. Note, that its value is only updated when revealNumber function is called: that’s expected to be occurred at least once per collection round which length in blocks can be retrieved with the collectRoundLength public getter. Since the revealing validator always knows the next random number before sending, your DApp should restrict any business logic actions (that depends on random) during reveals phase.

      An example of how the seed could be retrieved by an external smart contract.
      pragma solidity 0.5.11;   interface IPOSDAORandom {     function collectRoundLength() external view returns(uint256);     function currentSeed() external view returns(uint256); }  contract Example {     IPOSDAORandom private _posdaoRandomContract; // address of RandomAuRa contract     uint256 private _seed;     uint256 private _seedLastBlock;     uint256 private _updateInterval;      constructor(IPOSDAORandom _randomContract) public {         require(_randomContract != IPOSDAORandom(0));         _posdaoRandomContract = _randomContract;         _seed = _randomContract.currentSeed();         _seedLastBlock = block.number;         _updateInterval = _randomContract.collectRoundLength();         require(_updateInterval != 0);     }      function useSeed() public {         if (_wasSeedUpdated()) {             // using updated _seed ...         } else {             // using _seed ...         }     }      function _wasSeedUpdated() private returns(bool) {         if (block.number - _seedLastBlock <= _updateInterval) {             return false;         }          _updateInterval = _posdaoRandomContract.collectRoundLength();          uint256 remoteSeed = _posdaoRandomContract.currentSeed();         if (remoteSeed != _seed) {             _seed = remoteSeed;             _seedLastBlock = block.number;             return true;         }         return false;     } }
  • Registry: stores human-readable keys associated with addresses, like DNS information (see OpenEthereum Wiki). This contract is needed primarily to store the address of the Certifier contract (see OpenEthereum Wiki for details).

  • StakingAuRa: contains staking logic including:

    • creating, storing, and removing pools by candidates and validators;
    • staking tokens by participants (delegators, candidates, or validators) into the pools;
    • storing participants’ stakes;
    • withdrawing tokens and rewards by participants from the pools;
    • moving tokens between pools by participant.
  • TxPermission: along with the Certifier contract, controls the use of zero gas price by validators in service transactions, protecting the network against “transaction spamming” by malicious validators. The protection logic is declared in the allowedTxTypes function.

  • TxPriority: manages and stores the transactions priority list used by Ethereum client. See https://github.com/NethermindEth/nethermind/issues/2300 for description.

  • ValidatorSetAuRa: stores the current validator set and contains the logic for choosing new validators at the beginning of each staking epoch. The logic uses a random seed generated and stored by the RandomAuRa contract. Also, ValidatorSetAuRa is responsible for discovering and removing malicious validators. This contract is based on reporting ValidatorSet described in OpenEthereum Wiki.

For a detailed description of each function of the contracts, see their source code.

Usage

Install Dependencies

$ npm install

Testing

Note: Test development for unit testing and integration testing is in progress.

Integration test setup is available here: https://github.com/poanetwork/posdao-test-setup

To run unit tests:

$ npm run test 

Flatten

Flattened contracts can be used to verify the contract code in a block explorer like BlockScout or Etherscan. See https://docs.blockscout.com/for-users/smart-contract-interaction/verifying-a-smart-contract for Blockscout verification instructions.

To prepare flattened version of the contracts:

$ npm run flat

Once flattened, the contracts are available in the flat directory.

Contributing

See the CONTRIBUTING document for contribution, testing and pull request protocol.

License

Pending

Add TxPriority contract, remove obsolete docs system


POSDAO智能合约

POSDAO一致性算法在Solidity中的实现。

关于

POSDAO是一种实现为分散自治组织(DAO)的利害关系证明(POS)算法。它旨在为公共链提供分散、公平和节能的共识。该算法是一组可靠地编写的智能合约。POSDAO是用一个通用的BFT共识协议来实现的,比如AuthorityRound(AuRa)有一个leader和概率final,或者honeybacker BFT(HBBFT),无领导且具有即时终结性。它激励演员为网络的最佳利益而行动。

该算法提供了一种Sybil控制机制,用于报告恶意验证程序并调整其份额、分配块奖励和管理一组验证程序。作者在以太坊eth1.0协议的基础上实现了侧链的POSDAO。

POSDAO存储库和资源

  • 白皮书https://forum.poa.network/t/posdao-white-paper/2208
  • 后端口OpenEthism客户端,具有所有POSDAO功能https://github.com/poanetwork/open-ethereum/tree/posdao-backport所有支持OpenEli的客户端功能https://github.com/openeathum/openeathum从v3.0.0开始集成POSDAO网络的测试设置https://github.com/poanetwork/posdao-test-setup
  • 论坛https://forum.poa.network/c/posdao
  • BlockRewardAuRa:根据白皮书中描述的逻辑和公式生成和分配奖励。主要功能包括:在验证器池中分配从erc到erc、erc到erc和/或erc到native bridge的入口/出口费用;铸造erc到native bridge所需的本地硬币;在每个赌注纪元开始时制作验证器桩的快照。快照由锁紧光环索赔奖励函数将奖励转移给验证者和他们的委托人。
  • 在验证器池中分配从erc到erc、erc本地和/或erc到本地桥的入口/出口费用;

智能合约摘要

注意:以下描述仅适用于AuRa合同。HBBFT契约实现还没有开始,这里没有列出也没有描述。所有合同都位于合同目录中。

  • 铸造erc到native bridge所需的本地硬币;
  • ValidatorSetAuRa.Report恶意
  • 随机光环:以随机方式生成和存储随机数(并控制当它们被光环验证器显示时)。通过ValidatorSet契约,随机数用于在每个立桩纪元开始时形成一个新的验证器集。主要功能包括:

  • commitHash和revealNumber。只能由验证器的节点在生成和显示其秘密号码时调用(请参阅RANDAO了解原理)。每个验证程序节点必须在每个集合回合调用一次这些函数。这将创建一个由ValidatorSetAuRa协定使用的随机种子。有关详细信息,请参阅白皮书;

    • onFinishCollectRound。此函数由BlockRewardAuRa合同在每个收集回合结束时自动调用。它控制验证器节点的显示阶段,并在验证器不显示时惩罚验证器(有关禁止协议的详细信息,请参阅白皮书);

    • currentSeed。ValidatorSetAuRa契约在每个下注epoch的最新块使用此公共getter获取累积的随机种子,用于在活动池中随机选择新的验证器。它也可以被任何想要使用网络随机种子的人使用。注意,它的值只有在调用revealNumber函数时才会更新:这应该在每个集合轮中至少发生一次,该集合轮可以使用collectRoundLength公共getter检索块中的长度。由于揭示验证器在发送前总是知道下一个随机数,所以您的DApp应该在显示阶段限制任何业务逻辑操作(依赖于random)。

    • 注册表:存储与地址相关联的人类可读密钥,如DNS信息(请参阅openeathom Wiki)。此合同主要用于存储证明人合同的地址(有关详细信息,请参见OpenEthism Wiki)。

      An example of how the seed could be retrieved by an external smart contract.
      pragma solidity 0.5.11;   interface IPOSDAORandom {     function collectRoundLength() external view returns(uint256);     function currentSeed() external view returns(uint256); }  contract Example {     IPOSDAORandom private _posdaoRandomContract; // address of RandomAuRa contract     uint256 private _seed;     uint256 private _seedLastBlock;     uint256 private _updateInterval;      constructor(IPOSDAORandom _randomContract) public {         require(_randomContract != IPOSDAORandom(0));         _posdaoRandomContract = _randomContract;         _seed = _randomContract.currentSeed();         _seedLastBlock = block.number;         _updateInterval = _randomContract.collectRoundLength();         require(_updateInterval != 0);     }      function useSeed() public {         if (_wasSeedUpdated()) {             // using updated _seed ...         } else {             // using _seed ...         }     }      function _wasSeedUpdated() private returns(bool) {         if (block.number - _seedLastBlock <= _updateInterval) {             return false;         }          _updateInterval = _posdaoRandomContract.collectRoundLength();          uint256 remoteSeed = _posdaoRandomContract.currentSeed();         if (remoteSeed != _seed) {             _seed = remoteSeed;             _seedLastBlock = block.number;             return true;         }         return false;     } }
  • loatingaura:包含锁紧逻辑,包括:

  • TxPermission:与证明人合同一起,控制验证程序在服务交易中使用零天然气价格,保护网络不受恶意验证器的“交易垃圾邮件”。保护逻辑在allowedTxTypes函数中声明。

    • creating, storing, and removing pools by candidates and validators;
    • staking tokens by participants (delegators, candidates, or validators) into the pools;
    • storing participants’ stakes;
    • withdrawing tokens and rewards by participants from the pools;
    • moving tokens between pools by participant.
  • Tx优先级:管理和存储以太坊eth客户端使用的事务优先级列表。看到了吗https://github.com/NethermindEth/nethermind/issues/2300用于描述。

  • ValidatorSetAuRa:存储当前验证程序集,并包含在每个锁定纪元开始时选择新验证程序的逻辑。逻辑使用由RandomAuRa契约生成和存储的随机种子。此外,ValidatorSetAuRa还负责发现和删除恶意验证器。此合同基于OpenEthomWiki中描述的报告验证集。

  • 有关合同的每个功能的详细说明,请参见其源代码。

注意:单元测试和集成测试的测试开发正在进行中。

使用情况

测试

$ npm install

扁平化

此处提供集成测试设置:https://github.com/poanetwork/posdao-test-setup

要运行单元测试:

扁平化的契约可用于在BlockScout或Etherscan等块资源管理器中验证合同代码。看到了吗https://docs.blockscout.com/for-users/smart-contract-interaction/verifying-a-smart-contract对于Blockscout验证说明。

$ npm run test 

贡献

要准备合同的扁平化版本:

一旦展开,合同就可以在flat目录中找到。

$ npm run flat

有关贡献、测试和请求请求协议,请参阅贡献文档。

许可证

待定

License

Pending

Add TxPriority contract, remove obsolete docs system

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/17591.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 !
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » POSDAO Smart Contracts – POSDAO智能合约区块链毕设代写

提供最优质的资源集合

立即查看 了解详情