Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proof of authenticity of staked nodes by signing #583

Open
5u6r054 opened this issue Oct 7, 2024 · 0 comments
Open

Proof of authenticity of staked nodes by signing #583

5u6r054 opened this issue Oct 7, 2024 · 0 comments

Comments

@5u6r054
Copy link
Contributor

5u6r054 commented Oct 7, 2024

In a secure decentralized network, it's essential for nodes to prove their identity to prevent impersonation and ensure trust among peers. This is typically achieved by having nodes sign messages or challenges using their private keys corresponding to their public addresses (e.g., Ethereum addresses). This cryptographic proof allows other nodes to verify that a node truly controls the address it claims to represent.

Current Implementation in Masa Oracle Nodes

Based on the provided code snippets and the current state of the Masa Oracle Node codebase, it appears that nodes do not perform such a signing process during peer authentication. Here's an analysis of the current system:

1. Node Initialization and Identity

  • LibP2P Key Pair: Each node generates or loads a LibP2P key pair used for establishing secure connections and identifying itself on the network.
  • Ethereum Key Pair: Nodes also have an Ethereum key pair used for staking and interacting with smart contracts on the blockchain.

2. Node Discovery and Connection

  • Nodes use the LibP2P protocols for peer discovery and establishing connections.
  • DHT and mDNS: Nodes leverage the Distributed Hash Table (DHT) and Multicast DNS (mDNS) for finding peers.
  • Protocol Advertisement: Nodes advertise supported protocols and services.

3. Staking Verification

  • Local Verification: Each node checks its own staking status by querying the blockchain to see if its Ethereum address has staked the required tokens.
  • No Peer Verification: There is no mechanism implemented where nodes verify the staking status of other nodes during connection establishment.

4. Lack of Cryptographic Proof Between Nodes

  • Nodes do not sign messages or perform handshake protocols that would allow peers to verify their claimed identities.
  • There is no exchange of signed data that binds the node's network identity (LibP2P ID) to its Ethereum address.

Implications of Not Verifying Node Identities

  • Trust Issues: Without verifying that a peer controls a particular Ethereum address, nodes cannot be certain that they are communicating with a legitimate, staked node.
  • Impersonation Risk: Malicious actors could impersonate staked nodes, potentially disrupting network operations or undermining trust.
  • Network Integrity: The overall security and reliability of the network depend on the ability to authenticate and trust peers.

Recommended Solution: Implementing Identity Verification

To enhance the security and trustworthiness of the Masa Oracle Network, nodes should implement a mechanism to prove ownership of their claimed Ethereum addresses. Here's how this can be achieved:

1. Signing a Challenge Message

  • When two nodes establish a connection, they can perform an authentication handshake.
  • The node requesting proof sends a challenge message, which is a random nonce or a specific piece of data.
  • The challenged node signs this message using its Ethereum private key.

2. Verifying the Signature

  • The requesting node uses the Ethereum public address provided by the peer to verify the signature.
  • If the verification is successful, it confirms that the peer controls the private key corresponding to the claimed Ethereum address.

3. Binding LibP2P ID to Ethereum Address

  • Nodes can establish a mapping between their LibP2P ID (peer ID) and their Ethereum address.
  • By signing the LibP2P peer ID with the Ethereum private key and sharing the signature, peers can verify this binding.

4. Implementing in Code

Below is a simplified example of how this might be implemented:

// On the node side
func (node *OracleNode) SignChallenge(challenge []byte) ([]byte, error) {
    // Hash the challenge
    hash := crypto.Keccak256Hash(challenge)
    // Sign the hash with the Ethereum private key
    signature, err := crypto.Sign(hash.Bytes(), node.PrivateKey)
    if err != nil {
        return nil, err
    }
    return signature, nil
}
// On the peer verification side
func VerifyNodeIdentity(challenge, signature []byte, ethAddress common.Address) (bool, error) {
    // Hash the challenge
    hash := crypto.Keccak256Hash(challenge)
    // Recover the public key from the signature
    pubKey, err := crypto.SigToPub(hash.Bytes(), signature)
    if err != nil {
        return false, err
    }
    // Get the Ethereum address from the public key
    recoveredAddr := crypto.PubkeyToAddress(*pubKey)
    // Compare with the claimed Ethereum address
    return recoveredAddr == ethAddress, nil
}

5. Adjusting the Connection Process

  • Handshake Protocol: Incorporate the signing and verification steps into the initial handshake when establishing a new connection.
  • Fallbacks and Timeouts: Implement appropriate fallbacks and timeouts to handle cases where verification fails or nodes do not respond.

Benefits of Implementing Identity Verification

  • Enhanced Security: Prevents unauthorized nodes from impersonating staked nodes.
  • Trust Establishment: Nodes can make informed decisions about which peers to trust and interact with.
  • Compliance with Best Practices: Aligns the network implementation with standard security practices in decentralized systems.

Conclusion

  • Current State: Nodes in the Masa Oracle Network currently do not sign messages to prove ownership of their Ethereum addresses during peer connections.
  • Recommended Action: Implement a cryptographic identity verification mechanism where nodes sign challenges using their Ethereum private keys.
  • Expected Outcome: Improved security, trust, and integrity of the network, ensuring that only legitimate staked nodes participate fully.

Next Steps for Developers:

  • Design Protocol Extension: Define the messages and steps needed for the authentication handshake.
  • Update Node Implementation: Modify the node codebase to include signing and verification during connections.
  • Testing: Thoroughly test the new mechanism to ensure it works correctly and does not introduce vulnerabilities.
  • Documentation: Update documentation to reflect the new authentication process for node operators.

Implementing such a signing mechanism is a crucial step towards securing the network and building a robust, trustless environment where nodes can interact confidently.

@5u6r054 5u6r054 changed the title Proof of authenticity of staked nodes Proof of authenticity of staked nodes by signing Oct 7, 2024
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

No branches or pull requests

1 participant