Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

block.coinbase can't be used in autoExec() #493

Closed
luqz opened this issue Apr 22, 2019 · 14 comments
Closed

block.coinbase can't be used in autoExec() #493

luqz opened this issue Apr 22, 2019 · 14 comments
Assignees
Labels
bug Something isn't working upgrade vm & language vm & state

Comments

@luqz
Copy link
Contributor

luqz commented Apr 22, 2019

Description

block.coinbase can't be used in autoExec()

Steps to Reproduce

  1. Add SysConfig.autoExec=true when create chain;
  2. use address(block.coinbase).transfer(1) in function autoExec();
  3. create contract and registe it to AutoExec contract;
  4. Transfer token to contract.

Expected behavior: contract balance sub 1 per block

Actual behavior: contract balance remain unchanged

Reproduce how often: every time.

Versions

v0.22.0

Additional Information

address(0x5444B13eFe73A7de4d56f2c043424115C8e26eF1).transfer(1) works but address(block.coinbase).transfer(1) not.

@luqz luqz added the bug Something isn't working label Apr 22, 2019
@kaikai1024
Copy link
Contributor

What's the Solidity version?

@luqz
Copy link
Contributor Author

luqz commented Apr 22, 2019

What's the Solidity version?

^0.4.24

@kaikai1024
Copy link
Contributor

I've tried the block.coinbase on a normal conract and it works.
Maybe something wrong with the auto-exec.

#483

@kaikai1024
Copy link
Contributor

Would you give some other info? @luqz I can not reproduce.

the contract:

pragma solidity ^0.4.24;

contract X {
    address public addr;
    uint public x;

    constructor() payable public {
        addr = block.coinbase;
    }

    function autoExec() public {
        address(block.coinbase).transfer(1);
        x++;
    }
}

https://gist.github.com/kaikai1024/74944724904174cd59e4116dd6456b6e

@kaikai1024 kaikai1024 added the question Further information is requested label Apr 23, 2019
@luqz
Copy link
Contributor Author

luqz commented Apr 24, 2019

Sorry, I try it again. Your code works well.
I found that maybe the fact is block.coinbase==0x0.
If I remove require(to != address(0), "Invalid Address") in my contract, It works, but not Expected.
My contract:

pragma solidity ^0.4.24;

import './IAutoExec.sol';

contract TestAutoExec is IAutoExec {
    uint public count;

    event Transfer(address indexed from, address indexed to, uint256 indexed value);

    modifier onlyAutoExec {
        if (msg.sender == address(0xFFFfFfFffffffFfFFFFffffFfFFFffFFfF020013))
            _;
        else return;
    }

    function autoExec() external onlyAutoExec {
        incentive();
    }


    function incentive() private {
        _transfer(address(block.coinbase), 1);
        count ++;
    }


    function _transfer(address to, uint value) private returns (bool) {
        require(address(this).balance >= value, "Balance not enough");
        require(to != address(0), "Invalid Address");
        to.transfer(value);
        emit Transfer(address(this), to, value);
    }

    function () public payable {
        
    }

}

@kaikai1024
Copy link
Contributor

If I remove require(to != address(0), "Invalid Address") in my contract

Would you please get the coinbase address to double-check.

It works, but not Expected.

The balance is not right?

@luqz
Copy link
Contributor Author

luqz commented Apr 24, 2019

If I remove require(to != address(0), "Invalid Address") in my contract

Would you please get the coinbase address to double-check.

It works, but not Expected.

The balance is not right?

I checked the balance of 0x0000000000000000000000000000000000000000,
tokens was transfered to 0x0000000000000000000000000000000000000000。

@kaikai1024
Copy link
Contributor

kaikai1024 commented Apr 24, 2019

ok, i see. So the problem is why coinbase is zero.

I'll use your code to check it.

@kaikai1024
Copy link
Contributor

How do you start the chain? @luqz

@luqz
Copy link
Contributor Author

luqz commented Apr 24, 2019

How do you start the chain? @luqz

./scripts/create_cita_config.py create --super_admin "0x4b5ae4567ad5d9fb92bc9afd6a657e6fa13a2523" --nodes "127.0.0.1:4000,127.0.0.1:4001,127.0.0.1:4002,127.0.0.1:4003" --contract_arguments  SysConfig.economicalModel=1 SysConfig.autoExec=true

./bin/cita  setup test-chain/0
./bin/cita  start test-chain/0 

./bin/cita  setup test-chain/1
./bin/cita  start test-chain/1 

./bin/cita  setup test-chain/2
./bin/cita  start test-chain/2 

./bin/cita  setup test-chain/3
./bin/cita  start test-chain/3 

@kaikai1024
Copy link
Contributor

kaikai1024 commented Apr 24, 2019

It really can not get the coinbase using auto-exec...

@kaikai1024 kaikai1024 added vm & state and removed question Further information is requested labels Apr 24, 2019
boundless-forest added a commit to boundless-forest/cita that referenced this issue Apr 25, 2019
boundless-forest added a commit to boundless-forest/cita that referenced this issue Apr 25, 2019
@kaikai1024
Copy link
Contributor

@luqz It will be fixed at the next version of v0.23.0. and we will upgrade the protocol version.

You can use the develop after the #506 be merged.

@kaikai1024 kaikai1024 added this to To do in PROTOCOL VERSION 2 via automation Apr 25, 2019
@kaikai1024 kaikai1024 added the upgrade vm & language label Apr 25, 2019
@kaikai1024 kaikai1024 added this to the PROTOCOL VERSION 2 milestone Apr 25, 2019
@luqz
Copy link
Contributor Author

luqz commented Apr 25, 2019

@luqz It will be fixed at the next version of v0.23.0. and we will upgrade the protocol version.

You can use the develop after the #506 be merged.

Great!👏

@kaikai1024
Copy link
Contributor

Reconfirm: not v0.23.0. 🤦‍♂️
Check the new project
Check the new milstone

PROTOCOL VERSION 2 automation moved this from To do to Done Apr 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upgrade vm & language vm & state
Projects
No open projects
Development

No branches or pull requests

3 participants