forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fuzz the decoding and encoding of commitment_signed.
- Loading branch information
1 parent
38a329f
commit 1f974b8
Showing
1 changed file
with
52 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "config.h" | ||
#include <assert.h> | ||
#include <ccan/mem/mem.h> | ||
#include <stdint.h> | ||
#include <tests/fuzz/libfuzz.h> | ||
#include <tests/fuzz/wire.h> | ||
#include <wire/peer_wire.h> | ||
|
||
struct commitment_signed { | ||
struct channel_id channel_id; | ||
secp256k1_ecdsa_signature signature; | ||
secp256k1_ecdsa_signature *htlc_signature; | ||
struct tlv_commitment_signed_tlvs *tlvs; | ||
}; | ||
|
||
static void *encode(const tal_t *ctx, const struct commitment_signed *s) | ||
{ | ||
return towire_commitment_signed(ctx, &s->channel_id, &s->signature, | ||
s->htlc_signature, s->tlvs); | ||
} | ||
|
||
static struct commitment_signed *decode(const tal_t *ctx, const void *p) | ||
{ | ||
struct commitment_signed *s = tal(ctx, struct commitment_signed); | ||
|
||
if (fromwire_commitment_signed(s, p, &s->channel_id, &s->signature, | ||
&s->htlc_signature, &s->tlvs)) | ||
return s; | ||
return tal_free(s); | ||
} | ||
|
||
static bool equal(struct commitment_signed *x, struct commitment_signed *y) | ||
{ | ||
size_t upto_htlc_signature = | ||
(uintptr_t)&x->htlc_signature - (uintptr_t)x; | ||
if (memcmp(x, y, upto_htlc_signature) != 0) | ||
return false; | ||
|
||
if (!memeq(x->htlc_signature, tal_bytelen(x->htlc_signature), | ||
y->htlc_signature, tal_bytelen(y->htlc_signature))) | ||
return false; | ||
|
||
assert(x->tlvs && y->tlvs); | ||
return memeq(x->tlvs->splice_info, tal_bytelen(x->tlvs->splice_info), | ||
y->tlvs->splice_info, tal_bytelen(y->tlvs->splice_info)); | ||
} | ||
|
||
void run(const u8 *data, size_t size) | ||
{ | ||
test_decode_encode(data, size, WIRE_COMMITMENT_SIGNED, | ||
struct commitment_signed); | ||
} |