se3000 / ruby-eth

Gem for creating and signing Ethereum transactions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Signed transaction hash doesn't match with ethereum-tx.js

alexhanh opened this issue · comments

key = EthereumTx::Key.new(priv: 'f044a331c2962d2e81f35db618bafacdfad3e63ae8dd6e3d058052655704bedb')

tx = EthereumTx::Tx.new(
  to: '0xa4d81ea12abea768710a6c726a4543aa162308e4', 
  gas_price: 20000000000, 
  gas_limit: 21000, 
  value: 1,
  nonce: 0,
  data: '')

tx.sign key

puts tx.encoded.unpack("H*")[0]
# => f864808504a817c80082520894a4d81ea12abea768710a6c726a4543aa162308e401801ba0cde16f31b2bad6a10fb0e25d557800efcb4582c3e232b911bcae3ad3d42dae32a078817be48b3533a9a3e44428c636d47eac9508da92a2a89e69224947979792b6
const Tx = require('ethereumjs-tx');

const pk = new Buffer('f044a331c2962d2e81f35db618bafacdfad3e63ae8dd6e3d058052655704bedb', 'hex');

let tx = new Tx({
  to: '0xa4d81ea12abea768710a6c726a4543aa162308e4',
  gasPrice: '0x4a817c800',
  gasLimit: '0x5208',
  value: '0x1',
  nonce: '0x0',
  data: ''
});

tx.sign(pk);
console.log(tx.serialize().toString('hex'));
// f864808504a817c80082520894a4d81ea12abea768710a6c726a4543aa162308e401801ba054acff1e1850546d30f79a1dedb490a97e9e6f0684ccf43dd139272507b357fba07387d07303ddaa1d144b1dbf664d61c59c0d2bb8ced35f73f39f816147db7dea

I'm wondering whether this is an issue with the implementation.

This is expected, and I don't believe it's an issue. You'll actually get different hashes if you sign in ruby again and check the hash. The part that's changing is the signature. Specifically, we use a random K value, but some libraries use a deterministic K and are able to create the same signature repeatedly. Both versions should be valid, and the transaction ID is actually generated without the signature(see tx.unsigned_encoded).

I'm planning on adding libsecp256k1 support in the future, but part of the motivation of this gem was to make it usable with just ruby.

Both signatures should be valid. Are you seeing any problems with it? Is there another issue I'm missing?

Ahhh, that explains it. Thank you.

PS. There was a namespace collision with https://github.com/DigixGlobal/ethereum-ruby, so I renamed Ethereum:: to EthereumTx::, see https://github.com/alexhanh/ethereum-tx. Does merging the fork make sense?

Good question, sorry for the delay. Let me get back to you about that
though, I'm working on some coordination that with the guy behind
ruby-ethereum. I'll try to take ethereum-ruby into consideration as well,
that project and mine seem more like a compliment to each other.

On Sat, Jun 25, 2016 at 12:34 PM Alexander Hanhikoski <
notifications@github.com> wrote:

Ahhh, that explains it. Thank you.

PS. There was a namespace collision with
https://github.com/DigixGlobal/ethereum-ruby, so I renamed Ethereum:: to
EthereumTx::, see https://github.com/alexhanh/ethereum-tx. Does merging
the fork make sense?


You are receiving this because you commented.

Reply to this email directly, view it on GitHub
#1 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAjBg2r3ocYMp2H8dmK69j1AFA48BYsLks5qPViTgaJpZM4I-VCn
.

Sounds good. I'll close this one.

@alexhanh moved it to the Eth namespace.