From 5b879ecb9fc179ddfa822fc9d8a13fe52058baa5 Mon Sep 17 00:00:00 2001 From: Kolby Moroz Liebl <31669092+KolbyML@users.noreply.github.com> Date: Mon, 20 Jan 2025 10:44:39 -0700 Subject: [PATCH] Add test vectors for ping extensions (#357) --- .../extensions/template.md | 2 + ping-payload-extensions/extensions/type-0.md | 63 ++++++++++++++++++- ping-payload-extensions/extensions/type-1.md | 27 ++++++++ ping-payload-extensions/extensions/type-2.md | 30 +++++++++ .../extensions/type-65535.md | 20 +++++- portal-wire-test-vectors.md | 28 +-------- 6 files changed, 141 insertions(+), 29 deletions(-) diff --git a/ping-payload-extensions/extensions/template.md b/ping-payload-extensions/extensions/template.md index 8d95084b..7769dabb 100644 --- a/ping-payload-extensions/extensions/template.md +++ b/ping-payload-extensions/extensions/template.md @@ -26,3 +26,5 @@ Pong Message = Container( payload: [Payload] ) ``` + +## Test Vectors diff --git a/ping-payload-extensions/extensions/type-0.md b/ping-payload-extensions/extensions/type-0.md index 923c243f..99a2776d 100644 --- a/ping-payload-extensions/extensions/type-0.md +++ b/ping-payload-extensions/extensions/type-0.md @@ -1,7 +1,7 @@ # Client Info and Capabilities Payload ## Client Info -Client info are ASCII hex encoded strings. +Client info are UTF-8 hex encoded strings. Client info strings consist of 4 parts - client name (e.x. `trin`,`fluffy`) @@ -42,3 +42,64 @@ Ping/Pong Message = Container( ) ``` +## Test Vectors + +### Protocol Message to ssz encoded ping: case 1 with client info + +#### Input Parameters +``` +enr_seq = 1 +data_radius = 2^256 - 2 # Maximum value - 1 +client_info = "trin/v0.1.1-b61fdc5c/linux-x86_64/rustc1.81.0" +capabilities = [0, 1, 65535] +``` + +#### Expected Output +``` +message = 0x00010000000000000000000e00000028000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff550000007472696e2f76302e312e312d62363166646335632f6c696e75782d7838365f36342f7275737463312e38312e3000000100ffff +``` + +### Protocol Message to ssz encoded ping: case 2 without client info + +#### Input Parameters +``` +enr_seq = 1 +data_radius = 2^256 - 2 # Maximum value - 1 +client_info = "" +capabilities = [0, 1, 65535] +``` + +#### Expected Output +``` +message = 0x00010000000000000000000e00000028000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2800000000000100ffff +``` + +### Protocol Message to ssz encoded pong: case 1 with client info + +#### Input Parameters +``` +enr_seq = 1 +data_radius = 2^256 - 2 # Maximum value - 1 +client_info = "trin/v0.1.1-b61fdc5c/linux-x86_64/rustc1.81.0" +capabilities = [0, 1, 65535] +``` + +#### Expected Output +``` +message = 0x01010000000000000000000e00000028000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff550000007472696e2f76302e312e312d62363166646335632f6c696e75782d7838365f36342f7275737463312e38312e3000000100ffff +``` + +### Protocol Message to ssz encoded pong: case 2 without client info + +#### Input Parameters +``` +enr_seq = 1 +data_radius = 2^256 - 2 # Maximum value - 1 +client_info = "" +capabilities = [0, 1, 65535] +``` + +#### Expected Output +``` +message = 0x01010000000000000000000e00000028000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2800000000000100ffff +``` diff --git a/ping-payload-extensions/extensions/type-1.md b/ping-payload-extensions/extensions/type-1.md index b317fdf9..baf67bf5 100644 --- a/ping-payload-extensions/extensions/type-1.md +++ b/ping-payload-extensions/extensions/type-1.md @@ -14,3 +14,30 @@ Ping/Pong Message = Container( ) ``` +## Test Vectors + +### Protocol Message to ssz encoded ping + +#### Input Parameters +``` +enr_seq = 1 +data_radius = 2^256 - 2 # Maximum value - 1 +``` + +#### Expected Output +``` +message = 0x00010000000000000001000e000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +``` + +### Protocol Message to ssz encoded pong + +#### Input Parameters +``` +enr_seq = 1 +data_radius = 2^256 - 2 # Maximum value - 1 +``` + +#### Expected Output +``` +message = 0x01010000000000000001000e000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff +``` diff --git a/ping-payload-extensions/extensions/type-2.md b/ping-payload-extensions/extensions/type-2.md index cd80ec4b..4c45306f 100644 --- a/ping-payload-extensions/extensions/type-2.md +++ b/ping-payload-extensions/extensions/type-2.md @@ -13,3 +13,33 @@ Ping/Pong Message = Container( payload: history_radius ) ``` + +## Test Vectors + +### Protocol Message to ssz encoded ping + +#### Input Parameters +``` +enr_seq = 1 +data_radius = 2^256 - 2 # Maximum value - 1 +ephemeral_header_count = 4242 +``` + +#### Expected Output +``` +message = 0x00010000000000000002000e000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9210 +``` + +### Protocol Message to ssz encoded pong + +#### Input Parameters +``` +enr_seq = 1 +data_radius = 2^256 - 2 # Maximum value - 1 +ephemeral_header_count = 4242 +``` + +#### Expected Output +``` +message = 0x01010000000000000002000e000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9210 +``` diff --git a/ping-payload-extensions/extensions/type-65535.md b/ping-payload-extensions/extensions/type-65535.md index 8b2ac87e..1d635519 100644 --- a/ping-payload-extensions/extensions/type-65535.md +++ b/ping-payload-extensions/extensions/type-65535.md @@ -5,7 +5,7 @@ If the ping receiver can't handle the ping for any reason the pong should return Pong payload ```python -# Max ASCII hex encoded strings length +# Max UTF-8 hex encoded strings length MAX_ERROR_BYTE_LENGTH = 300 error_payload = SSZ.serialize(Container(error_code: u16, message: ByteList[MAX_ERROR_BYTE_LENGTH])) @@ -31,4 +31,20 @@ This error code should be used when a client is unable to provide the necessary Wasn't able to decode the payload #### 3: System error -A critical error happened and the ping can't be processed \ No newline at end of file +A critical error happened and the ping can't be processed + +## Test Vectors + +### Protocol Message to ssz encoded pong + +#### Input Parameters +``` +enr_seq = 1 +error_code = 2 +message = "hello world" +``` + +#### Expected Output +``` +message = 0x010100000000000000ffff0e00000002000600000068656c6c6f20776f726c64 +``` diff --git a/portal-wire-test-vectors.md b/portal-wire-test-vectors.md index e6e0efc0..1dc14942 100644 --- a/portal-wire-test-vectors.md +++ b/portal-wire-test-vectors.md @@ -9,33 +9,9 @@ This section provides test vectors for the individual protocol messages defined in the [Portal wire protocol](./portal-wire-protocol.md). These test vectors can primarily verify the SSZ encoding and decoding of each protocol message. -### Ping Request +### Ping Request and Pong Response -#### Input Parameters -``` -enr_seq = 1 -data_radius = 2^256 - 2 # Maximum value - 1 -custom_payload = serialize(Container(data_radius)) -``` - -#### Expected Output -``` -message = 0x0001000000000000000c000000feffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff -``` - -### Pong Response - -#### Input Parameters -``` -enr_seq = 1 -data_radius = (2^256 - 1) / 2 # Maximum value / 2 -custom_payload = serialize(Container(data_radius)) -``` - -#### Expected Output -``` -message = 0x0101000000000000000c000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f -``` +These test vectors are located in the specifications for each [ping extension type](./ping-payload-extensions/extensions/) ### Find Nodes Request