Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid signature with web3.eth.accounts.signTransaction on testrpc #1169

Closed
tensor5 opened this issue Nov 13, 2017 · 3 comments
Closed

Invalid signature with web3.eth.accounts.signTransaction on testrpc #1169

tensor5 opened this issue Nov 13, 2017 · 3 comments
Assignees
Labels
Bug Addressing a bug In Progress Currently being worked on
Projects

Comments

@tensor5
Copy link

tensor5 commented Nov 13, 2017

I'm using web3@1.0.0-beta.24 to replicate the example http://web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#id6 on testrpc:

web3.eth.accounts.signTransaction({to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55',
    value: '1000000000',
    gas: 2000000
}, '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318').then(console.log);

the output I get is:

{ messageHash: '0x9ce21594b026a4c3fc09dff6e152f69b9beb44bd31549b49c8124b3db831fc27',
  v: '0x.82bf6b784',
  r: 
   [ '0x0aaf3477fff968b4aa173d94f4e0d74c6a9ffdc1985febea5ad447f52c45c3196a03d1bcc7efbc9902c5' ],
  s: '0x3d',
  rawTransaction: '0xf96f.8808504a817c800831e848094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca008085.82bf6b784e7aa0aaf3477fff968b4aa173d94f4e0d74c6a9ffdc1985febea5ad447f52c45c3196a03d1bcc7efbc9902c53d4406c6b69c2c6d23b5ac4c29a68ea63a342433bde32a7' }

which is not a valid signature. If I manually specify the mainnet chainId then I don't have this problem:

web3.eth.accounts.signTransaction({
    to: '0xF0109fC8DF283027b6285cc889F5aA624EaC1F55',
    value: '1000000000',
    gas: 2000000,
    chainId: 0
}, '0x4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318').then(console.log);
{ messageHash: '0x6ef4e89eab7867ddf69fae20dd218dbfa337fa8e4d68ce6dc3fcad63e17fdd72',
  v: '0x24',
  r: '0x1b428275439f5d12a85dd70e919b17994abe4d3b2ba3cfd1e370c1a1c86d2a24',
  s: '0x4eebdddb5681d836fb938179d0002b12359c9b2287a8d6ffb156c15de9146251',
  rawTransaction: '0xf869808504a817c800831e848094f0109fc8df283027b6285cc889f5aa624eac1f55843b9aca008024a01b428275439f5d12a85dd70e919b17994abe4d3b2ba3cfd1e370c1a1c86d2a24a04eebdddb5681d836fb938179d0002b12359c9b2287a8d6ffb156c15de9146251' }
@mirek
Copy link

mirek commented Jan 29, 2018

It looks like rlp is broken for signing transaction when chain_id * 2 + 36 > 255 (overflows 1 byte), the workaround for now seems to be using chain_id in 0-109 range. For details you can have a look at #1334

@CryptoKiddies
Copy link

I wonder if this is the same issue here #1674 that's affecting sendTransaction under the hood when I use a local wallet

@nivida nivida self-assigned this Aug 9, 2018
@nivida nivida added the Bug Addressing a bug label Aug 9, 2018
@nivida nivida added the In Progress Currently being worked on label Aug 20, 2018
@captPython
Copy link

HI everyone,

I am trying to sign transaction using web3.eth.accounts.signTransaction .. tried using Gananche, Local Geth in Light sync mode and Infura ..

when I used Infura and geth with ChainId = 3 that time value of v in signature was 41 or 42 but when used ganache which was runing on chain id 4447 then the value of v was very high like 1228 or above ..

does the bug still exist ..

// Sample Code written
const Web3 = require('web3')
// Or When tried using Ganache
const web3 = new Web3(new Web3.providers.HttpProvider('http://127.0.0.1:7545'));

// Or When tried using GETH
const web3 = new Web3(new Web3.providers.HttpProvider('localhost:8545'));

// Or using infura
const web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/v3/cxxxxxxxxxx72'));

async function startApp() {
try {
let accounts = await web3.eth.getAccounts();
const sender = accounts[0];
const escrow = accounts[2];

   // Added 0x to private key 
    const privateKey = '0x''201E7B612xxxxxxxxxxx05876E9609D17818';

    // const chainId = await web3.eth.net.getId()

    let amount = '10000000';
    let tx = {
        nonce: web3.utils.toHex(web3.eth.getTransactionCount(sender)),
        chainId: "0x3",
        gas: "0x1e8480",
        gasPrice: web3.utils.toHex(web3.eth.getGasPrice()),
        to: escrow,
        value: "0x989680"
    }

    const signature = await web3.eth.accounts.signTransaction(tx, privateKey);
    console.log(signature);

    // Verify if the sender addres is recovered correctly
    let recover = web3.eth.accounts.recoverTransaction(signature.rawTransaction);

    const v = web3.utils.toDecimal(signature.v);           /// Vlaue is coming 41
    const r = Buffer.from(signature.r);
    const s = Buffer.from(signature.s);
    const mHash = Buffer.from(signature.messageHash);

    const rsv = await ethUtil.ecrecover(mHash, v, r, s);

    console.log(rsv);

} catch (error) {
    console.error(error);
}

}

startApp();

Any leads how should I proceed to get correct value? is this problem exist in other function calls as well like
### web3.eth.sign
web3.eth.signTransaction

@nivida nivida added this to In progress in 1.0 Nov 29, 2018
@nivida nivida mentioned this issue Mar 26, 2019
12 tasks
@nivida nivida closed this as completed Mar 27, 2019
1.0 automation moved this from In progress to Done Mar 27, 2019
@nivida nivida mentioned this issue Mar 28, 2019
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug In Progress Currently being worked on
Projects
No open projects
1.0
  
Done
Development

No branches or pull requests

5 participants