Bitcoin Forum
June 18, 2024, 08:01:29 AM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Transaction id hashing and var_ints  (Read 1287 times)
TierNolan (OP)
Legendary
*
Offline Offline

Activity: 1232
Merit: 1084


View Profile
November 14, 2014, 09:15:00 PM
 #1

The transaction serialization contains various var_int fields.  This means that you can change those and keep the actual data in the transaction the same.

For example, a transaction with 3 inputs could encode the 3 as "03" to encode 3 (single byte version) or "FD0300" (two byte version).  

Is it defined as the most compact version?  This isn't transaction malleability exactly.

The process when a tx is received is

- tx received
- convert to CTransaction object
- store 3 in the size of the vector
- calls UpdateHash
-- re-serializes transaction
-- compute hash
- store hash

This means that no matter how the transaction receives the 3, the 3 gets converted back into the shortest form before hashing for the txid.

Is this correct?

1LxbG5cKXzTwZg9mjL3gaRE835uNQEteWF
harding
Jr. Member
*
Offline Offline

Activity: 50
Merit: 46


View Profile WWW
November 16, 2014, 03:17:32 PM
 #2

It looks to me like CompactSize requires the smallest possible encoding.  See: https://github.com/bitcoin/bitcoin/blob/master/src/serialize.h#L218

It also looks like there are some tests to ensure non-canonical compatSize uints are forbidden in the test cases.  See: https://github.com/bitcoin/bitcoin/blob/master/src/test/serialize_tests.cpp#L81
TierNolan (OP)
Legendary
*
Offline Offline

Activity: 1232
Merit: 1084


View Profile
November 16, 2014, 06:06:35 PM
 #3

It looks to me like CompactSize requires the smallest possible encoding.  See: https://github.com/bitcoin/bitcoin/blob/master/src/serialize.h#L218

Interesting, I thought it was valid but discouraged.

1LxbG5cKXzTwZg9mjL3gaRE835uNQEteWF
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!