---
title: Stable-Semantic Graph (SSG)
url: https://www.emergentmind.com/topics/stable-semantic-graph-ssg
type: topic
---

# Stable-Semantic Graph (SSG)

A Stable-Semantic Graph (SSG) is a principled graph-based representation framework designed to robustly encode high-level semantic or functional relationships within complex environments or program structures. The SSG formalism has been pivotal in two major areas: robust loop closure in robot localization by modeling 3D semantic environments [2211.11977], and accurate similarity detection for Ethereum Virtual Machine (EVM) bytecode by capturing semantically stable instruction relationships [2511.12971]. In both contexts, the SSG structure explicitly models stable elements—objects in 3D space or stable EVM instructions—and their critical relational topologies, enabling resilience against noise, ambiguity, and superficial variation.

## 1. Formal Specification

### 3D Semantic SSG for Robotics

In the robotics context, the SSG encodes a global map as a graph \( G = (V, E) \), where each vertex represents a semantically annotated, volumetric object and each edge denotes co-visibility and topological distance between object pairs:
- **Node** \( o_j \): \( (V_j, T_{w o_j}, l_j, m_j, E_j) \), where \( V_j \) is the object’s TSDF model, \( T_{w o_j} \in SE(3) \) is its pose, \( l_j \) its semantic label, \( m_j \) its predicted mask, and \( E_j \) its embedding set.
- **Edge** \( e_{j_1, j_2} \): Euclidean distance between object centers, if co-visible in any local map: \( e_{j_1,j_2} = \| \mathrm{center}(o_{j_1}) - \mathrm{center}(o_{j_2}) \|_2 \).
- **Graph**: \( V = \{v_j \}_{j=1}^N \), \( E = \{e_{j_1,j_2} \mid (j_1, j_2) \text{ co-visible}\} \).

### SSG for EVM Bytecode Similarity

For smart contract analysis, the SSG of a single EVM function is a directed, heterogeneous graph:
\[
\mathcal{G}_{SSG} = (\mathcal{V},\,\mathcal{E},\,F,\,\phi,\,\varphi)
\]
- **Nodes** \( \mathcal{V} = \mathcal{C} \cup \mathcal{D} \):
   - \( \mathcal{C} \): Control-flow nodes, each a “stable instruction” (\( \mathcal{O}_{stable} \) = {SLOAD, SSTORE, LOG0…LOG4, CALL, STATICCALL, etc.}).
   - \( \mathcal{D} \): Data-flow nodes, including sources (constants, environment vars, etc.) and sinks (storage slots, call arguments, etc.).
- **Edges**:
   - \( E_c \subseteq \mathcal{C} \times \mathcal{C} \): Control-flow edges between stable instructions.
   - \( E_d \subseteq \mathcal{D} \times \mathcal{D} \): Data-flow edges from source to sink variables.
   - \( E_{cd} \subseteq \mathcal{C} \times \mathcal{D} \): Declarative links from stable instructions to the data elements they manipulate.
- **Type Maps and Features**:
   - Node type mapping \( \phi \), edge type mapping \( \varphi \), and node feature mapping \( F \) (opcode one-hot for instructions, structured encodings for data nodes).

## 2. Construction Algorithms

### Robotics: Semantic Map Building and Association

- Every incoming frame yields a set of object detections with associated mask, semantic label, confidence, and embedding.
- Data association cast as a linear assignment problem for binary assignment \( \mathbf{A} \in \{0,1\}^{N \times M} \), minimizing a fusion cost of mask IoU, embedding similarities, and semantic label uncertainty using:
\[
L_{jk} = 1.0 - W_{jk}\,p(l_k \mid l_j), \quad W_{jk} = \lambda\,\mathrm{IoU}(m_j, m_k) + (1-\lambda)\,\max_{e' \in E_j} \mathrm{cosine}(e', e_k)
\]
where \( \lambda \) tunes the balancing of cues.

- Edges in the SSG are dynamically updated with each new object observed as co-visible.

### EVM SSG: Stable Instruction Extraction and Graph Synthesis

- Bytecode is parsed, CFG obtained; each basic block is scanned for stable instructions (\( \mathcal{O}_{stable} \)), constructing \( \mathcal{C} \).
- For control-flow edges (\( E_c \)), link key statements within and across blocks in program order, handling cases where predecessor blocks lack stable instructions recursively.
- For data-flow edges (\( E_d \)), a backward taint analysis over the EVM’s local/stack/memory model identifies sources for each sink; edges are added from sources to sinks.
- For control-to-data (\( E_{cd} \)), connect each stable instruction to its sink data nodes.

Matrix representations:
\[
A_c \in \{0,1\}^{n_c \times n_c}, \quad A_d \in \{0,1\}^{n_d \times n_d}, \quad A_{cd} \in \{0,1\}^{n_c \times n_d}
\]
combine into adjacency tensors for heterogeneous GNN input.

## 3. SSG-Based Matching and Reasoning

### Robust Loop Closure (Robotics)

- Graph matching for loop closure is posed as a Quadratic Assignment Problem:
\[
\max_{\mathbf{A}} \sum_{(j_1,j_2) \in E_q}\;\sum_{(k_1,k_2) \in E_t}\;A_{k_1,j_1}\,A_{k_2,j_2}\,L(j_1,j_2,k_1,k_2)
\]
subject to assignment constraints, with
\[
L(j_1,j_2,k_1,k_2) = L(j_1, k_1) L(j_2, k_2) \exp(-\mu\,\|e_{j_1,j_2} - e_{k_1,k_2}\|_2)
\]
and
\[
L(j, k) = \begin{cases} 1 & l_j = l_k \\ 0 & \text{else}\end{cases}
\]

- The relaxation enables spectral approximation for efficiency, followed by pose alignment (RANSAC+ICP) and loop constraint injection into the global pose graph.

### EVM Bytecode Similarity

- SSG graphs are embedded via a two-tower Siamese heterogeneous GNN. Each SSG is decomposed into:
   - Node feature matrix \( X \)
   - Edge-type adjacency tensors \( A^{(1)}, A^{(2)}, A^{(3)} \)
- The heterogeneous GNN updates node states with relation-specific message passing:
\[
h_v^{(\ell+1)} = \sigma\left(\sum_{r=1}^3 \sum_{u:(u\to v)\in E_r} \frac{1}{|N_r(v)|} W_r^{(\ell)} h_u^{(\ell)} + W_0^{(\ell)} h_v^{(\ell)}\right)
\]
with graph-level pooling and cosine similarity for downstream contract matching.

- A pairwise contrastive loss trains the network, bringing together similar contract embeddings (positive pairs) and pushing apart dissimilar ones (negative pairs).

## 4. Empirical Evaluation

### Robotics

- The object-level assignment significantly outperforms nearest-neighbor in accuracy for object association.
- Graph matching-based loop closure is more robust to appearance changes than prior methods, as the SSG relies on semantically stable object representation and topological relationships, not purely visual or geometric cues [2211.11977].

### EVM Bytecode Analysis

Empirical metrics for SSG-based EVM analysis [2511.12971]:

| Aspect                     | Performance                  | Baseline Comparison   |
|----------------------------|------------------------------|-----------------------|
| SSG Control-Flow \(E_c\)   | F1 = 100%                    | -                     |
| SSG Data-Flow \(E_d\)      | F1 = 95.16%                  | -                     |
| Similarity Detection (AUC) | 0.963 (Siamese GNN)          | FuzzHash: 0.818, Genius (ACFG): 0.837, Eclone: ≈0.94 |
| SSG Extraction Time        | 26 s/contract                | -                     |
| SSG Embedding Time         | 0.06 s/graph                 | -                     |
| Large-Scale Search         | <5 s (2.6M contracts/6 chains) | -                   |

SSG-based similarity detection outperforms all tested baselines, including Etherscan, especially in cross-version and optimization-variant scenarios.

## 5. Distinguishing Features and Stability

- SSGs grant robustness by exclusively representing stable, high-level semantic units:
   - In 3D mapping: objects that act as viewpoint- and appearance-invariant landmarks.
   - In EVM: instructions whose semantics are preserved across compiler versions and source diversity.
- The explicit encoding of both control-flow and data-flow, as well as heterogeneous relationships, imparts the invariance needed to resist both spurious code changes and environmental fluctuations.
- In robotics, the SSG’s topological structure ensures that even partial or occluded environments retain matchability for loop closure, correcting drift via semantic alignment rather than dependence on repeatable local features.
- In contract analysis, the methodology yields graph representations that remain stable despite optimizer or compiler idiosyncrasies, allowing reliable fuzzy (cross-version) matching.

## 6. Applications and Impact

- In robotics, SSGs enable consistent long-term localization and mapping via robust semantic loop closure, contributing to persistent autonomy in environments with appearance or partial geometric changes [2211.11977].
- In the context of blockchain, SSG empowers large-scale, accurate detection of functionally similar EVM bytecode, advancing security, code similarity measurement, and vulnerability search across millions of contracts with verified efficiency and high recall [2511.12971].

A plausible implication is that SSGs, by prioritizing stable semantic structure over superficial or low-level patterns, set a general paradigm for robust representation in both physical and digital domains characterized by structural variability.

Source: https://www.emergentmind.com/topics/stable-semantic-graph-ssg