From 60c933911d86624112c4a188c61ac28dbf76a572 Mon Sep 17 00:00:00 2001 From: Advaita Saha Date: Sat, 27 Jul 2024 03:40:45 +0530 Subject: [PATCH] fix test suite for banderwagon (#442) --- tests/t_ethereum_verkle_primitives.nim | 106 ++++++++++--------------- 1 file changed, 43 insertions(+), 63 deletions(-) diff --git a/tests/t_ethereum_verkle_primitives.nim b/tests/t_ethereum_verkle_primitives.nim index b08f620e..65c8a915 100644 --- a/tests/t_ethereum_verkle_primitives.nim +++ b/tests/t_ethereum_verkle_primitives.nim @@ -115,69 +115,49 @@ proc testDeserialize(hexString: string, status: CttCodecEccStatus) : bool = # ############################################################ suite "Banderwagon Serialization Tests": - # ## Check encoding if it is as expected or not - # test "Test Encoding from Fixed Vectors": - # proc testSerialize(len: int) = - # # First the point is set to generator P - # # then with each iteration 2P, 4P, . . . doubling - # var points: seq[EC_TwEdw_Aff[Fp[Banderwagon]]] - # var point {.noInit.}: EC_TwEdw_Aff[Fp[Banderwagon]] - # point.setGenerator() - - # for i in 0 ..< len: - # var arr: array[32, byte] - # let stat = arr.serialize(point) - - # # Check if the serialization took place and in expected way - # doAssert stat == cttCodecEcc_Success, "Serialization Failed" - # doAssert expected_bit_strings[i] == arr.toHex(), "bit string does not match expected" - # points.add(point) - - # point.double() #doubling the point - - # testSerialize(expected_bit_strings.len) - - # ## Check decoding if it is as expected or not - # test "Decoding Each bit string": - # proc testDeserialization(len: int) = - # # Checks if the point serialized in the previous - # # tests matches with the deserialization of expected strings - # for i, bit_string in expected_bit_strings: - - # # converts serialized value in hex to byte array - # var arr: array[32, byte] - # discard arr.parseHex(bit_string) - - # # deserialization from expected bits - # var point{.noInit.}: EC_TwEdw_Aff[Fp[Banderwagon]] - # let stat = point.deserialize(arr) - - # # Assertion check for the Deserialization Success & correctness - # doAssert stat == cttCodecEcc_Success, "Deserialization Failed" - # doAssert (point == points[i]).bool(), "Decoded Element is different from expected element" - - # testDeserialization(expected_bit_strings.len) - - # ## Check decoding if it is as expected or not ( vartime impl ) - # test "vartime - Decoding Each bit string": - # proc testDeserialization_vartime(len: int) = - # # Checks if the point serialized in the previous - # # tests matches with the deserialization of expected strings - # for i, bit_string in expected_bit_strings: - - # # converts serialized value in hex to byte array - # var arr: array[32, byte] - # discard arr.parseHex(bit_string) - - # # deserialization from expected bits - # var point{.noInit.}: EC_TwEdw_Prj[Fp[Banderwagon]] - # let stat = point.deserialize_vartime(arr) - - # # Assertion check for the Deserialization Success & correctness - # doAssert stat == cttCodecEcc_Success, "Deserialization Failed" - # doAssert (point == points[i]).bool(), "Decoded Element is different from expected element" - - # testDeserialization_vartime(expected_bit_strings.len) + var points: seq[EC_TwEdw_Prj[Fp[Banderwagon]]] + + ## Check encoding if it is as expected or not + test "Test Encoding from Fixed Vectors": + proc testSerialize(len: int) = + # First the point is set to generator P + # then with each iteration 2P, 4P, . . . doubling + var point {.noInit.}: EC_TwEdw_Prj[Fp[Banderwagon]] + point.setGenerator() + + for i in 0 ..< len: + var arr: array[32, byte] + let stat = arr.serialize(point) + + # Check if the serialization took place and in expected way + doAssert stat == cttCodecEcc_Success, "Serialization Failed" + doAssert expected_bit_strings[i] == arr.toHex(), "bit string does not match expected" + points.add(point) + + point.double() #doubling the point + + testSerialize(expected_bit_strings.len) + + ## Check decoding if it is as expected or not ( vartime impl ) + test "Decoding Each bit string": + proc testDeserialization(len: int) = + # Checks if the point serialized in the previous + # tests matches with the deserialization of expected strings + for i, bit_string in expected_bit_strings: + + # converts serialized value in hex to byte array + var arr: array[32, byte] + discard arr.parseHex(bit_string) + + # deserialization from expected bits + var point{.noInit.}: EC_TwEdw_Aff[Fp[Banderwagon]] + let stat = point.deserialize_vartime(arr) + + # Assertion check for the Deserialization Success & correctness + doAssert stat == cttCodecEcc_Success, "Deserialization Failed" + doAssert (point == points[i].getAffine()).bool(), "Decoded Element is different from expected element" + + testDeserialization(expected_bit_strings.len) # Check if the subgroup check is working on eliminating # points which don't lie on banderwagon, while