Skip to content

Commit

Permalink
Test vectors 009 and 010 by Ignacio passing (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
agnxsh authored Jan 18, 2024
1 parent c4be82d commit dbd2630
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
61 changes: 60 additions & 1 deletion tests/t_ethereum_verkle_ipa_primitives.nim
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,72 @@ suite "Computing the Correct Vector Commitment":
testVectorComm()


# #######################################################################################################
#
# Test for Deserializing a Scalar whose final size is bigger than the Scalar Field Size
#
# ########################################################################################################

suite "Deserialize a proof which contains an invalid final scalar by @Ignacio":

test "Deserialize a proof which contains a final scalar bigger than the field size (MUST fail)":

proc testBiggerThanFieldSizeDeserialize() =
var test_big {.noInit.} : matchingOrderBigInt(Banderwagon)

var proof1_bytes = newSeq[byte](serializedProof1.len)
proof1_bytes.fromHex(serializedProof1)

var proof2_bytes : array[32, byte]

for i in 0 ..< 32:
proof2_bytes[i] = proof1_bytes[i]

let stat1 = test_big.deserialize_scalar(proof2_bytes, littleEndian)

doAssert stat1 != cttCodecScalar_Success, "This test should have FAILED"

testBiggerThanFieldSizeDeserialize()

# #######################################################################################################
#
# Test for Deserializing a Scalar whose final size is INVALID
#
# ########################################################################################################

suite "Deserialize a proof which wrong lengths by @Ignacio":

test "Deserialize a proof which wrong lengths (all MUST fail)":

proc testInvalidFieldSizeDeserialize() =

var test_big {.noInit.} : array[3, matchingOrderBigInt(Banderwagon)]

var i : int = 0

while i != 3:
var proof_bytes = newSeq[byte](serializedProofs2[2].len)
proof_bytes.fromHex(serializedProofs2[i])

var proof2_bytes : array[32, byte]

for j in 0 ..< 32:
proof2_bytes[j] = proof_bytes[j]

let stat = test_big[i].deserialize_scalar(proof2_bytes, littleEndian)

i = i + 1
doAssert stat != cttCodecScalar_Success, "This test should FAIL"


testInvalidFieldSizeDeserialize()

# ############################################################
#
# Test for Transcript and Challenge Scalar
#
# ############################################################


suite "Transcript Tests":

test "Transcript Testing with different challenge scalars to test randomness":
Expand Down
29 changes: 29 additions & 0 deletions tests/t_ethereum_verkle_ipa_test_helper.nim
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,35 @@ func getDegreeOfPoly*(res: var int, p: openArray[Fr]) =
else:
res = -1


###################################################################
##
##
## Test Vector for Incorrect Deserialization 1
##
## (Length is bigger than the Field Size)
##
##
###################################################################

const serializedProof1* : string = "0x323041383230303130623231376132423730416230313038373843383130393732304138323030313062323137613242373041623031303837384338313039373230413832303031306232313761324237304162303130383738433831303937323041383230303130623231376132423730416230313038373843383130393732304138323030313062323137613242373041623031303837384338313039373230413832303031306232313761324237304162303130383738433831303937323041383230303130623231376132423730416230313038373843383130393732304138323030313062323137613242373041623031303837384338313039373230413832303031306232313761324237304162303130383738433831303937323041383230303130623231376132423730416230313038373843383130393732304138323030313062323137613242373041623031303837384338313039373230413832303031306232313761324237304162303130383738433831303937323041383230303130623231376132423730416230313038373843383130393732304138323030313062323137613242373041623031303837384338313039373230413832303031306232313761324237304162303130383738433831303937323041383230303130623231376132423730416230313038373843383130393730323031303031313131303230423031303032303131303032323232303030303030303030303030303030303030303030303030303030303030303030303030"

###################################################################
##
##
## Test Vector for Incorrect Deserialization 2
##
## (Scalars that are of invalid length)
##
##
###################################################################

const serializedProofs2*: array[3, string] = [
"0x",
"0x37375a3130316332313032313063373239305a31313237313731323063303230",
"0x4f53588244efaf07a370ee3f9c467f933eed360d4fbf7a19dfc8bc49b67df4711bf1d0a720717cd6a8c75f1a668cb7cbdd63b48c676b89a7aee4298e71bd7f4013d7657146aa9736817da47051ed6a45fc7b5a61d00eb23e5df82a7f285cc10e67d444e91618465ca68d8ae4f2c916d1942201b7e2aae491ef0f809867d00e83468fb7f9af9b42ede76c1e90d89dd789ff22eb09e8b1d062d8a58b6f88b3cbe80136fc68331178cd45a1df9496ded092d976911b5244b85bc3de41e844ec194256b39aeee4ea55538a36139211e9910ad6b7a74e75d45b869d0a67aa4bf600930a5f760dfb8e4df9938d1f47b743d71c78ba8585e3b80aba26d24b1f50b36fa1458e79d54c05f58049245392bc3e2b5c5f9a1b99d43ed112ca82b201fb143d401741713188e47f1d6682b0bf496a5d4182836121efff0fd3b030fc6bfb5e21d6314a200963fe75cb856d444a813426b2084dfdc49dca2e649cb9da8bcb47859a4c629e97898e3547c591e39764110a224150d579c33fb74fa5eb96427036899c04154feab5344873d36a53a5baefd78c132be419f3f3a8dd8f60f72eb78dd5f43c53226f5ceb68947da3e19a750d760fb31fa8d4c7f53bfef11c4b89158aa56b1f4395430e16a3128f88e234ce1df7ef865f2d2c4975e8c82225f578310c31fd41d265fd530cbfa2b8895b228a510b806c31dff3b1fa5c08bffad443d567ed0e628febdd22775776e0cc9cebcaea9c6df9279a5d91dd0ee5e7a0434e989a160005321c97026cb559f71db23360105460d959bcdf74bee22c4ad8805a1d497507FF"
]

###################################################################
##
##
Expand Down

0 comments on commit dbd2630

Please sign in to comment.