Bitcoin slices
ZERO allocations parse library for Bitcoin data structures.
Data is accessed by providing visitor structs for the data the user is interested in.
Data structures are read-only and parsed data must be in memory, no streaming API.
Tradeoffs
Check the CONS before using this library, use rust-bitcoin if they are too restrictive for your case.
Pros
- Deserialization is amazingly fast, since no allocation is made during parsing.
- Serialization is incredibly fast, since a slice of the serialized data is kept in the structure.
- hashing a little faster because slice are ready without the need of re-serializing data.
- No mandatory dependency.
- No standard.
- Calculate txid and block hash via optional dep
bitcoin_hashesorsha2. - Visitor pattern to visit just what you are interested in.
Cons
- Full data must be in memory, there is no streaming (Read/Write) API.
- Data structure are read-only, cannot be modified.
- Visitor pattern requires user-built data structure for visiting.
Test
Bench
RUSTFLAGS='--cfg=bench'
)
)
)
)
)
)
)
)
)
)
)
)
)
)
- benches ending with
_bitcoinuserust-bitcoin - benches ending with
_sha2usesha2lib instead ofbitcoin_hashes
Fuzz
Use cargo fuzz Run fuzzing with transaction as target.
Other target available in fuzz/fuzz_targets
Miniminze corpus:
cargo +nightly fuzz cmin transaction
Previous work and credits
- Bitiodine use similar visitor pattern (parser credited to Mathias Svensson)
- Some previous work on the idea to parse while reducing allocations in this PR
- Matt Corallo mentioned something like this in a comment in that PR
TODO
- create rotating buffer that consume and produce keeping a linear memory (rotate back when it can't append), this would overcome a bit the absence of streaming API
- implements network types
- add github actions CI