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
- I check the transaction Receipt and see that the full gas has been consumed.
- I increase the gas to 10000000 and try again. Again the full gas is consumed
- Then I wonder what is going on with this simple function. So I call
> B.increase.estimateGas() 4712388 <-- this is the block gas limit !!!
- 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.