您正在查看: Ethereum-优秀转载 分类下的文章

Trust EVM 让EOS支持以太坊合约

先记录下,做个笔记,翻译来自谷歌,有能力看原文。。
https://docs.trust.one/

Trust 是基于 EOS 网络的以太坊虚拟机,为开发者提供了一个交钥匙解决方案,可以在完全兼容以太坊的链上运行他们的应用程序,同时享受 EOS 的高吞吐量、可扩展性、安全性和可靠性,以及低交易成本 他们的用户。

由于设计的高度兼容性,以太坊原生应用程序可以无缝移植到 Trust。 开发人员在这里使用他们的 Solidity 智能合约时可能会喜欢熟悉的以太坊工具。

特点:

  • 确定性的Gas计算
  • 指令集级别的EVM兼容性
  • 完全的RPC兼容

技术实现

https://docs.trust.one/understanding-trust/architecture
EVM 作为 EOS 网络中的智能合约实现。 在 EVM 网络中生成交易是通过调用 EOS 网络上的 EVM 合约来完成的,EVM 的状态可以从 EOS 上的信息中得出。
为了实现完全 RPC 兼容性的目标,我们利用功能齐全的以太坊节点(当前设计中的 Geth)来提供所有读取 API,而所有写入访问将被转发到一个小型服务,以将它们打包到对 EVM 合约的 EOS 调用中。

我们所做的是设置一个“翻译器”服务,该服务读取运行在 EOS 上的 EVM 智能合约的共识输出,将该信息翻译成相应的 ETH 格式块并将这些块提供给 Geth 节点。 然后我们可以公开以太坊客户端 Web3 JSON RPC API(如有必要,还可以公开其他 API)。
如果我们发现它们更适合这种情况,我们也可能会在不同的场景中使用以太坊节点的其他实现。

未来的改进

当前设计正在运行并提供预期的兼容性级别。 还有一些潜在的方法可以改进整个系统:
合并 Translator 服务和 Geth 节点,去除相对不可靠的 p2p eth/66 通道。
将所有内容合并到一个 EOSIO 插件中,以便于部署。

MetaMask测试

https://docs.trust.one/about-the-testnet/connect-metamask

Network Name: Trust Network Testnet Preview
Chain ID: 15555
New RPC URL*: https://api.testnet-dev.trust.one
Currency Symbol: EVM
Block Explorer URL (Optional): https://trustscan.one

Faucet

https://faucet.testnet-dev.trust.one/

https://www.odaily.news/post/5178155
https://www.odaily.news/post/5178155

使用standard-input-json验证Solidity源码

使用 standard-input-json(以BSC测试链为例)

合约源码

Storage.sol

// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;
import "@openzeppelin/contracts/access/Ownable.sol";

contract Storage is Ownable {
    uint256 number;

    function setNumber(uint256 num) public onlyOwner {
        number = num;
    }

    function getNumber() public view returns (uint256) {
        return number;
    }
}

JSON格式的输入

Storage.json

{
    "language": "Solidity",
    "sources": {
        "contracts/Storage.sol": {
            "content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.7.0 <0.9.0;\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\ncontract Storage is Ownable {\n    uint256 number;\n\n    function setNumber(uint256 num) public onlyOwner {\n        number = num;\n    }\n\n    function getNumber() public view returns (uint256) {\n        return number;\n    }\n}"
        },
        "@openzeppelin/contracts/access/Ownable.sol": {
            "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    constructor() {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n        _;\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions anymore. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby removing any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"
        },
        "@openzeppelin/contracts/utils/Context.sol": {
            "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n}\n"
        }
    },
    "settings": {
        "optimizer": {
            "enabled": true,
            "runs": 200
        },
        "outputSelection": {
            "*": {
                "*": [
                    "abi",
                    "evm.bytecode",
                    "evm.deployedBytecode",
                    "evm.methodIdentifiers",
                    "metadata"
                ],
                "": [
                    "ast"
                ]
            }
        }
    }
}

content内容:将solidity源码转换为JSON字符串。

Javascript Serializer(推荐方法2、方法3)

Convert/Escapes an object to a JSON string
将solidity源码转换为JSON字符串

方法1.BSC网址

去掉最后的 ”

方法2.字符串转义

// SPDX-License-Identifier: MIT\n\npragma solidity >=0.7.0 <0.9.0;\nimport \"@openzeppelin/contracts/access/Ownable.sol\";\n\ncontract Storage is Ownable {\n    uint256 number;\n\n    function setNumber(uint256 num) public onlyOwner {\n        number = num;\n    }\n\n    function getNumber() public view returns (uint256) {\n        return number;\n    }\n}

方法3. Hardhat项目下

编译合约:

npx hardhat compile

打开artifacts\build-info路径下的json文件
input字段内容

部署合约

部署合约

与Storage.json配置文件相同

BSC浏览器验证合约

https://testnet.bscscan.com/address/0x1b3104004ebda264b88d04afb6ea66d70a2d51ac#code


  1. 转载自:https://learnblockchain.cn/article/3415

以太坊中的叔块(uncle block)

孤块(orphan block)

在比特币协议中,最长的链被认为是绝对的正确。如果一个块不是最长链的一部分,那么它被称为是“孤块”。一个孤立的块是一个块,它也是合法的,但是发现的稍晚,或者是网络传输稍慢,而没有能成为最长的链的一部分。在比特币中,孤块没有意义,随后将被抛弃,发现这个孤块的矿工也拿不到采矿相关的奖励。

最重的链(heaviest)

Ethereum的GHOST协议,不认为孤块没有价值,而是会给与发现孤块的矿工以回报。在以太坊中,孤块被称为“叔块”(uncle block),它们可以为主链的安全作出贡献。

相对来说,比特币有很长的块间隔时间。在比特币区块中,平均约10分钟可以得到一个确认(也就是发现一个新的后续区块)。但是自从比特币成立以来,大量关于块链技术的研究已经发展起来。这些研究表明,更短的块间隔确实是可能的,而且在很多应用场景下是需要的。然而,随着拥有更快的出块速度,孤块的增加而带来的昂贵的成本和浪费也随之增加。

GHOST协议支付报酬给叔块,这激励了矿工在新发现的块中去引用叔块。引用叔块使主链更重。在比特币,最长的链是主链。在以太坊中,主链是指最重的链。

叔块的好处

解决了两个问题:

  1. 以太坊十几秒的出块间隔,大大增加了孤块的产生,并且降低了安全性。通过鼓励引用叔块,使引用主链获得更多的安全保证(因为孤块本身也是合法的)
  2. 比特币中,采矿中心化(大量的集中矿池)成为一个问题。给与叔块报酬,可以一定程度上缓解这个问题。

叔块的引用

区块可以不引用,或者最多引用两个叔块
叔块必须是区块的前2层~前7层的祖先的直接的子块
被引用过的叔块不能重复引用
引用叔块的区块,可以获得挖矿报酬的1/32,也就是51/32=0.15625 Ether。最多获得20.15625=0.3125 Ether
被引用的叔块,其矿工的报酬和叔块与区块之间的间隔层数有关系。

间隔层数 报酬比例 报酬(ether)
1 7/8 4.375
2 6/8 3.75
3 5/8 3.125
4 4/8 2.5
5 3/8 1.875
6 2/8 1.25

原文链接:https://blog.csdn.net/superswords/article/details/76445278