trufflesuite / ganache

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
2.61k stars 676 forks source link

Invalid signature v value #4367

Open Kevin-Mok opened 1 year ago

Kevin-Mok commented 1 year ago

When trying to send a transaction, I'm getting an error with the message Invalid signature v value. I've seen issue #1638, but @davidmurdoch seemed to say it was an issue of the wrong chainId, but I've set it correctly to the default Ganache value of 1337. I'm using ethereumjs/tx to create my transaction and added the chainId to the transaction data in hex like they did in their example. I also tried adding the chainId to a Common for the transaction in my code. Neither of these additions helped.

It should be noted that this code works on the Goerli testnet with this commented out line. So, what could be causing the issue here? You can run my code using the instructions found here and running Ganache on the default port (http://127.0.0.1:8545). Then, simply click on the send button next to "Enter Vote Question" in the frontend (http://localhost:3001/). I know most of the setup/code works because I can see the console logs right until sendSignedTransaction, and I can see eth_getTransactionCount and eth_sendRawTransaction in the Ganache log. I'm using version v7.8.0 of Ganache.

davidmurdoch commented 1 year ago

Not sure what's going wrong here. I'll look into it.

davidmurdoch commented 1 year ago

The instructions aren't working for me. When starting the backend the server options get set to {port: ""}, which fails, and when the front end loads I get an error:

SyntaxError: Failed to construct 'EventSource': Cannot open an EventSource to 'http://:/registered'. The URL is invalid.
(anonymous function)
src/components/views/vote/Registration.tsx:41
  38 | }, [sealers, requiredSealers])
  39 | 
  40 | useEffect(() => {
> 41 |   const events = new EventSource(`${DEV_URL}/registered`)
     | ^  42 |   events.onmessage = (event): void => {
  43 |     const parsedData = JSON.parse(event.data)
  44 |     setSealers(sealers => sealers.concat(parsedData).filter((element, index, arr) => arr.indexOf(element) === index))
Kevin-Mok commented 1 year ago

That's weird. I've never seen that error before. Are you using the ganache branch? I tried cloning the repo fresh before I posted, and it worked. I'll try to see if I can reproduce it on my end.

davidmurdoch commented 1 year ago

What version of node and npm?

Kevin-Mok commented 1 year ago

Node v18.7.0. npm 8.18.0.

ajaysathvik commented 1 year ago

i also have the same issue

davidmurdoch commented 1 year ago

I can get the front-end to render with Node v18 if I run the start command with node options: NODE_OPTIONS=--openssl-legacy-provider npm run start:localhost. However, clicking the Next Step button results in a Network Error error; http://localhost:4001/registered doesn't work because there is nothing running at 4001.

I tried building the frontend because the backend script was complaining about a frontend path not existing. Here is what I'm seeing when starting the backend now:

~/code/provotum-v2 (ganache) $ cd voting-authority/backend
~/code/provotum-v2/voting-authority/backend (ganache) $ npm run serve:localhost

> admin-backend@1.0.0 serve:localhost
> ./dev.sh

The mode is: development
##########################################################################
# Installing NPM Packages for you                                         
##########################################################################

removed 38 packages, changed 3 packages, and audited 934 packages in 9s

34 packages are looking for funding
  run `npm fund` for details

61 vulnerabilities (14 moderate, 20 high, 27 critical)

To address issues that do not require attention, run:
  npm audit fix

To address all issues possible (including breaking changes), run:
  npm audit fix --force

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.

> admin-backend@1.0.0 serve:dev:clean
> npm run clean:db && NODE_ENV=development ts-node-dev --respawn --poll --transpileOnly ./src/server.ts

> admin-backend@1.0.0 clean:db
> rm -f src/database/db.json

Using ts-node version 7.0.1, typescript version 3.8.3
0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d
{
  address: '0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1',
  privateKey: '0x4f3edf983ac636a65a842ce7c78d9aa706d3b113bce9c46f30d7d21715b23b1d',
  signTransaction: [Function: signTransaction],
  sign: [Function: sign],
  encrypt: [Function: encrypt]
}
/home/david/code/provotum-v2/voting-authority/frontend/build/ exists!

(don't worry about that private key; it is public already)

Kevin-Mok commented 1 year ago

@davidmurdoch Can you try running this simple repo I created? I'm just trying to send a simple send transaction, and I'm getting the same error. The instructions to run it are in the README.

davidmurdoch commented 1 year ago

Can you try my PR: https://github.com/Kevin-Mok/ganache-tx/pull/1 and let me know if that fixes it?

Kevin-Mok commented 1 year ago

I'm not getting the error in this issue any more, but I can't run my code still because of #4404.

mr-possible commented 12 months ago

I am learning Web3 with Flutter. I tried to call sendTransaction method of the web3client, but I am getting this error:

flutter: RPCError: got code -32700 with msg "Invalid signature v value".

IJSK10 commented 12 months ago

@mr-possible I am also facing the same issue. DId you got any solutions?

mr-possible commented 12 months ago

@mr-possible I am also facing the same issue. Did you get any solutions?

No, I haven't got any fix for this. I have been trying to resolve this for the past 3 days. I am losing hope now. I wanted to make a cross-platform blockchain voting app but now, it seems to me that I have to make peace with just a web-based app.

mr-possible commented 12 months ago

@IJSK10 Can you provide a screenshot of:

  1. Ganache showing any of your private keys (I watched tonnes of videos showing the private keys but they were not in hexadecimal format. Mine is already in hexadecimal format in Ganache)

  2. What platform did you try - Android or iOS?

  3. Are you using - Windows or MacOS?

IJSK10 commented 12 months ago
  1. Yeah for me also its showing hexadecimal values image
  2. Android emulator
  3. Windows os
  4. I created credentials both using client.credentialsfromprivatekey("cfd3f6c108a29b40bd09d8b151282cd8552a9bc25d54dca8858ef24060af79c4"), and Ethprivatekeyfromhex("0xcfd3f6c108a29b40bd09d8b151282cd8552a9bc25d54dca8858ef24060af79c4"), both are giving the same address as 0x2fc434349db125a27c7ce54e8880c53395771f7d And i found that the problem is caused by client.sendTransaction method image here the transaction instance is successfully created and i am getting error when the sendtransaction method
mr-possible commented 12 months ago
  • Yeah for me also its showing hexadecimal values image
  • Android emulator
  • Windows os
  • I created credentials both using client.credentialsfromprivatekey("cfd3f6c108a29b40bd09d8b151282cd8552a9bc25d54dca8858ef24060af79c4"), and Ethprivatekeyfromhex("0xcfd3f6c108a29b40bd09d8b151282cd8552a9bc25d54dca8858ef24060af79c4"), both are giving the same address as 0x2fc434349db125a27c7ce54e8880c53395771f7d And i found that the problem is caused by client.sendTransaction method image Here, the transaction instance is successfully created and I am getting an error when the sendTransaction method

Thanks for the detailed reply @IJSK10. @davidmurdoch could you please help here in any way?

You may refer to a rather detailed query on StackOverflow as well: https://stackoverflow.com/questions/76674364/facing-flutter-rpcerror-got-code-32700-with-msg-invalid-signature-v-valu

mr-possible commented 12 months ago

@IJSK10 I managed to solve this issue. I didn't change anything extra-ordinary, but I think we need to pass the chain id as well while calling sendTransaction method. Please have a look:

await _client.sendTransaction(
        _credentials,
        Transaction.callContract(
            contract: _deployedContract,
            function: _setSentence,
            parameters: [value]),
        chainId: 1337,
        fetchChainIdFromNetworkId: false);

Here, _deployedContract is my Solidity Contract. And _setSentence is just a setter method of that contract.

Also, note that I changed the version for the dependency web3dart to 2.7.0 (latest as of now). A portion of my pubspec.yaml is given below:

dependencies:
  flutter:
    sdk: flutter
  http: ^1.1.0
  provider: ^6.0.5
  web3dart: ^2.7.0
  web_socket_channel: ^2.4.0
Zataxo commented 11 months ago

@IJSK10 I managed to solve this issue. I didn't change anything extra-ordinary, but I think we need to pass the chain id as well while calling sendTransaction method. Please have a look:

await _client.sendTransaction(
        _credentials,
        Transaction.callContract(
            contract: _deployedContract,
            function: _setSentence,
            parameters: [value]),
        chainId: 1337,
        fetchChainIdFromNetworkId: false);

You saved me , i've been searching for a long time

mr-possible commented 11 months ago

@IJSK10 I managed to solve this issue. I didn't change anything extra-ordinary, but I think we need to pass the chain id as well while calling sendTransaction method. Please have a look:

await _client.sendTransaction(
        _credentials,
        Transaction.callContract(
            contract: _deployedContract,
            function: _setSentence,
            parameters: [value]),
        chainId: 1337,
        fetchChainIdFromNetworkId: false);

You saved me , i've been searching for a long time

You can also find the detailed answer here

Zataxo commented 11 months ago

well I've checked it all , its better to not pass the context to the provider , and do this: replace : await DefaultAssetBundle.of(context) .loadString('build/contracts/MyContract.json'); with : RootBundle.loadString

sylar123abc commented 9 months ago

I have the same problem, I use the ECDSA.recover (from openzeppelin) function to verify signatures, It was working perfectly fine with ganache v7.6.0 but started throwing "the invalid signature 'v' value." with v7.7.3 I think the new version that supports the merge broke something, because nothing from my on chain code changed

EDIT : after some research it seems the problem is coming from the eth_sign call made to ganache, that changed it's behaviour since 7.7.0