Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

ethereumjs-tx generates wrong signature #99

Closed
ChandraNakka opened this issue Jun 10, 2018 · 2 comments
Closed

ethereumjs-tx generates wrong signature #99

ChandraNakka opened this issue Jun 10, 2018 · 2 comments

Comments

@ChandraNakka
Copy link

ChandraNakka commented Jun 10, 2018

I'm using this below example code to prepare transaction signature

const ethTx = require('ethereumjs-tx');
const privateKey = Buffer.from('74d1b4f06f610da2761953996c8f1a6df2540342bbef575bd91fb03004557cc5', 'hex');

const txParams = {
    "nonce": "0x02",
    "gasPrice": "0x06fc23ac00",
    "gasLimit": "0x5208",
    "to": "0x58f9ce2c1af3b540580561259955d66d5853e77a",
    "value": "0x00",
    "data": "0x",
    "chainId": 3
};

const tx = new ethTx(txParams);
tx.sign(privateKey);
console.log(tx.serialize().toString('hex'));

Above code is generating this below signature (wrong signature)

f864028506fc23ac008252089458f9ce2c1af3b540580561259955d66d5853e77a808029a07453af3e32aa4a67575c9d321ed86c082b158d36e5ec7fca7b90ac8845b5948ca00acc0393bf8881127624d366afdcf33e3f276d98b13ea581a2362a63e5c8ddf5

But, MyEtherWallet generates this signature (working signature)

f864028506fc23ac008252089458f9ce2c1af3b540580561259955d66d5853e77a80802aa0fcca5dc42e49f26bb5545291b33eacb932d8f2ee40a1a97be02f6916c7ae4f3aa0318507b28e5e94380a7af2efd057ab11d2dc8c863f7c9ad66477e19b259e066c

This is my configuration:

ethereumjs-tx: 1.3.4
nodejs: v8.10.0
ubuntu: 18.04 64bit
@fanatid
Copy link
Contributor

fanatid commented Jun 10, 2018

@ChandraNakka can you paste example how I can generate signature with MEW?
How you identified that signature generated by this lib is wrong and MEW is right and working?

const secp256k1 = require('secp256k1')
const privateKey = Buffer.from('74d1b4f06f610da2761953996c8f1a6df2540342bbef575bd91fb03004557cc5', 'hex')
const publicKey = secp256k1.publicKeyCreate(privateKey, false).slice(1)

// ethjs tx
const tx1 = new EthTx('f864028506fc23ac008252089458f9ce2c1af3b540580561259955d66d5853e77a808029a07453af3e32aa4a67575c9d321ed86c082b158d36e5ec7fca7b90ac8845b5948ca00acc0393bf8881127624d366afdcf33e3f276d98b13ea581a2362a63e5c8ddf5')
console.log(tx1.getSenderPublicKey().equals(publicKey))

// mew
const tx2 = new EthTx('f864028506fc23ac008252089458f9ce2c1af3b540580561259955d66d5853e77a80802aa0fcca5dc42e49f26bb5545291b33eacb932d8f2ee40a1a97be02f6916c7ae4f3aa0318507b28e5e94380a7af2efd057ab11d2dc8c863f7c9ad66477e19b259e066c')
console.log(tx2.getSenderPublicKey().equals(publicKey))

Result:

true
false

@fanatid
Copy link
Contributor

fanatid commented Jun 10, 2018

@ChandraNakka issue related with ethjs/ethjs-util#8
When ethjs-util will be fixed, signatures will be right (I already tested with old libs and all fine).
I tested code with [email protected] (contain bad code).
Probably https://github.com/ethereumjs/ethereumjs-tx/issues/101 should help avoid such situations.

@fanatid fanatid closed this as completed Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants