Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Handling XOR required #122

Open
Open
@mikeymezher

Description

@mikeymezher

XOR obfuscation has been implemented in Bitcoin Core v28
(See: bitcoin/bitcoin#28052)

This breaks most of the functionality contained in this lib.

The fix is pretty simple:

Either
A.) Require users to use -blocksxor=0 during IBD.
B.) Extract the XOR key from xor.dat within the blocks directory and use it to reverse the XOR that's applied during IBD, something like:


    xor_file = os.path.join('./bitcoin-data/blocks','xor.dat')
    with open(xor_file, 'rb') as tmp:
        xor_key = tmp.read()
    
    # Cache blockfile 
    with open(blockfile,'rb') as tmp:
        raw_data = tmp.read()
    
    def undo_xor(block_data, xor_key, truncate_at_length=None):
        chunks = len(raw_data) // len(xor_key) # TODO: Parse remainder
        csize = len(xor_key)
        d = b''
        for c in range(chunks):
            b_data = block_data[csize*c:csize*(c+1)]
            for a,b in zip(xor_key,b_data):
                d += (a ^ b).to_bytes(1)
            print(f'completed {c+1}/{chunks}', end='\r')
            if truncate_at_length is not None:
                if c > truncate_at_length:
                    return d
        return d
    
    raw = undo_xor(raw_data,xor_key, truncate_at_length=100000)

Using an optimized lib like: https://github.com/GDPSApp/xor-cipher-python for this purpose is probably necessary, as iteratively applying the XOR cipher in Python is prohibitively slow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions