| 295 | } |
| 296 | |
| 297 | const char *check_payer_proof(const tal_t *ctx, |
| 298 | const struct tlv_payer_proof *pptlv) |
| 299 | { |
| 300 | struct sha256 hash, merkle, shash; |
| 301 | struct checker checker; |
| 302 | |
| 303 | /* BOLT-payer_proof #12: |
| 304 | * A reader of a payer_proof: |
| 305 | * - MUST reject the payer_proof if: |
| 306 | * - `invreq_payer_id`, `invoice_payment_hash`, `invoice_node_id`, |
| 307 | * `signature`, `proof_preimage`, `proof_missing_hashes`, |
| 308 | * `proof_leaf_hashes` or `proof_signature` are missing. |
| 309 | */ |
| 310 | if (!pptlv->invreq_payer_id) |
| 311 | return tal_fmt(ctx, "Missing invreq_payer_id"); |
| 312 | if (!pptlv->invoice_payment_hash) |
| 313 | return tal_fmt(ctx, "Missing invoice_payment_hash"); |
| 314 | if (!pptlv->invoice_node_id) |
| 315 | return tal_fmt(ctx, "Missing invoice_node_id"); |
| 316 | if (!pptlv->signature) |
| 317 | return tal_fmt(ctx, "Missing signature"); |
| 318 | if (!pptlv->proof_preimage) |
| 319 | return tal_fmt(ctx, "Missing proof_preimage"); |
| 320 | if (!pptlv->proof_missing_hashes) |
| 321 | return tal_fmt(ctx, "Missing proof_missing_hashes"); |
| 322 | if (!pptlv->proof_leaf_hashes) |
| 323 | return tal_fmt(ctx, "Missing proof_leaf_hashes"); |
| 324 | if (!pptlv->proof_signature) |
| 325 | return tal_fmt(ctx, "Missing proof_signature"); |
| 326 | |
| 327 | /* BOLT-payer_proof #12: |
| 328 | *... |
| 329 | * - SHA256(`proof_preimage`) does not equal `invoice_payment_hash`. |
| 330 | */ |
| 331 | sha256(&hash, pptlv->proof_preimage, sizeof(*pptlv->proof_preimage)); |
| 332 | if (!sha256_eq(&hash, pptlv->invoice_payment_hash)) |
| 333 | return tal_fmt(ctx, "Incorrect preimage"); |
| 334 | |
| 335 | /* BOLT-payer_proof #12: |
| 336 | *... |
| 337 | * - `proof_omitted_tlvs` are not in strict ascending order (no duplicates). |
| 338 | */ |
| 339 | for (size_t i = 0; i < tal_count(pptlv->proof_omitted_tlvs); i++) { |
| 340 | bigsize_t omitted = pptlv->proof_omitted_tlvs[i], prev_omitted; |
| 341 | |
| 342 | /* BOLT-payer_proof #12: |
| 343 | *... |
| 344 | * - `proof_omitted_tlvs` contains 0. |
| 345 | */ |
| 346 | if (omitted == 0) |
| 347 | return tal_fmt(ctx, "proof_omitted_tlvs[%zu] is 0", i); |
| 348 | /* BOLT-payer_proof #12: |
| 349 | *... |
| 350 | * - `proof_omitted_tlvs` contains number outside both ranges 1 to 239 and 1000000000 to 3999999999. |
| 351 | */ |
| 352 | if (!(omitted >= 1 && omitted <= 239) |
| 353 | && !(omitted >= 1000000000 && omitted <= 3999999999)) { |
| 354 | return tal_fmt(ctx, "proof_omitted_tlvs[%zi] is" |