keep-starknet-strange / raito

Bitcoin ZK client written in Cairo.
https://raito.wtf
MIT License
40 stars 34 forks source link

[feat] Generate most important blocks #60

Closed TAdev0 closed 2 months ago

TAdev0 commented 2 months ago

@maciejka I encountered a curious issue while generating the blocks:

all other blocks generate a weird output for value in TxOut , for example:

  value: 1573890.9999999998_u64,

Basically, not all but some value (a lot, actually) in TxOut in all these blocks are generated with a dot, with various number of 9 after that (or 0 like value: 114936575.00000001_u64,), ending with any number between 1 and 9.

Example of random tx in block 420000 :

Transaction {
        version: 1,
        is_segwit: false,
        inputs: array![TxIn {
        script: from_base16("00483045022100b550b7ea029bdea3e37644fde28992aef0676e093accc81d59d783c8c37c960102207aabcfbe8c079df18cfd64e087cc59d81806ff2a401c755e91f655a15b1be96001483045022100ba64c25a88baff572dc42253470037e8bc9148ce32022071dca8027918a2a8e602201abfd2ea4930d71dfaa1af0b75dd8c22889dcf3864c35d3d4abeb3fe9cc0190901475221030f68ba91e3aa3e521faa5a10b7301436d4cf651466e9bf0515f9dd6876a420cd21025ac4139197851bf65160bcbdaa9cdeb3708e7a8c9253b1b51ee57bcf17ac66c252ae"),
        sequence: 4294967295,
        previous_output: OutPoint {
            txid: 0x7e113e616350d46d3ae3657d7240fcc4ae3a418711cf67ac57c470126e2ed5fd,
            vout: 1,
            txo_index: 0, // TODO: implement
        },
        witness: @""
    }].span(),
        outputs: array![TxOut {
        value: 4890910_u64,
        pk_script: from_base16("76a91460133067343855e64d7296dc27ea1d1598d0dadf88ac"),
    },
TxOut {
        value: 3343669950.9999995_u64,
        pk_script: from_base16("a91400dc0c864884c2e79df7eb20202d7a02056be3c287"),
    }].span(),
        lock_time: 0
    },

first TxOut is correct, second one is not correct.

Any idea whats going on?

vercel[bot] commented 2 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
raito ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 12, 2024 5:18pm
maciejka commented 2 months ago

@maciejka I encountered a curious issue while generating the blocks:

  • blocks 0, 170, 24835 and 57043 are generated correctly

all other blocks generate a weird output for value in TxOut , for example:

  value: 1573890.9999999998_u64,

Basically, not all but some value (a lot, actually) in TxOut in all these blocks are generated with a dot, with various number of 9 after that, ending with any number between 1 and 9.

Example of random tx in block 420000 :

Transaction {
        version: 1,
        is_segwit: false,
        inputs: array![TxIn {
        script: from_base16("00483045022100b550b7ea029bdea3e37644fde28992aef0676e093accc81d59d783c8c37c960102207aabcfbe8c079df18cfd64e087cc59d81806ff2a401c755e91f655a15b1be96001483045022100ba64c25a88baff572dc42253470037e8bc9148ce32022071dca8027918a2a8e602201abfd2ea4930d71dfaa1af0b75dd8c22889dcf3864c35d3d4abeb3fe9cc0190901475221030f68ba91e3aa3e521faa5a10b7301436d4cf651466e9bf0515f9dd6876a420cd21025ac4139197851bf65160bcbdaa9cdeb3708e7a8c9253b1b51ee57bcf17ac66c252ae"),
        sequence: 4294967295,
        previous_output: OutPoint {
            txid: 0x7e113e616350d46d3ae3657d7240fcc4ae3a418711cf67ac57c470126e2ed5fd,
            vout: 1,
            txo_index: 0, // TODO: implement
        },
        witness: @""
    }].span(),
        outputs: array![TxOut {
        value: 4890910_u64,
        pk_script: from_base16("76a91460133067343855e64d7296dc27ea1d1598d0dadf88ac"),
    },
TxOut {
        value: 3343669950.9999995_u64,
        pk_script: from_base16("a91400dc0c864884c2e79df7eb20202d7a02056be3c287"),
    }].span(),
        lock_time: 0
    },

first TxOut is correct, second one is not correct.

Any idea whats going on?

there is a multiplication in the jq script:

def txout:
    "TxOut {
        value: \(.value*100000000)_u64,
        pk_script: from_base16(\"\(.scriptPubKey.hex)\"),
    }"
;

Value returned from the RPC is in Bitcoins not Satoshis. What exactly RPC returns as value? It is a result of using floating point representation. For now we should probably just round: (.value*100000000). Mid term we should move to python: https://github.com/keep-starknet-strange/raito/issues/28.

TAdev0 commented 2 months ago

from https://developer.bitcoin.org/reference/rpc/getrawtransaction.html?highlight=getrawtransaction

   "value" : n,                   (numeric) The value in BTC

and we are multiplying by 10^8 in the block_filter so we should normally get the result in satoshi?

def txout:
    "TxOut {
        value: \(.value*100000000)_u64,
        pk_script: from_base16(\"\(.scriptPubKey.hex)\"),
    }"
;
TAdev0 commented 2 months ago

@maciejka ok got it , will just round , its working fine like that. thanks!

maciejka commented 2 months ago

@maciejka ok got it , will just round , its working fine like that. thanks!

Some numbers are just not represented in floating point, try this in js console: 0.1 + 0.2. You will get closest approximation which is 0.30000000000000004

TAdev0 commented 2 months ago

Ok now blocks are correctly built regarding value, i double checked and compared with block explorer.

Given that all these blocks are in Tests crate, running scarb test is like impossible now. Its been a few minutes on my M2 and its not compiled yet.

will comment the Blocks module in lib.cairo file of Tests crate for CI to pass. Dont know how we can make this work. Maybe adding the biggest block in bitcoin history is not a great idea?

maciejka commented 2 months ago

Ok now blocks are correctly built regarding value, i double checked and compared with block explorer.

Given that all these blocks are in Tests crate, running scarb test is like impossible now. Its been a few minutes on my M2 and its not compiled yet.

will comment the Blocks module in lib.cairo file of Tests crate for CI to pass. Dont know how we can make this work. Maybe adding the biggest block in bitcoin history is not a great idea?

Let's comment for now, we will see later how to handle them. Just add some explanation in the code.

TAdev0 commented 2 months ago

@maciejka added a phrase to explain why its commented out

maciejka commented 2 months ago

@maciejka added a phrase to explain why its commented out

Comment out just those blocks that are too big.

TAdev0 commented 2 months ago

@maciejka should be good like this