smite: add channel_update and short_channel_id codecs#81
Open
devvaansh wants to merge 1 commit into
Open
Conversation
5803c3b to
4912bcb
Compare
morehouse
requested changes
May 19, 2026
4912bcb to
d712702
Compare
a0967e5 to
07229fb
Compare
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.
07229fb to
3cb0419
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the wire codec,
Messageenum wiring, and ECDSA sign/verify helpers for BOLT 7channel_update(msg type 258) and the supportingshort_channel_idpacked 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 codecsbolt::short_channel_id::ShortChannelId— packed 8-byte type withnew/from_u64/as_u64/block/tx_index/output_indexaccessors,Displayin BOLT 7<block>x<tx>x<out>form, andWireFormatimpl.bolt::channel_update::ChannelUpdate— full BOLT 7 wire layout (signature, chain_hash, scid, timestamp, flags, cltv_expiry_delta, htlc min/max msat, fees), plussigning_region()exposing the post-signature body bytes.Message::ChannelUpdatevariant + msg_type/encode/decode arms + roundtrip test, so the dispatcher can actually receive/emitchannel_updatefrom the wire (not just dead-code the codec).Commit 2 —
smite: add sign and verify methods to ChannelUpdateChannelUpdate::sign(&mut self, sk)— ECDSA over double-SHA256 of the signing region.ChannelUpdate::verify(&self, pk)— takes the pubkey explicitly, since unlikenode_announcement,channel_updatedoes not embednode_idon the wire (the receiver looks it up from the correspondingchannel_announcementfor the scid).This commit shape mirrors #78.
Notes for review
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 apubmethod (rather than only inlining insidesign/verify) so the gossip generator can reuse it when producing deliberately-malformed signatures.cargo clippy -p smiteis clean on the touched files.Out of scope
channel_announcementcodec — will be a follow-up;channel_updatewas chosen first because it's by far the more frequent gossip message and is the one most useful for fuzzing forwarding-policy logic.ChannelUpdateGenerator) and the gossip scenario — will land in subsequent PRs once Matt'snode_announcementwork (smite: addnode_announcementcodec #78) and this codec are both in.Refs #71.