I reccomend npm i -g jsonogram for pretty printing json
testrpc -m "pencil blouse boat super visual window huge image flip usual debris hospital"
curl -X POST -d '{"method": "eth_sendTransaction", "params": [{"from": "0x435d00bd45e771cc663da08d8f3b9173414cd24c","data": "6060604052600160a060020a03321660009081526020819052604090206127109055609f80602d6000396000f3606060405260e060020a600035046390b98a1181146024578063f8b2cb4f146050575b005b606c60043560243533600160a060020a0316600090815260208190526040812054829010156076576099565b600160a060020a03600435166000908152602081905260409020545b6060908152602090f35b604080822080548490039055600160a060020a0384168252902080548201905560015b9291505056"}]}' localhost:8545 | jsonogram
curl -X POST -d '{"method": "eth_estimateGas", "params": [{"from": "0x435d00bd45e771cc663da08d8f3b9173414cd24c","to":"0xc01508458a7bb72d63f996561115069a2c328202","data":"0x90b98a11000000000000000000000000b0a34f864f14506216e7178df35e031161cc3c9e0000000000000000000000000000000000000000000000000000000000000001"}]}' localhost:8545 | jsonogram
-> "0x82b5" 33461
curl -X POST -d '{"method": "eth_sendTransaction", "params": [{"from": "0x435d00bd45e771cc663da08d8f3b9173414cd24c","to":"0xc01508458a7bb72d63f996561115069a2c328202","data":"0x90b98a11000000000000000000000000b0a34f864f14506216e7178df35e031161cc3c9e0000000000000000000000000000000000000000000000000000000000000001"}]}' localhost:8545 | jsonogram
curl -X POST -d '{"method": "eth_getTransactionByHash", "params": ["0x850bc690fcca104b4f0f3b9523ba65e9d920a9c98d7587efd4e0fba62cd5043d"]}' http://localhost:8545/ | jsonogram
-> "0x47e7c4" 4712388
"0x82b5" 33461 !== "0x47e7c4" 4712388
ZOMG
explicitly setting a high gas or gasLimit parameter for eth_estimateGas does not change the estimate
curl -X POST -d '{"method": "eth_estimateGas", "params": [{"gas":"0x47e7c4", "from": "0x435d00bd45e771cc663da08d8f3b9173414cd24c","to":"0xc01508458a7bb72d63f996561115069a2c328202","data":"0x90b98a11000000000000000000000000b0a34f864f14506216e7178df35e031161cc3c9e0000000000000000000000000000000000000000000000000000000000000001"}]}' localhost:8545 | jsonogram
estimateGas vm trace initially looks healthy
https://gist.github.com/kumavis/b5ce65afe69faf7ba7ea7fe69be53520
so to make things weirder: publishing the same contract to morden + estimating gas via geth offers a different number:
publish:
{"from": "0x5fda30bb72b8dfe20e48a00dfc108d0915be9bb0","data": "6060604052600160a060020a03321660009081526020819052604090206127109055609f80602d6000396000f3606060405260e060020a600035046390b98a1181146024578063f8b2cb4f146050575b005b606c60043560243533600160a060020a0316600090815260208190526040812054829010156076576099565b600160a060020a03600435166000908152602081905260409020545b6060908152602090f35b604080822080548490039055600160a060020a0384168252902080548201905560015b9291505056"}
produces: http://testnet.etherscan.io/address/0x272c19a069cdfea31e913524501494c26830a3f1
estimating gas of a transfer tx against this MetaCoin contract
curl -X POST -d '{"id":1234, "method": "eth_estimateGas", "params": [{"from": "0x5fda30bb72b8dfe20e48a00dfc108d0915be9bb0","to":"0x272c19a069cdfea31e913524501494c26830a3f1","data":"0x90b98a11000000000000000000000000b0a34f864f14506216e7178df35e031161cc3c9e0000000000000000000000000000000000000000000000000000000000000001"}]}' https://morden.infura.io | jsonogram
gives us a new number
-> "0xbd4d" 48461
what the math??
actually executing the tx
http://testnet.etherscan.io/tx/0x2d933ff8da5a61da181f2c0228eab1c3513cc665854f5ab6d2983d7c611119f3
yields the same number
-> "0xbd4d" 48461
I've replicated this failing example with the testrpc test suite on this branch.
Interestingly, the gas estimation was correct when I used the testrpc internal sample contract, but did occur when using @kumavis's example transaction.
I'm probably going crazy here, but the ratio of wrongness is approximately the square root of 2.
actual / estimated = 48844 / 34524 = 1.4147839184335536
Math.sqrt(2) = 1.4142135623730951
@tcoulter Could you please take a look at this, and at least figure out if this is a problem with testrpc or ethereumjs-vm? This has broken the interaction between MetaMask and testrpc, and I was hoping to show that off at our presentation tomorrow.
@flyswatter looks like your test "should return the same value from estimateGas as eth_sendTransaction actually uses for another contract" is setup incorrectly
it falls through all entry points (3fa4f245, 55241077) and ends (035 STOP)
seems like the tx is pointing at a contract with an incompatible abi
should return the same value from estimateGas as eth_sendTransaction actually uses for another contract
000 PUSH1 60
002 PUSH1 40
004 MSTORE
005 PUSH1 e0
007 PUSH1 02
009 EXP
010 PUSH1 00
012 CALLDATALOAD
013 DIV
014 PUSH4 3fa4f245
019 DUP2
020 EQ
021 PUSH1 24
023 JUMPI
024 DUP1
025 PUSH4 55241077
030 EQ
031 PUSH1 2c
033 JUMPI
034 JUMPDEST
035 STOP
so for my original setup, the stack traces for estimateGas and processing the tx are 100% the same
https://www.diffchecker.com/etmg8ehh
which means the issue is 100% related to https://github.com/ethereumjs/ethereumjs-vm/issues/64
continuing the thread on ethereumjs/ethereumjs-vm#64
![]()
despite how many times I wrote 100% up there, it turns out it was unrelated to ethereumjs/ethereumjs-vm#64 !
Most helpful comment
I'm probably going crazy here, but the ratio of wrongness is approximately the square root of 2.
actual / estimated = 48844 / 34524 = 1.4147839184335536
Math.sqrt(2) = 1.4142135623730951