Ganache-cli: transaction hash returned by testrpc is different from geth

Created on 10 Sep 2017  路  12Comments  路  Source: trufflesuite/ganache-cli

the txHash of a transaction should be the sha3(raw_transaction_string)

this is the case on any ethereum node, except testrpc

I created a sample. in this example, testrpc has been launched with

testrpc --port 8544 --network-id 256 --gasLimit 0x5F5E100 --account="0x29469148b567bb0142b4e33c518d833c77ef36b3894b56c7291bed448c943a03,100000000000000000000000000"

when executed this code yields two rows on the console, the first one says that the hashes are NOT equal while the second confirms that they are

let Web3 = require('web3')
let EthereumTx = require('ethereumjs-tx')

let txObj = {
  from: "0x855e89aee346d780aa5912838d0fd16b4fcf12a3",
  to: "0x3532727c1126ddad9a6e9f935b74e41e7b1d4025"
}

let web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8544/'))
submitTx().then(() => {
  web3 = new Web3(new Web3.providers.HttpProvider('https://kovan.infura.io/NgjvCOUF5UIhCgRKndzD/'))
  return submitTx()
})


function submitTx() {
  return web3.eth.getTransactionCount(txObj.from, 'pending')
    .then(nonce => {
      txObj.nonce = nonce
      txObj.gasLimit = web3.utils.toHex(22000)
      txObj.gasPrice = web3.utils.toHex(2)
      txObj.value = web3.utils.toHex(1e9)
      const tx = new EthereumTx(txObj)
      tx.sign(Buffer.from("29469148b567bb0142b4e33c518d833c77ef36b3894b56c7291bed448c943a03", 'hex'))
      let signedTxHexString = tx.serialize().toString('hex')
      txObj.txHash = "0x" + tx.hash().toString('hex')
      return web3.eth.sendSignedTransaction("0x" + signedTxHexString, (err, txHash) => {
        if(txHash === txObj.txHash) {
          console.log("computed and returned are the same", txHash, txObj.txHash)
        } else {
          console.log("computed and returned are NOT the same", txHash, txObj.txHash)
        }
      })
    })
}
consistenccorrectness priority-medium

Most helpful comment

Fixed in [email protected].

All 12 comments

@drgorb thanks for reporting this. If we aren't following the prescribed method for generating a tx hash that would be a bit troubling. I've got a fairly deep backlog at the moment, but I'll add this to the list.

This is happening because TestRPC doesn't sign transactions. Instead it uses ethereumjs-tx/fake.js to fake out a signed transaction hash. I have a fix in the works for this, but it breaks some forking behaviour, so it'll take a bit of time to sort that out.

Fixed in develop by trufflesuite/ganache-core#92. Thanks for the contribution @AusIV!

@benjamincburns - I'm not sure trufflesuite/ganache-core#92 actually fixes this. My PR addressed block level hashes, but not transaction hashes.

Met the same problem when signing tx by myself.
This is causing a little trouble, since I am fetching tx receipt by tx hash.

version: ganache-1.1.0-x86_64

Reopening this due to the two different instances reporting this not fixed

It is also not working for me. Is it related to this issue in ganache-core:
https://github.com/trufflesuite/ganache-core/issues/56

I met the same problem. Hope my test input can help. :)
I am didn't use EIP155 signature.

From Ganache Cli

  • version: Ganache CLI v6.2.3 (ganache-core: 2.3.1)
   > {
   >   "jsonrpc": "2.0",
   >   "method": "eth_getTransactionByHash",
   >   "params": [
   >     "0xbed7a8d01e51b7bd38d5850c889c3ff7c77187096d65759563a3af6948aa14dd"
   >   ],
   >   "id": 0
   > }
 <   {
 <     "id": 0,
 <     "jsonrpc": "2.0",
 <     "result": {
 <       "hash": "0xbed7a8d01e51b7bd38d5850c889c3ff7c77187096d65759563a3af6948aa14dd",
 <       "nonce": "0x0",
 <       "blockHash": "0xa6fae628979e440a3aec283b59bd700903adc4ddc46d5d4bb316d7d688b2cd14",
 <       "blockNumber": "0x2",
 <       "transactionIndex": "0x0",
 <       "from": "0x9e0b01422022d36c49e9e7367bb913a21971f31d",
 <       "to": "0xb5e64298c11ae039a26a9bd337a08e0a16ff8f7c",
 <       "value": "0xde0b6b3a7640000",
 <       "gas": "0x5208",
 <       "gasPrice": "0x10642ac00",
 <       "input": "0x",
 <       "v": "0x1c",
 <       "r": "0x4d27429c02ae442b1a7fed7e97b02d9ac6ac943f9a2aead49cc4d4bc8ef49a86",
 <       "s": "0x33e11db734724dcdb1f5988ea4fcbf9dd992ba74e14288f3801f9cc954c82e7b"
 <     }
 <   }

From Geth

  • the transaction is signed without chainId
curl \
  -H "Content-Type: application/json" \
  -X POST \
  --data '{"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":["0x201c35a2b4e65289100b7c06e4ea3f00037f4f8ad57ee6a627611993becebabd"],"id":67}' \
http://localhost:8545 | jq
  • geth version
Version: 1.8.19-stable
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.11.2
Operating System: darwin
GOPATH=
GOROOT=/usr/local/Cellar/go/1.11.2/libexec
  • result
{
  "jsonrpc": "2.0",
  "id": 67,
  "result": {
    "blockHash": "0xcfdb376a115ac00c171c1b0adcbe76d59e2d2476988236b356b770c21ed07344",
    "blockNumber": "0x1",
    "from": "0x9e0b01422022d36c49e9e7367bb913a21971f31d",
    "gas": "0x5208",
    "gasPrice": "0x10642ac00",
    "hash": "0x201c35a2b4e65289100b7c06e4ea3f00037f4f8ad57ee6a627611993becebabd",
    "input": "0x",
    "nonce": "0x0",
    "to": "0xb5e64298c11ae039a26a9bd337a08e0a16ff8f7c",
    "transactionIndex": "0x0",
    "value": "0xde0b6b3a7640000",
    "v": "0x1c",
    "r": "0x4d27429c02ae442b1a7fed7e97b02d9ac6ac943f9a2aead49cc4d4bc8ef49a86",
    "s": "0x33e11db734724dcdb1f5988ea4fcbf9dd992ba74e14288f3801f9cc954c82e7b"
  }
}

This still seems to be an open issue. I'm writing a test in Go that uses go-ethereum as a dependency. The test sends a transaction and then gets its receipt using tx.Hash(). When this runs against the SimulatedBackend from go-ethereum, everything works. When running against a Dockerized Ganache CLI, I see that a different hash is returned from the json-rpc call. Oddly enough, when running against a GUI truffle running on my macOS, everything DOES seem to work, so I'm wondering what's the difference between the two...

any clues?

My dockerized ganache is running:

Ganache CLI v6.2.3 (ganache-core: 2.3.1)

When using trufflesuite/ganache-cli:v6.1.8 which runs ganache-core 2.2.1, my test passes as expected. My solution is to use the older Docker image, but this seems like a bug introduced in ganache-core 2.3.1...

@electricmonk This should be fixed in ganache-cli@beta, ganache-core@beta, and trufflesuite/ganache-cli:latest docker build now.

Can you try it out and let me know if you still see the issue?

Fixed in [email protected].

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ralph-pichler picture ralph-pichler  路  6Comments

xavierlepretre picture xavierlepretre  路  5Comments

zweicoder picture zweicoder  路  3Comments

juanfranblanco picture juanfranblanco  路  3Comments

axic picture axic  路  5Comments