MCPcopy Create free account
hub / github.com/ElementsProject/lightning / run

Function run

tests/fuzz/fuzz-close_tx.c:19–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19void run(const uint8_t *data, size_t size)
20{
21 const uint8_t *wire_ptr;
22 size_t wire_max, min_size, script_size;
23 struct bitcoin_outpoint outpoint;
24 struct amount_sat funding, to_us, to_them, dust_limit, max;
25 const uint8_t *our_script, *their_script, *funding_script;
26 struct pubkey *pk1, *pk2;
27
28 /* create_close_tx wants:
29 * - 3 scripts: 3 * N bytes
30 * - 1 txid: 32 bytes
31 * - 1 u32: 4 bytes
32 * - 4 amount_sat: 4 * 8 bytes
33 *
34 * Since both output scripts size are not restricted, we also try
35 * to vary their length.
36 * Therefore, we allocate the entire remaining bytes to scripts.
37 */
38 min_size = 8 * 3 + 4 + 32;
39 if (size < min_size + 2)
40 return;
41
42 script_size = (size - min_size) / 2;
43 wire_ptr = data;
44
45 wire_max = 8;
46 to_us = fromwire_amount_sat(&wire_ptr, &wire_max);
47 assert(wire_ptr);
48 wire_max = 8;
49 to_them = fromwire_amount_sat(&wire_ptr, &wire_max);
50 assert(wire_ptr);
51 wire_max = 8;
52 dust_limit = fromwire_amount_sat(&wire_ptr, &wire_max);
53 /* The funding must be > to_us + to_them (TODO: we could simulate some fees) .. */
54 if (!(amount_sat_add(&funding, to_us, to_them)))
55 return;
56 /* .. And < max_btc as we assert it's not nonsensical! */
57 max = AMOUNT_SAT((u32)WALLY_SATOSHI_PER_BTC * WALLY_BTC_MAX);
58 if (amount_sat_greater(funding, max)) {
59 funding = max;
60 to_us = amount_sat_div(max, 2);
61 to_them = amount_sat_div(max, 2);
62 }
63
64 wire_max = 36;
65 fromwire_bitcoin_outpoint(&wire_ptr, &wire_max, &outpoint);
66
67 our_script = tal_dup_arr(tmpctx, const uint8_t, wire_ptr, script_size, 0);
68 their_script = tal_dup_arr(tmpctx, const uint8_t, wire_ptr + script_size,
69 script_size, 0);
70
71 /* We assert it's valid, so we can't throw garbage at the funding script.. */
72 pk1 = tal(tmpctx, struct pubkey);
73 pk2 = tal(tmpctx, struct pubkey);
74 pubkey_from_hexstr("034fede2c619f647fe7c01d40ae22e4c285291ca2ffb47937bbfb7d6e8285a081f",
75 PUBKEY_CMPR_LEN, pk1);
76 pubkey_from_hexstr("028dfe31019dd61fa04c76ad065410e5d063ac2949c04c14b214c1b363e517452f",

Callers

nothing calls this directly

Calls 9

amount_sat_greaterFunction · 0.85
amount_sat_divFunction · 0.85
pubkey_from_hexstrFunction · 0.85
bitcoin_redeem_2of2Function · 0.85
create_close_txFunction · 0.85
clean_tmpctxFunction · 0.85
fromwire_amount_satFunction · 0.50
amount_sat_addFunction · 0.50

Tested by

no test coverage detected