Skip to content

smite: add channel_update and short_channel_id codecs#81

Open
devvaansh wants to merge 1 commit into
morehouse:masterfrom
devvaansh:gossip-codecs-bolt7
Open

smite: add channel_update and short_channel_id codecs#81
devvaansh wants to merge 1 commit into
morehouse:masterfrom
devvaansh:gossip-codecs-bolt7

Conversation

@devvaansh
Copy link
Copy Markdown
Contributor

Adds the wire codec, Message enum wiring, and ECDSA sign/verify helpers for BOLT 7 channel_update (msg type 258) and the supporting short_channel_id packed type.

This is the first vertical slice of the BOLT 7 gossip-fuzzing milestone (#71): the codec layer that everything else (IR generators, gossip scenario, harnesses) will sit on top of.

What's in the PR

Commit 1 — smite: implement short_channel_id and channel_update codecs

  • bolt::short_channel_id::ShortChannelId — packed 8-byte type with new / from_u64 / as_u64 / block / tx_index / output_index accessors, Display in BOLT 7 <block>x<tx>x<out> form, and WireFormat impl.
  • bolt::channel_update::ChannelUpdate — full BOLT 7 wire layout (signature, chain_hash, scid, timestamp, flags, cltv_expiry_delta, htlc min/max msat, fees), plus signing_region() exposing the post-signature body bytes.
  • Message::ChannelUpdate variant + msg_type/encode/decode arms + roundtrip test, so the dispatcher can actually receive/emit channel_update from the wire (not just dead-code the codec).

Commit 2 — smite: add sign and verify methods to ChannelUpdate

  • ChannelUpdate::sign(&mut self, sk) — ECDSA over double-SHA256 of the signing region.
  • ChannelUpdate::verify(&self, pk) — takes the pubkey explicitly, since unlike node_announcement, channel_update does not embed node_id on the wire (the receiver looks it up from the corresponding channel_announcement for the scid).
  • 4 verify tests: succeeds-after-sign, fails-on-tampered-body, fails-on-wrong-pubkey, roundtrips-through-encode-decode.

This commit shape mirrors #78.

Notes for review

  • The decoder is intentionally lenient about message_flags / channel_flags: it preserves all bits and leaves policy enforcement (e.g. must_be_one) to the caller. This is what we want when fuzzing implementations that disagree on which bits are reserved.
  • signing_region() is kept as a pub method (rather than only inlining inside sign / verify) so the gossip generator can reuse it when producing deliberately-malformed signatures.
  • All 12 new tests pass; cargo clippy -p smite is clean on the touched files.

Out of scope

  • channel_announcement codec — will be a follow-up; channel_update was chosen first because it's by far the more frequent gossip message and is the one most useful for fuzzing forwarding-policy logic.
  • IR generator (ChannelUpdateGenerator) and the gossip scenario — will land in subsequent PRs once Matt's node_announcement work (smite: add node_announcement codec #78) and this codec are both in.

Refs #71.

@devvaansh devvaansh force-pushed the gossip-codecs-bolt7 branch 2 times, most recently from 5803c3b to 4912bcb Compare May 15, 2026 20:42
Comment thread smite/src/bolt.rs Outdated
Comment thread smite/src/bolt/short_channel_id.rs Outdated
Comment thread smite/src/bolt/short_channel_id.rs Outdated
Comment thread smite/src/bolt/short_channel_id.rs Outdated
Comment thread smite/src/bolt/short_channel_id.rs Outdated
Comment thread smite/src/bolt/channel_update.rs
Comment thread smite/src/bolt/channel_update.rs Outdated
Comment thread smite/src/bolt/channel_update.rs Outdated
Comment thread smite/src/bolt/channel_update.rs Outdated
Comment thread smite/src/bolt/channel_update.rs Outdated
@devvaansh devvaansh force-pushed the gossip-codecs-bolt7 branch from 4912bcb to d712702 Compare May 19, 2026 19:23
Copy link
Copy Markdown
Owner

@morehouse morehouse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread smite/src/bolt/channel_update.rs Outdated
Comment thread smite/src/bolt/short_channel_id.rs Outdated
Comment thread smite/src/bolt/short_channel_id.rs Outdated
@devvaansh devvaansh force-pushed the gossip-codecs-bolt7 branch 2 times, most recently from a0967e5 to 07229fb Compare May 20, 2026 19:37
Adds wire codecs for the BOLT 7 short_channel_id packed type and the
channel_update gossip message (type 258), including sign/verify helpers
backed by secp256k1 ECDSA, and wires ChannelUpdate into the central
Message enum so it can be dispatched off the wire.

short_channel_id:

  * Packed u64 representation per BOLT 7 (3 bytes block || 3 bytes tx ||
    2 bytes output). new() panics on out-of-range components (24-bit
    block / tx index), which would be a programmer error in every
    realistic caller. from_u64 is the infallible inverse of as_u64.

channel_update:

  * Preserves any trailing unknown bytes via a pub extra: Vec<u8> field
    so that re-encoding is byte-identical and the signature still
    verifies. Per BOLT 7 the signature covers everything after the
    leading signature field, including unknown fields following
    fee_proportional_millionths.
  * sign(&mut self, sk) writes the body via write_body (which includes
    extra) and stores the resulting ECDSA signature.
  * verify(&self, pk) -> bool recomputes the digest and returns whether
    the stored signature matches the supplied pubkey. Unlike
    node_announcement, channel_update does not embed node_id on the
    wire, so the receiver must look the key up from the previously-seen
    channel_announcement for short_channel_id and pass it explicitly.
  * The decoder is intentionally lenient about flag bits (it preserves
    message_flags / channel_flags verbatim) and leaves policy decisions
    such as enforcement of must_be_one to the caller -- this matches
    how we want to fuzz divergent BOLT 7 implementations.
@devvaansh devvaansh force-pushed the gossip-codecs-bolt7 branch from 07229fb to 3cb0419 Compare May 20, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants