utxo – Can’t unserialize chainstate transaction outputs after de-obfuscation

0
20


I used to be in a position to learn chainstate database.

Getting the important thing and de-obfuscating to get a legitimate final block.

Nonetheless, on the subject of transactions that observe after that,

I can not de-serialize them it doesn’t matter what I am doing.

obtained the important thing: 1e9ad7d35416f693
final block:
ind:  42
key:  1e9ad7d35416f6931e9ad7d35416f6931e9ad7d35416f6931e9ad7d35416f693
val:  1e9ad7d35416f6931e9d0500458046bf32a7a4316479e1d99a33ea499237f9c3
xor:  00000000000000000007d2d31196b02c2c3d73e2306f174a84a93d9ac6210f50 <- that is good
transaction:
ind:  430000000001ec3a985ee53d32ef164b58f69ab50792d1f97119b4780a96d476d100
key:  1e9ad7d35416f6931e9ad7d35416f6931e9ad7d35416f6931e
val:  badbd53e2b2b9a9893a09c755e97af385069c874d3520a3641
xor:  a44102ed7f3d6c0b8d3a4ba60a8159ab4ef31fa78744fca55f      <- seems like flawed? idk
model:  164  nCode:  65  fCoinBase:  1  vAvail 1&2:  false false  N:  7
transaction:
ind:  430000000001ec3a985ee53d32ef164b58f69ab50792d1f97119b4780a96d476d102
key:  1e9ad7d35416f6931e9ad7d35416f6931e9ad7d35416f6931e9ad7d35416f6931e9ad7d35416f693
val:  01c855e08c6c63663c160665a736b7977b4d3f1049a47bc6ee9ad7d35416fb853e9afff7d50a3641
xor:  1f528233d87a95f5228cd1b6f320410465d7e8c31db28d55f000000000000d1620002824811cc0d2
model:  31  nCode:  82  fCoinBase:  0  vAvail 1&2:  true false  N:  10
transaction:
ind:  430000000001ec3a985ee53d32ef164b58f69ab50792d1f97119b4780a96d476d103
key:  1e9ad7d35416f6931e9ad7d35416f6931e9ad7d35416f6931e9ad7d35416f6931e9ad7d35416f693
val:  76a2bac0ed1819a6ce9bd2da2eaff013b1f584bf68e82e1b8d145941e1aca4ac3e9afff7d50a3641
xor:  68386d13b90eef35d00105097ab90680af6f536c3cfed888938e8e92b5ba523f20002824811cc0d2
model:  104  nCode:  56  fCoinBase:  0  vAvail 1&2:  false false  N:  6
transaction:
ind:  430000000001ec3a985ee53d32ef164b58f69ab50792d1f97119b4780a96d476d104
key:  1e9ad7d35416f6931e9ad7d35416f6931e9ad7d35416f6931e9ad7d35416f6931e9ad7d35416f693
val:  17528449f55864088b11ccf31519fb6f26ab84223f38016b613fd83116fe6e853e9afff7d50a3641
xor:  09c8539aa14e929b958b1b20410f0dfc383153f16b2ef7f87fa50fe242e8981620002824811cc0d2
model:  9  nCode:  200  fCoinBase:  0  vAvail 1&2:  false false  N:  24
transaction:
ind:  430000000001ec3a985ee53d32ef164b58f69ab50792d1f97119b4780a96d476d105
key:  1e9ad7d35416f6931e9ad7d35416f6931e9ad7d35416f6931e9ad7d35416f6931e9ad7d35416f693
val:  1db5122772cdab7b79e9d625261bc618652539fa4250aeb3efde1c950f6c588a3e9afff7d50a3641
xor:  032fc5f426db5de8677301f6720d308b7bbfee2916465820f144cb465b7aae1920002824811cc0d2
model:  3  nCode:  47  fCoinBase:  1  vAvail 1&2:  true true  N:  5

They simply do not appear to observe the foundations. Once I take the primary two bytes of the transition worth, they produce arbitrary model and unreasonably giant N. I consider, it needs to be zero or a few bytes at greatest.

  • The upper bits encode N, the variety of non-zero bytes within the following bitvector.
  • In case each bit 2 and bit 4 are unset, they encode N-1, as there have to be no less than one non-spent output).

Do not know how you can make the appropriate bitvector out of it. Additionally it is unclear to me when one vout ends and the opposite one begins.
Likewise, no concept how you can determine the peak, particularly as a result of it is in a c++ varint format.

Right here is code, am I getting the appropriate XORs for transactions proper?
I’m altering endianness instantly after retrieving every worth.

var stage = require('stage')
var db = stage('kaka-read', {  valueEncoding: 'hex', keyEncoding: 'hex'})

db.createReadStream({ restrict:1000 })
    .on('information', operate (information) {
        var worth= reverseBytes(information.worth);                // altering endiannes for all values
        var index= information.key;
        
        if (!this.hasOwnProperty('key')){
            var key_val = worth.slice(0,-2);                    // eradicating extreme byte from the obfuscation key
            console.log('obtained the important thing: '+key_val);
            
            this.key= class {                               // organising the obfuscation key class
                constructor(new_len=0){
                    this.pos=-1;
                    this.len= key_val.size;
                    this.verbose= key_val;
                    this.prolonged='';
                    this.prolong(new_len);
                }
                generate(){
                    this.pos = (this.pos+ 1) % this.len;
                    this.prolonged += this.verbose[this.pos];
                }
                prolong(new_len){
                    for (var i=0; i<new_len; this.generate(), i++);
                    return this.prolonged;
                }
            }
            return;                                         // obfuscation key has been arrange
        }       
        
        //// de-obfuscating
        var key = new this.key(worth.size).prolonged;      // extending the obfuscation key
        
        var array_1 = hexToBytes(key);
        var array_2 = hexToBytes(worth);                    
        var array_3 = [];
        for (var i = 0; i<array_1.size; i++)              // xor ensuing byte arrays
            array_3[i]= array_2[i] ^ array_1[i];
            
        var decoded= bytesToHex(array_3);                   // changing outcome to hex string
        
        
        //// reporting to console
        var ind_1byte=index.substring(0, 2);                // checking the primary byte of the index
        console.log(ind_1byte=='42'?'final block:':ind_1byte=='43'?'transaction:':'?' );
        console.log('ind: ',index );
        console.log('key: ',key);
        console.log('val: ',worth);
        console.log('xor: ',decoded);
        if (ind_1byte=='42') return;        // if block we're completed, in any other case attempt to unserialize transaction
        
        
        //// unserializing
        var model =array_3[0];
        var nCode = array_3[1];                 // nCode~00000000-11111111
        
        var vAvail= [];                         // & = bitwise AND                              
        var fCoinBase = nCode & 1;              // 1 = 001 binary (bit 1)
        vAvail[0] = (nCode & 2) !=0;            // 2 = 010 binary (bit 2)
        vAvail[1] = (nCode & 4) !=0;            // 4 = 100 binary (bit 3)
        N = nCode>>3;                           // shift 3 proper (bit 4+)
        if (vAvail[0]==0 && vAvail[1]==0) N--;  // if each spent, N-1
        
        //// the outcomes do not appear to look proper, but I do not know
        console.log('model: ', model,' nCode: ',nCode,' fCoinBase: ', fCoinBase,' vAvail 1&2: ', vAvail[0],vAvail[1],' N: ',N);
    })
    
    .on('finish', operate () {
        console.log('Fin')
    })

// Convert a hex string to a byte array
operate hexToBytes(hex) {
    for (var bytes = [], c = 0; c < hex.size; c += 2)
    bytes.push(parseInt(hex.substr(c, 2), 16));
    return bytes;
}

// Convert a byte array to a hex string
operate bytesToHex(bytes) {
    for (var hex = [], i = 0; i < bytes.size; i++) {
        var present = bytes[i] < 0 ? bytes[i] + 256 : bytes[i];
        hex.push((present >>> 4).toString(16));
        hex.push((present & 0xF).toString(16));
    }
    return hex.be part of("");
}

operate reverseBytes(enter){
    return bytesToHex(hexToBytes(enter).reverse());
}



Supply hyperlink

Leave a reply