keep-starknet-strange / raito Goto Github PK
View Code? Open in Web Editor NEWBitcoin ZK client written in Cairo.
Home Page: https://raito.wtf
License: MIT License
Bitcoin ZK client written in Cairo.
Home Page: https://raito.wtf
License: MIT License
ver:
The coinbase transaction reward should not be included in the total output of the fee() function.
How to reproduce:
validate_and_apply on genesis block or block 170
The test helper used for converting hex strings into byte arrays works incorrectly
We need tests for:
u256
to Hash
and Hash
to u256
shl
and shr
fast_pow
Also need to add docstrings for every undocumented method.
All txid, best_block_hash should be of type Hash
Implement function to calculate transaction fee:
Line 44 in 4bf3aab
ZeroSync version:
https://github.com/ZeroSync/ZeroSync/blob/f1bd4736b0bac190ac48cbc8d5fcd92e2e1be7b9/src/transaction/transaction.cairo#L262
Define a ChainState
struct to represent the current state of the blockchain.
Acceptance Criteria:
ChainState
struct with fields:
Default
trait for ChainState
Resources:
block_header.cairo
Add two verification tests of blocks from tests/blocks
. Add tests to tests/blocks.cairo
.
When assigned please join project tg group.
Provide python version of: #18.
It should be easy to extend it to include corresponding utxs for each tx input when we add them to the data types.
Current behavior: oldest timestamp is removed from the beginning of the array, new timestamp also added to the beginning of the array.
Expected behavior: oldest timestamp is removed from the beginning of the array, new timestamp added to the end.
Notes: in Zerosync implementation they use reversed order i.e. oldest timestamps are in the end of the array while the recent ones in the beginning. However for validation purposes (more specifically for computing the median) it does not matter.
Create a function to convert a 256-bit target back to the compact bits
representation.
Acceptance Criteria:
target_to_bits(target: U256) -> Result<u32, Error>
Resources:
block_header.cairo
Prepare a script to fetch bitcoin blocks and format them as Cairo structs:
ver:
The validate_coinbase function takes into account all the outputs of all the transactions in the block to verify the coinbase transaction.
How to reproduce:
Execute this function with the transactions of block 170, it reverts.
2txs:
tx1: ouput 50BTC (coinbase)
tx2: input 50
ouput (10 + 40)
fee: 0
Therefore:
total_output = 100 > 0 +50
Computer block reward function based on ZeroSync version
Create a function to compute the Merkle root of a list of transaction hashes.
Acceptance Criteria:
compute_merkle_root(leaves: Span<u256>) -> Result<u256, Error>
Resources:
merkle_tree.cairo
Introduce Encode
trait (SCALE like) for serializing Bitcoin structures (transactions, inputs, outputs, scripts) into bytes.
Create a function to read a block header from a byte stream.
Acceptance Criteria:
read_block_header(reader: &mut Reader) -> Result<BlockHeader, Error>
BlockHeader
struct if successfulResources:
block_header.cairo
Make shr
and shl
functions generic over its input types(not type). Functions are here:
Line 5 in 29337d8
Some ideas are here:
but note, we are using Cairo 2.7.0, wide mull is in core lib now.
#77 introduced Encode
trait and implemented it for Span<T>
and ByteArray
types. We also need to implement it for some structs that need it
Using scarb get_block
should generate interesting bitcoin blocks. What means interesting? For sure we need blocks representing all soft forks, halvings, historial blocks like block containing pizza transaction. I assume we can start with 10 - 20 blocks.
In order to use get_block you will need RPC endpoint and credentials. You will get those in pm on tg.
When assigned please join project tg group.
Current merkle_root
calculation uses u256
to represent internal hashes in the tree. While this seems very natural, it is not how things work internally. Under the hood compute_sha256_u32_array
which accepts Array<u32>
and returns [u32; 8]
, so some work is wasted doing conversions. Try to optimise the process. Don't go too far though merkle_root
function should still return u256
but can accept Array<Array<u32>>
.
Provide speedup measurements.
Implement block_hash
function:
Line 50 in 4bf3aab
Description:
https://learnmeabitcoin.com/technical/block/hash/
Don't forget about unit tests.
Define a BlockHeader
struct to represent a Bitcoin block header.
Acceptance Criteria:
BlockHeader
struct with fields:
Default
trait for BlockHeader
Resources:
block_header.cairo
Create a function to convert the compact bits
representation to the full 256-bit target.
Acceptance Criteria:
bits_to_target(bits: u32) -> Result<U256, Error>
bits
Resources:
block_header.cairo
Create a function to validate coinbase transaction of a block:
Line 171 in 4bf3aab
Create a function to calculate txid:
Line 40 in 4bf3aab
according to the cdescription given here:
https://learnmeabitcoin.com/technical/transaction/input/txid/
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.