2

I have an issue with a simple library configuration and I need an advise to resolve this.

Context: Local private block chain

Version:

> web3.version
{
  api: "0.18.1",
  ethereum: "0x3f",
  network: "260674",
  node: "Geth/v1.5.8-stable-f58fb322/darwin/go1.7.5",
}

Solidity code:

pragma solidity ^0.4.9;

library BasicLib {
    function add(uint into, uint val) returns(uint) {
        return into + val;
    }
}


contract Basic {
    uint public data;

    function increase() {
        data = BasicLib.add(data, 10);
    }    
}

Then, I use javascript web3 to compile I publish the BasicLib with a contract.new({data: code, gas:1000000}) and get a correct address after mining.

I take this address, remove the "0x" and replace the __BasicLib____ placeholder of the Basic contract code and the result look nice

BasicLib.address: "0x8de8e5f4b91b67915a07279f9095155fa0ed5114"
Basic.code: "0x6060604052341561000c57fe5b5b6101048061001c6000396000f300606060405263ffffffff60e060020a60003504166373d4a13a8114602a578063e8927fbc146049575bfe5b3415603157fe5b60376058565b60408051918252519081900360200190f35b3415605057fe5b6056605e565b005b60005481565b738de8e5f4b91b67915a07279f9095155fa0ed511463771602f7600054600a6000604051602001526040518363ffffffff1660e060020a028152600401808381526020018281526020019250505060206040518083038186803b151560bf57fe5b60325a03f4151560cb57fe5b505060405151600055505b5600a165627a7a72305820e35203973e69040bc9a24c63526485e87946e2f2b688172fcda1e89f2beb09060029"

Then I deploy the Basic contract, it gets mined and i get an address. So far so good. I test the increase() function and it gets mined but the data field does not get increased.

Now, i start investigating the issue

  1. I check the transaction Receipt and see that the full gas has been consumed.
  2. I increase the gas to 10000000 and try again. Again the full gas is consumed
  3. Then I wonder what is going on with this simple function. So I call
> B.increase.estimateGas()
4712388      <-- this is the block gas limit !!!
  1. Then I say, lets run in debug to see where there is a loop in the evm code
> var deb = debug.traceTransaction("0x233b27c9a7ad577b0860261b23bd9ab544df1513839fce2b7800fd286eab8a51")
> deb.structLogs.length
90        <- so nothing extraordinary here


> deb
{
  gas: 1000000,       <-- ok, i passed a good amount of gas
  returnValue: "",
  structLogs: [{
      depth: 1,
      error: null,
      gas: 978725,    
      gasCost: 3,
      memory: null,
      op: "PUSH1",
      pc: 0,
      stack: [],
      storage: {}
  }, {
      depth: 1,
      error: null,
      gas: 978722,
      gasCost: 3,
      memory: null,
      op: "PUSH1",
      pc: 2,
      stack: ["0000000000000000000000000000000000000000000000000000000000000060"],
      storage: {}
  }, { ...  I CUT THE DETAILS HERE .... }, {
  depth: 1,
  error: {},
  gas: 7,
  gasCost: 978317,
  memory: ["0000000000000000000000000000000000000000000000000000000000000000", "0000000000000000000000000000000000000000000000000000000000000000", "0000000000000000000000000000000000000000000000000000000000000060", "771602f700000000000000000000000000000000000000000000000000000000", "0000000000000000000000000000000000000000000000000000000000000000", "0000000a00000000000000000000000000000000000000000000000000000000"],
  op: "DELEGATECALL",   <-- This is the last OP code called
  pc: 196,
  stack: ["00000000000000000000000000000000000000000000000000000000e8927fbc", "0000000000000000000000000000000000000000000000000000000000000056", "0000000000000000000000008de8e5f4b91b67915a07279f9095155fa0ed5114", "00000000000000000000000000000000000000000000000000000000771602f7", "00000000000000000000000000000000000000000000000000000000000000a4", "0000000000000000000000000000000000000000000000000000000000000020", "0000000000000000000000000000000000000000000000000000000000000060", "0000000000000000000000000000000000000000000000000000000000000044", "0000000000000000000000000000000000000000000000000000000000000060", "0000000000000000000000008de8e5f4b91b67915a07279f9095155fa0ed5114", "00000000000000000000000000000000000000000000000000000000000eed65"],
  storage: {}   }]

So I conclude that the code is not looping, just stopping at the DELEGATECALL and stops without error.

What the f... am I doing wrong here. Must be the linkage of the lib, but when using Remix Solidity Browser connected to my blockchain and letting it deploy the lib before the contract it behave in the same way.

Pleaaaaase advise.

1 Answer 1

1

You have to initialise your private blockchain with a genesis.json that specifies that the homesteadBlock begins at an earlier block:

Wocket:ESE bok$ more genesis.json 
{
    "config": {
        "homesteadBlock": 10
    },
    "nonce": "0",
    "difficulty": "0x400",
    "mixhash": "0x00000000000000000000000000000000000000647572616c65787365646c6578",
    "coinbase": "0x0000000000000000000000000000000000000000",
    "timestamp": "0x00",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "extraData": "0x",
    "gasLimit": "0x3B4A1B44",
    "alloc": {}
}

Then initialise your blockchain using the following commands:

Wocket:ESE bok$ geth --datadir mydatadir init genesis.json
Wocket:ESE bok$ geth --datadir mydatadir --mine --minerthreads 1 console

More details at How could I update default homesteadBlock value on my private Ethereum blockchain?

4
  • Thanks. I read a lot of stuff so far but I didn't pick that library implementation was only for Homestead version of the blockchain. I also now understand that Ethereum is Homestead only from block 1500000. With all these changes / forks in Ethereum (DAO, future change to PoS) I am starting to loose trust in Ethereum stability :-( Commented Mar 4, 2017 at 10:19
  • It's hard to keep up with, but the Ethereum ecosystem is just beautiful and still evolving at a rapid rate. Commented Mar 4, 2017 at 10:43
  • Is it what is expected of a blockchain ? I need a longterm trustability from my side. But let it mature first. It is not yet a real business production environment but more a playground. Commented Mar 4, 2017 at 10:46
  • 1
    Well, recreating my private blockchain with this homesteadBlock fixed the issue. thanks. Commented Mar 4, 2017 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.