@@ -12,11 +12,11 @@ use crate::dfg::types::DFGTaskInput;
1212use crate :: dfg:: { DFGOp , OpEdge } ;
1313use fhevm_engine_common:: common:: FheOperation ;
1414
15- /// Encoding version byte ( self-describing, decodable) .
16- pub ( super ) const ENCODING_VERSION : u8 = 0x01 ;
15+ /// Tag byte for the inline, self-describing pattern encoding .
16+ pub ( super ) const INLINE_PATTERN_TAG : u8 = 0x01 ;
1717
18- /// Hash version byte (Keccak-256 truncated, not decodable).
19- pub ( super ) const HASH_VERSION : u8 = 0x02 ;
18+ /// Tag byte for the hashed pattern encoding (Keccak-256 truncated, not decodable).
19+ pub ( super ) const HASHED_PATTERN_TAG : u8 = 0x02 ;
2020
2121/// Number of bytes to keep from the Keccak-256 digest.
2222const HASH_DIGEST_LEN : usize = 20 ;
@@ -48,14 +48,14 @@ pub fn pattern_to_base64url(bytes: &[u8]) -> String {
4848
4949/// Decode a binary pattern encoding into a [`PatternDescription`].
5050///
51- /// Returns `None` if the encoding is malformed (wrong version , truncated, etc.)
52- /// or if the pattern is a hashed v2 form (hashes are not decodable).
51+ /// Returns `None` if the encoding is malformed (wrong tag , truncated, etc.)
52+ /// or if the pattern is a hashed form (hashes are not decodable).
5353pub fn decode_pattern ( bytes : & [ u8 ] ) -> Option < PatternDescription > {
5454 if bytes. len ( ) < 2 {
5555 return None ;
5656 }
57- // Only v1 encodings are decodable; hashed (v2) and unknown versions are not.
58- if bytes[ 0 ] != ENCODING_VERSION {
57+ // Only inline encodings are decodable; hashed and unknown tags are not.
58+ if bytes[ 0 ] != INLINE_PATTERN_TAG {
5959 return None ;
6060 }
6161 let node_count = bytes[ 1 ] as usize ;
@@ -116,9 +116,9 @@ pub fn decode_pattern(bytes: &[u8]) -> Option<PatternDescription> {
116116// Two-tier finalization (encoding vs hash)
117117// ---------------------------------------------------------------------------
118118
119- /// Returns `true` if the pattern bytes represent a hashed (v2) pattern.
119+ /// Returns `true` if the pattern bytes represent a hashed pattern.
120120pub fn is_hashed_pattern ( bytes : & [ u8 ] ) -> bool {
121- !bytes. is_empty ( ) && bytes[ 0 ] == HASH_VERSION
121+ !bytes. is_empty ( ) && bytes[ 0 ] == HASHED_PATTERN_TAG
122122}
123123
124124/// Hash threshold read once from `FHEVM_PATTERN_HASH_THRESHOLD` env var,
@@ -130,11 +130,11 @@ pub(super) static PATTERN_HASH_THRESHOLD: LazyLock<usize> = LazyLock::new(|| {
130130 . unwrap_or ( DEFAULT_PATTERN_HASH_THRESHOLD )
131131} ) ;
132132
133- /// If the v1 encoding has `node_count ≤ threshold`, return it as-is.
134- /// Otherwise hash it into a compact 23-byte v2 form and log the full
133+ /// If the inline encoding has `node_count ≤ threshold`, return it as-is.
134+ /// Otherwise hash it into a compact 23-byte form and log the full
135135/// encoding once (per unique hash) for operator linkability.
136136pub ( super ) fn finalize_pattern ( encoding : Vec < u8 > , threshold : usize ) -> Vec < u8 > {
137- debug_assert ! ( encoding. len( ) >= 2 && encoding[ 0 ] == ENCODING_VERSION ) ;
137+ debug_assert ! ( encoding. len( ) >= 2 && encoding[ 0 ] == INLINE_PATTERN_TAG ) ;
138138 let node_count = encoding[ 1 ] as usize ;
139139
140140 if node_count <= threshold {
@@ -144,12 +144,12 @@ pub(super) fn finalize_pattern(encoding: Vec<u8>, threshold: usize) -> Vec<u8> {
144144 build_hash_pattern ( & encoding, node_count, true )
145145}
146146
147- /// Build a 23-byte v2 hashed pattern from arbitrary encoding bytes.
147+ /// Build a 23-byte hashed pattern from arbitrary encoding bytes.
148148///
149149/// ## Hashed pattern binary layout
150150///
151151/// ```text
152- /// Byte 0: 0x02 (HASH_VERSION )
152+ /// Byte 0: 0x02 (HASHED_PATTERN_TAG )
153153/// Bytes 1-2: node_count as u16 big-endian
154154/// Bytes 3-22: first 20 bytes of Keccak-256(encoding)
155155/// Total: 23 bytes
@@ -162,7 +162,7 @@ pub(super) fn build_hash_pattern(
162162 let digest = Keccak256 :: digest ( encoding) ;
163163
164164 let mut buf = Vec :: with_capacity ( 1 + 2 + HASH_DIGEST_LEN ) ;
165- buf. push ( HASH_VERSION ) ;
165+ buf. push ( HASHED_PATTERN_TAG ) ;
166166 let node_count_u16 = u16:: try_from ( node_count) . unwrap_or ( u16:: MAX ) ;
167167 buf. extend_from_slice ( & node_count_u16. to_be_bytes ( ) ) ;
168168 buf. extend_from_slice ( & digest[ ..HASH_DIGEST_LEN ] ) ;
@@ -220,10 +220,10 @@ pub(super) fn compute_subgraph_layout(
220220 Some ( ( local_topo, topo_pos) )
221221}
222222
223- /// Maximum number of nodes that a v1 encoding can represent (node_count is u8).
223+ /// Maximum number of nodes that an inline encoding can represent (node_count is u8).
224224const V1_MAX_NODES : usize = 255 ;
225225
226- /// Maximum number of inputs per node that a v1 encoding can represent
226+ /// Maximum number of inputs per node that an inline encoding can represent
227227/// (3-bit field in the flags byte).
228228const V1_MAX_INPUTS_PER_NODE : usize = 7 ;
229229
@@ -243,14 +243,14 @@ const V1_MAX_INTERNAL_REF: usize = 127;
243243/// nodes, allowed nodes from other groups, DB handles) are treated as external
244244/// (byte 0x00).
245245///
246- /// Returns `None` if the group exceeds the v1 encoding limits (\>255 nodes,
246+ /// Returns `None` if the group exceeds the inline encoding limits (\>255 nodes,
247247/// \>7 inputs per node, or \>127 internal-ref position). Callers can fall back
248248/// to wide-format hashing so oversized groups are still attributable via hash.
249249///
250- /// ## Binary layout (version 1)
250+ /// ## Inline binary layout
251251///
252252/// ```text
253- /// Byte 0: 0x01 (version )
253+ /// Byte 0: 0x01 (inline pattern tag )
254254/// Byte 1: node_count (u8, max 255)
255255///
256256/// Per node in canonical topological order:
@@ -276,11 +276,11 @@ pub(super) fn encode_subgraph(
276276 return None ;
277277 }
278278
279- // Pre-allocate: version (1) + count(1) + per-node ~4 bytes average
279+ // Pre-allocate: tag (1) + count(1) + per-node ~4 bytes average
280280 let mut buf: Vec < u8 > = Vec :: with_capacity ( 2 + node_count * 4 ) ;
281281
282282 // Header
283- buf. push ( ENCODING_VERSION ) ;
283+ buf. push ( INLINE_PATTERN_TAG ) ;
284284 buf. push ( node_count as u8 ) ;
285285
286286 // Nodes
@@ -326,7 +326,7 @@ pub(super) fn encode_subgraph(
326326 Some ( buf)
327327}
328328
329- /// Wide-format encoding used only as hash input when a group exceeds v1 limits.
329+ /// Wide-format encoding used only as hash input when a group exceeds inline encoding limits.
330330///
331331/// This is intentionally not emitted as a pattern attribute directly: only the
332332/// resulting hash is used.
0 commit comments