TeachMeBitcoin

ASMAP and Eclipse Attack Defense: Territorial Sovereignty

From TeachMeBitcoin, the free encyclopedia Reading time: 4 min

18. ASMAP and Eclipse Attack Defense: Territorial Sovereignty

In our next 1,100 words, we perform an audit of the Sovereign's Borders. An "Eclipse Attack" is a sophisticated hack where an attacker surrounds your node with "Fake Peers" until you can only see the "Attacker's Version" of the blockchain. ASMAP (Autonomous System Map) is our architectural defense against this isolation.

The Physics of the Network Map

The internet is not a single giant cloud. It is a collection of "Autonomous Systems" (ASes)—large networks managed by ISPs like Comcast, AT&T, or Deutsche Telekom. If your node connects to 10 different peers, but all 10 are on "Comcast's Network," then Comcast can "Eclipse" you.

ASMAP allows the node to understand the "Geography of the Internet." It uses a compressed database to map every IP address to its corresponding Autonomous System. The node then ensures that its connections are "Diverse"—meaning it tries to connect to peers in as many different ASes as possible. This ensures that no single company or country can "Surround" your node.

Analyzing the Borders: The src/util/asmap.cpp Audit

/**
 * PEDAGOGICAL ANALYSIS: THE TERRITORY INTERPRETER
 * This logic (from src/util/asmap.cpp) reads the 
 * compressed "AS Map" to identify which ISP a peer belongs to.
 */
uint32_t Interpret(const std::span<const std::byte> asmap, 
                  const std::span<const std::byte> ip)
{
    size_t pos{0};
    uint8_t ip_bit{0};
    uint32_t default_asn = 0;

    // 1. Traverse the "Compressed Trie."
    // We use bits of the IP address to navigate 
    // through the binary tree of ISPs.
    while (pos < endpos) {
        Instruction opcode = DecodeType(pos, asmap);

        if (opcode == Instruction::RETURN) {
            // 2. Found the ISP ID (ASN).
            // We now know which "Territory" this peer lives in.
            return DecodeASN(pos, asmap);
        } else if (opcode == Instruction::JUMP) {
            // 3. Navigate left or right based on the IP bit.
            if (ConsumeBitBE(ip_bit, ip)) {
                pos += jump; // Bit = 1: Go to the right subtree.
            }
            // Bit = 0: Fall through to the left subtree.
        }
    }
    return 0; // Unknown ISP.
}

Explaining the Borders: The Wisdom of the Mesh

The Philosophy of the Borders

As a Sovereign Architect, you know that "Strength comes from diversity." ASMAP is the node's way of "Building a Global Alliance." It is the understanding that for the network to be "One," it must be "Everywhere" and "Nowhere" at the same time.

We are moving away from a "Random Mesh" and toward a "Strategically Diverse Mesh." By understanding the "Territories" of the internet, we ensure that the "Truth of Bitcoin" can never be eclipsed by any single entity. You are not just connecting to peers; you are Maintaining the Territorial Integrity of the Global Ledger.


☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!