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

add: IPA Serde roundtrip test #418

Merged
merged 3 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/t_ethereum_verkle_ipa_primitives.nim
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,27 @@ suite "IPA proof tests":

testIPAProofInDomain()

test "IPAProof Serialization and Deserialization":
proc testIPAProofSerDe() =

## Pull a valid IPAProof from a valid hex test vector as used in Go-IPA https://github.com/crate-crypto/go-ipa/blob/b1e8a79/ipa/ipa_test.go#L128
var validIPAProof_bytes {.noInit.}: EthVerkleIpaProofBytes
validIPAProof_bytes.fromHex(validIPAProof)

# Deserialize it into the IPAProof type
var ipa_proof {.noInit.}: IpaProof[8, EC_TwEdw_Aff[Fp[Banderwagon]], Fr[Banderwagon]]
let s1 = ipa_proof.deserialize(validIPAProof_bytes)
doAssert s1 == cttEthVerkleIpa_Success, "Failed to deserialize IPA Proof"

## Serialize the IPAProof type in to a serialize IPAProof byte array
var validIPAproof_bytes2 {.noInit} : EthVerkleIpaProofBytes
validIPAproof_bytes2.serialize(ipa_proof)
doAssert validIPAproof_bytes2.toHex() == validIPAProof, "Error in the IPAProof serialization!\n" & (block:
" expected: " & validIPAProof & "\n" &
" computed: " & validIPAproof_bytes2.toHex()
)
testIPAProofSerDe()

test "Test for IPA proof consistency":
proc testIPAProofConsistency()=
# Common setup
Expand Down
10 changes: 10 additions & 0 deletions tests/t_ethereum_verkle_ipa_test_helper.nim
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ const IPAEvaluationPoint*: int = 13
const IPAEvaluationResultFr*: string = "0x000000000000000000000000000000000000000000000000000000000000000e"
const IPASerializedProofVec*: string = "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d3e383cf2ca36482707617daf4230f2261cff2abeb98a7d1e139cf386970f7a67cea4e0dcf8c437e5cd9852d95613a255ef625412a3ac7fb1a0d27227a32a7c1292f14b7c189f033c91217f02b34c7832958afc7ae3bb498b29ca08277dc60d1c53bb5f07280c16238a7f99c059cbbdbbc933bef4b74d604721a09b526aac1751a4bdf0df2d303418e7e5642ac4aacc730625514c87a4bcce5369cc4c1e1d2a1ee9125e09db763e7d99fa857928fabeb94ba822d5cf1cc8f5be372683ee7089082c0ca302a243f0124cc25319d069e0c689f03e4cb32e266fffd4b8c9a5e1cb2c708dc7960531ecea4331e376d7f6604228fc0606a08bda95ee3350c8bca83f37b23160af7bae3db95f0c66ed4535fc5397b43dcdc1d09c1e3a0376a6705d916d96cb64feb47d00ebf1ddbad7eaf3b5d8c381d31098c5c8a909793bd6063c2f0450320af78de387938261eba3e984271f31c3f71a55b33631b90505f8209b384aa55feb1c1c72a5e2abce15f24eb18715a309f5517ac3079c64c8ff157d3e35d5bad17b86f9599b1e34f1f4b7c6600a83913261645a0811fba0ad1ed104fe0c"

#######################################################################
##
##
## Test Vector for Valid IPAProof Hex
##
##
#######################################################################

const validIPAProof*: string = "0x273395a8febdaed38e94c3d874e99c911a47dd84616d54c55021d5c4131b507e46a4ec2c7e82b77ec2f533994c91ca7edaef212c666a1169b29c323eabb0cf690e0146638d0e2d543f81da4bd597bf3013e1663f340a8f87b845495598d0a3951590b6417f868edaeb3424ff174901d1185a53a3ee127fb7be0af42dda44bf992885bde279ef821a298087717ef3f2b78b2ede7f5d2ea1b60a4195de86a530eb247fd7e456012ae9a070c61635e55d1b7a340dfab8dae991d6273d099d9552815434cc1ba7bcdae341cf7928c6f25102370bdf4b26aad3af654d9dff4b3735661db3177342de5aad774a59d3e1b12754aee641d5f9cd1ecd2751471b308d2d8410add1c9fcc5a2b7371259f0538270832a98d18151f653efbc60895fab8be9650510449081626b5cd24671d1a3253487d44f589c2ff0da3557e307e520cf4e0054bbf8bdffaa24b7e4cce5092ccae5a08281ee24758374f4e65f126cacce64051905b5e2038060ad399c69ca6cb1d596d7c9cb5e161c7dcddc1a7ad62660dd4a5f69b31229b80e6b3df520714e4ea2b5896ebd48d14c7455e91c1ecf4acc5ffb36937c49413b7d1005dd6efbd526f5af5d61131ca3fcdae1218ce81c75e62b39100ec7f474b48a2bee6cef453fa1bc3db95c7c6575bc2d5927cbf7413181ac905766a4038a7b422a8ef2bf7b5059b5c546c19a33c1049482b9a9093f864913ca82290decf6e9a65bf3f66bc3ba4a8ed17b56d890a83bcbe74435a42499dec115"

#######################################################################
##
##
Expand Down
Loading