Skip to content

Commit 8bcec68

Browse files
committed
Update to newest API
1 parent 30f67f9 commit 8bcec68

File tree

5 files changed

+182
-330
lines changed

5 files changed

+182
-330
lines changed

fuzz/fuzz_targets/fuzz_target_chainman.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use libbitcoinkernel_sys::{
1515
fn create_context(chain_type: ChainType) -> Context {
1616
ContextBuilder::new()
1717
.chain_type(chain_type)
18-
.unwrap()
1918
.kn_callbacks(Box::new(KernelNotificationInterfaceCallbackHolder {
2019
kn_block_tip: Box::new(|_state, _block_index| {}),
2120
kn_header_tip: Box::new(|_state, _height, _timestamp, _presync| {}),
@@ -25,7 +24,6 @@ fn create_context(chain_type: ChainType) -> Context {
2524
kn_flush_error: Box::new(|_message| {}),
2625
kn_fatal_error: Box::new(|_message| {}),
2726
}))
28-
.unwrap()
2927
.build()
3028
.unwrap()
3129
}
@@ -89,15 +87,13 @@ fuzz_target!(|data: ChainstateManagerInput| {
8987
match chainman.load_chainstate(
9088
ChainstateLoadOptions::new()
9189
.set_reindex(data.wipe_block_index)
92-
.unwrap()
9390
.set_wipe_chainstate_db(data.wipe_chainstate_index)
94-
.unwrap()
9591
.set_block_tree_db_in_memory(data.block_tree_db_in_memory)
96-
.unwrap()
97-
.set_chainstate_db_in_memory(data.chainstate_db_in_memory)
98-
.unwrap(),
92+
.set_chainstate_db_in_memory(data.chainstate_db_in_memory),
9993
) {
100-
Err(libbitcoinkernel_sys::KernelError::Internal(_)) => {}
94+
Err(libbitcoinkernel_sys::KernelError::Internal(_)) => {
95+
return;
96+
}
10197
Err(err) => {
10298
let _ = std::fs::remove_dir_all(data_dir);
10399
panic!("this should never happen: {}", err);

fuzz/fuzz_targets/fuzz_target_verify.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use arbitrary::Arbitrary;
44
use libfuzzer_sys::fuzz_target;
55

6-
use libbitcoinkernel_sys::{verify, Utxo};
6+
use libbitcoinkernel_sys::{verify, ScriptPubkey, Transaction, TxOut};
77

88
#[derive(Debug, Arbitrary)]
99
pub struct UtxoWrapper {
@@ -23,19 +23,26 @@ pub struct VerifyInput {
2323

2424
fuzz_target!(|data: VerifyInput| {
2525
// Call the verify function with the fuzzed inputs
26-
let spent_outputs: Vec<Utxo> = data
26+
let spent_outputs: Vec<TxOut> = data
2727
.spent_outputs
2828
.iter()
29-
.map(|utxo| Utxo {
30-
value: utxo.value,
31-
script_pubkey: &utxo.script_pubkey,
29+
.map(|utxo| {
30+
let script_pubkey = ScriptPubkey::try_from(utxo.script_pubkey.as_slice()).unwrap();
31+
TxOut::new(&script_pubkey, utxo.value)
3232
})
3333
.collect();
3434

35+
let script_pubkey = ScriptPubkey::try_from(data.script_pubkey.as_slice()).unwrap();
36+
let transaction = if let Ok(res) = Transaction::try_from(data.tx_to.as_slice()) {
37+
res
38+
} else {
39+
return;
40+
};
41+
3542
let _ = verify(
36-
&data.script_pubkey,
43+
&script_pubkey,
3744
data.amount,
38-
&data.tx_to,
45+
&transaction,
3946
data.input_index,
4047
data.flags,
4148
&spent_outputs,

0 commit comments

Comments
 (0)