blockchain - 为什么我们不能通过智能合约将以太币发送到以太坊地址 0x1

标签 blockchain ethereum solidity smartcontracts ether

使用以下可靠代码,我尝试将以太币发送到以太坊钱包地址 0x1 通过智能合约,它变得失败。但是,当我尝试将以太币发送到地址 时0x1 直接从我的钱包里就成功了。

pragma solidity ^0.4.24;

contract Transfer {

    constructor () public payable {
        // Deploy contract with 1000 wei for testing purpose
        require(msg.value == 1000);
    }

    function done() public {
        address(0).transfer(1); // Transaction success
    }

    function fail() public {
        address(1).transfer(1); // Transaction failed
    }

    function send(address account) public {
        account.transfer(1); // Transaction success (except 0x1)
    }

}

Why we can't send ether to address 0x1 via contracts ?



引用:
  • 直接从我的钱包发送以太币是成功的
    https://ropsten.etherscan.io/tx/0x1fdc3a9d03e23b0838c23b00ff99739b775bf4dd7b5b7f2fa38043056f731cdc
  • done() 函数成功
    https://ropsten.etherscan.io/tx/0xd319c40fcf50bd8188ae039ce9d41830ab795e0f92d611b16efde0bfa1ee82cd
  • fail() 函数失败
    https://ropsten.etherscan.io/tx/0x0c98eafa0e608cfa66777f1c77267ce9bdf81c6476bdefe2a7615158d17b59ad


  • 更新:

    经过对以太坊的研究 预编译契约(Contract)我在solidity代码下面写了这个,将以太发送到 0x1 通过智能合约地址,它正在工作。
    pragma solidity ^0.4.24;
    
    contract Learning {
    
        constructor () public payable {
            // Deploy contract with 1000 wei for testing purpose
            require(msg.value == 1000);
        }
    
        function test() public returns (bool) {
            // Set minimum gas limit as 700 to send ether to 0x1
            transfer(0x0000000000000000000000000000000000000001, 1, 700);
            return true;
        }
    
        function transfer(address _account, uint _wei, uint _gas) private {
            require(_account.call.value(_wei).gas(_gas)());
        }
    }
    

    对于测试,只需使用 部署合约1000 wei 并执行 test()功能。它的工作:)

    最佳答案

    您不小心偶然发现了以太坊鲜为人知的“功能”之一。该链实际上有一些预编译的合约(黄皮书中的附录 E),其中之一位于 0x0000000000000000000000000000000000000001 (ecrecover 合约)。

    您的 fail()由于 ecrecover 的事实,函数会因耗尽气体而失败合约的回退执行需要的不仅仅是 2300 gastransfer 转发方法。
    0x0 address 不是一个特殊的合约,所以一个普通的转移调用就可以正常工作,就像任何其他地址一样。

    关于blockchain - 为什么我们不能通过智能合约将以太币发送到以太坊地址 0x1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52139936/

    相关文章:

    ethereum - Gas资金不足*价格+值(value)错误

    struct - Solidity,Solc 错误 : Struct containing a (nested) mapping cannot be constructed

    javascript - 如何在 Javascript 中将 0x Protocol BigNumber 转换为 String

    linux - 未收到来自 REGISTER 请求 hypereldger 的响应

    blockchain - Hyperledger:运行 "/bin/bash: ./scripts/script.sh: No such file or directory"时获取 "./byfn -m up"

    docker - hyperledger fabric 在对等体上注册 ID 类型错误?

    ethereum - 如何获取或验证合约的源代码?

    ethereum - 如何从代币实例中获取erc-20代币合约的地址

    blockchain - ERC20 标准中的批准和允许方法真正在做什么?

    node.js - 代码未在 nodejs 中编译,抛出意外错误(Web3.js)