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

bump ganache to support istanbul fork #319

Merged
merged 1 commit into from
Nov 18, 2019
Merged

bump ganache to support istanbul fork #319

merged 1 commit into from
Nov 18, 2019

Conversation

djudjuu
Copy link
Contributor

@djudjuu djudjuu commented Nov 13, 2019

closes #318

OPEN QUESTIONS:

truffle.js defines many networks. For some of them I can pass istanbul as evm-version, but for many I am not sure how to do that or what they even run.
so going by network_name if have the following questions (assumptions)


    localhost: {
      provider: multiWalletProvider("http://localhost:8545", "localhost"),
      // istanbul? > what will run at 8545 at that time?? if ganache it would not be enabled by default.


    inprocess: {
        hardfork: "istanbul", all goodd!


    nf_private: {
        "http://parity-instant-seal-byzantium-enabled:8545",
        will be enabled with pairty repo PR

    nf_private_io: {
      provider: multiWalletProvider("https://platform.neufund.io/nodes/private", "nf_private_io"),
      > "parity in dev mode with our contracts deployed,  redeployed at night around 2 in mornin"
      > parity self-sealing --> istanbul yes

    coverage: {
    ???


    forked_live: {
      // would need to refork?


    nano_live: {
        "https://nd.neufund.org/",
        // what is running there?

    forked_nano_live: {
        "http://ethexp2-node.neustg.net:8545",
      // can't find url



    console_pk_live: {
      provider: consolePKProvider("https://platform.neufund.org/nodes/mainnet", "console_pk_live"),
      // istanbul? not sure what runs there? cant find the relevant docs

    live: {
      // istanbul? not sure what runs there? cant find the relevant docs

    localhost_live: {
    localhost_test:
    // run on 8545, what will be running there?

Also, I tried adding a test to our testsuite that verifies whether the current provider can deal with istanbul. It did not work as expected though, as unknown opcodes are just represented as "INVALID" and I failed at writing a solidity-contract that would use it directly (e.g. return the chainId in a function). See my attached notes for more details.

ATTENTION this PR is tightly connected to the one enable the istanbul on the parity self sealing node (see issue desciripton below)

How will this be deployed?
Please note that backend and frontend tests are using parity node for which istanbul fork version is not merged yet. that is next step
Neufund/parity-instant-seal-byzantium-enabled#24
also was tested and works fine

@djudjuu djudjuu changed the title bump ganache to support istanbul fork [WIP] bump ganache to support istanbul fork Nov 13, 2019
@djudjuu
Copy link
Contributor Author

djudjuu commented Nov 14, 2019

Table of Contents

  1. TASK3: update to istanbul (contracts#318)
    1. part1 in contracts repo:
      1. research what Istanbul fork is about and how it could be relevant for our smart contracts
      2. update ganache && ganache-core
      3. enable istanbul support
      4. write a test BLOCKED
    2. part 2 in parity repo

TODO TASK3: update to istanbul (contracts#318)

part1 in contracts repo:

research what Istanbul fork is about and how it could be relevant for our smart contracts

  • increased gas costs for SLOAD, which reads an integer from storage
  • increase interoperability with zcash? how?
  • EIP155 makes chainID available to smart-contracts by a new opcode, which
    will allow to prevent replay attacks on the contract itself. easier
    verifying of signatures BUT also requires one to prepare for dealing with
    updates to the chainID
  • somewhere i read that smart contracts can no longer send funds to each other?

update ganache && ganache-core

enable istanbul support

  • add cml arg
  • enable it in ganache-core, server or provider options
    • "To use the new istanbul hardfork pass "istanbul" as the hardfork option in ganache-core's server or provider options"
    • ??: If the provider is the self-sealing parity-node, istanbul support must be enabled there

write a test BLOCKED

  1. maybe use the new opcode in a contract

    1. simply add contract to .sol files > truffle's solc version can not compile it

    2. DONE sample code with new opcodes (taken from solidity-repo)

        contract C {
            function f() pure external {
                assembly {
                    pop(chainid())
                }
            }
            function g() view external {
                assembly {
                    pop(selfbalance())
                }
            }
        }
  1. use new opcode in test BLOCKED: solidity does not support istanbul yet

    1. DONE verify that contract is correct istanbul evm

      $ solc –evm-version istanbul contracts/test/istanbul.sol

    2. write a test that uses provider web3 to compile it.

      • look up how to do that using web3 0.2 version (it would be really cool to update that!)
      • use it
    3. TODO disable istanbul support and see if the test fails >NOPE

      • it does not :/
      • make call to the contract that returns the chain id
        • modify the contract to have a function that returns the chainId and call it
        • or any function to see if it really has been deployed
    4. BLOCKER: Solidity does not yet support istanbul,

      so unless I know how to write a contract with opcodes I can not write a
      function that uses it. Also, invalid opcodes will just compile to INVALID
      and still deploy, so merely using it in a contract and seeing if it
      deploys is not enough

      this can be verified with;
      $ solc –evm-version istanbul –combined-json opcodes istanbul.sol

  2. test pipeline:

    run it:
    $ yarn truffle test –network inprocesstest test/evm.js test/setup.js

    use truffle console:
    $ npx truffle console

    TIP: to avoid having to recompile all contracts everytime you run the test, do
    $ npx truffle migrate –reset –network inprocesstest

  3. truffle-testfile: /test/evm.js

    import { expect } from "chai";
    
    contract("Provider", ([…accounts]) => {
      it("should support evm-version 'istanbul'", () => {
        // create a contract that uses an istanbul only opcode: selfbalance
        const contractCode = " contract C {function f() pure external {assembly {pop(chainid())}}}";
        */ created abi & binary with (solc 0.5.12 )
        /* $ solc –bin –abi –evm-version istanbul istanbul.sol
        const abi = [{"constant":true,"inputs":[],"name":"f","outputs":[],"payable":false,"stateMutability":"pure","type":"function"}]
        const binary = "0x6080604052348015600f57600080fd5b50606c80601d6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c806326121ff014602d575b600080fd5b60336035565b005b56fea265627a7a7231582057d27718fd45a3e47cebaba18efe6a5ee4ae5286d466cb98c337217fd55f1fcc64736f6c634300050c0032"
    
        var Istanbul = web3.eth.contract(abi);
        let gasEstimate = web3.eth.estimateGas({data: binary} , (err, res) => {
          console.log('gas estimate', res, err);
        });
        */ TODO this test always gives a green checkmark, as it does not await the result of the deployment.
        /* If it can't deploy it throws an error though.
        // So i need to figure out how to promisify the deployment / or return 
        try {
          var instance = Istanbul.new(
            {
              from: accounts[0],
              data: binary,
              gas: 100000,
            }, function (err, myContract) {
              if (!err) {
                if (!myContract.address) {
                  console.log(myContract.transactionHash);
                } else {
                  console.log("contract deployed at ", myContract.address);
                  assert(true);
                }
              } else {
                console.log("Oooops", err);
                assert(false, "Istanbul contract could not be deployed");
                return false;
                // TODO make test fail
              }
            });
        } catch (e) {
          assert(false, "22222Istanbul contract could not be deployed", e.toString());
        }
      });
    });

part 2 in parity repo

large chunk done by marcin
?? verify that the truffle js does not need to change once parity is updated

@djudjuu djudjuu changed the title [WIP] bump ganache to support istanbul fork bump ganache to support istanbul fork Nov 14, 2019
@djudjuu djudjuu merged commit 18509ee into master Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

update ganache and enable istanbul fork
2 participants