-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from hax0kartik/cmpctblocks
Add target for compact block messages
- Loading branch information
Showing
6 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <fuzzer/FuzzedDataProvider.h> | ||
#include <string> | ||
#include <iostream> | ||
|
||
#include "cmpctblocks.h" | ||
#include "bitcoin/src/blockencodings.h" | ||
#include "bitcoin/src/streams.h" | ||
|
||
extern "C" int rust_bitcoin_cmpctblocks(uint8_t *data, size_t len); | ||
|
||
int CmpctBlocksCore(Span<const uint8_t> buffer) | ||
{ | ||
DataStream ds{buffer}; | ||
CBlockHeaderAndShortTxIDs block_header_and_short_txids; | ||
try { | ||
ds >> block_header_and_short_txids; | ||
} catch (const std::ios_base::failure& e) { | ||
if (std::string(e.what()).find("Superfluous witness record") != std::string::npos) | ||
return -2; | ||
return -1; | ||
} | ||
return block_header_and_short_txids.BlockTxCount(); | ||
} | ||
|
||
void CmpctBlocks(FuzzedDataProvider& provider) | ||
{ | ||
std::vector<uint8_t> buffer{provider.ConsumeRemainingBytes<uint8_t>()}; | ||
int core{CmpctBlocksCore(buffer)}; | ||
int rust_bitcoin{rust_bitcoin_cmpctblocks(buffer.data(), buffer.size())}; | ||
|
||
if (core == -2 || rust_bitcoin == -2) | ||
return; | ||
|
||
assert(core == rust_bitcoin); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef CMPCT_BLOCKS_H | ||
#define CMPCT_BLOCKS_H | ||
|
||
#include <fuzzer/FuzzedDataProvider.h> | ||
|
||
void CmpctBlocks(FuzzedDataProvider& provider); | ||
#endif |