From 98e028a1841d1e971f7d7736e5cf32dfb5fb3983 Mon Sep 17 00:00:00 2001 From: Pablo Deymonnaz Date: Mon, 30 Oct 2023 15:16:28 -0300 Subject: [PATCH] Deserialize proof in solidity (#53) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * deserialization of opening proof * improving error return in deserializeOpeningProof * changes in test_deserialize_opening_proof * small changes * Demo verifier eth test deserialize (#57) * Added rmp serialization * Better test for deser * Refactor, cleared some code * Formatting * Removed unused circuit_gen * WIP Deserialize URS * WIP URS deserialization * Fixed deser, added test * Added comments' * Implemented pow for base field * Removed unnecesary log * Added FFT * Fix fft * WIP generating basis * Finish iFFT * Finished calculate_lagrange_bases * Implemented inv for field * Refactor xgcd * Fixed lagrange_base nested arrays problem * WIP Iterative FFT * Finished iterative FFT * Fixed circular dependency --------- Co-authored-by: Pablo Deymonnaz Co-authored-by: Estéfano Bargas --- demo/circuit_gen/Cargo.lock | 2 + demo/circuit_gen/Cargo.toml | 2 + demo/circuit_gen/opening_proof.json | 4 + demo/circuit_gen/opening_proof.mpk | 1 + demo/circuit_gen/proof.json | 176 ++-- demo/circuit_gen/src/main.rs | 24 +- demo/circuit_gen/urs.json | 37 + demo/circuit_gen/urs.mpk | Bin 0 -> 1126 bytes demo/circuit_gen/verifier_index.json | 32 +- demo/eth_verifier/circuit_gen/.gitignore | 1 - demo/eth_verifier/circuit_gen/Cargo.lock | 944 ------------------ demo/eth_verifier/circuit_gen/Cargo.toml | 19 - demo/eth_verifier/circuit_gen/src/main.rs | 82 -- demo/eth_verifier/proof.json | 502 ---------- demo/eth_verifier/src/BN254.sol | 6 +- demo/eth_verifier/src/Commitment.sol | 44 +- demo/eth_verifier/src/Fields.sol | 157 ++- demo/eth_verifier/src/Utils.sol | 191 +++- demo/eth_verifier/src/UtilsExternal.sol | 59 ++ demo/eth_verifier/src/Verifier.sol | 77 +- demo/eth_verifier/src/VerifierIndex.sol | 7 +- demo/eth_verifier/src/msgpack/Deserialize.sol | 126 +++ demo/eth_verifier/test/BN254.t.sol | 17 + demo/eth_verifier/test/Deserialize.t.sol | 183 ++++ demo/eth_verifier/test/Integration.t.sol | 21 + demo/eth_verifier/test/Verifier.t.sol | 97 +- demo/eth_verifier/verifier_index.json | 195 ---- 27 files changed, 1076 insertions(+), 1930 deletions(-) create mode 100644 demo/circuit_gen/opening_proof.json create mode 100644 demo/circuit_gen/opening_proof.mpk create mode 100644 demo/circuit_gen/urs.json create mode 100644 demo/circuit_gen/urs.mpk delete mode 100644 demo/eth_verifier/circuit_gen/.gitignore delete mode 100644 demo/eth_verifier/circuit_gen/Cargo.lock delete mode 100644 demo/eth_verifier/circuit_gen/Cargo.toml delete mode 100644 demo/eth_verifier/circuit_gen/src/main.rs delete mode 100644 demo/eth_verifier/proof.json create mode 100644 demo/eth_verifier/src/UtilsExternal.sol create mode 100644 demo/eth_verifier/src/msgpack/Deserialize.sol create mode 100644 demo/eth_verifier/test/BN254.t.sol create mode 100644 demo/eth_verifier/test/Deserialize.t.sol create mode 100644 demo/eth_verifier/test/Integration.t.sol delete mode 100644 demo/eth_verifier/verifier_index.json diff --git a/demo/circuit_gen/Cargo.lock b/demo/circuit_gen/Cargo.lock index b187ec4b..c250bcab 100644 --- a/demo/circuit_gen/Cargo.lock +++ b/demo/circuit_gen/Cargo.lock @@ -181,11 +181,13 @@ dependencies = [ "ark-ec", "ark-ff", "ark-poly", + "ark-serialize", "kimchi", "num-bigint", "num-traits", "rand", "rand_core", + "rmp-serde", "serde", "serde_json", ] diff --git a/demo/circuit_gen/Cargo.toml b/demo/circuit_gen/Cargo.toml index ed36ba12..fc7c9d8b 100644 --- a/demo/circuit_gen/Cargo.toml +++ b/demo/circuit_gen/Cargo.toml @@ -11,9 +11,11 @@ num-traits = "0.2" ark-ff = { version = "0.3.0", features = [ "parallel", "asm" ] } ark-ec = { version = "0.3.0", features = [ "parallel" ] } ark-poly = { version = "0.3.0", features = [ "parallel" ] } +ark-serialize = "0.3.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" num-bigint = "0.4.3" ark-bn254 = "0.3.0" rand = "0.8.0" rand_core = "0.6.3" +rmp-serde = "1.1.2" diff --git a/demo/circuit_gen/opening_proof.json b/demo/circuit_gen/opening_proof.json new file mode 100644 index 00000000..1ad727a2 --- /dev/null +++ b/demo/circuit_gen/opening_proof.json @@ -0,0 +1,4 @@ +{ + "quotient": "a5a3ad49d6784ac81e6da0a2cb147038f4ce4b98e8a22c862bbba2854f87da0b", + "blinding": "138a93e53cf407225b1ee3da019c79d58b5c0597089e9fdf411102ce28365613" +} \ No newline at end of file diff --git a/demo/circuit_gen/opening_proof.mpk b/demo/circuit_gen/opening_proof.mpk new file mode 100644 index 00000000..1f3c60c3 --- /dev/null +++ b/demo/circuit_gen/opening_proof.mpk @@ -0,0 +1 @@ +�� ���I�xJ�m���p8��K��,�+���O�� � ���<�"[���yՋ\����A�(6V \ No newline at end of file diff --git a/demo/circuit_gen/proof.json b/demo/circuit_gen/proof.json index 86f0a60b..6d6c202e 100644 --- a/demo/circuit_gen/proof.json +++ b/demo/circuit_gen/proof.json @@ -3,118 +3,118 @@ "w_comm": [ { "unshifted": [ - "5e483425f08687bf4e88cb9c190ae3363ffea3e06c1b21c7797fcb98b323d209" + "2909277cb795efc96cd426b4f89cfaa07523446764a9f56b9f761d3bdfde199d" ], "shifted": null }, { "unshifted": [ - "7b41ec5110d7de72e1aebecae0fc73f343d8687d5d5140d0c8c218c34e7b7c9c" + "88a7d1c1762f3fe2fc15550ba901b47b372033d9ce64e0dffe57837fb10c7d8f" ], "shifted": null }, { "unshifted": [ - "5901db7b19a79635e911e67bdea815a25f9c744d06a45ebd92c5da6957caab85" + "b1c4d71ee661b950dd783950179cc13404e688ae5ea3ddb399a857f941a47f07" ], "shifted": null }, { "unshifted": [ - "3a332e7c36c698ba1c2b81765ebe66b336dae3d86b1dec73d19a2bd6b043348e" + "82304186b2d1f094d7c9e54df353ccecbbc1b323419ef603e6223f16e7af52a8" ], "shifted": null }, { "unshifted": [ - "d63c8ad8184df11c9af78d58a5a30750e96cf91584398514e4b4bc8a956de1a9" + "f2820f13575b16533f82bd42ea6187dab347212bd64c0586dd8129e830d4c61e" ], "shifted": null }, { "unshifted": [ - "9debbc515820c3f1436e6c55c0f52af3ecae383e5e8afc74cb4bc989e24ef712" + "e15507ef7ec0f1006ce0b70425ed69d1bbbddb9c8b6bc0a655a6d0bc51aacc24" ], "shifted": null }, { "unshifted": [ - "15b1e757b3e948902f80b9bca4332949afe270c8cf6c10e248a5200f64eca71d" + "deae4dc87578cb7c1a22357e43184da0cc91e1dc6fdc307e57482baac31e488d" ], "shifted": null }, { "unshifted": [ - "2cc6c45e95e6689bac4211c202f88d56f8391ba9ff206149d83e59fbfd5f338b" + "1270b02e30baefa8f02053ada8eaf474d3dbccae7d7479f0e39fa24f5378fe83" ], "shifted": null }, { "unshifted": [ - "c274b88415b63138d1ac3b958646a4fa495f18ab70f92a568df1edbbba7d6b10" + "0be91a612ca997d337c3e409c9bc4cda6317474f786bda6822ee995889feac89" ], "shifted": null }, { "unshifted": [ - "da909683108e9c80074dd138dd11a890762adf8ccca4fb1607c7716dd287a894" + "c940e709981ee285d357bc57b79c0ce0c8769cda78f26a2b1729ddc6a1586a89" ], "shifted": null }, { "unshifted": [ - "0e17a91e65bef2fc38208cb93bfc1ab582615e430df389f773a06780edacdd9e" + "47a87e44f83622e3b258086f4b818015c5a684cbaf781beceee15fa51beefe0e" ], "shifted": null }, { "unshifted": [ - "a71a426dcc194a16f860828caa66c18709a0861bb5fe83ff2dd13706fa3e2d16" + "05426a3b80f024c3b54fad165c8b720e0ecffcdf565a81d918ef40f1ae8b629d" ], "shifted": null }, { "unshifted": [ - "e55921d849f075ddb6443f70194c05a302f7538bc1fbcc47c4830b00ad561486" + "613494bbb5194680b2671c03e4047327b2116ab58f6b861e93c201f081d46f29" ], "shifted": null }, { "unshifted": [ - "6c7ae807364b8931454ba2d8afcc3a2c7feaed0670dca8745f7ef717fa32379e" + "1761868d3eb5ac2c4103be805acbff107728e184b0ac87f7abda9066c3390e07" ], "shifted": null }, { "unshifted": [ - "7aed1a79765bbece3985d376ce2fecd0c36c7d366769deb705490058e9d60429" + "1da261bbd3b8e662e9b180cd33e6efdbe99aceffdfc1739cbda9e6a2132b2215" ], "shifted": null } ], "z_comm": { "unshifted": [ - "03ba6230beaf0eea8664d5cf83427b5c6a87ceaa580489970340f88f45793823" + "7bc0d70c5e12e2e2fc0eb2fd03ca98e31f66cce35cf37b0b3c8a40c3502de109" ], "shifted": null }, "t_comm": { "unshifted": [ - "0a99829518275c7b8c3f35e736a4924f58e2e14fdaecfcc3c490f2ed028ff0a7", - "694e879c0c388653d8782d3d969304e848a7418200652e2e5aeee226b9ffe1a2", - "682559bcb3b55606bec102aed0cab8d0d967ca3f34d30b3bc43c774bed6d2e2f", - "21225ad3c9e176ca1a4faac15b5f99cbef632c554b4af1be6fdcc7bdfdb86223", - "f9af960841f7c23fc0db2bf4b257553c226fdf58d933f709ecb995c21d65d597", - "16859898929333aa1095c5638a459a0c8b4698783a2f8672c88e5fdb6a9b5588", - "e454d8c899094342d73affe240bb4df2294806165ffc247577555023e93f1609" + "d0dad6d7c55c418b159d7ddad2b350a2c2603441920db0b0c790739d4d42eb81", + "78b954f394bb7d473216de23b86a17d478a59ab528ddbbdf73f6d29c2038ec22", + "78e676e460641443e12708be255e31f2aba0ccc53c56b50566ce87a42df89daa", + "35184919f31c053c9a1886766574df45c18be0ab098c722917adaa516b78e600", + "4d84da8a7564007beb9ceae6966d2d68756015745b7646bd32ce730bbb25d01c", + "bb5128b23b69310ea0b66a804e1f520e71190c2196e3c3bb2c7478da0b751107", + "77725f73b5acfd6e2e85686f9f265d9f910520cf6616bafa562c8bbc6b20821a" ], "shifted": null }, "lookup": null }, "proof": { - "quotient": "9262c9b9e59e64e6e00efdb4dec1ec531914554fc9b60da27ceae9b414e5e018", - "blinding": "999e77318f489b4c48f7d58cddf2486f8b45df3a492b90e7622d613cb709b703" + "quotient": "a5a3ad49d6784ac81e6da0a2cb147038f4ce4b98e8a22c862bbba2854f87da0b", + "blinding": "138a93e53cf407225b1ee3da019c79d58b5c0597089e9fdf411102ce28365613" }, "evals": { "public": { @@ -128,206 +128,206 @@ "w": [ { "zeta": [ - "97c742032d7528df86309b24c9ad84914e7de33866d42ae3602582b05dc85509" + "48ea3ed27a1da76698d0a090a9473ccc458693283cc332f9351059977af4782b" ], "zeta_omega": [ - "dd3560e8623f267b0d26f70c7dde9365c525384bbdd4587db4f2ecff1868a21f" + "5912dc9c0f6a7b051aeddbf604e0ff7ae497c1d03a06b586dc40ed241165fd1c" ] }, { "zeta": [ - "f71e843c0c87053cf6a7d3c9ef7ea002a90b6db113e6187dcf2896317d0e7d28" + "06c1a7a24d297724faba3770a23333122b5bd609688b657353b67b7aee3ca815" ], "zeta_omega": [ - "703827ff16caa92c8e84357de9dccce2bb478668a9c08961e9fb82e4213b2c17" + "d3d0feebc09971d2bb8e6bc159cfccb8eeca804db6026f7581c8353c6355af0c" ] }, { "zeta": [ - "c4ede8afd7560b5a9cb7957c7660186d2702b840ef68794c6e0fe1259373b70f" + "1491f75193b1b2432b9a8c7ad90e9b8fba98316c52c87fcb200a561c9be94a14" ], "zeta_omega": [ - "e2a2ebd899a618f1bfe4bb9386c9332ac1b61f284c82ead081c214dc45f5e20c" + "cef69ce3c860667c74350c1c58572da5de6a40328a4c5a9d6aa6f1f319b05e23" ] }, { "zeta": [ - "abb68e57681b1db449fc19b61a2e80ccf5c05cd62e789d981ce7d466a9e7870f" + "b634fdccadc39f3d2284d7fde4b44ca67bbf8731158f3e10f9904f3ceec9a22e" ], "zeta_omega": [ - "a580dae2cc0522f2b0481259a58556ce730cd2a96971820db9d64c322281bc08" + "3d9e66f3e311a794d4ebbbc8c2e9ad5aa4529052007ce1472a302b41b96b5408" ] }, { "zeta": [ - "c75903b776e7b07a03dd85db780f551306e055acbb0f5d167c993cf1bd66f512" + "2abe192824cb02d997a635ed99f4c1dcc66f8f2aeca4456f71182fdd9f54ae12" ], "zeta_omega": [ - "725e4161578d51a79d3731a321ba69c1e8b21f43f8a2177b59996c3e3eae9a02" + "4b24473ea1121fd156103fdfaafa39eee745db8455c40607021f18a8024a6525" ] }, { "zeta": [ - "0d7aee8fb212c9b9eb951c31838ae8f9455fcfa2dea8ccea8802c41748bad529" + "c08604943f94ea4584a572df1e64acc303c96ffb22592a4749086a782a1a482b" ], "zeta_omega": [ - "705226ca2b20f68b7568799e65d1f78f4415bf0c64f88189a5ea3e16a370ab12" + "2a39d5c21d2f69514b0b3de591673f0dd88d36712c0997c4cecbb167079f9327" ] }, { "zeta": [ - "17dc554411276e15247ebeeaef2f44505804d6855ff6f1f9152512df5392561b" + "9827f749eb42339b3739da7aa3b9b596191ab218e35e119ba6cab3ac3ac0ee01" ], "zeta_omega": [ - "1b2724b5e8b93b040e3b38d4a8149c7841619298eea13f27c7e5dbc960c18c16" + "0cf233c37cb670de4eae2bc70603d6a5f31ebb2135bdc986d1b5b2d768a1c80e" ] }, { "zeta": [ - "002db958840a494244e5a0d20eca0f740bb59d8c63e0b26d7308663956939520" + "640b475434507047c436b1d651dd9b2d01c23795795ace49ae9e63531e059b03" ], "zeta_omega": [ - "783e1a908480b8043b40592bd13ac209a9b39719ee07232985e5916e36125707" + "0fdaaae263f8a5db4d3adf665aba2feea161590d57f58585790f52fc39de1524" ] }, { "zeta": [ - "c3babe71ad08e313a6251f460fb122cecff73f4ff7f94d7d42fde1c5c294ad03" + "0724237296fdc3279682531ffa0e7e1a4264ae567f767c8c7155181f7123e410" ], "zeta_omega": [ - "3ea5007f3bad0a55c5c027cf2293c5bc503ea3577967845deb7556994f850b26" + "2bfecb4751215d2c37021d3486717fa9f1e5f6a4491e3d121a84b24f1dc5ba17" ] }, { "zeta": [ - "7c1f87e4a9206778ac32959e7fa19a3ed878412dddabe6fa41ee25c9522fee02" + "c42b974abc8577afd08cfa2fb367d7560d718f721c8b95815098993af2bec001" ], "zeta_omega": [ - "9dbd8b22c59511d36e658116a1c7afefb9233630ff7c8b04cb01051c1af51b0e" + "ca4a69e2b4cd6fefbb0b0f7907d56e0137e19b0c35a912afc79e300d60181026" ] }, { "zeta": [ - "ee675fe48ba52e1e3cc2289823c491b0d1b7c12f8b7c82ea6167bd964e6d2f12" + "173aaa6fe4fa6cc7c33009a4890b169ae140b49c5d3c9ac7cf4fe0837bc4d422" ], "zeta_omega": [ - "4e455abfea5ed3651571762757771282448e7cdb11a3b44be550b87fabddbc14" + "bb34ee1905499b0a816ed32c1e7fe5e52e10f0c3ae05244311293f2c18596f07" ] }, { "zeta": [ - "8461f9720b7082fb52be0df1476bda8110ddb5e982050ae40bf8e6bed23f580a" + "147759affeb7fd04ffa2bec9c1ee7cde04ff68c13ddfeb36de3d79ad49a6e20c" ], "zeta_omega": [ - "828e181fcc2ebc0c1dcda7995a3c3bf8649d525ccad6fd719a5eecaf48bd2005" + "a5c15b5c8c7389a7352840e789b8e2a14222df380de598c26d87abf91182cc1b" ] }, { "zeta": [ - "70ced98a3f52f041667d68e4ea536b1186380cb685bd2a5211c51af1766f1812" + "67a90e7f3acd1272276773bb743645fe278b95ecd04a36314396977b3d7ebe0f" ], "zeta_omega": [ - "054a6c1e90a035b45cee53c7874ef863386930a18c6eeffd8ec7d4ec4ba99206" + "ec2b75c0391663b640a7cb6c196d0db1813855873770b33900338dd123403c1a" ] }, { "zeta": [ - "33a5f4fe1adf576894acd25c45038c805ee6bec1e572d306aa225689ed5de21e" + "544171dfb731a82cc1a071c7187643e47e15ef14d54c82573b61eb64f095150a" ], "zeta_omega": [ - "de9602e6f3be5807ffabe49d7aa1be62893818520bbad2763b5b4708a7a6ad0a" + "8eda49b23e9d28ab699ce078957f9d205295c202848f54ebb2c0501d1859720a" ] }, { "zeta": [ - "17b105f6573e8cf6a070fa0147ca046a03714679502efb1f2f06e6a098dfa410" + "0d314bc731103e9407d8d683991105bfb3a63573c753d1373ed13f82ffd4b827" ], "zeta_omega": [ - "b503414606161651383e4b63ce6e992b23368fe5a3788bb2308c33bf25714620" + "505041122b12bb501df8d823da36b6700f425b148a735360c3afc0520e368f0f" ] } ], "z": { "zeta": [ - "445f63b10e1c19dc6b4b89b464c7185e264b4adb69aef900b6da1e71e08bb41a" + "704f1782d3616c597964f9863483428c868b42529ae6ec59682fbf4ccefc6b29" ], "zeta_omega": [ - "b8ea8cf6ada26317d7c357d10d050fd59a7f9d6bc84fdf44d0aba0cf9a21cd16" + "c79b173370cd76266b26f4d07cf9816a628c40767ef4c98f0aa7db6b05a7ce0a" ] }, "s": [ { "zeta": [ - "f934ca901de3c79b3e6e40e741196c87d609a4aa5f419dbeaf2e3bcdd7897223" + "9eb07c2a6b6bb04df9ec7e29d99a1acbc6e08e1488e4a7c5cb37726f07b4af2c" ], "zeta_omega": [ - "a7366c8543f8d22e4c12bdc43af2411031cb5e9e291fd1fea495d029f7043512" + "7a2e1d7a57ac12d0bd2887b02b0d6c62cb09d96ba771735b846c051953c21302" ] }, { "zeta": [ - "7001d9e61d1635d71edc8cbd12ea5edef3f66585ca83e825cfd51a61e7b85816" + "bfcf9deb04bada3e5d50aa223567b0b2b98a780f3add62ea25221f96d9421910" ], "zeta_omega": [ - "c3dc23cac34303f805565bec68c465d59795caf8c88363c3f6e8fc4c90cd3c0c" + "af4d46324bcc2bf57a0d0ae5b3612cfffde2c2b64c6314a0234f64fefbc1c516" ] }, { "zeta": [ - "773a66ffb177cd91fa3ec83e205ef5b55d2f2e6ddcd7f486ea61067f4200cc25" + "4362080c76a26ebc1ac7d4346c1291ef880a22c4a177b20e32bf2ff351558713" ], "zeta_omega": [ - "a601b3485e6d54561492aac9d3ce4ce083c2603b9d37411042698cc8e8add719" + "125a2ad0ae1a8024697b75d4fa2ade0d183b17d401f872797fd9e525f943f811" ] }, { "zeta": [ - "e853cec2c9c70a1ea4ea728f0290b7b9e3ab065668034936b967a634d3574a1d" + "49cfb1d219bff3787f7bcdc60cbd61a0a26b30196d736612775314fbed0fa700" ], "zeta_omega": [ - "2122699c84d7f8ef849ae080d1c6fbda03d68bf72c6462b181f66569a6104c1d" + "dca3503971d427b0774abd962636dabad8ca264c757cd84de8bccad58b423d21" ] }, { "zeta": [ - "560f0a8669643500fe265ffa3c3aeb69ff94784cdb678a1bf1a89bdbabc86003" + "6b92ce19a1ccc70a4a99c6f35a2608ba5b7bbc74c4f41dec347c4f6e35cbf60b" ], "zeta_omega": [ - "e47bfa7daa768b491c4b6c1f0ea4d0d0af878f31dfc8bd1c951cb8a9e0ec1d13" + "dc06bd28ef5995175d39f7b8842550eda684fae1aa54ab0c444c143426f1d324" ] }, { "zeta": [ - "9b3cf41390353c2c78d2dd3a0d4131a535bcc71376800e8eaaf36ce188478427" + "6cc07815722f1e33ff6b6884b0fcec4549ef368382c8dd4c4c5ce7daeb519d0b" ], "zeta_omega": [ - "c58c8c11fb4e08cd9d75e814ea9c4ca56b3f7db8c782194f2d2996d6f9e0940b" + "6a463020b3621beaf70b14c096ed3ecc016a0a9f0b5be3a50521d85a48516e22" ] } ], "coefficients": [ { "zeta": [ - "e733b5e65f295dea13c4d3a635f7ddf7523c6cc2042445232e9fc15e147adf29" + "c427c8ca533443d74167a763225d529c4f020dbf0678435b076d7d8ad82ac01a" ], "zeta_omega": [ - "05c300309b78e589fa5eb71705c19c39535d6d24344933b3d7aec8cc1ebb700d" + "7045cb48fe0c11e7b7eda81fa288f7abcb215e1f5aa3ae2ce1bdecc48cb4451d" ] }, { "zeta": [ - "b72a7978ccafb9910d7dae6c7eff02f71970c57a8787f885988e7b409fd9ee09" + "0cae699108a2fd1b631c5051f7346392cd3fa775476bcbf90a09afa31eacc903" ], "zeta_omega": [ - "da173ba5ebae94d855fd68529c84ae906ab74d52b695260433cf9226a4d00803" + "da966bf7eb93fe2f6c841f8b93272a5ddc623615f15b329cd775f4ba1ca1e80e" ] }, { "zeta": [ - "19478222c913aefc06cc96d7b045cc1de06a14d8a1568da39390a2801741f31c" + "fdc5dc1491bfe28fc511f4b3a0d612a21843f404f421b70f269d4c551315212f" ], "zeta_omega": [ - "634decb89a105ba6747196b369114f4de4c5bc10cf13eeb6185bab293c5e612f" + "0d23dc528d20a106b74e33fae6eaad4380fc182497f809b470631462c739290b" ] }, { @@ -340,18 +340,18 @@ }, { "zeta": [ - "058f59946814489e85825fe5b6d2048838c404b89cec19458b91cbc7ba567d1d" + "c236111135f0f71dc0c7cc1921eed30d99e9823ba08ea15848029ac67ac85114" ], "zeta_omega": [ - "ccce3805ae3ac67ef750fc84d5290c0ccef78666d0ffdca2d5626aa1baed1a0b" + "8cc609fd18588f02679c971f3e5eaba933ae1eba4ffdc686877c912e5c20e017" ] }, { "zeta": [ - "ff7a3719954729a3891fb1049e5476edd54eff18f034820e988f32feb86c6e16" + "c0eda4ef50fe43237608e29d7a4b31160bed7f424454aab2036a98fe78f17c19" ], "zeta_omega": [ - "6710edf8a1935eecdd5f945126eab75edacaa8b34c17d1b1c6694215e8ca6d0c" + "7d68a79b8b2db2ed6e3cdc198973a5ef4b1e7743f19bb8e05121012754ee6e28" ] }, { @@ -364,26 +364,26 @@ }, { "zeta": [ - "19478222c913aefc06cc96d7b045cc1de06a14d8a1568da39390a2801741f31c" + "fdc5dc1491bfe28fc511f4b3a0d612a21843f404f421b70f269d4c551315212f" ], "zeta_omega": [ - "634decb89a105ba6747196b369114f4de4c5bc10cf13eeb6185bab293c5e612f" + "0d23dc528d20a106b74e33fae6eaad4380fc182497f809b470631462c739290b" ] }, { "zeta": [ - "d071fb9a95c3678e144945442f45cf14fadad95229de85292c1f1ec1b61ae226" + "087446b6056cfe6797bd8a8b4f23420c892a1af9844732510706ca17bf728602" ], "zeta_omega": [ - "3c65276ef2c90d3b39fe458cbdadc9b5f12489e1ce63c402228a0c6f6de00502" + "e7b9474a79b49f3623d352857a12d8a05c5f4f3988543c5048d9081de4da111a" ] }, { "zeta": [ - "0899ea51d27ad79b03b4b655c3114cd5e97e870773c865e0841298acbbcb0421" + "435bc72127e9511b6527c257743fa509e0670438ce2b9dab6ace9aaafb33bc11" ], "zeta_omega": [ - "ffad5e03fe08ebe9cc018d5bd13dd07676bab680ed168bf7712f17585da6a322" + "94f5baa529e8eeaeab0452dfbc47c81a56223336da50f635377af2a299e0ca27" ] }, { @@ -429,10 +429,10 @@ ], "generic_selector": { "zeta": [ - "e733b5e65f295dea13c4d3a635f7ddf7523c6cc2042445232e9fc15e147adf29" + "c427c8ca533443d74167a763225d529c4f020dbf0678435b076d7d8ad82ac01a" ], "zeta_omega": [ - "05c300309b78e589fa5eb71705c19c39535d6d24344933b3d7aec8cc1ebb700d" + "7045cb48fe0c11e7b7eda81fa288f7abcb215e1f5aa3ae2ce1bdecc48cb4451d" ] }, "poseidon_selector": { @@ -497,6 +497,6 @@ "range_check_lookup_selector": null, "foreign_field_mul_lookup_selector": null }, - "ft_eval1": "542098672ddd106f3684e1a5bd3ecae1591d101bce3fbcb87ca41225096df90b", + "ft_eval1": "537e91d90c5e4a853c788373a658f6c34603e27067e799d41c67051307572220", "prev_challenges": [] } \ No newline at end of file diff --git a/demo/circuit_gen/src/main.rs b/demo/circuit_gen/src/main.rs index 257124cc..8396e526 100644 --- a/demo/circuit_gen/src/main.rs +++ b/demo/circuit_gen/src/main.rs @@ -68,15 +68,31 @@ fn main() { ) .unwrap(); + let verifier_index = prover_index.verifier_index(); + // Serialize into JSON file + fs::write("proof.json", serde_json::to_string_pretty(&proof).unwrap()).unwrap(); fs::write( - "proof.json", - serde_json::to_string_pretty(&proof).unwrap(), + "verifier_index.json", + serde_json::to_string_pretty(&verifier_index).unwrap(), ) .unwrap(); + + // Serialize OpeningProof into JSON and MessagePack fs::write( - "verifier_index.json", - serde_json::to_string_pretty(&prover_index.verifier_index()).unwrap(), + "opening_proof.json", + serde_json::to_string_pretty(&proof.proof).unwrap(), ) .unwrap(); + fs::write( + "opening_proof.mpk", + rmp_serde::to_vec(&proof.proof).unwrap(), + ) + .unwrap(); + + let srs = (**verifier_index.srs()).clone(); + + // Serialize URS into JSON and MessagePack + fs::write("urs.json", serde_json::to_vec(&srs.full_srs).unwrap()).unwrap(); + fs::write("urs.mpk", rmp_serde::to_vec(&srs.full_srs).unwrap()).unwrap(); } diff --git a/demo/circuit_gen/urs.json b/demo/circuit_gen/urs.json new file mode 100644 index 00000000..097393d6 --- /dev/null +++ b/demo/circuit_gen/urs.json @@ -0,0 +1,37 @@ +{ + "g": [ + "0100000000000000000000000000000000000000000000000000000000000000", + "c15287bf9a0794c64555226a3862bc1aeb39e8aad844581e723b67a802c2d200", + "1f802ae7cee777c4a9635b0d499f4c886fa6c47d4072e96cc26530d15b083d25", + "e0752a65456aa6c1ecb93a7931ff3e43199e2d4b1273401412f4c00fe8ad51a9", + "026343c3bdf37693ab62bb0dd04f4bc4f8d0a77d544a64669e27fd2e24e1ee8e", + "6c114d52b7eb6d23ae463573a8bbf0e91fd8138d340c299d12f25c4d731ce887", + "0914ebdfff8997a8501fd1b93e689aee29eae370f133ca9f88e7f88947243907", + "d539d5e716135beae185d95dc3fac0ee35bb98e1f3b7909979ceb411337fce9c", + "bc11e571a4803533c2723d024fea9aaba5d9423fae6637c94c6daf9314b46425", + "814773d414de1f50dcff758526e6877a042e51b868076b7da3c3afc4ff275401", + "2da7df893b0456968f6afb97e50ab28d5bc81869ef1d5f9988b3b6f15b2f94a5", + "3560dd9a565f91170aab5c45feb2c6a004f7278321fbed458ceb15c211b5650d", + "622ba1eff34c757f6435c8d59b15a9c771234de866c747327ded0f70845d5f86", + "1d968108e0231a433b57816f5b2c70a464ad304af31660812c40bc1a32a9ad29", + "6d56d3e821f4be962f131ac49e92213fd85a44f93aed0239fb8ba94881856da4", + "82250edc5447b67544f1c87c35f376b9deb21cd96db0463e8455c211c08d9c0c", + "7c17b9700c136bcbb900d1b6baec4a250ab12606c868c798451fe8388839592b", + "5c80a94157de865b4ec5bdf5ccabba4f94726d8e205d4cc615d89812f0085613", + "e5d7c84c36219e7d7d6d8d0febcbe10c348d3750429221a027a757c0510498a8", + "6b540f8d1ed249e0a78de276a52785c187dd05e342c1dbdfb0f9715a04d46412", + "94808425cc281bd9b8b11d2ef27b779b295c73f3214676fe060a0c385c2fd000", + "6a6406f21367cfe541348149abc113ccb8c1dc503a2da31292a883a999e53399", + "4dfaf6966cfc50183d3f3fc1bb282359cc65fa354d5aa419c24e160a64001a8c", + "f40b449f058665b6089cd1b504be10cc50020e96907f13ac1f15a05f6c026b89", + "f3279a49e71c425c2191140d24dfc297e467e2de7ba9c7d4c239442cd6b910a6", + "cce20cd27fc82bebd4ec1fd8e1fbfd8933a3fba895c540880029407569e09c25", + "f7ab0b34c1f07439f05efaadab6e167d91b318836aa6a491b2a41ff7329a30aa", + "0fd08ca2bce648b9de54892b8467aa9bf16e9b1da0141bb4e0bd8bede8b9b8a1", + "ed1baaf4e4aef12f38f6d17f169d2084ab1e5d65159cd8007bbbe88fcd5dd18b", + "7772fb08d4297019aac78dfdf8bd7a7a2c89949e6b4b9a9275a2aa34b07d0316", + "dc2ecbe23e969b204d0b4ba93cb2c18e47a9fde596e9985ed401ed8be753842d", + "5f9659cc449129d9466d720429b221532603a3bf796571716ff32ca631280e11" + ], + "h": "723737cf1cc96bb40021504a4ff45d21914e9484f2113d66545a3826919a9c25" +} diff --git a/demo/circuit_gen/urs.mpk b/demo/circuit_gen/urs.mpk new file mode 100644 index 0000000000000000000000000000000000000000..bdc2bda576a8036cb09a0e580b050e05e585a928 GIT binary patch literal 1126 zcmV-s1eyDi+yEfNAOQdX000000000000000000000000000000000000K_1{Qis2q z2b9J|RU&FQV!RsbIq0g`L|7hjJ7=f@!qNc5ARmA#=g#MM#HnLj4N0F&h;OFEeL!;Q zY{F$Q(OU>TCBz`$bt+{=YNo;LxjK0<|2{(*o-Iofb3hal^uQ13tx>7OAOd4U!@cu% zldEF84bV?Z#Q4yseN;+hW}YYgE+paZj>I5r5lvFJ>un>hMm2M&yYT5B*b|L33@M!w z@?1@G9O#F{APE%f-~Wl1s8Ao#xjtx`?kVcyaPc$BpNQx9iAN+k2gD%NIo0PD6I<%x zh1p%h`oQiryO`ngw~(26&a@FTf6ko5AiNRfaioAXGs1E`0#E9itEJgOKdxps$xLmp zlN7XMCBz_sM|0E^-XBoh|8<2X=7)L&E>XB>2Wx$!!>`2uCsYB%AT6igi8};VmXB)t zm*onwja$eVY406hnTWHt@mnvHrNkgLVBMNlUy&CIt6W9?vc{kU_a}oP`|U-H>lMNg zwPg*&AYv<_@AFJ`e`Gbt)teQm$8jS~=w`=9GJWk2aD-i7hQuHpmVpT1BN{_HSAlO^ zEO4Y`tuRXS7GQxaK)f059`a}3^a{5P(qR+peLtSz)=L4sKg*^R1b|F(n;W_jpBBtCxyX> z-38-9!Q0=k`EgnV)MOIGAe4ZFCCn%r*|@PCF7kVKn<-p#^C3od{ssyRI9xB#0K_0_ zWCrpRXV2w9G=WL0!4u55!Q4>t?S`~8VCqx-0p z#XyJvDL{2;;G8AIAor^aG{Nw6Iq+Wkt*dSpeUY;mgKDOvk+P&8_cEF=s>C1<(2SzI z=195TREaBuXR4d=ZkrvT6dSbQy^HPWxwxUkAnhBf^yIGbFF5wme-@n}gsUE1Wfh#* z0DHUWkIh}ti^L#za{CC>DR3F8$Bq5?y?S~qiIkpeOPZ2(qN+5oeFGN6Alxp?;y#v} zAWaKPsXVg5jz_8e<(BD~Uep2Yi|12>EyN&SmRZb1ktx|mZE^%DvLRC@1EarrWpQzD s^DL$@C=LB7%A(2j$gz^zRW>i`@CXt$)CAX9h*#H0l literal 0 HcmV?d00001 diff --git a/demo/circuit_gen/verifier_index.json b/demo/circuit_gen/verifier_index.json index 8e0d07b2..282fa63f 100644 --- a/demo/circuit_gen/verifier_index.json +++ b/demo/circuit_gen/verifier_index.json @@ -7,43 +7,43 @@ "sigma_comm": [ { "unshifted": [ - "ab072d9912cc6cece112c817a0ce57f1265024821ba7c40fa01b280a84d33e2f" + "c15287bf9a0794c64555226a3862bc1aeb39e8aad844581e723b67a802c2d200" ], "shifted": null }, { "unshifted": [ - "82c7744bc5a7d9c589de3a7175fcce0c9ee5de3d6c756d2ba10d0ddfef894f97" + "2a9a2958a6535e5a26afb56c1b3233d7273b7b0da51fb6153b5afdc927fdd52b" ], "shifted": null }, { "unshifted": [ - "29cf34cd431032eb8469cb89b7f0ab144280eeb7d3ab68538541ae18c8138891" + "eb6b17b21ec1995e24c59d1e63b55958c4f46a05e448f7c525bcffd5ebf4489d" ], "shifted": null }, { "unshifted": [ - "36e916e11564c6972ab10f43c68afab264b746ee4dde03236da219d0037b5a1b" + "3ec9eba0c797728d69b500dca9c1d7cdebc3fa2d2d00838e849a6a5dc958698c" ], "shifted": null }, { "unshifted": [ - "8b628e7a1588034b8966d61b2d31a139564dca934f885446e191a093b5cf4006" + "2456c4cf016229e3d0c4b83a4fd5682ea1c4be33b0f9235af360f226be9c6d84" ], "shifted": null }, { "unshifted": [ - "503a9810f73149e644a8bde47bac62c3acaf9b789a7e23da963db7316fd22a04" + "f77a54c3d9e2d43916fa678ee1f823d94513670560c4178f984967b3c85e410b" ], "shifted": null }, { "unshifted": [ - "a040ce5e98b017d31531b553bcc14977abd163a410dcdca49cf3b2f809f6b202" + "4bd85131af9afef5d44e86e8ee08cb2e79c43079c83cb87b28a89ceb864db61a" ], "shifted": null } @@ -51,19 +51,19 @@ "coefficients_comm": [ { "unshifted": [ - "9f1b384886d693ec674a693e2247f92305ab771cb3afdeb5163dad04add9db83" + "b0b4e48f2e3a036f0bb04d29069d4740a7010700d3db35be4b08cc0adae1f71b" ], "shifted": null }, { "unshifted": [ - "1d715571095dae8ef8e332fe576e3cdfae7dbbe9dcb93c77f6ee389a09397a06" + "9baf244fbaad16ce3a6af71f77dc5a05e3c01fa1b2c609a9736e5e6a8c0e5ca1" ], "shifted": null }, { "unshifted": [ - "7c8300015f6710d4cfb9dd8e6f681d7eb659bbf939862779e00a81a6fe816d99" + "2e150d1fa7abbb6545d34bc31452d83d2197d4a216e5dea6fd38baf4cd1f5d29" ], "shifted": null }, @@ -75,13 +75,13 @@ }, { "unshifted": [ - "e0cfbaf6f6785e9960860f7dbab6ac2b73a53ff12a1a327b40684415005b328d" + "3eb7153e5aad8f8bfda559866c3e269f0841d4ae77c0882e918636118db36c0f" ], "shifted": null }, { "unshifted": [ - "c9e887d26a71b1c153d862e980a38d24d9d8965d9b17c738e177e6f6388b3ba2" + "9d0e1fc9395922509d0a54fe98982d107ca0f5a0bd4e62137b6970cf43d9698a" ], "shifted": null }, @@ -93,19 +93,19 @@ }, { "unshifted": [ - "7c8300015f6710d4cfb9dd8e6f681d7eb659bbf939862779e00a81a6fe816d99" + "2e150d1fa7abbb6545d34bc31452d83d2197d4a216e5dea6fd38baf4cd1f5d29" ], "shifted": null }, { "unshifted": [ - "437739969e31d43feddf1cf368f0704ff736a5d92a01383ed83046fd0731d186" + "58a006e0ab70efc385b75133d5511bc9b47c5d1d33883adf130637b7b48bed08" ], "shifted": null }, { "unshifted": [ - "441192708a53a1b9194ec519448fc9577a7257395a20bb2ee8b2c1177aa72387" + "3b98501b54683210b6a846e46ddd89a3c1cbf59f23baa4668b1c391a6b50b906" ], "shifted": null }, @@ -142,7 +142,7 @@ ], "generic_comm": { "unshifted": [ - "3f3b6b3f03af17bbe35b1d8f9d438a340b5ef7509083545b055a96b1167a0d8a" + "5a7bc54b696d3531c5f1b81640912cae7da9fb756afefd2dec71afe96184d628" ], "shifted": null }, diff --git a/demo/eth_verifier/circuit_gen/.gitignore b/demo/eth_verifier/circuit_gen/.gitignore deleted file mode 100644 index 2f7896d1..00000000 --- a/demo/eth_verifier/circuit_gen/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target/ diff --git a/demo/eth_verifier/circuit_gen/Cargo.lock b/demo/eth_verifier/circuit_gen/Cargo.lock deleted file mode 100644 index b187ec4b..00000000 --- a/demo/eth_verifier/circuit_gen/Cargo.lock +++ /dev/null @@ -1,944 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - -[[package]] -name = "ark-bn254" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea691771ebbb28aea556c044e2e5c5227398d840cee0c34d4d20fa8eb2689e8c" -dependencies = [ - "ark-ec", - "ark-ff", - "ark-std", -] - -[[package]] -name = "ark-ec" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dea978406c4b1ca13c2db2373b05cc55429c3575b8b21f1b9ee859aa5b03dd42" -dependencies = [ - "ark-ff", - "ark-serialize", - "ark-std", - "derivative", - "num-traits", - "rayon", - "zeroize", -] - -[[package]] -name = "ark-ff" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b3235cc41ee7a12aaaf2c575a2ad7b46713a8a50bda2fc3b003a04845c05dd6" -dependencies = [ - "ark-ff-asm", - "ark-ff-macros", - "ark-serialize", - "ark-std", - "derivative", - "num-bigint", - "num-traits", - "paste", - "rayon", - "rustc_version", - "zeroize", -] - -[[package]] -name = "ark-ff-asm" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db02d390bf6643fb404d3d22d31aee1c4bc4459600aef9113833d17e786c6e44" -dependencies = [ - "quote", - "syn 1.0.109", -] - -[[package]] -name = "ark-ff-macros" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db2fd794a08ccb318058009eefdf15bcaaaaf6f8161eb3345f907222bac38b20" -dependencies = [ - "num-bigint", - "num-traits", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "ark-poly" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0f78f47537c2f15706db7e98fe64cc1711dbf9def81218194e17239e53e5aa" -dependencies = [ - "ark-ff", - "ark-serialize", - "ark-std", - "derivative", - "hashbrown", - "rayon", -] - -[[package]] -name = "ark-serialize" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6c2b318ee6e10f8c2853e73a83adc0ccb88995aa978d8a3408d492ab2ee671" -dependencies = [ - "ark-serialize-derive", - "ark-std", - "digest 0.9.0", -] - -[[package]] -name = "ark-serialize-derive" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dd4e5f0bf8285d5ed538d27fab7411f3e297908fd93c62195de8bee3f199e82" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "ark-std" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" -dependencies = [ - "num-traits", - "rand", - "rayon", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bcs" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85b6598a2f5d564fb7855dc6b06fd1c38cff5a72bd8b863a4d021938497b440a" -dependencies = [ - "serde", - "thiserror", -] - -[[package]] -name = "blake2" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" -dependencies = [ - "digest 0.10.7", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "circuit_gen" -version = "0.1.0" -dependencies = [ - "ark-bn254", - "ark-ec", - "ark-ff", - "ark-poly", - "kimchi", - "num-bigint", - "num-traits", - "rand", - "rand_core", - "serde", - "serde_json", -] - -[[package]] -name = "cpufeatures" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" -dependencies = [ - "libc", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" -dependencies = [ - "cfg-if", - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" -dependencies = [ - "autocfg", - "cfg-if", - "crossbeam-utils", - "memoffset", - "scopeguard", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "crypto-common" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" -dependencies = [ - "generic-array", - "typenum", -] - -[[package]] -name = "darling" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn 1.0.109", -] - -[[package]] -name = "darling_macro" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" -dependencies = [ - "darling_core", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "derivative" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", - "subtle", -] - -[[package]] -name = "disjoint-set" -version = "0.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d102f1a462fdcdddce88d6d46c06c074a2d2749b262230333726b06c52bb7585" - -[[package]] -name = "either" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "groupmap" -version = "0.1.0" -source = "git+https://github.com/o1-labs/proof-systems.git?branch=develop#88bf98662fbdb3f7647e8857af48f7705a94dd5e" -dependencies = [ - "ark-ec", - "ark-ff", - "rand", -] - -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash", -] - -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -dependencies = [ - "serde", -] - -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - -[[package]] -name = "internal-tracing" -version = "0.1.0" -source = "git+https://github.com/o1-labs/proof-systems.git?branch=develop#88bf98662fbdb3f7647e8857af48f7705a94dd5e" - -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "kimchi" -version = "0.1.0" -source = "git+https://github.com/o1-labs/proof-systems.git?branch=develop#88bf98662fbdb3f7647e8857af48f7705a94dd5e" -dependencies = [ - "ark-bn254", - "ark-ec", - "ark-ff", - "ark-poly", - "ark-serialize", - "blake2", - "disjoint-set", - "groupmap", - "hex", - "internal-tracing", - "itertools", - "mina-curves", - "mina-poseidon", - "num-bigint", - "num-derive", - "num-integer", - "num-traits", - "o1-utils", - "once_cell", - "poly-commitment", - "rand", - "rand_core", - "rayon", - "rmp-serde", - "serde", - "serde_with", - "strum", - "strum_macros", - "thiserror", - "turshi", -] - -[[package]] -name = "libc" -version = "0.2.149" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" - -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "memoffset" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" -dependencies = [ - "autocfg", -] - -[[package]] -name = "mina-curves" -version = "0.1.0" -source = "git+https://github.com/o1-labs/proof-systems.git?branch=develop#88bf98662fbdb3f7647e8857af48f7705a94dd5e" -dependencies = [ - "ark-ec", - "ark-ff", -] - -[[package]] -name = "mina-poseidon" -version = "0.1.0" -source = "git+https://github.com/o1-labs/proof-systems.git?branch=develop#88bf98662fbdb3f7647e8857af48f7705a94dd5e" -dependencies = [ - "ark-ec", - "ark-ff", - "ark-poly", - "mina-curves", - "o1-utils", - "once_cell", - "rand", - "rayon", - "serde", - "serde_with", -] - -[[package]] -name = "num-bigint" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", - "rand", - "serde", -] - -[[package]] -name = "num-derive" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" -dependencies = [ - "autocfg", -] - -[[package]] -name = "o1-utils" -version = "0.1.0" -source = "git+https://github.com/o1-labs/proof-systems.git?branch=develop#88bf98662fbdb3f7647e8857af48f7705a94dd5e" -dependencies = [ - "ark-ec", - "ark-ff", - "ark-poly", - "ark-serialize", - "bcs", - "hex", - "num-bigint", - "num-integer", - "num-traits", - "rand", - "rand_core", - "rayon", - "serde", - "serde_with", - "sha2", - "thiserror", -] - -[[package]] -name = "once_cell" -version = "1.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" - -[[package]] -name = "paste" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" - -[[package]] -name = "pest" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c022f1e7b65d6a24c0dbbd5fb344c66881bc01f3e5ae74a1c8100f2f985d98a4" -dependencies = [ - "memchr", - "thiserror", - "ucd-trie", -] - -[[package]] -name = "poly-commitment" -version = "0.1.0" -source = "git+https://github.com/o1-labs/proof-systems.git?branch=develop#88bf98662fbdb3f7647e8857af48f7705a94dd5e" -dependencies = [ - "ark-ec", - "ark-ff", - "ark-poly", - "ark-serialize", - "blake2", - "groupmap", - "itertools", - "mina-curves", - "mina-poseidon", - "o1-utils", - "once_cell", - "rand", - "rand_core", - "rayon", - "rmp-serde", - "serde", - "serde_with", - "thiserror", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - -[[package]] -name = "proc-macro2" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - -[[package]] -name = "rayon" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - -[[package]] -name = "rmp" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9860a6cc38ed1da53456442089b4dfa35e7cedaa326df63017af88385e6b20" -dependencies = [ - "byteorder", - "num-traits", - "paste", -] - -[[package]] -name = "rmp-serde" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bffea85eea980d8a74453e5d02a8d93028f3c34725de143085a844ebe953258a" -dependencies = [ - "byteorder", - "rmp", - "serde", -] - -[[package]] -name = "rustc_version" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" -dependencies = [ - "semver", -] - -[[package]] -name = "rustversion" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "semver" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] - -[[package]] -name = "serde" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.189" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "serde_json" -version = "1.0.107" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "serde_with" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff" -dependencies = [ - "serde", - "serde_with_macros", -] - -[[package]] -name = "serde_with_macros" -version = "1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "sha2" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.7", -] - -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] -name = "strum" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" - -[[package]] -name = "strum_macros" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "rustversion", - "syn 1.0.109", -] - -[[package]] -name = "subtle" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - -[[package]] -name = "turshi" -version = "0.1.0" -source = "git+https://github.com/o1-labs/proof-systems.git?branch=develop#88bf98662fbdb3f7647e8857af48f7705a94dd5e" -dependencies = [ - "ark-ff", - "hex", - "o1-utils", -] - -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - -[[package]] -name = "ucd-trie" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "zeroize" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" -dependencies = [ - "zeroize_derive", -] - -[[package]] -name = "zeroize_derive" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] diff --git a/demo/eth_verifier/circuit_gen/Cargo.toml b/demo/eth_verifier/circuit_gen/Cargo.toml deleted file mode 100644 index ed36ba12..00000000 --- a/demo/eth_verifier/circuit_gen/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "circuit_gen" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -kimchi = { git = "https://github.com/o1-labs/proof-systems.git", branch = "develop", features = [ "bn254" ] } -num-traits = "0.2" -ark-ff = { version = "0.3.0", features = [ "parallel", "asm" ] } -ark-ec = { version = "0.3.0", features = [ "parallel" ] } -ark-poly = { version = "0.3.0", features = [ "parallel" ] } -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -num-bigint = "0.4.3" -ark-bn254 = "0.3.0" -rand = "0.8.0" -rand_core = "0.6.3" diff --git a/demo/eth_verifier/circuit_gen/src/main.rs b/demo/eth_verifier/circuit_gen/src/main.rs deleted file mode 100644 index c7ea9f64..00000000 --- a/demo/eth_verifier/circuit_gen/src/main.rs +++ /dev/null @@ -1,82 +0,0 @@ -//! Will create a KZG proof over a test circuit and serialize it into JSON -//! for feeding the Solidity verifier. -//! -//! This crate is based on `verifier_circuit_tests/` and the Kimchi test -//! "test_generic_gate_pairing". - -use std::{array, fs}; - -use ark_ec::short_weierstrass_jacobian::GroupAffine; -use ark_ff::UniformRand; -use kimchi::{ - circuits::{ - polynomials::generic::testing::{create_circuit, fill_in_witness}, - wires::COLUMNS, - }, - groupmap::GroupMap, - mina_poseidon::{ - constants::PlonkSpongeConstantsKimchi, - sponge::{DefaultFqSponge, DefaultFrSponge}, - }, - poly_commitment::{ - commitment::CommitmentCurve, - pairing_proof::{PairingProof, PairingSRS}, - }, - proof::ProverProof, - prover_index::testing::new_index_for_test_with_lookups_and_custom_srs, -}; -use num_traits::Zero; - -type Fp = ark_bn254::Fr; -type Proof = PairingProof>; -type G = GroupAffine; - -type SpongeParams = PlonkSpongeConstantsKimchi; -type BaseSponge = DefaultFqSponge; -type ScalarSponge = DefaultFrSponge; - -fn main() { - // Create test circuit - let gates = create_circuit(0, 0); - - // Create witnesses - let mut witness: [Vec; COLUMNS] = array::from_fn(|_| vec![Fp::zero(); gates.len()]); - fill_in_witness(0, &mut witness, &vec![]); - - // Create proof - let x = Fp::rand(&mut rand::rngs::OsRng); - let prover_index = new_index_for_test_with_lookups_and_custom_srs::<_, Proof, _>( - gates, - 0, - 0, - vec![], - None, - true, - None, - |d1, size| { - let mut srs = PairingSRS::create(x, size); - srs.full_srs.add_lagrange_basis(d1); - srs - }, - ); - let group_map = ::Map::setup(); - let proof = ProverProof::create::( - &group_map, - witness, - &vec![], - &prover_index, - ) - .unwrap(); - - // Serialize into JSON file - fs::write( - "../proof.json", - serde_json::to_string_pretty(&proof).unwrap(), - ) - .unwrap(); - fs::write( - "../verifier_index.json", - serde_json::to_string_pretty(&prover_index.verifier_index()).unwrap(), - ) - .unwrap(); -} diff --git a/demo/eth_verifier/proof.json b/demo/eth_verifier/proof.json deleted file mode 100644 index 18dac07b..00000000 --- a/demo/eth_verifier/proof.json +++ /dev/null @@ -1,502 +0,0 @@ -{ - "commitments": { - "w_comm": [ - { - "unshifted": [ - "0b56eae598a1ed5527764bffcc416291b045b138f7631008f01c3fe42f68af98" - ], - "shifted": null - }, - { - "unshifted": [ - "8b7e4d4a1d6e855fafc207e464c1c7d29433c50f2081b4ae3a5188995cdd7898" - ], - "shifted": null - }, - { - "unshifted": [ - "d7a7ef1389a19180b1fe377b0c5a088bff1e4863ce9e3a624d9aeac45f07c185" - ], - "shifted": null - }, - { - "unshifted": [ - "cc5de9f9df249c23c5a6c7a5c9b1f10a8be8d607974273ca68e9a65728ea9c09" - ], - "shifted": null - }, - { - "unshifted": [ - "b188685acd63863bc6ebb19f7870f243073a468391922e72ac6ec49b5b62858b" - ], - "shifted": null - }, - { - "unshifted": [ - "e96666121a1764c1805a2e2d3962fbe4b254211f7d6674d6c09d420976671b1c" - ], - "shifted": null - }, - { - "unshifted": [ - "f65abe15d7c31f22387039f0caefd3666fd6b723a3e1c4434dd02daf9db01fa5" - ], - "shifted": null - }, - { - "unshifted": [ - "57fa32a6d998966779f068fb20aca9974348c22a099501dab5de7dd4ef914821" - ], - "shifted": null - }, - { - "unshifted": [ - "353287be7a6c284651e876d3ea6c0faa57da3a0dd3c4bb36043640aba70be516" - ], - "shifted": null - }, - { - "unshifted": [ - "6f65390ccd8529e087c74abc5462c546e9f72e31e68317472d87b723f72dc4a8" - ], - "shifted": null - }, - { - "unshifted": [ - "3641742673a3de1355232df799f92adff0f37283cf85f20ccd9ebd077b35de86" - ], - "shifted": null - }, - { - "unshifted": [ - "03c38e4f01400eb2f19fd9e31f7a2fc794b5f5906b1fadb4438e22e8829d689d" - ], - "shifted": null - }, - { - "unshifted": [ - "8d125ac9180254c24744aa627c3c32d2414adf1aeb3d7085aa3c9250d611fd8e" - ], - "shifted": null - }, - { - "unshifted": [ - "289b4f036e28dfbebccd0d24cb37ccb238245b899a5d7b6395b034c614231a04" - ], - "shifted": null - }, - { - "unshifted": [ - "88821710d04df4e4beef43604e8cb93a875b8c6fa85166c3e65cb230a4a82008" - ], - "shifted": null - } - ], - "z_comm": { - "unshifted": [ - "2f58158ae158f459cc6dac7af2ca45eace49c4c2bf3069b17d1c426be22af798" - ], - "shifted": null - }, - "t_comm": { - "unshifted": [ - "765251cc692c3d2f1935685f81937745db617a559ca7c3575ac04dba7586cf99", - "c5470ac2bdfc43f57f1c042a8d3e4ea2e3eb3d6506bdca46a0764d268aae87a5", - "92f45a41a07cade83c741eac994af5da3cf887679b91bf21608c46da97cfb598", - "35b96bea7200e6ee3ec1e091e8e8a162677728c6dda8c4c93ee8712111ea961a", - "82f266ad87ba1ec4a8125bd2964dbe16144bc0e2fbb5f5d7fd27eb4048c25aab", - "ce2fe9134bc2c48eac356e177583e46f774fb1ce5e6c9ac6ba7de9fa00358d13", - "b35c086ea4dea5f43469c2c381fc9c8bc0e3c2d6172ab78d34ebb4f558fb1381" - ], - "shifted": null - }, - "lookup": null - }, - "proof": { - "quotient": "8a7e48015fbd0cb5af3a56ae4ab5c8e9071504ae3133b633011e2bd3b78a90aa", - "blinding": "18c29c8a592861e5242471f9b519120e589827e70cbf2ae1dbe27997787e2922" - }, - "evals": { - "public": { - "zeta": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ], - "zeta_omega": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ] - }, - "w": [ - { - "zeta": [ - "df6b31000296a5e49e2dc84283e346e06b826293371cdcc23ac904aeb665e52c" - ], - "zeta_omega": [ - "38724dbf89f6465bfbfb1185654d1dd20f06394d31a6886b9c207da99b4b321a" - ] - }, - { - "zeta": [ - "9650948488dbbf49bdf7cd72b5295097a547a1f5c225bd41015985b73b7aa01c" - ], - "zeta_omega": [ - "bbd96cfd1d7c1a83eeff527888b39d6b685d8e996999d0e6e4fd833fd1b91117" - ] - }, - { - "zeta": [ - "b7ba3caa086d4b4f85aa4fee67922dee69f9c9496cc72332f51723ef524e680e" - ], - "zeta_omega": [ - "d340420392473afeccb802d38ad51445bbebf9df29a6fe278b44e2d979da870c" - ] - }, - { - "zeta": [ - "bd606b39ffa077333bec4106b6a1533909aa3daa47cd72d0d9c5304b5d5afe21" - ], - "zeta_omega": [ - "6d5f89510e44445fd7d7423404fad1023e9f104c6bfc88a4a287220ec955d020" - ] - }, - { - "zeta": [ - "c15c14364cd4a2a185fd063c71c854f0ea9460328b7751f7c7e79dbec8a3f310" - ], - "zeta_omega": [ - "467f05a1b0017ef6c601c72344f99950d47404ec9503bf739da0597a5f6c730d" - ] - }, - { - "zeta": [ - "37da9fdeee4282c46693c469707635d164742a946883e9b670f86007d516991e" - ], - "zeta_omega": [ - "2d7531922342f49d87517b8e7af18571eb6bac9c08a934e73d9d18f77d634e20" - ] - }, - { - "zeta": [ - "a8e6a5862653253a71b2d9d21848473c23a48d89f960fd1884fd214e7f2eb618" - ], - "zeta_omega": [ - "7a6b7e12fda1aa1d242cf67d458c7478fde0d4463463384e89b6452049a6dc25" - ] - }, - { - "zeta": [ - "85cd987a797ac20d114127e352e7250ce92dd136514d91eda6d7458d9f1dec2a" - ], - "zeta_omega": [ - "1a1ecc3f737f908768ae4710bed52697ccb7d4879d22028bfe42cd7fcf382709" - ] - }, - { - "zeta": [ - "be533642a62bcc353cdfea060e9d874d08be597c5fc11120a6046cb75edd0c0a" - ], - "zeta_omega": [ - "b9f03d99dec6cabe571ba7fc477efcd20eb60b816bdd8d5b199571cda3f2f00c" - ] - }, - { - "zeta": [ - "4827dcc49aa9893f92513a26cd438087689b9c4f47ddb55bce410381a1e67d10" - ], - "zeta_omega": [ - "ea7913d1ae94895bb9127db1c7d7fc65c07fbddc7d70a9918fbda932b710c01a" - ] - }, - { - "zeta": [ - "c596ff6ae37f57c63cc81fb6be17083b1cf18421f28098aba77f6ed500b8a606" - ], - "zeta_omega": [ - "c59c5f74534e7de693d6b00c03a1ecf4a214529b56d3af33ee74085e32ee7504" - ] - }, - { - "zeta": [ - "6954dee73738a8657d3b7fb89019bd82d2a8d46584e06f017032609d6f6bb21f" - ], - "zeta_omega": [ - "258b2289ee0a253c2a89c9f6b99ebac2cead3d4d3e5a7bf4dc8b3e8b32c3ce1f" - ] - }, - { - "zeta": [ - "af4dea5788d6e3fe5fbf94c7e0d2f76d0b4b1fad9920d44930eea75ae3a8f206" - ], - "zeta_omega": [ - "5ac0829ed8c850306456bfff7afdf9baa23049283eb2052c8138004a3206770b" - ] - }, - { - "zeta": [ - "4cff0a3e81a63eea3550668da3c64ea33da888ab48ffb62d8f02d0dd6f628b17" - ], - "zeta_omega": [ - "22ca99115c6c076307e2a205e0de1e9427eefc55722e7e49dc31cbd00b70b214" - ] - }, - { - "zeta": [ - "23443097271757010f439954567fa123fa98d1d20f8bededc2286cec5478f22b" - ], - "zeta_omega": [ - "1c47e5dcb915cfcafb4bc61143f65e23513d154bfdf2a4d41d5b4fd5f9c1e524" - ] - } - ], - "z": { - "zeta": [ - "0d0e47a2d4bfab476d6b9f1fe6542ac05129a403ff256c3e1296ff78105cb61c" - ], - "zeta_omega": [ - "8ba81446cb48bb6a492e4f33fded37a3ba38cd996e726ec53b38ba7338f3b41f" - ] - }, - "s": [ - { - "zeta": [ - "86c6420a9526a569128d639aba63866450380558047cba8bcaf0d210d4063c1f" - ], - "zeta_omega": [ - "2c3711f2a33df2fc08c1ac6546ad64325a0223f706763bcf674f2f6310cd1226" - ] - }, - { - "zeta": [ - "f11d9346b24bfd399e774cd2698acdf1c6bd12fef17a572810a30185fac7541b" - ], - "zeta_omega": [ - "4374260ee7c58060c85b4da20192c29bbdaf876b4aa6e1a0767fd1e8e02b0a18" - ] - }, - { - "zeta": [ - "88c0f72964cf4d724ca3df2d249fc37245e430e2e9d5c380c235e808e2794325" - ], - "zeta_omega": [ - "de4afda3d06764e6b90e3c91df498ff072b71e5c2a06712dfc8a7e96e658961e" - ] - }, - { - "zeta": [ - "f8cc02d5df6b40429fa9f6bbda818f8d2468be125337933f00371a18743ca22f" - ], - "zeta_omega": [ - "8ef9333e123bc5970197e129891b8a504f50c37ed51a1377c02ac8058187f309" - ] - }, - { - "zeta": [ - "2268b1ea0fd949b8f0a0e6d9e8c9d0ca9e02738a45bb5b7c9c1232823e5b5f13" - ], - "zeta_omega": [ - "24b33fed7f1b63b719099a5235882021d8af31e11779eed5e74f0d77ee81b72e" - ] - }, - { - "zeta": [ - "c150da54b2e2ddebe8a936089d88e2f5c9a32cb603e87d6769f9035c96187c0d" - ], - "zeta_omega": [ - "ea99be9759951bec64281e1a98bf3fc783b1d3b29df02e764c1c83f18656fe14" - ] - } - ], - "coefficients": [ - { - "zeta": [ - "b4fb661f50092b982c3009757477c67e6668dafb55a021ec26ef5382d81dca1d" - ], - "zeta_omega": [ - "55b0ee7b84e474fafe8c62f497796f2e900a04c87ec8cb9f7fcbecce7fe6530d" - ] - }, - { - "zeta": [ - "805289d65350abb30f09f78c013fa0117e23222c38ff71b185dc6d9363379a29" - ], - "zeta_omega": [ - "a9ef1126fe9caa8f92985b6a97f0751153279b06a83b5fb9b3e37c76a908242c" - ] - }, - { - "zeta": [ - "d639d2ad46deb246064829228530ed14142fa047bc2eba3fefcb51ba80cc6412" - ], - "zeta_omega": [ - "c85a4f43871dbde6549d745a90523fb25810a2d304aea5ffd13e3cceedc16a01" - ] - }, - { - "zeta": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ], - "zeta_omega": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ] - }, - { - "zeta": [ - "655f5468f7290c2f1be994a7ecc080bda74214baec635da53aafa3ed4c2ca000" - ], - "zeta_omega": [ - "aade45b270ef4ba095f1338dcf832786a2078fae2be2fbd93481b6092a552804" - ] - }, - { - "zeta": [ - "8a3539cd96e7ddde32783297f9a7b3937a977a4312cfdb2b16bba53c59ea2e30" - ], - "zeta_omega": [ - "1d0b3ebf0b0232e1532ad74e28ccaee0e81aa69b8376719f510a299d6da8be0e" - ] - }, - { - "zeta": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ], - "zeta_omega": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ] - }, - { - "zeta": [ - "d639d2ad46deb246064829228530ed14142fa047bc2eba3fefcb51ba80cc6412" - ], - "zeta_omega": [ - "c85a4f43871dbde6549d745a90523fb25810a2d304aea5ffd13e3cceedc16a01" - ] - }, - { - "zeta": [ - "558c5b9406397cb684e066353e8759fe34fa40f23de8db384b088e6c71b59a0b" - ], - "zeta_omega": [ - "714a616985ba6776e735d0c42743b5c3ab373ddaace904b98522b94497ca8e2d" - ] - }, - { - "zeta": [ - "53f4e1adf14514f9d7d9a26c8a4181e66cc42136355146be6179bb3680f40a01" - ], - "zeta_omega": [ - "71c8c923ede0c9217f0d3f69c7d3fdec2d2ac4f8da3a6953bb0c96b0c1520f17" - ] - }, - { - "zeta": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ], - "zeta_omega": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ] - }, - { - "zeta": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ], - "zeta_omega": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ] - }, - { - "zeta": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ], - "zeta_omega": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ] - }, - { - "zeta": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ], - "zeta_omega": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ] - }, - { - "zeta": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ], - "zeta_omega": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ] - } - ], - "generic_selector": { - "zeta": [ - "b4fb661f50092b982c3009757477c67e6668dafb55a021ec26ef5382d81dca1d" - ], - "zeta_omega": [ - "55b0ee7b84e474fafe8c62f497796f2e900a04c87ec8cb9f7fcbecce7fe6530d" - ] - }, - "poseidon_selector": { - "zeta": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ], - "zeta_omega": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ] - }, - "complete_add_selector": { - "zeta": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ], - "zeta_omega": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ] - }, - "mul_selector": { - "zeta": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ], - "zeta_omega": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ] - }, - "emul_selector": { - "zeta": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ], - "zeta_omega": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ] - }, - "endomul_scalar_selector": { - "zeta": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ], - "zeta_omega": [ - "0000000000000000000000000000000000000000000000000000000000000000" - ] - }, - "range_check0_selector": null, - "range_check1_selector": null, - "foreign_field_add_selector": null, - "foreign_field_mul_selector": null, - "xor_selector": null, - "rot_selector": null, - "lookup_aggregation": null, - "lookup_table": null, - "lookup_sorted": [ - null, - null, - null, - null, - null - ], - "runtime_lookup_table": null, - "runtime_lookup_table_selector": null, - "xor_lookup_selector": null, - "lookup_gate_lookup_selector": null, - "range_check_lookup_selector": null, - "foreign_field_mul_lookup_selector": null - }, - "ft_eval1": "6e5dc661878703d1da605680b7cf5a7bc6da4314c901aa8273c5037d6ceaa724", - "prev_challenges": [] -} \ No newline at end of file diff --git a/demo/eth_verifier/src/BN254.sol b/demo/eth_verifier/src/BN254.sol index 012964b2..4fff6e54 100644 --- a/demo/eth_verifier/src/BN254.sol +++ b/demo/eth_verifier/src/BN254.sol @@ -14,7 +14,7 @@ pragma solidity ^0.8.0; -import "./Utils.sol"; +import "./UtilsExternal.sol"; import "./Fields.sol"; /// @notice Barreto-Naehrig curve over a 254 bit prime field @@ -306,12 +306,12 @@ library BN254 { mask = 0x8000000000000000000000000000000000000000000000000000000000000000; } - return abi.encodePacked(Utils.reverseEndianness(point.x | mask)); + return abi.encodePacked(UtilsExternal.reverseEndianness(point.x | mask)); } function g1Deserialize(bytes32 input) internal view returns (G1Point memory point) { uint256 mask = 0x4000000000000000000000000000000000000000000000000000000000000000; - uint256 x = Utils.reverseEndianness(uint256(input)); + uint256 x = UtilsExternal.reverseEndianness(uint256(input)); uint256 y; bool isQuadraticResidue; bool isYPositive; diff --git a/demo/eth_verifier/src/Commitment.sol b/demo/eth_verifier/src/Commitment.sol index 82e7e788..f143f346 100644 --- a/demo/eth_verifier/src/Commitment.sol +++ b/demo/eth_verifier/src/Commitment.sol @@ -2,7 +2,8 @@ pragma solidity >=0.4.16 <0.9.0; import "./BN254.sol"; -import {Scalar} from "./Fields.sol"; +import "./Fields.sol"; +import "./Utils.sol"; using { BN254.add, BN254.scale_scalar } for BN254.G1Point; @@ -120,3 +121,44 @@ function mask_custom( return BlindedCommitment(PolyComm(unshifted), blinders); } + +// Reference: Kimchi +// https://github.com/o1-labs/proof-systems/ +function calculate_lagrange_bases( + BN254.G1Point[] memory g, + BN254.G1Point memory h, + uint domain_size, + mapping(uint256 => PolyComm[]) storage lagrange_bases +) { + uint urs_size = g.length; + uint num_unshifteds = (domain_size + urs_size - 1) / urs_size; + BN254.G1Point[][] memory unshifted = new BN254.G1Point[][](num_unshifteds); + + // For each chunk + for (uint i = 0; i < num_unshifteds; i++) { + // Initialize the vector with zero curve points + BN254.G1Point[] memory lg = new BN254.G1Point[](domain_size); + for (uint j = 0; j < lg.length; j++) { + lg[j] = BN254.point_at_inf(); + } + + // Overwrite the terms corresponding to that chunk with the SRS curve points + uint start_offset = i * urs_size; + uint num_terms = Utils.min((i + 1) * urs_size, domain_size) - start_offset; + for (uint j = 0; j < num_terms; j++) { + lg[start_offset + j] = g[j]; + } + // Apply the IFFT + BN254.G1Point[] memory lg_fft = Utils.ifft(lg); + // Append the 'partial Langrange polynomials' to the vector of unshifted chunks + unshifted[i] = lg_fft; + } + + PolyComm[] storage bases = lagrange_bases[domain_size]; + + for (uint i = 0; i < domain_size; i++) { + for (uint j = 0; j < unshifted.length; j++) { + bases[i].unshifted.push(unshifted[j][i]); + } + } +} diff --git a/demo/eth_verifier/src/Fields.sol b/demo/eth_verifier/src/Fields.sol index ec8eb240..c2bc5811 100644 --- a/demo/eth_verifier/src/Fields.sol +++ b/demo/eth_verifier/src/Fields.sol @@ -26,6 +26,10 @@ library Base { } } + function square(FE self) public pure returns (FE res) { + res = mul(self, self); + } + function inv(FE self) public view returns (FE) { // TODO: return FE.wrap(0); @@ -40,6 +44,38 @@ library Base { res := addmod(self, sub(MODULUS, other), MODULUS) } } + + // Reference: Lambdaworks + // https://github.com/lambdaclass/lambdaworks/ + function pow(FE self, uint exponent) public pure returns (FE result) { + if (exponent == 0) { + return FE.wrap(1); + } else if (exponent == 1) { + return self; + } else { + result = self; + + while (exponent & 1 == 0) { + result = square(result); + exponent = exponent >> 1; + } + + if (exponent == 0) { + return result; + } else { + FE base = result; + exponent = exponent >> 1; + + while (exponent != 0) { + base = square(base); + if (exponent & 1 == 1) { + result = mul(result, base); + } + exponent = exponent >> 1; + } + } + } + } } /// @notice Implements 256 bit modular arithmetic over the scalar field of bn254. @@ -51,6 +87,14 @@ library Scalar { uint256 public constant MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617; + uint256 public constant TWO_ADIC_PRIMITIVE_ROOT_OF_UNITY = + 11026779196025039675543067535165575398706865421176733435921293210460577938844; + uint256 public constant TWO_ADICITY = 28; + + function from(uint n) public pure returns (FE) { + return FE.wrap(n % MODULUS); + } + function add( FE self, FE other @@ -69,9 +113,15 @@ library Scalar { } } - function inv(FE self) public view returns (FE) { - // TODO: - return FE.wrap(0); + function square(FE self) public pure returns (FE res) { + res = mul(self, self); + } + + function inv(FE self) public pure returns (FE) { + (uint gcd, uint inverse) = Aux.xgcd(FE.unwrap(self), MODULUS); + require(gcd == 1); + + return FE.wrap(inverse); } function neg(FE self) public pure returns (FE) { @@ -83,4 +133,105 @@ library Scalar { res := addmod(self, sub(MODULUS, other), MODULUS) } } + + // Reference: Lambdaworks + // https://github.com/lambdaclass/lambdaworks/ + function pow(FE self, uint exponent) public pure returns (FE result) { + if (exponent == 0) { + return FE.wrap(1); + } else if (exponent == 1) { + return self; + } else { + result = self; + + while (exponent & 1 == 0) { + result = square(result); + exponent = exponent >> 1; + } + + if (exponent == 0) { + return result; + } else { + FE base = result; + exponent = exponent >> 1; + + while (exponent != 0) { + base = square(base); + if (exponent & 1 == 1) { + result = mul(result, base); + } + exponent = exponent >> 1; + } + } + } + } + + error RootOfUnityError(); + /// @notice returns a primitive root of unity of order $2^{order}$. + // Reference: Lambdaworks + // https://github.com/lambdaclass/lambdaworks/ + function get_primitive_root_of_unity( + uint order + ) public pure returns (FE) { + if (order == 0) { + return FE.wrap(1); + } + if (order > TWO_ADICITY) { + revert RootOfUnityError(); + } + + uint log_power = TWO_ADICITY - order; + FE root = from(TWO_ADIC_PRIMITIVE_ROOT_OF_UNITY); + for (uint i = 0; i < log_power; i++) { + root = square(root); + } + + require(FE.unwrap(pow(root, order)) == 1, "not a root of unity"); + return root; + } +} + +library Aux { + + /// @notice Extended euclidean algorithm. Returns [gcd, Bezout_a] + /// @notice so gcd = a*Bezout_a + b*Bezout_b. + /// @notice source: https://www.extendedeuclideanalgorithm.com/code + function xgcd( + uint a, + uint b + ) public pure returns (uint s1, uint t1) { + uint r1 = a; + uint r2 = b; + s1 = 1; + t1 = 0; + uint s2 = 0; + uint t2 = 1; + + uint n = 0; + while (r2 > 0) { + uint q = r1 / r2; + r1 = r1 > q*r2 ? r1 - q*r2 : q*r2 - r1; // abs + s1 = s1 + q*s2; + + // swap s1, s2 + uint temp = s1; + s1 = s2; + s2 = temp; + + t1 = t1 + q*t2; + + // swap t1, t2 + temp = t1; + t1 = t2; + t2 = temp; + + n += 1; + } + + if (n % 2 > 0) { + s1 = b - s1; + } else { + t1 = a - t1; + } + } } diff --git a/demo/eth_verifier/src/Utils.sol b/demo/eth_verifier/src/Utils.sol index c480ddc0..6ada2919 100644 --- a/demo/eth_verifier/src/Utils.sol +++ b/demo/eth_verifier/src/Utils.sol @@ -1,39 +1,162 @@ -// SPDX-License-Identifier: GPL-3.0-or-later -// -// Copyright (c) 2022 Espresso Systems (espressosys.com) -// This file is part of the Configurable Asset Privacy for Ethereum (CAPE) library. -// -// This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -// You should have received a copy of the GNU General Public License along with this program. If not, see . +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.4.16 <0.9.0; -pragma solidity ^0.8.0; +import "./BN254.sol"; +import "./Fields.sol"; +import "./UtilsExternal.sol"; +import "forge-std/console.sol"; + +using { BN254.add, BN254.neg, BN254.scalarMul } for BN254.G1Point; +using { Scalar.pow, Scalar.inv } for Scalar.FE; library Utils { - function reverseEndianness(uint256 input) internal pure returns (uint256 v) { - v = input; - - // swap bytes - v = - ((v & 0xFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00) >> 8) | - ((v & 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << 8); - - // swap 2-byte long pairs - v = - ((v & 0xFFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000) >> 16) | - ((v & 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << 16); - - // swap 4-byte long pairs - v = - ((v & 0xFFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000) >> 32) | - ((v & 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << 32); - - // swap 8-byte long pairs - v = - ((v & 0xFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF0000000000000000) >> 64) | - ((v & 0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF) << 64); - - // swap 16-byte long pairs - v = (v >> 128) | (v << 128); + /// @notice implements iterative FFT via the Cooley-Tukey algorithm for BN254. + /// @notice needs a final bit reversing permutation of the output. + // Reference: Lambdaworks + // https://github.com/lambdaclass/lambdaworks/ + function nr_2radix_fft(BN254.G1Point[] memory points, Scalar.FE[] memory twiddles) + public + view + returns (BN254.G1Point[] memory results) + { + uint256 n = points.length; + require(is_power_of_two(n), "fft with size non power of two"); + + if (n == 1) { + return points; + } + + // divide input in groups, starting with 1, duplicating the number of groups in each stage. + uint group_count = 1; + uint group_size = points.length; + + // for each group, there'll be group_size / 2 butterflies. + // a butterfly is the atomic operation of a FFT, e.g: (a, b) = (a + wb, a - wb). + // The 0.5 factor is what gives FFT its performance, it recursively halves the problem size + // (group size). + + results = points; + + while (group_count < points.length) { + for (uint group = 0; group < group_count; group++) { + uint first_in_group = group * group_size; + uint first_in_next_group = first_in_group + group_size / 2; + + uint w = Scalar.FE.unwrap(twiddles[group]); // a twiddle factor is used per group + + for (uint i = first_in_group; i < first_in_next_group; i++) { + BN254.G1Point memory wi = results[i + group_size / 2].scalarMul(w); + + BN254.G1Point memory y0 = results[i].add(wi); + BN254.G1Point memory y1 = results[i].add(wi.neg()); + + results[i] = y0; + results[i + group_size / 2] = y1; + } + } + group_count *= 2; + group_size /= 2; + } + } + + function get_twiddles(uint order) public view returns (Scalar.FE[] memory twiddles) { + Scalar.FE root_inv = Scalar.get_primitive_root_of_unity(order).inv(); + + for (uint i = 0; i < 1 << (order - 1); i++) { + twiddles[i] = root_inv.pow(i); + } + } + + /// @notice permutes the elements in bit-reverse order. + function bit_reverse_permut(BN254.G1Point[] memory points) public pure returns (BN254.G1Point[] memory result){ + result = points; + for (uint i = 0; i < points.length; i++) { + uint bit_reverse_index = bit_reverse(i, points.length); + if (bit_reverse_index > i) { + BN254.G1Point memory temp = result[i]; + result[i] = result[bit_reverse_index]; + result[bit_reverse_index] = temp; + } + } + } + + /// @notice reverses the `log2(size)` first bits of `i` + function bit_reverse(uint i, uint size) public pure returns (uint) { + if (size == 1) return i; + return UtilsExternal.reverseEndianness(i) >> (256 - log2(size)); + } + + /// @notice runs inverse FFT for BN254. + function ifft(BN254.G1Point[] memory points) public view returns (BN254.G1Point[] memory results) { + (uint size, uint order) = next_power_of_two(points.length); + + if (size > points.length) { + // zero padding + BN254.G1Point[] memory new_points = new BN254.G1Point[](size); + for (uint i = 0; i < size; i++) { + new_points[i] = i < points.length ? points[i] : BN254.point_at_inf(); + } + points = new_points; + } + + BN254.G1Point[] memory unordered_res = nr_2radix_fft(points, get_twiddles(order)); + return bit_reverse_permut(unordered_res); + } + + /// @notice returns true if n is a power of two. + function is_power_of_two(uint256 n) public pure returns (bool) { + do { + if (n == 1) return true; + n /= 2; + } while (n % 2 == 0); + + return false; + } + + /// @notice returns the binary logarithm of n. + function log2(uint256 n) public pure returns (uint256 res) { + res = n - 1; + for (uint i = 1; i < 256; i *= 2) { + res |= res >> i; + } + } + + /// @notice returns the next power of two of n, or n if it's already a pow of two, + // and the order. + function next_power_of_two(uint256 n) public pure returns (uint256 res, uint256 pow) { + if (is_power_of_two(n)) { + return (n, log2(n)); + } + pow = log2(n) + 1; + res = 1 << pow; + + require(is_power_of_two(res)); + require(res > n); + } + + /// @notice returns the odd and even terms of the `points` array. + function get_odd_even(BN254.G1Point[] memory points) + public + pure + returns (BN254.G1Point[] memory odd, BN254.G1Point[] memory even) + { + uint256 n = points.length; + require( + n % 2 == 0, + "can't get odd and even from a non even sized array" + ); + + odd = new BN254.G1Point[](n / 2); + even = new BN254.G1Point[](n / 2); + + for (uint256 i = 0; i < n / 2; i++) { + odd[i] = points[2 * i - 1]; + even[i] = points[2 * i]; + } + } + + /// @notice returns minimum between a and b. + function min(uint a, uint b) public pure returns (uint) { + return a < b ? a : b; } } diff --git a/demo/eth_verifier/src/UtilsExternal.sol b/demo/eth_verifier/src/UtilsExternal.sol new file mode 100644 index 00000000..7694a73e --- /dev/null +++ b/demo/eth_verifier/src/UtilsExternal.sol @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// +// Copyright (c) 2022 Espresso Systems (espressosys.com) +// This file is part of the Configurable Asset Privacy for Ethereum (CAPE) library. +// +// This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +// You should have received a copy of the GNU General Public License along with this program. If not, see . + +pragma solidity ^0.8.0; + +library UtilsExternal { + function reverseEndianness(uint256 input) + internal + pure + returns (uint256 v) + { + v = input; + + // swap bytes + v = + ((v & + 0xFF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00) >> + 8) | + ((v & + 0x00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF00FF) << + 8); + + // swap 2-byte long pairs + v = + ((v & + 0xFFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000) >> + 16) | + ((v & + 0x0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF0000FFFF) << + 16); + + // swap 4-byte long pairs + v = + ((v & + 0xFFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000) >> + 32) | + ((v & + 0x00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF00000000FFFFFFFF) << + 32); + + // swap 8-byte long pairs + v = + ((v & + 0xFFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF0000000000000000) >> + 64) | + ((v & + 0x0000000000000000FFFFFFFFFFFFFFFF0000000000000000FFFFFFFFFFFFFFFF) << + 64); + + // swap 16-byte long pairs + v = (v >> 128) | (v << 128); + } +} diff --git a/demo/eth_verifier/src/Verifier.sol b/demo/eth_verifier/src/Verifier.sol index 8dde0d8a..83ba8eae 100644 --- a/demo/eth_verifier/src/Verifier.sol +++ b/demo/eth_verifier/src/Verifier.sol @@ -1,37 +1,75 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.4.16 <0.9.0; -import {Scalar, Base} from "./Fields.sol"; -import {VerifierIndex} from "./VerifierIndex.sol"; -import {PolyComm, polycomm_msm, mask_custom} from "./Commitment.sol"; +import "./Fields.sol"; import "./BN254.sol"; +import {VerifierIndex} from "./VerifierIndex.sol"; +import "./Commitment.sol"; + +// import "forge-std/console.sol"; import {console} from "forge-std/Test.sol"; -using { BN254.neg } for BN254.G1Point; -using { Scalar.neg } for Scalar.FE; +using {BN254.neg} for BN254.G1Point; +using {Scalar.neg} for Scalar.FE; library Kimchi { struct Proof { uint256 data; } -} -struct ProofInput { - uint256[] serializedProof; + struct ProofInput { + uint256[] serializedProof; + } + + struct ProverProof { + // evals + + // opening proof + BN254.G1Point opening_proof_quotient; + uint256 opening_proof_blinding; + } + + struct Evals { + Base.FE zeta; + Base.FE zeta_omega; + } + + /* + function deserializeEvals( + uint8[71] calldata serialized_evals + ) public view returns (Evals memory evals) {} + */ } contract KimchiVerifier { VerifierIndex verifier_index; + constructor( + BN254.G1Point[] memory g, + BN254.G1Point memory h, + uint256 public_len, + uint256 domain_size, + uint256 max_poly_size + ) { + for (uint i = 0; i < g.length; i++) { + verifier_index.urs.g[i] = g[i]; + } + verifier_index.urs.h = h; + calculate_lagrange_bases(g, h, domain_size, verifier_index.urs.lagrange_bases); + verifier_index.public_len = public_len; + verifier_index.domain_size = domain_size; + verifier_index.max_poly_size = max_poly_size; + } + // 1) deserialize // 2) staticcall to precompile of pairing check - function verify(uint256[] memory serializedProof) - public - view - returns (bool) - { + function verify( + uint256[] memory serializedProof + ) public view returns (bool) { bool success; + + /* NOTE: this is an example of the use of the precompile assembly { let freeMemPointer := 0x40 success := staticcall( @@ -43,6 +81,7 @@ contract KimchiVerifier { 0x00 ) } + */ //require(success); /* @@ -102,7 +141,7 @@ contract KimchiVerifier { if (public_inputs.length == 0) { BN254.G1Point[] memory blindings = new BN254.G1Point[](chunk_size); for (uint256 i = 0; i < chunk_size; i++) { - blindings[i] = verifier_index.blinding_commitment; + blindings[i] = verifier_index.urs.h; } public_comm = PolyComm(blindings); } else { @@ -111,11 +150,17 @@ contract KimchiVerifier { elm[i] = public_inputs[i].neg(); } PolyComm memory public_comm_tmp = polycomm_msm(comm, elm); - Scalar.FE[] memory blinders = new Scalar.FE[](public_comm_tmp.unshifted.length); + Scalar.FE[] memory blinders = new Scalar.FE[]( + public_comm_tmp.unshifted.length + ); for (uint i = 0; i < public_comm_tmp.unshifted.length; i++) { blinders[i] = Scalar.FE.wrap(1); } - public_comm = mask_custom(verifier_index.urs, public_comm_tmp, blinders).commitment; + public_comm = mask_custom( + verifier_index.urs, + public_comm_tmp, + blinders + ).commitment; } } diff --git a/demo/eth_verifier/src/VerifierIndex.sol b/demo/eth_verifier/src/VerifierIndex.sol index 95e4a9fe..92aa518d 100644 --- a/demo/eth_verifier/src/VerifierIndex.sol +++ b/demo/eth_verifier/src/VerifierIndex.sol @@ -6,8 +6,7 @@ import {URS} from "./Commitment.sol"; struct VerifierIndex { URS urs; - uint public_len; - uint domain_size; - uint max_poly_size; - BN254.G1Point blinding_commitment; + uint256 public_len; + uint256 domain_size; + uint256 max_poly_size; } diff --git a/demo/eth_verifier/src/msgpack/Deserialize.sol b/demo/eth_verifier/src/msgpack/Deserialize.sol new file mode 100644 index 00000000..84689235 --- /dev/null +++ b/demo/eth_verifier/src/msgpack/Deserialize.sol @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.4.16 <0.9.0; + +import "../Verifier.sol"; +import "../Commitment.sol"; +import "../BN254.sol"; + +library MsgPk { + /// @notice deserializes an array of G1Point and also returns the rest of the + // data, excluding the consumed bytes. `i` is the index that we start to read + // the data from. + function deserializeG1Point(bytes calldata data, uint256 i) + public + view + returns (BN254.G1Point memory p, uint256 final_i) + { + // read length of the data + require(data[i] == 0xC4, "not a stream of bin8 (bytes)"); + + // next byte is the length of the stream in one byte + i += 1; + require(data[i] == 0x20, "size of element is not 32 bytes"); + + // read data + i += 1; + bytes32 compressed = abi.decode(data[i:i + 32], (bytes32)); + p = BN254.g1Deserialize(compressed); + + // go to next + i += 32; + + final_i = i; + } + + /// @notice deserializes an URS excluding the lagrange bases, and also + // returns the final index which points at the end of the consumed data. + function deserializeURS(bytes calldata data) + public + view + returns ( + BN254.G1Point[] memory, + BN254.G1Point memory, + uint256 + ) + { + uint256 i = 0; + require(data[i] == 0x92, "not a fix array of two elements"); + + i += 1; + require( + data[i] == 0xdc || data[i] == 0xdd, + "not an array16 or array32" + ); + // 0xdc means that the next 2 bytes represent the size, + // 0xdd means that the next 4 bytes represent the size. + uint256 byte_count = data[i] == 0xdc ? 2 : 4; + + // next bytes are size of the array + i += 1; + uint256 size = uint256(bytes32(data[i:i + byte_count])) >> + ((32 - byte_count) * 8); + // shift is necessary because conversion pads with zeros to the left + BN254.G1Point[] memory g = new BN254.G1Point[](size); + i += byte_count; + + // read elements + for (uint256 elem = 0; elem < size; elem++) { + (BN254.G1Point memory p, uint256 new_index) = deserializeG1Point( + data, + i + ); + g[elem] = p; + i = new_index; + } + + (BN254.G1Point memory h, uint256 final_i) = deserializeG1Point(data, i); + return (g, h, final_i); + } + + function deserializeOpeningProof(bytes calldata serialized_proof) + public + view + returns (Kimchi.ProverProof memory proof) + { + uint256 i = 0; + bytes1 firstbyte = serialized_proof[i]; + // first byte is 0x92, indicating this is an array with 2 elements + require(firstbyte == 0x92, "first byte is not 0x92"); + + // read length of the data + i += 1; + require(serialized_proof[i] == 0xC4, "second byte is not 0xC4"); + + // next byte is the length of the data in one byte + i += 1; + require(serialized_proof[i] == 0x20, "size of element is not 32 bytes"); + + // read data + i += 1; + bytes32 data_quotient = abi.decode( + serialized_proof[i:i + 32], + (bytes32) + ); + + proof.opening_proof_quotient = BN254.g1Deserialize(data_quotient); + + // read blinding + i += 32; + // read length of the data + require(serialized_proof[i] == 0xC4, "second byte is not 0xC4"); + + // next byte is the length of the data in one byte + i += 1; + require(serialized_proof[i] == 0x20, "size of element is not 32 bytes"); + + // read data + i += 1; + uint256 data_blinding = abi.decode( + serialized_proof[i:i + 32], + (uint256) + ); + + proof.opening_proof_blinding = data_blinding; + return proof; + } +} diff --git a/demo/eth_verifier/test/BN254.t.sol b/demo/eth_verifier/test/BN254.t.sol new file mode 100644 index 00000000..9b61352c --- /dev/null +++ b/demo/eth_verifier/test/BN254.t.sol @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.4.16 <0.9.0; + +import {Test} from "forge-std/Test.sol"; +import {console} from "forge-std/console.sol"; +import {BN254} from "../src/BN254.sol"; + +contract DeserializeTest is Test { + function test_deserialize() public { + bytes32 input = 0xce6c6d7118ed4276a5eca6b1000f52462844b3c962075696eb0bf95d2218432d; + + BN254.G1Point memory p = BN254.g1Deserialize(input); + + //bytes memory inp + //assertEq(0, 0, "0 == 0"); + } +} diff --git a/demo/eth_verifier/test/Deserialize.t.sol b/demo/eth_verifier/test/Deserialize.t.sol new file mode 100644 index 00000000..4f2942d3 --- /dev/null +++ b/demo/eth_verifier/test/Deserialize.t.sol @@ -0,0 +1,183 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.13; + +import {Test, console2} from "forge-std/Test.sol"; +import "../src/BN254.sol"; +import "../src/Verifier.sol"; +import "../src/msgpack/Deserialize.sol"; + +contract DeserializeTest is Test { + // Test to check that the destructuring of the message pack byte array is correct. + // If we know that g1Deserialize() is correct, then this asserts that the whole + // deserialization is working. + function test_deserialize_opening_proof() public { + // Data was taken from running the circuit_gen crate. + + bytes + memory opening_proof_serialized = hex"92c42004082c5fa22d4d2bf78f2aa71269510911c1b414b8bedfe41afb3c7147f99325c42017a3bfd724d88bf23ed3d13155cd09c0a4d1d1d520b869599f00958810100621"; + + Kimchi.ProverProof memory proof = MsgPk.deserializeOpeningProof( + opening_proof_serialized + ); + + BN254.G1Point memory expected_quotient = BN254.g1Deserialize( + 0x04082c5fa22d4d2bf78f2aa71269510911c1b414b8bedfe41afb3c7147f99325 + ); + uint256 expected_blinding = 0x17a3bfd724d88bf23ed3d13155cd09c0a4d1d1d520b869599f00958810100621; + + assertEq( + proof.opening_proof_blinding, + expected_blinding, + "wrong blinding" + ); + assertEq( + proof.opening_proof_quotient.x, + expected_quotient.x, + "wrong quotient x" + ); + assertEq( + proof.opening_proof_quotient.y, + expected_quotient.y, + "wrong quotient y" + ); + } + + // Test to check that the destructuring of the message pack byte array is correct. + // If we know that g1Deserialize() is correct, then this asserts that the whole + // deserialization is working. + function test_deserialize_urs() public { + // Data was taken from running the circuit_gen crate. + + bytes + memory urs_serialized = hex"92dc0020c4200100000000000000000000000000000000000000000000000000000000000000c42055a8e8d2b2221c2e7641eb8f5b656e352c9e7b5aca91da8ca92fe127e7fb2c21c42003bc09f3825fafdefe1cb25b4a296b60f2129a1c3a90826c3dc2021be421aa8ec4206422698aa4f80a088fd4e0d3a3cd517c2cb1f280cb95c9313823b8f8060f1786c4203558cb03f0cf841ed3a8145a7a8084e182731a9628779ef59d3bc47bae8a1192c4202ac41dd231cb8e97ffc3281b20e6799c0ae18afc13d3de1b4b363a0cd070baa7c420b6205dfa129f52601adfd87829901f06f1fd32e22a71f44b769d674448f05d83c4205d1b9b83cdcba66ff9424c7242c67394d7956dabf5407f4105124b7239d43e80c420e95ffc0999a8997b045430aa564c7bd9a25303e8a5ebbe4a99f6329b7f2a64aac4206cca50f1237f867fee63ac65249d6911494680f42d0e71386b1586be39092f9cc4204b9b17d64b384a65d7c80c8ab0f5fff75c69fd147835599753beea03152a3923c4205c0f706b036ed361e787af70acea3533d6e349869e83368979fdbbf382a4900bc420da6652a81754a6263e677d23a55bd729205f5fb64fa39b6771d9b811e5548bafc4208db1ad69d758362a4ecacff98a6910a95b3c2697e455271b2d7c078f1894eb1fc42010f56f1046a1121b1df5c401969b5acbf80eef8bfd5438270e09243413382788c4200cca37d1a3a721792dc232bb6a95bd14143350b6784bcdd4898a0bb34dd8bd2cc4202b7a1991e05b77d911d15ae590ff6f6ad7d1ed572b34654e3ce92e38e4839425c4201977ca4631e9eea53c7ba59d334c14dac7ee1071d6bf6ebf2ab7450c16975d23c4209eb742379ee8664a8bf9c18a40a534bb2961020bd0077cd0b603d2a8b9fe5a17c4201c50af6002db8dfa5a310ce795dcb06de94ead6687687263fd59acbc8612f180c4205241cbed55fbe1193f366e7ea8ad11bc97742eb35ca39129c4931b9bef64df1ec420646e69eb7d4682ad6bff24d40bf22184694c569246385cc127b3ec4a99875a85c42046b77ed1e120130743344ea9372ea58118604c730800e0d7038f2c80211f4f90c4208f20f3c39a09b5615bd8b2a09eec7dbc11b5ea1f8fe7eb0d5a69c1264412d199c42095f0b87ed771c169a8b6c0a6e21b13ab715407a4e6637a0b8fe0a1e3278f32a7c420a80440e1a07157bad23d7a7d3ddd7445f578021650016fc4bfb3324ed967c82bc4202b94fd0b89e7e2c9d245a4e94a539b14c5db26ed5ba4b3989ef0ba0712d4582ec42068f583079aa73425184a328127be63421eae683a25be94a0aa697ce74b5b972dc4209fa10b770e452852612ea392b8521683999d0a168c5eb85a6925d1ffe21d418ac420826a0976821c9309ed896678a97634a2fb1392a64ab8c59c8380012ffb601189c4203096ba3ed0b597fa29da6caa9000a409702b1f945561e82d02ab77b0cfdb649fc4204a718bc27174d557e036bcbcb9874ce5a6e1a63ccbe491e509d4201bfcb50806c420723737cf1cc96bb40021504a4ff45d21914e9484f2113d66545a3826919a9c250a"; + + (BN254.G1Point[] memory g, BN254.G1Point memory h, uint256 _i) = MsgPk + .deserializeURS(urs_serialized); + + BN254.G1Point[32] memory expected_g = [ + BN254.g1Deserialize( + 0x0100000000000000000000000000000000000000000000000000000000000000 + ), + BN254.g1Deserialize( + 0x55a8e8d2b2221c2e7641eb8f5b656e352c9e7b5aca91da8ca92fe127e7fb2c21 + ), + BN254.g1Deserialize( + 0x03bc09f3825fafdefe1cb25b4a296b60f2129a1c3a90826c3dc2021be421aa8e + ), + BN254.g1Deserialize( + 0x6422698aa4f80a088fd4e0d3a3cd517c2cb1f280cb95c9313823b8f8060f1786 + ), + BN254.g1Deserialize( + 0x3558cb03f0cf841ed3a8145a7a8084e182731a9628779ef59d3bc47bae8a1192 + ), + BN254.g1Deserialize( + 0x2ac41dd231cb8e97ffc3281b20e6799c0ae18afc13d3de1b4b363a0cd070baa7 + ), + BN254.g1Deserialize( + 0xb6205dfa129f52601adfd87829901f06f1fd32e22a71f44b769d674448f05d83 + ), + BN254.g1Deserialize( + 0x5d1b9b83cdcba66ff9424c7242c67394d7956dabf5407f4105124b7239d43e80 + ), + BN254.g1Deserialize( + 0xe95ffc0999a8997b045430aa564c7bd9a25303e8a5ebbe4a99f6329b7f2a64aa + ), + BN254.g1Deserialize( + 0x6cca50f1237f867fee63ac65249d6911494680f42d0e71386b1586be39092f9c + ), + BN254.g1Deserialize( + 0x4b9b17d64b384a65d7c80c8ab0f5fff75c69fd147835599753beea03152a3923 + ), + BN254.g1Deserialize( + 0x5c0f706b036ed361e787af70acea3533d6e349869e83368979fdbbf382a4900b + ), + BN254.g1Deserialize( + 0xda6652a81754a6263e677d23a55bd729205f5fb64fa39b6771d9b811e5548baf + ), + BN254.g1Deserialize( + 0x8db1ad69d758362a4ecacff98a6910a95b3c2697e455271b2d7c078f1894eb1f + ), + BN254.g1Deserialize( + 0x10f56f1046a1121b1df5c401969b5acbf80eef8bfd5438270e09243413382788 + ), + BN254.g1Deserialize( + 0x0cca37d1a3a721792dc232bb6a95bd14143350b6784bcdd4898a0bb34dd8bd2c + ), + BN254.g1Deserialize( + 0x2b7a1991e05b77d911d15ae590ff6f6ad7d1ed572b34654e3ce92e38e4839425 + ), + BN254.g1Deserialize( + 0x1977ca4631e9eea53c7ba59d334c14dac7ee1071d6bf6ebf2ab7450c16975d23 + ), + BN254.g1Deserialize( + 0x9eb742379ee8664a8bf9c18a40a534bb2961020bd0077cd0b603d2a8b9fe5a17 + ), + BN254.g1Deserialize( + 0x1c50af6002db8dfa5a310ce795dcb06de94ead6687687263fd59acbc8612f180 + ), + BN254.g1Deserialize( + 0x5241cbed55fbe1193f366e7ea8ad11bc97742eb35ca39129c4931b9bef64df1e + ), + BN254.g1Deserialize( + 0x646e69eb7d4682ad6bff24d40bf22184694c569246385cc127b3ec4a99875a85 + ), + BN254.g1Deserialize( + 0x46b77ed1e120130743344ea9372ea58118604c730800e0d7038f2c80211f4f90 + ), + BN254.g1Deserialize( + 0x8f20f3c39a09b5615bd8b2a09eec7dbc11b5ea1f8fe7eb0d5a69c1264412d199 + ), + BN254.g1Deserialize( + 0x95f0b87ed771c169a8b6c0a6e21b13ab715407a4e6637a0b8fe0a1e3278f32a7 + ), + BN254.g1Deserialize( + 0xa80440e1a07157bad23d7a7d3ddd7445f578021650016fc4bfb3324ed967c82b + ), + BN254.g1Deserialize( + 0x2b94fd0b89e7e2c9d245a4e94a539b14c5db26ed5ba4b3989ef0ba0712d4582e + ), + BN254.g1Deserialize( + 0x68f583079aa73425184a328127be63421eae683a25be94a0aa697ce74b5b972d + ), + BN254.g1Deserialize( + 0x9fa10b770e452852612ea392b8521683999d0a168c5eb85a6925d1ffe21d418a + ), + BN254.g1Deserialize( + 0x826a0976821c9309ed896678a97634a2fb1392a64ab8c59c8380012ffb601189 + ), + BN254.g1Deserialize( + 0x3096ba3ed0b597fa29da6caa9000a409702b1f945561e82d02ab77b0cfdb649f + ), + BN254.g1Deserialize( + 0x4a718bc27174d557e036bcbcb9874ce5a6e1a63ccbe491e509d4201bfcb50806 + ) + ]; + + for (uint256 i = 0; i < expected_g.length; i++) { + assertEq(expected_g[i].x, g[i].x, "g.x not equal"); + assertEq(expected_g[i].y, g[i].y, "g.y not equal"); + } + + BN254.G1Point memory expected_blinding = BN254.g1Deserialize( + 0x723737cf1cc96bb40021504a4ff45d21914e9484f2113d66545a3826919a9c25 + ); + + assertEq(expected_blinding.x, h.x, "blinding x not equal"); + assertEq(expected_blinding.y, h.y, "blinding y not equal"); + } + + // Reference test to check that g1Deserialize is correct, taking a point from + // the circuit_gen crate as reference. + function test_deserialize_g1point() public { + BN254.G1Point memory p = BN254.G1Point( + 0x00D2C202A8673B721E5844D8AAE839EB1ABC62386A225545C694079ABF8752C1, + 0x0DF10F9AD0DF8AC9D2BDD487B530CF559B8F19F6F4CF1EB99132C12D4AA60C81 + ); + BN254.G1Point memory deserialized = BN254.g1Deserialize( + 0xc15287bf9a0794c64555226a3862bc1aeb39e8aad844581e723b67a802c2d200 + ); + + assertEq(p.x, deserialized.x, "x not equal"); + assertEq(p.y, deserialized.y, "y not equal"); + } +} diff --git a/demo/eth_verifier/test/Integration.t.sol b/demo/eth_verifier/test/Integration.t.sol new file mode 100644 index 00000000..0dd981a6 --- /dev/null +++ b/demo/eth_verifier/test/Integration.t.sol @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.4.16 <0.9.0; + +import {Test, console2} from "forge-std/Test.sol"; +import "../src/BN254.sol"; +import "../src/Verifier.sol"; +import "../src/msgpack/Deserialize.sol"; +import "../src/Commitment.sol"; + +contract DeserializeTest is Test { + function test_partial_verify() public { + // Data was taken from running the circuit_gen crate. + bytes + memory urs_serialized = hex"92dc0020c4200100000000000000000000000000000000000000000000000000000000000000c42055a8e8d2b2221c2e7641eb8f5b656e352c9e7b5aca91da8ca92fe127e7fb2c21c42003bc09f3825fafdefe1cb25b4a296b60f2129a1c3a90826c3dc2021be421aa8ec4206422698aa4f80a088fd4e0d3a3cd517c2cb1f280cb95c9313823b8f8060f1786c4203558cb03f0cf841ed3a8145a7a8084e182731a9628779ef59d3bc47bae8a1192c4202ac41dd231cb8e97ffc3281b20e6799c0ae18afc13d3de1b4b363a0cd070baa7c420b6205dfa129f52601adfd87829901f06f1fd32e22a71f44b769d674448f05d83c4205d1b9b83cdcba66ff9424c7242c67394d7956dabf5407f4105124b7239d43e80c420e95ffc0999a8997b045430aa564c7bd9a25303e8a5ebbe4a99f6329b7f2a64aac4206cca50f1237f867fee63ac65249d6911494680f42d0e71386b1586be39092f9cc4204b9b17d64b384a65d7c80c8ab0f5fff75c69fd147835599753beea03152a3923c4205c0f706b036ed361e787af70acea3533d6e349869e83368979fdbbf382a4900bc420da6652a81754a6263e677d23a55bd729205f5fb64fa39b6771d9b811e5548bafc4208db1ad69d758362a4ecacff98a6910a95b3c2697e455271b2d7c078f1894eb1fc42010f56f1046a1121b1df5c401969b5acbf80eef8bfd5438270e09243413382788c4200cca37d1a3a721792dc232bb6a95bd14143350b6784bcdd4898a0bb34dd8bd2cc4202b7a1991e05b77d911d15ae590ff6f6ad7d1ed572b34654e3ce92e38e4839425c4201977ca4631e9eea53c7ba59d334c14dac7ee1071d6bf6ebf2ab7450c16975d23c4209eb742379ee8664a8bf9c18a40a534bb2961020bd0077cd0b603d2a8b9fe5a17c4201c50af6002db8dfa5a310ce795dcb06de94ead6687687263fd59acbc8612f180c4205241cbed55fbe1193f366e7ea8ad11bc97742eb35ca39129c4931b9bef64df1ec420646e69eb7d4682ad6bff24d40bf22184694c569246385cc127b3ec4a99875a85c42046b77ed1e120130743344ea9372ea58118604c730800e0d7038f2c80211f4f90c4208f20f3c39a09b5615bd8b2a09eec7dbc11b5ea1f8fe7eb0d5a69c1264412d199c42095f0b87ed771c169a8b6c0a6e21b13ab715407a4e6637a0b8fe0a1e3278f32a7c420a80440e1a07157bad23d7a7d3ddd7445f578021650016fc4bfb3324ed967c82bc4202b94fd0b89e7e2c9d245a4e94a539b14c5db26ed5ba4b3989ef0ba0712d4582ec42068f583079aa73425184a328127be63421eae683a25be94a0aa697ce74b5b972dc4209fa10b770e452852612ea392b8521683999d0a168c5eb85a6925d1ffe21d418ac420826a0976821c9309ed896678a97634a2fb1392a64ab8c59c8380012ffb601189c4203096ba3ed0b597fa29da6caa9000a409702b1f945561e82d02ab77b0cfdb649fc4204a718bc27174d557e036bcbcb9874ce5a6e1a63ccbe491e509d4201bfcb50806c420723737cf1cc96bb40021504a4ff45d21914e9484f2113d66545a3826919a9c250a"; + + (BN254.G1Point[] memory g, BN254.G1Point memory h, uint256 _i) = MsgPk + .deserializeURS(urs_serialized); + + //KimchiVerifier verifier = new KimchiVerifier(g, h, 0, 32, 32); + } +} diff --git a/demo/eth_verifier/test/Verifier.t.sol b/demo/eth_verifier/test/Verifier.t.sol index 92d7d137..482bfabf 100644 --- a/demo/eth_verifier/test/Verifier.t.sol +++ b/demo/eth_verifier/test/Verifier.t.sol @@ -2,22 +2,13 @@ pragma solidity ^0.8.13; import {Test, console2} from "forge-std/Test.sol"; -import {KimchiVerifier} from "../src/Verifier.sol"; -import "../src/BN254.sol"; +import "forge-std/console.sol"; +import {KimchiVerifier, Kimchi} from "../src/Verifier.sol"; +import {BN254} from "../src/BN254.sol"; import "../src/Fields.sol"; +import "../src/msgpack/Deserialize.sol"; contract CounterTest is Test { - KimchiVerifier public verifier; - - function setUp() public { - verifier = new KimchiVerifier(); - } - - function test_Verify() public { - uint256[] memory serializedProof = new uint256[](1); - assertEq(verifier.verify(serializedProof), true); - } - function test_BN254_add_scale() public { BN254.G1Point memory g = BN254.P1(); @@ -28,9 +19,79 @@ contract CounterTest is Test { assertEq(g_plus_g.y, two_g.y, "g + g should equal 2g"); } - function test_PartialVerify() public { - Scalar.FE[] memory public_inputs = new Scalar.FE[](0); - verifier.set_verifier_index_for_testing(); - verifier.partial_verify(public_inputs); - } + /* +[ + 0x92, + 0x91, + 0xc4, + 0x20, + 0x1, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x91, + 0xc4, + 0x20, + 0x1, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, + 0x0, +] + */ } diff --git a/demo/eth_verifier/verifier_index.json b/demo/eth_verifier/verifier_index.json deleted file mode 100644 index 9eb69a39..00000000 --- a/demo/eth_verifier/verifier_index.json +++ /dev/null @@ -1,195 +0,0 @@ -{ - "domain": "200000000000000005000000200000000000000000000000000000000000000000000000000000000000000001008050e7e5c2b90ca5eb350649f23e9a4d75cd88c38d6a2813284aff2be12ed012b53b534ced3e1deb8e831bd5189ca9b2c0470d207896d2936b30c632c5099d9710f20c98998c4d5b903413318fefe7d825dfe7f3ea0a79bdbf0336712427676666c6d4fbf3e7062d4acae95caea98b56cd337cb5b949aad9135a94525b13", - "max_poly_size": 32, - "zk_rows": 3, - "public": 0, - "prev_challenges": 0, - "sigma_comm": [ - { - "unshifted": [ - "e824044629235eade6c8f9d244e221fc2145e9c41403bbf35783ff930bb2c498" - ], - "shifted": null - }, - { - "unshifted": [ - "86224abf2e51c5e4c4b3e205b14e6b56dd3f57d3b5244d003da4d75a005e1a96" - ], - "shifted": null - }, - { - "unshifted": [ - "70676edc5b830cf519d7c59a5405e85a879ea170781430df7fa29633306d5113" - ], - "shifted": null - }, - { - "unshifted": [ - "51fd0f8c5a67853fd0fc96a893bc2f055f542ef64d14ae8620601cf26a08cc07" - ], - "shifted": null - }, - { - "unshifted": [ - "78d374f86b14e6d42602b65a230c48afcc1d9159128744a02510d3dd5d3cc18c" - ], - "shifted": null - }, - { - "unshifted": [ - "e0798f3d3ef574ad901ef908f2041c29a49e9d603449762dbc65120c9ed41086" - ], - "shifted": null - }, - { - "unshifted": [ - "0af27ce1201fb663983b8580be808aea4bda967900538b0b991d96805e92f2a5" - ], - "shifted": null - } - ], - "coefficients_comm": [ - { - "unshifted": [ - "96fcb79f39e1b2ca05c24ec59b663abce1951e4d975df52bb30c66d25aa00aac" - ], - "shifted": null - }, - { - "unshifted": [ - "fce49faaaf73f1a7f97eb1b419522e767a3f4c491db9d9794656c95209d91629" - ], - "shifted": null - }, - { - "unshifted": [ - "cc70b15a765c878faf4dc60f290639815ed97d5de66eca39840fd8401a602717" - ], - "shifted": null - }, - { - "unshifted": [ - "0000000000000000000000000000000000000000000000000000000000000040" - ], - "shifted": null - }, - { - "unshifted": [ - "66bc81618cdcc614a866ec8f5e31519b9c2dfbbe7ebda52a2e1a93690fb999ad" - ], - "shifted": null - }, - { - "unshifted": [ - "ac7cfed4ced44c7a00f21c4da5ea16dcdc363a998852669a440f389582449e0a" - ], - "shifted": null - }, - { - "unshifted": [ - "0000000000000000000000000000000000000000000000000000000000000040" - ], - "shifted": null - }, - { - "unshifted": [ - "cc70b15a765c878faf4dc60f290639815ed97d5de66eca39840fd8401a602717" - ], - "shifted": null - }, - { - "unshifted": [ - "1f7e7d9c6cd2d542f2bd0593889dbb9e15d0784e78d0b3d5e0db55d0380adbae" - ], - "shifted": null - }, - { - "unshifted": [ - "2155549de8bb8e319fb079e27b111317a943daabee44675ba60b7bc70829eda2" - ], - "shifted": null - }, - { - "unshifted": [ - "0000000000000000000000000000000000000000000000000000000000000040" - ], - "shifted": null - }, - { - "unshifted": [ - "0000000000000000000000000000000000000000000000000000000000000040" - ], - "shifted": null - }, - { - "unshifted": [ - "0000000000000000000000000000000000000000000000000000000000000040" - ], - "shifted": null - }, - { - "unshifted": [ - "0000000000000000000000000000000000000000000000000000000000000040" - ], - "shifted": null - }, - { - "unshifted": [ - "0000000000000000000000000000000000000000000000000000000000000040" - ], - "shifted": null - } - ], - "generic_comm": { - "unshifted": [ - "3fb77ea14130b6c6a6ec7a783b0295215f658f7c08f92f6a0bd22322395eaf25" - ], - "shifted": null - }, - "psm_comm": { - "unshifted": [ - "723737cf1cc96bb40021504a4ff45d21914e9484f2113d66545a3826919a9c25" - ], - "shifted": null - }, - "complete_add_comm": { - "unshifted": [ - "723737cf1cc96bb40021504a4ff45d21914e9484f2113d66545a3826919a9c25" - ], - "shifted": null - }, - "mul_comm": { - "unshifted": [ - "723737cf1cc96bb40021504a4ff45d21914e9484f2113d66545a3826919a9c25" - ], - "shifted": null - }, - "emul_comm": { - "unshifted": [ - "723737cf1cc96bb40021504a4ff45d21914e9484f2113d66545a3826919a9c25" - ], - "shifted": null - }, - "endomul_scalar_comm": { - "unshifted": [ - "723737cf1cc96bb40021504a4ff45d21914e9484f2113d66545a3826919a9c25" - ], - "shifted": null - }, - "range_check0_comm": null, - "range_check1_comm": null, - "foreign_field_add_comm": null, - "foreign_field_mul_comm": null, - "xor_comm": null, - "rot_comm": null, - "shift": [ - "0100000000000000000000000000000000000000000000000000000000000000", - "e3a214e91334d0caf1eb85df5bd7524d73d5eb7aaf742a7eb2d40bfdc8cdb900", - "6d0f44339a339fb8a4e49bf1099620aa649918482b95a397ae39b9ec5ad47700", - "b40923bd78e619c80a7b39c0f3f11e48005519d2fef16a1f77d40545e5c77700", - "f9c95cd6b11b38df7855fd4d2a036329adcad613f100b923109540356a597c00", - "5a696526fa309c412c10e86604c3c0ad2cd9443dd85b823203721281cfbf3300", - "43423bb307cec19f297c4188deb23acc7b5812719b2eaccbf1b7034ae6ace800" - ], - "lookup_index": null -} \ No newline at end of file