0

I just want to be sure I understood well how each of them are generated. I'm a bit confused because of the similarity of the names and because I couldn't find in the yellow paper how the transaction ID is generated.

Hash of the transaction

Keccak-256(nonce,gasPrice,gasLimit,to,value,data,v)
//Being the arguments not RLP encoded

Used to calculate the signature along with the private key through ECDSA Sign

Transaction Hash/Transaction ID

Keccak-256(RLP(nonce,gasPrice,gasLimit,to,value,data,v,r,s))
//Being the arguments RLP encoded

Tracking transaction ID given by the local node once the transaction is broadcasted


Can someone confirm I'm right or tell me why I'm wrong?

1 Answer 1

2

The transaction ID calculation is correct. For the signing, the arguments are still RLP encoded (the dummy "v" for EIP-155 is a bit special, see below).

Take this live transaction as an example. It has the following parameters.

nonce = 0 [RLP: 0x80]
gasPrice = 50000000000 wei (0x0BA43B7400) [RLP: 85 0BA43B7400]
gasLimit = 21000 (0x5208) [RLP: 82 5208]
to = 0x7917bc33eea648809c285607579c9919fb864f8f [RLP: 94 7917bc33eea648809c285607579c9919fb864f8f]
value = 1050000000000000 wei (0x03BAF82D03A000) [RLP: 87 03BAF82D03A000]
data = <empty> [RLP: 80]
v = 018080 (this is a place-holder value before signing, see EIP-155)

Then the input parameters for the hash is the RLP of the concatenation:

EB80850BA43B7400825208947917bc33eea648809c285607579c9919fb864f8f8703BAF82D03A00080018080

And the hash value for the signing is:

python3
>>> from Crypto.Hash import keccak
>>> keccak_hash=keccak.new(digest_bits=256)
>>> txn=bytearray.fromhex('EB80850BA43B7400825208947917bc33eea648809c285607579c9919fb864f8f8703BAF82D03A00080018080')
>>> keccak_hash.update(bytes(txn))
<Crypto.Hash.keccak.Keccak_Hash object at 0x10fb6e2e8>
>>> print(keccak_hash.hexdigest())

which gives the result

a4060d01d4add248db470b4121616cbe5b2015daf328809000ec9a1d0954d649

For the transaction ID, do Keccak hash on the final raw transaction bytes (RLP encoded as you mentioned, which are also readable from Etherscan) and it will give the same result as shown on Etherscan.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.