From 1572b9350605cd13e0fe94846e07aa60774698be Mon Sep 17 00:00:00 2001 From: cf Date: Sat, 14 Oct 2023 16:29:36 +0800 Subject: [PATCH] Updated to use the same round constants as other (previously using custom parameters generated by sage) --- src/goldilocks-12/constants.ts | 434 ++++++++++----------------------- test/goldilocks-12.test.ts | 51 ++-- 2 files changed, 157 insertions(+), 328 deletions(-) diff --git a/src/goldilocks-12/constants.ts b/src/goldilocks-12/constants.ts index d8abe50..f37f2bb 100644 --- a/src/goldilocks-12/constants.ts +++ b/src/goldilocks-12/constants.ts @@ -1,249 +1,79 @@ const MAT_DIAG12_M_1: bigint[] = [ - BigInt("0xcf6f77ac16722af9"), - BigInt("0x3fd4c0d74672aebc"), - BigInt("0x9b72bf1c1c3d08a8"), - BigInt("0xe4940f84b71e4ac2"), - BigInt("0x61b27b077118bc72"), - BigInt("0x2efd8379b8e661e2"), - BigInt("0x858edcf353df0341"), - BigInt("0x2d9c20affb5c4516"), - BigInt("0x5120143f0695defb"), - BigInt("0x62fc898ae34a5c5b"), - BigInt("0xa3d9560c99123ed2"), - BigInt("0x98fd739d8e7fc933"), -]; -const one = BigInt(1); -const zero = BigInt(0); -const MAT_INTERNAL12: bigint[][] = [ - [ - BigInt("0xcf6f77ac16722afa"), - one, - one, - one, - one, - one, - one, - one, - one, - one, - one, - one, - ], - [ - one, - BigInt("0x3fd4c0d74672aebd"), - one, - one, - one, - one, - one, - one, - one, - one, - one, - one, - ], - [ - one, - one, - BigInt("0x9b72bf1c1c3d08a9"), - one, - one, - one, - one, - one, - one, - one, - one, - one, - ], - [ - one, - one, - one, - BigInt("0xe4940f84b71e4ac3"), - one, - one, - one, - one, - one, - one, - one, - one, - ], - [ - one, - one, - one, - one, - BigInt("0x61b27b077118bc73"), - one, - one, - one, - one, - one, - one, - one, - ], - [ - one, - one, - one, - one, - one, - BigInt("0x2efd8379b8e661e3"), - one, - one, - one, - one, - one, - one, - ], - [ - one, - one, - one, - one, - one, - one, - BigInt("0x858edcf353df0342"), - one, - one, - one, - one, - one, - ], - [ - one, - one, - one, - one, - one, - one, - one, - BigInt("0x2d9c20affb5c4517"), - one, - one, - one, - one, - ], - [ - one, - one, - one, - one, - one, - one, - one, - one, - BigInt("0x5120143f0695defc"), - one, - one, - one, - ], - [ - one, - one, - one, - one, - one, - one, - one, - one, - one, - BigInt("0x62fc898ae34a5c5c"), - one, - one, - ], - [ - one, - one, - one, - one, - one, - one, - one, - one, - one, - one, - BigInt("0xa3d9560c99123ed3"), - one, - ], - [ - one, - one, - one, - one, - one, - one, - one, - one, - one, - one, - one, - BigInt("0x98fd739d8e7fc934"), - ], + BigInt("14102670999874605823"), + BigInt("15585654191999307701"), + BigInt("940187017142450254"), + BigInt("8747386241522630710"), + BigInt("6750641561540124746"), + BigInt("7440998025584530006"), + BigInt("6136358134615751535"), + BigInt("12413576830284969610"), + BigInt("11675438539028694708"), + BigInt("17580553691069642925"), + BigInt("892707462476851330"), + BigInt("15167485180850043743"), ]; +const zero = BigInt(0); +const MAT_INTERNAL12: bigint[][] = []; const RC12: bigint[][] = [ [ - BigInt("0xe034a8785fd284a7"), - BigInt("0xe2463f1ea42e1b80"), - BigInt("0x048742e681ae290a"), - BigInt("0xe4af50ade990154c"), - BigInt("0x8b13ffaaf4f78f8a"), - BigInt("0xe3fbead7dccd8d63"), - BigInt("0x631a47705eb92bf8"), - BigInt("0x88fbbb8698548659"), - BigInt("0x74cd2003b0f349c9"), - BigInt("0xe16a3df6764a3f5d"), - BigInt("0x57ce63971a71aaa2"), - BigInt("0xdc1f7fd3e7823051"), + BigInt("0x13dcf33aba214f46"), + BigInt("0x30b3b654a1da6d83"), + BigInt("0x1fc634ada6159b56"), + BigInt("0x937459964dc03466"), + BigInt("0xedd2ef2ca7949924"), + BigInt("0xede9affde0e22f68"), + BigInt("0x8515b9d6bac9282d"), + BigInt("0x6b5c07b4e9e900d8"), + BigInt("0x1ec66368838c8a08"), + BigInt("0x9042367d80d1fbab"), + BigInt("0x400283564a3c3799"), + BigInt("0x4a00be0466bca75e"), ], [ - BigInt("0xbb8423be34c18d7a"), - BigInt("0xf8bc5a2a0c1b3d6d"), - BigInt("0xf1a01bbd6f7123e5"), - BigInt("0xed960a080f5e348b"), - BigInt("0x1b9c0c1e87e2390e"), - BigInt("0x18c83caf729a613e"), - BigInt("0x671ab9fe037a72c4"), - BigInt("0x508565f67d4c276a"), - BigInt("0x4d2cd8827a482590"), - BigInt("0xa48e11e84dd3500b"), - BigInt("0x825a8c955fc2442b"), - BigInt("0xf573a6ee07cddc68"), + BigInt("0x7913beee58e3817f"), + BigInt("0xf545e88532237d90"), + BigInt("0x22f8cb8736042005"), + BigInt("0x6f04990e247a2623"), + BigInt("0xfe22e87ba37c38cd"), + BigInt("0xd20e32c85ffe2815"), + BigInt("0x117227674048fe73"), + BigInt("0x4e9fb7ea98a6b145"), + BigInt("0xe0866c232b8af08b"), + BigInt("0x00bbc77916884964"), + BigInt("0x7031c0fb990d7116"), + BigInt("0x240a9e87cf35108f"), ], [ - BigInt("0x7dd3f19c73a39e0b"), - BigInt("0xcc0f13537a796fa6"), - BigInt("0x1d9006bfaedac57f"), - BigInt("0x4705f69b68b0b7de"), - BigInt("0x5b62bfb718bcc57f"), - BigInt("0x879d821770563827"), - BigInt("0x3da5ccb7f8dff0e3"), - BigInt("0xb49d6a706923fc5b"), - BigInt("0xb6a0babe883a969d"), - BigInt("0x2984f9b055401960"), - BigInt("0xcd3496f05511d79d"), - BigInt("0x4791da5d63854fc5"), + BigInt("0x2e6363a5a12244b3"), + BigInt("0x5e1c3787d1b5011c"), + BigInt("0x4132660e2a196e8b"), + BigInt("0x3a013b648d3d4327"), + BigInt("0xf79839f49888ea43"), + BigInt("0xfe85658ebafe1439"), + BigInt("0xb6889825a14240bd"), + BigInt("0x578453605541382b"), + BigInt("0x4508cda8f6b63ce9"), + BigInt("0x9c3ef35848684c91"), + BigInt("0x0812bde23c87178c"), + BigInt("0xfe49638f7f722c14"), ], [ - BigInt("0xdb7344d0580a39d4"), - BigInt("0x5aedc4dad1de120a"), - BigInt("0x5e1bdc1fb8e1abf0"), - BigInt("0x3904c09a0e46747c"), - BigInt("0xb54a0e23ab85ddcd"), - BigInt("0xc0c3cf05bccbdb3a"), - BigInt("0xb362076a73baf7e9"), - BigInt("0x212c953d81a5d5ba"), - BigInt("0x212d4cc965d898bd"), - BigInt("0xdd44ddd0f41509b9"), - BigInt("0x8931329fa67823c0"), - BigInt("0xc65510f4d2a873be"), + BigInt("0x8e3f688ce885cbf5"), + BigInt("0xb8e110acf746a87d"), + BigInt("0xb4b2e8973a6dabef"), + BigInt("0x9e714c5da3d462ec"), + BigInt("0x6438f9033d3d0c15"), + BigInt("0x24312f7cf1a27199"), + BigInt("0x23f843bb47acbf71"), + BigInt("0x9183f11a34be9f01"), + BigInt("0x839062fbb9d45dbf"), + BigInt("0x24b56e7e6c2e43fa"), + BigInt("0xe1683da61c962a72"), + BigInt("0xa95c63971a19bfa7"), ], [ - BigInt("0xe3ecbb6ba1e16211"), + BigInt("0x4adf842aa75d4316"), zero, zero, zero, @@ -257,7 +87,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0x70f5b3266792bbb6"), + BigInt("0xf8fbb871aa4ab4eb"), zero, zero, zero, @@ -271,7 +101,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0xe7560e690634757e"), + BigInt("0x68e85b6eb2dd6aeb"), zero, zero, zero, @@ -285,7 +115,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0xafd0202bc7eaf66e"), + BigInt("0x07a0b06b2d270380"), zero, zero, zero, @@ -299,7 +129,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0x349f4c5871f220fd"), + BigInt("0xd94e0228bd282de4"), zero, zero, zero, @@ -313,7 +143,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0x3697eb3e31529e0d"), + BigInt("0x8bdd91d3250c5278"), zero, zero, zero, @@ -327,7 +157,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0x7735d5b0622d9900"), + BigInt("0x209c68b88bba778f"), zero, zero, zero, @@ -341,7 +171,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0x5f5b58b9cf997668"), + BigInt("0xb5e18cdab77f3877"), zero, zero, zero, @@ -355,7 +185,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0x645534b6548af9d9"), + BigInt("0xb296a3e808da93fa"), zero, zero, zero, @@ -369,7 +199,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0x4232d29d91a426a8"), + BigInt("0x8370ecbda11a327e"), zero, zero, zero, @@ -383,7 +213,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0xb987278aed485d35"), + BigInt("0x3f9075283775dad8"), zero, zero, zero, @@ -397,7 +227,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0x6dabeef669bb406e"), + BigInt("0xb78095bb23c6aa84"), zero, zero, zero, @@ -411,7 +241,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0x35ee78288b749d40"), + BigInt("0x3f36b9fe72ad4e5f"), zero, zero, zero, @@ -425,7 +255,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0x6dcd560f14af0fc3"), + BigInt("0x69bc96780b10b553"), zero, zero, zero, @@ -439,7 +269,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0x71ed3dc007ea6383"), + BigInt("0x3f1d341f2eb7b881"), zero, zero, zero, @@ -453,7 +283,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0x8b6b51caab7f5b6f"), + BigInt("0x4e939e9815838818"), zero, zero, zero, @@ -467,7 +297,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0xcf2e8cc4181dbfa8"), + BigInt("0xda366b3ae2a31604"), zero, zero, zero, @@ -481,7 +311,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0xa01d3f1c306f825a"), + BigInt("0xbc89db1e7287d509"), zero, zero, zero, @@ -495,7 +325,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0xccee646a5d8ddb87"), + BigInt("0x6102f411f9ef5659"), zero, zero, zero, @@ -509,7 +339,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0x70df6f277cbaffeb"), + BigInt("0x58725c5e7ac1f0ab"), zero, zero, zero, @@ -523,7 +353,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0x64ec0a6556b8f45c"), + BigInt("0x0df5856c798883e7"), zero, zero, zero, @@ -537,7 +367,7 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0x6f68c9664fda6e37"), + BigInt("0xf7bb62a8da4c961b"), zero, zero, zero, @@ -551,60 +381,60 @@ const RC12: bigint[][] = [ zero, ], [ - BigInt("0x387356e4516fab6f"), - BigInt("0x35310dce33903e67"), - BigInt("0x45f3e5251d30f912"), - BigInt("0x7c97f480ca428f45"), - BigInt("0x74d5874c20b50de2"), - BigInt("0xff1d5b7cee3dc67f"), - BigInt("0xa04d5d5ac0ff3de9"), - BigInt("0x1cefb5eb7d24580e"), - BigInt("0xf685e1bfcc0104ad"), - BigInt("0x6204dd95db22ead4"), - BigInt("0x8265c6c57c73c440"), - BigInt("0x4f708ab0b4e1e382"), + BigInt("0xc68be7c94882a24d"), + BigInt("0xaf996d5d5cdaedd9"), + BigInt("0x9717f025e7daf6a5"), + BigInt("0x6436679e6e7216f4"), + BigInt("0x8a223d99047af267"), + BigInt("0xbb512e35a133ba9a"), + BigInt("0xfbbf44097671aa03"), + BigInt("0xf04058ebf6811e61"), + BigInt("0x5cca84703fac7ffb"), + BigInt("0x9b55c7945de6469f"), + BigInt("0x8e05bf09808e934f"), + BigInt("0x2ea900de876307d7"), ], [ - BigInt("0xcfc60c7a52fbffa7"), - BigInt("0x9c0c1951d8910306"), - BigInt("0x4d06df27c89819f2"), - BigInt("0x621bdb0e75eca660"), - BigInt("0x343adffd079cee57"), - BigInt("0xa760f0e5debde398"), - BigInt("0xe3110fefd97b188a"), - BigInt("0x0ed6584e6b150297"), - BigInt("0x2b10e625d0d079c0"), - BigInt("0xefa493442057264f"), - BigInt("0xebcfaa7b3f26a2b6"), - BigInt("0xf36bcda28e343e2a"), + BigInt("0x7748fff2b38dfb89"), + BigInt("0x6b99a676dd3b5d81"), + BigInt("0xac4bb7c627cf7c13"), + BigInt("0xadb6ebe5e9e2f5ba"), + BigInt("0x2d33378cafa24ae3"), + BigInt("0x1e5b73807543f8c2"), + BigInt("0x09208814bfebb10f"), + BigInt("0x782e64b6bb5b93dd"), + BigInt("0xadd5a48eac90b50f"), + BigInt("0xadd4c54c736ea4b1"), + BigInt("0xd58dbb86ed817fd8"), + BigInt("0x6d5ed1a533f34ddd"), ], [ - BigInt("0xa1183cb63b67aa9e"), - BigInt("0x40f3e415d5e5b0ba"), - BigInt("0xc51fc2367eff7b15"), - BigInt("0xe07fe5f3aebc649f"), - BigInt("0xc9cb2be56968e8aa"), - BigInt("0x648600db69078a0e"), - BigInt("0x4e9135ab1256edb9"), - BigInt("0x00382c73435556c2"), - BigInt("0x1d78cafac9150ddf"), - BigInt("0xb8df60ab6215a233"), - BigInt("0xa7a65ba31f8fcd9a"), - BigInt("0x907d436dd964006b"), + BigInt("0x28686aa3e36b7cb9"), + BigInt("0x591abd3476689f36"), + BigInt("0x047d766678f13875"), + BigInt("0xa2a11112625f5b49"), + BigInt("0x21fd10a3f8304958"), + BigInt("0xf9b40711443b0280"), + BigInt("0xd2697eb8b2bde88e"), + BigInt("0x3493790b51731b3f"), + BigInt("0x11caf9dd73764023"), + BigInt("0x7acfb8f72878164e"), + BigInt("0x744ec4db23cefc26"), + BigInt("0x1e00e58f422c6340"), ], [ - BigInt("0x3bdf7fd528633b97"), - BigInt("0x265adb359c0cc0f8"), - BigInt("0xf16cfc4034b39614"), - BigInt("0x71f0751b08fa0947"), - BigInt("0x3165eda4b5403a37"), - BigInt("0xca30fc5680467e46"), - BigInt("0x4c743354d37777c5"), - BigInt("0x3d1f0a4e6bba4a09"), - BigInt("0xc0c2e289afa75181"), - BigInt("0x1e4fa2ad948978b7"), - BigInt("0x2a226a127a0bb26a"), - BigInt("0xe61738a70357ce76"), + BigInt("0x21dd28d906a62dda"), + BigInt("0xf32a46ab5f465b5f"), + BigInt("0xbfce13201f3f7e6b"), + BigInt("0xf30d2e7adb5304e2"), + BigInt("0xecdf4ee4abad48e9"), + BigInt("0xf94e82182d395019"), + BigInt("0x4ee52e3744d887c5"), + BigInt("0xa1341c7cac0083b2"), + BigInt("0x2302fb26c30c834a"), + BigInt("0xaea3c587273bf7d3"), + BigInt("0xf798e24961823ec7"), + BigInt("0x962deba3e9a2cd94"), ], ]; diff --git a/test/goldilocks-12.test.ts b/test/goldilocks-12.test.ts index 7bb489c..e436712 100644 --- a/test/goldilocks-12.test.ts +++ b/test/goldilocks-12.test.ts @@ -1,6 +1,5 @@ import { describe, expect, it } from "vitest"; -import { Poseidon2Goldilocks12 } from "../src/goldilocks-12"; - +import { Poseidon2Goldilocks12, hashNoPad } from "../src/goldilocks-12"; describe("poseidon2 goldilocks 12", () => { it("permute [0,0,0,0,0,0,0,0,0,0,0,0] ", () => { const zero = BigInt(0); @@ -20,18 +19,18 @@ describe("poseidon2 goldilocks 12", () => { ]; const permuteResult = Poseidon2Goldilocks12.permute(state); expect(permuteResult).toEqual([ - BigInt("4676078130971295920"), - BigInt("10183258696855793571"), - BigInt("15600641847707049561"), - BigInt("6602041563876587060"), - BigInt("13137619883760816643"), - BigInt("8849590418944608963"), - BigInt("10998040560159952847"), - BigInt("15206271513183927451"), - BigInt("5975958540203922369"), - BigInt("15926261106117560013"), - BigInt("17396220699479397239"), - BigInt("16744530920792852206"), + BigInt("2706484646582314364"), + BigInt("16460758560799937193"), + BigInt("2052063466144512209"), + BigInt("9649607828149110866"), + BigInt("2033662915869228037"), + BigInt("16251664193980936151"), + BigInt("1869425810546879860"), + BigInt("399174958178618195"), + BigInt("963282781129924902"), + BigInt("348076645890865798"), + BigInt("8513101393627905513"), + BigInt("13429406292428034341"), ]); }); it("permute [0,1,2,3,4,5,6,7,8,9,10,11] ", () => { @@ -51,18 +50,18 @@ describe("poseidon2 goldilocks 12", () => { ]; const permuteResult = Poseidon2Goldilocks12.permute(state); expect(permuteResult).toEqual([ - BigInt("17095027314848075059"), - BigInt("18124150414442078544"), - BigInt("15284687323142546159"), - BigInt("6784844296492226711"), - BigInt("4870838776976620139"), - BigInt("6222185298486530077"), - BigInt("16450947849879353518"), - BigInt("643974238185471420"), - BigInt("2975392058905691406"), - BigInt("11609261642319894788"), - BigInt("11999098011033569640"), - BigInt("1713291167031093441"), + BigInt("14495112113092593719"), + BigInt("10329066293759305023"), + BigInt("4698416604356330095"), + BigInt("14656054275012077034"), + BigInt("14040445052016575643"), + BigInt("18281582380570098475"), + BigInt("6807696650297444323"), + BigInt("6066054412809714982"), + BigInt("5411921328316089755"), + BigInt("14958086802832817041"), + BigInt("4858815946660806269"), + BigInt("8971086601262742856"), ]); }); });