Benjamin-Loison / opentimestamps-client

OpenTimestamps client
Other
0 stars 0 forks source link

How to only run Bitcoin SPV to *less securely* verify OpenTimeStamps proofs? #11

Open Benjamin-Loison opened 2 months ago

Benjamin-Loison commented 2 months ago

If I remember correctly this is doable and I already discussed about that online.

Not in the original repository according to opentimestamps-client/issues/created_by/Benjamin-Loison just checking Benjamin-Loison and Benjamin Loison occurrences do not return any result.

https://gitea.lemnoslife.com/Benjamin_Loison?q=Bitcoin&tab=repositories returns Benjamin_Loison/bitcoin but both issues and wiki do not seem interesting. https://github.com/Benjamin-Loison?tab=repositories&q=Bitcoin does not seem interesting https://codeberg.org/Benjamin_Loison?q=Bitcoin&tab=repositories does not return anything.

Maybe took similar notes in the context of my Master Parisien de Recherche en Informatique M2 internship. See mining-in-logarithmic-space/issues/8.

My Bitcoin Stack Exchange answer and comments do not seem interesting despite the potentially interesting comment 135971_87413.

If I remember correctly the trick is to disable network or peers with bitcoind. DuckDuckGo and Google "networkactive" "Benjamin Loison" do not return anything. Maybe I have not taken notes online or at all.

Tracked at: Benjamin_Loison/bitcoin/issues/2.

Benjamin-Loison commented 2 months ago
bitcoind --help
  -prune=<n>
       Reduce storage requirements by enabling pruning (deleting) of old
       blocks. This allows the pruneblockchain RPC to be called to
       delete specific blocks and enables automatic pruning of old
       blocks if a target size in MiB is provided. This mode is
       incompatible with -txindex. Warning: Reverting this setting
       requires re-downloading the entire blockchain. (default: 0 =
       disable pruning blocks, 1 = allow manual pruning via RPC, >=550 =
       automatically prune block files to stay under the specified
       target size in MiB)

...

  -maxconnections=<n>
       Maintain at most <n> connections to peers (default: 125). This limit
       does not apply to connections manually added via -addnode or the
       addnode RPC, which have a separate limit of 8.

  -maxreceivebuffer=<n>
       Maximum per-connection receive buffer, <n>*1000 bytes (default: 5000)

  -maxsendbuffer=<n>
       Maximum per-connection send buffer, <n>*1000 bytes (default: 1000)

...

  -maxuploadtarget=<n>
       Tries to keep outbound traffic under the given target per 24h. Limit
       does not apply to peers with 'download' permission or blocks
       created within past week. 0 = no limit (default: 0M). Optional
       suffix units [k|K|m|M|g|G|t|T] (default: M). Lowercase is 1000
       base while uppercase is 1024 base

...

  -networkactive
       Enable all P2P network activity (default: 1). Can be changed by the
       setnetworkactive RPC command

...

  -whitelist=<[permissions@]IP address or network>
       Add permission flags to the peers connecting from the given IP address
       (e.g. 1.2.3.4) or CIDR-notated network (e.g. 1.2.3.0/24). Uses
       the same permissions as -whitebind. Can be specified multiple
       times.
Benjamin-Loison commented 2 months ago
history | grep bitcoind
(until bitcoin-cli setnetworkactive false &> /dev/null; do echo 'Waiting' && sleep 1; done; echo 'bitcoind network is now disabled!') & bitcoind

does not seem better than bitcoind -networkactive=0.

Maybe it makes Python RPC work.

Benjamin-Loison commented 2 months ago
ots --no-bitcoin verify examples/hello-world.txt.ots
Assuming target filename is 'examples/hello-world.txt'
Not checking Bitcoin attestation; Bitcoin disabled
To verify manually, check that Bitcoin block 358391 has merkleroot 8a1b66ecb7cbd07d8139a7e7d7f2c41aab1f5009b8364aaf61d03ad245e47e00
Benjamin-Loison commented 2 months ago

mining-in-logarithmic-space/src/commit/6e3147b5df4438be605ea55ceac98bc690be4795/bitcoin.py

import subprocess
import json
import requests

# https://github.com/bitcoin/bitcoin/blob/dfe2dc1d84436d4eae351612dbf0b92f032389be/share/rpcauth/rpcauth.py
serverURL = f'http://user:test@localhost:8332'

def split_list(alist, wanted_parts):
    length = len(alist)
    return [alist[i*length // wanted_parts: (i+1)*length // wanted_parts] for i in range(wanted_parts)]

def pull(command, params, slices):
    paramsChunks = split_list(params, slices)
    pullResults = []
    for params in paramsChunks:
        payload = [{'method': command, 'params': [param]} for param in params]
        responses = requests.post(serverURL, json=payload)
        print(responses.text)
        data = responses.json()
        results = [response['result'] for response in data]
        pullResults += results
    return pullResults

def loadHeaders(break_at):
    global headers
    print('Loading headers...')
    headersNumber = break_at if break_at else int(cli(['getblockcount']))
    headerHashes = pull('getblockhash', list(range(headersNumber)), 2)
    headers = pull('getblockheader', headerHashes, 4)
    print('Headers were loaded!')
    return headersNumber

def cli(arguments):
    return subprocess.check_output(['bitcoin-cli'] + arguments).decode('utf-8')[:-1]

def cli_json(arguments):
    return json.loads(cli(arguments))
pull('getblockhash', [358391], 1)
[{"result":null,"error":{"code":-8,"message":"Block height out of range"},"id":null}]

Maybe what I did before was to check online the block hash (like https://www.blockchain.com/explorer/blocks/btc/358391, an API would be nice, https://bitcoinexplorer.org/api/block/358391 is such an API) and then check locally with bitcoin-cli getblockheader 000000000000000003e892881a8cdcdc117c06d444057c98b6f04a9ee75a2319 if it matches with the height I provided and if it has the expected Merkle tree hash.