Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
28 changes: 24 additions & 4 deletions tests/fuzz/fuzz-initial_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ void init(int *argc, char ***argv)
chainparams = chainparams_for_network("bitcoin");
}

#define MAX_SATS (u64)WALLY_SATOSHI_PER_BTC * WALLY_BTC_MAX

static void test_channel_update_funding(struct channel *channel, const u8 **cursor, size_t *max) {
struct bitcoin_outpoint funding;
struct amount_sat funding_sats;
s64 splice_amnt;

if (*max < sizeof(funding) + sizeof(funding_sats) + sizeof(splice_amnt))
return;

fromwire_bitcoin_outpoint(cursor, max, &funding);
funding_sats = fromwire_amount_sat(cursor, max);
funding_sats.satoshis %= MAX_SATS;
splice_amnt = fromwire_s64(cursor, max) % MAX_SATS;

channel_update_funding(channel, &funding, funding_sats, splice_amnt);
}

void run(const uint8_t *data, size_t size)
{
struct channel_id cid;
Expand All @@ -49,7 +67,7 @@ void run(const uint8_t *data, size_t size)
minimum_depth = fromwire_u32(&data, &size);
funding_sats = fromwire_amount_sat(&data, &size);
local_msatoshi = fromwire_amount_msat(&data, &size);
max = AMOUNT_SAT((u32)WALLY_SATOSHI_PER_BTC * WALLY_BTC_MAX);
max = AMOUNT_SAT(MAX_SATS);
if (amount_sat_greater(funding_sats, max))
funding_sats = max;
feerate_per_kw = fromwire_u32(&data, &size);
Expand All @@ -71,8 +89,10 @@ void run(const uint8_t *data, size_t size)

/* TODO: determine if it makes sense to check at each step for libfuzzer
* to deduce pertinent inputs */
if (!data || !size)
if (!data || !size) {
clean_tmpctx();
return;
}

for (enum side opener = 0; opener < NUM_SIDES; opener++) {
channel = new_initial_channel(tmpctx, &cid, &funding,
Expand All @@ -91,8 +111,8 @@ void run(const uint8_t *data, size_t size)
channel_type,
wumbo, opener);

/* TODO: make initial_channel_tx() work with ASAN.. */
(void)channel;
if (channel)
test_channel_update_funding(channel, &data, &size);
}

clean_tmpctx();
Expand Down
Loading