Skip to content

Commit e456fd1

Browse files
committed
ETCM-167: Sanity check on the example node ID.
1 parent ffdd6db commit e456fd1

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/test/scala/io/iohk/ethereum/network/discovery/codecs/ENRCodecsSpec.scala

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package io.iohk.ethereum.network.discovery.codecs
33
import org.scalatest.matchers.should.Matchers
44
import org.scalatest.flatspec.AnyFlatSpec
55
import io.iohk.scalanet.discovery.ethereum.{Node, EthereumNodeRecord}
6-
import io.iohk.scalanet.discovery.crypto.{SigAlg, PrivateKey, PublicKey}
6+
import io.iohk.scalanet.discovery.crypto.{SigAlg, PrivateKey}
7+
import io.iohk.scalanet.discovery.hash.{Hash, Keccak256}
78
import io.iohk.ethereum.network.discovery.crypto.Secp256k1SigAlg
89
import io.iohk.ethereum.rlp
910
import io.iohk.ethereum.rlp.{RLPList, RLPEncoder}
@@ -25,8 +26,9 @@ class ENRCodecsSpec extends AnyFlatSpec with Matchers {
2526
behavior of "RLPCodecs with ENR"
2627

2728
// https://github.com/ethereum/devp2p/blob/master/enr.md#test-vectors
28-
val nodeId = hex"a448f24c6d18e575453db13171562b71999873db5b286df957af199ec94617f7"
29-
val privateKey = hex"b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291"
29+
val nodeId = Hash(hex"a448f24c6d18e575453db13171562b71999873db5b286df957af199ec94617f7".toBitVector)
30+
val privateKey = PrivateKey(hex"b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291".toBitVector)
31+
val publicKey = sigalg.toPublicKey(privateKey)
3032
val enrString =
3133
"enr:-IS4QHCYrYZbAKWCBRlAy5zzaDZXJBGkcnh4MHcBFZntXNFrdvJjX04jRzjzCBOonrkTfj499SZuOh8R33Ls8RRcy5wBgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQPKY0yuDUmstAHYpMa2_oxVtw0RW_QAdpzBQA8yWM0xOIN1ZHCCdl8"
3234

@@ -54,11 +56,11 @@ class ENRCodecsSpec extends AnyFlatSpec with Matchers {
5456
// Construct a Node which should give us the same results.
5557
// Unfortunately there's no option to omit the TCP port from it :(
5658
val node = Node(
57-
id = PublicKey(nodeId.toBitVector),
59+
id = publicKey,
5860
address = Node.Address(localhost, udpPort = 30303, tcpPort = 0)
5961
)
6062

61-
val enr = EthereumNodeRecord.fromNode(node, PrivateKey(privateKey.toBitVector), seq = 1).require
63+
val enr = EthereumNodeRecord.fromNode(node, privateKey, seq = 1).require
6264

6365
val rlpStructureFromNode = RLPEncoder.encode(enr)
6466

@@ -117,8 +119,14 @@ class ENRCodecsSpec extends AnyFlatSpec with Matchers {
117119
}
118120

119121
it should "verify the signature of the example ENR" in {
120-
val publicKey = sigalg.toPublicKey(PrivateKey(privateKey.toBitVector))
122+
val publicKey = sigalg.toPublicKey(privateKey)
121123
val enr = RLPDecoder.decode[EthereumNodeRecord](enrRLP)
122124
EthereumNodeRecord.validateSignature(enr, publicKey).require shouldBe true
123125
}
126+
127+
it should "verify that the node ID in the example is the hash of the public key" in {
128+
// This is what we use in Kademlia, but the node ID in the wire protocol
129+
// should be the 64 byte public key, at least I thought so based on the spec.
130+
Keccak256(publicKey) shouldBe nodeId
131+
}
124132
}

0 commit comments

Comments
 (0)