From 9bf867b8216c883d4501af750ce8c8f69a0aa203 Mon Sep 17 00:00:00 2001 From: Balazs Komuves Date: Sun, 29 Sep 2024 19:26:40 +0200 Subject: [PATCH] add tests for Poseidon2 permutations --- poseidon2/permutation.nim | 8 ++- reference/Poseidon2.hs | 5 +- .../{TestGen.hs => TestGen/TestGoldilocks.hs} | 4 +- reference/TestGen/TestPermutation.hs | 64 +++++++++++++++++++ tests/poseidon2/permTestCases.nim | 25 ++++++++ tests/poseidon2/reference.nim | 5 -- tests/poseidon2/testPermutation.nim | 10 +++ 7 files changed, 112 insertions(+), 9 deletions(-) rename reference/{TestGen.hs => TestGen/TestGoldilocks.hs} (96%) create mode 100644 reference/TestGen/TestPermutation.hs create mode 100644 tests/poseidon2/permTestCases.nim delete mode 100644 tests/poseidon2/reference.nim diff --git a/poseidon2/permutation.nim b/poseidon2/permutation.nim index 3c7915f..e9ee2c1 100644 --- a/poseidon2/permutation.nim +++ b/poseidon2/permutation.nim @@ -2,10 +2,16 @@ import ./types # the Poseidon2 permutation (mutable, in-place version) -proc permInPlace*(state: var State) {. header: "../cbits/goldilocks.h", importc: "goldilocks_poseidon2_permutation", cdecl .} +proc permInPlace* (state: var State) {. header: "../cbits/goldilocks.h", importc: "goldilocks_poseidon2_permutation", cdecl .} +proc permInPlaceF12*(state: var F12 ) {. header: "../cbits/goldilocks.h", importc: "goldilocks_poseidon2_permutation", cdecl .} # the Poseidon2 permutation (pure version) func perm*(state: State): State = var tmp = state permInPlace(tmp) return tmp + +func permF12*(state: F12): F12 = + var tmp = state + permInPlaceF12(tmp) + return tmp diff --git a/reference/Poseidon2.hs b/reference/Poseidon2.hs index 08257d0..d2ba9c1 100644 --- a/reference/Poseidon2.hs +++ b/reference/Poseidon2.hs @@ -14,8 +14,11 @@ import Constants type State = Array Int F +listToState :: [F] -> State +listToState = listArray (0,11) + zeroState :: State -zeroState = listArray (0,11) (replicate 12 0) +zeroState = listToState (replicate 12 0) -------------------------------------------------------------------------------- diff --git a/reference/TestGen.hs b/reference/TestGen/TestGoldilocks.hs similarity index 96% rename from reference/TestGen.hs rename to reference/TestGen/TestGoldilocks.hs index 4dfc793..fc69335 100644 --- a/reference/TestGen.hs +++ b/reference/TestGen/TestGoldilocks.hs @@ -1,7 +1,7 @@ -- | Generate test cases for Nim -module TestGen where +module TestGen.TestGoldilocks where -------------------------------------------------------------------------------- @@ -80,7 +80,7 @@ hPrintTests h = hPutStrLn h $ unlines writeTests :: IO () writeTests = withFile "fieldTestCases.nim" WriteMode $ \h -> do - hPutStrLn h "# generated by TestGen.hs\n" + hPutStrLn h "# generated by TestGen/TestGoldilocks.hs\n" -- hPutStrLn h "import poseidon2/types\n" hPrintTests h diff --git a/reference/TestGen/TestPermutation.hs b/reference/TestGen/TestPermutation.hs new file mode 100644 index 0000000..bf2f22f --- /dev/null +++ b/reference/TestGen/TestPermutation.hs @@ -0,0 +1,64 @@ + +-- | Generate test cases for Nim + +module TestGen.TestPermutation where + +-------------------------------------------------------------------------------- + +import Data.Array +import Data.List + +import System.IO + +import Goldilocks +import Poseidon2 + +-------------------------------------------------------------------------------- + +nimShowF :: F -> String +nimShowF x = "toF( " ++ show x ++ "'u64 )" + +nimShowState :: State -> String +nimShowState xs = "[ " ++ intercalate ", " (map nimShowF (elems xs)) ++ " ]" + +nimShowStatePair :: (State,State) -> String +nimShowStatePair (x,y) = "( " ++ nimShowState x ++ " , " ++ nimShowState y ++ " )" + +showListWith :: (a -> String) -> [a] -> [String] +showListWith f xys = zipWith (++) prefix (map f xys) where + prefix = " [ " : repeat " , " + +---------------------------------------- + +perms :: String -> (State -> State) -> [State] -> String +perms varname f xs = unlines (header : stuff ++ footer) where + header = "const " ++ varname ++ "* : array[" ++ show (length xs) ++ ", tuple[xs:F12, ys:F12]] = " + footer = [" ]",""] + stuff = showListWith nimShowStatePair [ (x, f x) | x<-xs ] + +-------------------------------------------------------------------------------- + +testStates :: [State] +testStates = + [ listToState [ fromInteger (a + b*i) | i<-[0..11] ] + | a <- [0,10,200,3000] + , b <- [1, 7, 23, 666] + ] + +-------------------------------------------------------------------------------- + +printTests :: IO () +printTests = hPrintTests stdout + +hPrintTests :: Handle -> IO () +hPrintTests h = hPutStrLn h $ unlines + [ perms "testcases_perm" permutation testStates + ] + +writeTests :: IO () +writeTests = withFile "permTestCases.nim" WriteMode $ \h -> do + hPutStrLn h "# generated by TestGen/TestPermutation.hs\n" + -- hPutStrLn h "import poseidon2/types\n" + hPrintTests h + +-------------------------------------------------------------------------------- diff --git a/tests/poseidon2/permTestCases.nim b/tests/poseidon2/permTestCases.nim new file mode 100644 index 0000000..e1f055d --- /dev/null +++ b/tests/poseidon2/permTestCases.nim @@ -0,0 +1,25 @@ +# generated by TestGen/TestPermutation.hs + +import poseidon2/types + +const testcases_perm* : array[16, tuple[xs:F12, ys:F12]] = + [ ( [ toF( 0x0000000000000000'u64 ), toF( 0x0000000000000001'u64 ), toF( 0x0000000000000002'u64 ), toF( 0x0000000000000003'u64 ), toF( 0x0000000000000004'u64 ), toF( 0x0000000000000005'u64 ), toF( 0x0000000000000006'u64 ), toF( 0x0000000000000007'u64 ), toF( 0x0000000000000008'u64 ), toF( 0x0000000000000009'u64 ), toF( 0x000000000000000a'u64 ), toF( 0x000000000000000b'u64 ) ] , [ toF( 0x01eaef96bdf1c0c1'u64 ), toF( 0x1f0d2cc525b2540c'u64 ), toF( 0x6282c1dfe1e0358d'u64 ), toF( 0xe780d721f698e1e6'u64 ), toF( 0x280c0b6f753d833b'u64 ), toF( 0x1b942dd5023156ab'u64 ), toF( 0x43f0df3fcccb8398'u64 ), toF( 0xe8e8190585489025'u64 ), toF( 0x56bdbf72f77ada22'u64 ), toF( 0x7911c32bf9dcd705'u64 ), toF( 0xec467926508fbe67'u64 ), toF( 0x6a50450ddf85a6ed'u64 ) ] ) + , ( [ toF( 0x0000000000000000'u64 ), toF( 0x0000000000000007'u64 ), toF( 0x000000000000000e'u64 ), toF( 0x0000000000000015'u64 ), toF( 0x000000000000001c'u64 ), toF( 0x0000000000000023'u64 ), toF( 0x000000000000002a'u64 ), toF( 0x0000000000000031'u64 ), toF( 0x0000000000000038'u64 ), toF( 0x000000000000003f'u64 ), toF( 0x0000000000000046'u64 ), toF( 0x000000000000004d'u64 ) ] , [ toF( 0xcc6b406ad4c5760d'u64 ), toF( 0x56c8746a765d8464'u64 ), toF( 0xb5f7cafbfa5770ab'u64 ), toF( 0x2e60e0c789dc2a61'u64 ), toF( 0xaafafd27b236c935'u64 ), toF( 0xf0423c0b2592a28a'u64 ), toF( 0x0ed35368cb5b52eb'u64 ), toF( 0xf782cde221cb0a2b'u64 ), toF( 0x77b9bd47dcd3daee'u64 ), toF( 0x48e0d4ac0f477e58'u64 ), toF( 0xe373a032dbfb5636'u64 ), toF( 0x7f6bd0246f0e835d'u64 ) ] ) + , ( [ toF( 0x0000000000000000'u64 ), toF( 0x0000000000000017'u64 ), toF( 0x000000000000002e'u64 ), toF( 0x0000000000000045'u64 ), toF( 0x000000000000005c'u64 ), toF( 0x0000000000000073'u64 ), toF( 0x000000000000008a'u64 ), toF( 0x00000000000000a1'u64 ), toF( 0x00000000000000b8'u64 ), toF( 0x00000000000000cf'u64 ), toF( 0x00000000000000e6'u64 ), toF( 0x00000000000000fd'u64 ) ] , [ toF( 0xbb56371ffc6e427e'u64 ), toF( 0xf0236404542eb106'u64 ), toF( 0xf9ac54b9387bbf56'u64 ), toF( 0x31fdde0cbaf5de06'u64 ), toF( 0xdb9959ea7846607a'u64 ), toF( 0x514f58fb8f3b37d7'u64 ), toF( 0x70b6f3e1f900266c'u64 ), toF( 0x1c533b5692acd23e'u64 ), toF( 0x38a22bc2b2bbb094'u64 ), toF( 0x0cce7d10bd665781'u64 ), toF( 0xc57ef51b15b4c7f0'u64 ), toF( 0x5cdb523d93d10683'u64 ) ] ) + , ( [ toF( 0x0000000000000000'u64 ), toF( 0x000000000000029a'u64 ), toF( 0x0000000000000534'u64 ), toF( 0x00000000000007ce'u64 ), toF( 0x0000000000000a68'u64 ), toF( 0x0000000000000d02'u64 ), toF( 0x0000000000000f9c'u64 ), toF( 0x0000000000001236'u64 ), toF( 0x00000000000014d0'u64 ), toF( 0x000000000000176a'u64 ), toF( 0x0000000000001a04'u64 ), toF( 0x0000000000001c9e'u64 ) ] , [ toF( 0x7baee2c959bd6a21'u64 ), toF( 0x1e010f30fe27dc83'u64 ), toF( 0x3eb0b4a52409df49'u64 ), toF( 0xd2233ef2ef6df35a'u64 ), toF( 0xdd221afa3b2610b4'u64 ), toF( 0xde7a46cf3ac8eb08'u64 ), toF( 0x0e3d69b5c977c57b'u64 ), toF( 0x44cfa74beddc2195'u64 ), toF( 0x0372ac777efa24b7'u64 ), toF( 0x75d3ff9b55510855'u64 ), toF( 0x8c2e839cb8fc2b52'u64 ), toF( 0x6c00f51375619c7c'u64 ) ] ) + , ( [ toF( 0x000000000000000a'u64 ), toF( 0x000000000000000b'u64 ), toF( 0x000000000000000c'u64 ), toF( 0x000000000000000d'u64 ), toF( 0x000000000000000e'u64 ), toF( 0x000000000000000f'u64 ), toF( 0x0000000000000010'u64 ), toF( 0x0000000000000011'u64 ), toF( 0x0000000000000012'u64 ), toF( 0x0000000000000013'u64 ), toF( 0x0000000000000014'u64 ), toF( 0x0000000000000015'u64 ) ] , [ toF( 0x873fac46ec6c5c8f'u64 ), toF( 0x3c25ab35affd533c'u64 ), toF( 0x27dfa19a47645734'u64 ), toF( 0xb0748186a0a44db1'u64 ), toF( 0x40eb79bddcce8ad4'u64 ), toF( 0x53fc7bce6012f6b1'u64 ), toF( 0x669eae43871d106a'u64 ), toF( 0xfdcb8f1d4b140cc6'u64 ), toF( 0xcca492be074f0ab7'u64 ), toF( 0x71a9565835735d91'u64 ), toF( 0x876dc052e0d551cd'u64 ), toF( 0x9b860b421fada35b'u64 ) ] ) + , ( [ toF( 0x000000000000000a'u64 ), toF( 0x0000000000000011'u64 ), toF( 0x0000000000000018'u64 ), toF( 0x000000000000001f'u64 ), toF( 0x0000000000000026'u64 ), toF( 0x000000000000002d'u64 ), toF( 0x0000000000000034'u64 ), toF( 0x000000000000003b'u64 ), toF( 0x0000000000000042'u64 ), toF( 0x0000000000000049'u64 ), toF( 0x0000000000000050'u64 ), toF( 0x0000000000000057'u64 ) ] , [ toF( 0x13b2e757ea41c2c0'u64 ), toF( 0x6a1e5d4afcde4311'u64 ), toF( 0x99c4beb7c43dce09'u64 ), toF( 0x855ca4373afebec1'u64 ), toF( 0xd9b1887d9df974c2'u64 ), toF( 0xc504554003d76ead'u64 ), toF( 0x4c2650647e77e3c5'u64 ), toF( 0xa2f837acd356439a'u64 ), toF( 0xd6e8405cb8641ba5'u64 ), toF( 0x1409945c89f35957'u64 ), toF( 0xc1fabd6c1eb2c2bc'u64 ), toF( 0xae88e92fbdf566df'u64 ) ] ) + , ( [ toF( 0x000000000000000a'u64 ), toF( 0x0000000000000021'u64 ), toF( 0x0000000000000038'u64 ), toF( 0x000000000000004f'u64 ), toF( 0x0000000000000066'u64 ), toF( 0x000000000000007d'u64 ), toF( 0x0000000000000094'u64 ), toF( 0x00000000000000ab'u64 ), toF( 0x00000000000000c2'u64 ), toF( 0x00000000000000d9'u64 ), toF( 0x00000000000000f0'u64 ), toF( 0x0000000000000107'u64 ) ] , [ toF( 0x20316582540c4ada'u64 ), toF( 0x7a04b87fd931bf51'u64 ), toF( 0x1188efce3485450e'u64 ), toF( 0x51c38e5573a8bcb7'u64 ), toF( 0xdae7a1d45b1e9b50'u64 ), toF( 0x2e422190ab96b035'u64 ), toF( 0x6403ba0b5a3b58a2'u64 ), toF( 0x67029e059ffadfa1'u64 ), toF( 0xadbd9209c4158113'u64 ), toF( 0x4b0c055686a9c210'u64 ), toF( 0xd0a383ca9b4ca6e9'u64 ), toF( 0x2028a5ce56b02da2'u64 ) ] ) + , ( [ toF( 0x000000000000000a'u64 ), toF( 0x00000000000002a4'u64 ), toF( 0x000000000000053e'u64 ), toF( 0x00000000000007d8'u64 ), toF( 0x0000000000000a72'u64 ), toF( 0x0000000000000d0c'u64 ), toF( 0x0000000000000fa6'u64 ), toF( 0x0000000000001240'u64 ), toF( 0x00000000000014da'u64 ), toF( 0x0000000000001774'u64 ), toF( 0x0000000000001a0e'u64 ), toF( 0x0000000000001ca8'u64 ) ] , [ toF( 0xd8d954390dc72c85'u64 ), toF( 0xc6d38c0b72b95593'u64 ), toF( 0x5236bfb703f62d0f'u64 ), toF( 0xd9166a97fbc88595'u64 ), toF( 0x3595c730fd281216'u64 ), toF( 0x7f5131edbbb37367'u64 ), toF( 0x94705c22830dde86'u64 ), toF( 0xc754b4ef402525c1'u64 ), toF( 0xbbcbca1cf91db8c6'u64 ), toF( 0x628f78b36777ec2c'u64 ), toF( 0x217dc0305c25d8a9'u64 ), toF( 0x5c040507f3f43986'u64 ) ] ) + , ( [ toF( 0x00000000000000c8'u64 ), toF( 0x00000000000000c9'u64 ), toF( 0x00000000000000ca'u64 ), toF( 0x00000000000000cb'u64 ), toF( 0x00000000000000cc'u64 ), toF( 0x00000000000000cd'u64 ), toF( 0x00000000000000ce'u64 ), toF( 0x00000000000000cf'u64 ), toF( 0x00000000000000d0'u64 ), toF( 0x00000000000000d1'u64 ), toF( 0x00000000000000d2'u64 ), toF( 0x00000000000000d3'u64 ) ] , [ toF( 0xc820597bd8de08e9'u64 ), toF( 0xd9501dddc15edad3'u64 ), toF( 0xb6059c25a7c20234'u64 ), toF( 0x303ff52a8db7306b'u64 ), toF( 0x21a59e9dba6a5b0f'u64 ), toF( 0xd0f0349025afb3f5'u64 ), toF( 0x28baf335e388dd18'u64 ), toF( 0x2df0c8d3e785abf1'u64 ), toF( 0xbb65c6814789f970'u64 ), toF( 0xea32b917c2b5112c'u64 ), toF( 0xe98d09937f0788e0'u64 ), toF( 0x3bebcf85f2b14c34'u64 ) ] ) + , ( [ toF( 0x00000000000000c8'u64 ), toF( 0x00000000000000cf'u64 ), toF( 0x00000000000000d6'u64 ), toF( 0x00000000000000dd'u64 ), toF( 0x00000000000000e4'u64 ), toF( 0x00000000000000eb'u64 ), toF( 0x00000000000000f2'u64 ), toF( 0x00000000000000f9'u64 ), toF( 0x0000000000000100'u64 ), toF( 0x0000000000000107'u64 ), toF( 0x000000000000010e'u64 ), toF( 0x0000000000000115'u64 ) ] , [ toF( 0xc064a2dff76ea7e5'u64 ), toF( 0x475331915c8b1ea2'u64 ), toF( 0x652b80c1949f44c1'u64 ), toF( 0x96d0972aaa940064'u64 ), toF( 0x7eb52b238c19383a'u64 ), toF( 0x8dcbf422cbb5a12c'u64 ), toF( 0x041b1e94beed9c56'u64 ), toF( 0x285a6a1d502b8871'u64 ), toF( 0x9ef736988d562172'u64 ), toF( 0xa7780dfb83e1ef27'u64 ), toF( 0x95fde5e4d6e0ffca'u64 ), toF( 0x4b8c50cdcc4a7177'u64 ) ] ) + , ( [ toF( 0x00000000000000c8'u64 ), toF( 0x00000000000000df'u64 ), toF( 0x00000000000000f6'u64 ), toF( 0x000000000000010d'u64 ), toF( 0x0000000000000124'u64 ), toF( 0x000000000000013b'u64 ), toF( 0x0000000000000152'u64 ), toF( 0x0000000000000169'u64 ), toF( 0x0000000000000180'u64 ), toF( 0x0000000000000197'u64 ), toF( 0x00000000000001ae'u64 ), toF( 0x00000000000001c5'u64 ) ] , [ toF( 0x52d7ffd93559b883'u64 ), toF( 0x58ae9b95c3938c98'u64 ), toF( 0xd6102152b46e6e76'u64 ), toF( 0x1c7e76cc8b6ea992'u64 ), toF( 0x8f4d0857a117bd65'u64 ), toF( 0xcfc70518952307fb'u64 ), toF( 0x35896376dd31f53c'u64 ), toF( 0x6277acedb23e61a5'u64 ), toF( 0x63e9f75edb3c565b'u64 ), toF( 0x3d4514e531d507cf'u64 ), toF( 0xf34a613b5eb0b0de'u64 ), toF( 0x5a46ea2fc7908598'u64 ) ] ) + , ( [ toF( 0x00000000000000c8'u64 ), toF( 0x0000000000000362'u64 ), toF( 0x00000000000005fc'u64 ), toF( 0x0000000000000896'u64 ), toF( 0x0000000000000b30'u64 ), toF( 0x0000000000000dca'u64 ), toF( 0x0000000000001064'u64 ), toF( 0x00000000000012fe'u64 ), toF( 0x0000000000001598'u64 ), toF( 0x0000000000001832'u64 ), toF( 0x0000000000001acc'u64 ), toF( 0x0000000000001d66'u64 ) ] , [ toF( 0x3d2ab66a526edba7'u64 ), toF( 0x3046996f1b17eeb3'u64 ), toF( 0xc669d240c97a4dc6'u64 ), toF( 0xf9b07f13e5bb0d74'u64 ), toF( 0x598630c3ffd46917'u64 ), toF( 0x46683b30442e75bc'u64 ), toF( 0x2fbce225b5568461'u64 ), toF( 0x1bcdb001c0bd2deb'u64 ), toF( 0x9556719ed803dd68'u64 ), toF( 0x14ae9f43f8aece17'u64 ), toF( 0x44134f15b88d2414'u64 ), toF( 0x7ee25477327cb257'u64 ) ] ) + , ( [ toF( 0x0000000000000bb8'u64 ), toF( 0x0000000000000bb9'u64 ), toF( 0x0000000000000bba'u64 ), toF( 0x0000000000000bbb'u64 ), toF( 0x0000000000000bbc'u64 ), toF( 0x0000000000000bbd'u64 ), toF( 0x0000000000000bbe'u64 ), toF( 0x0000000000000bbf'u64 ), toF( 0x0000000000000bc0'u64 ), toF( 0x0000000000000bc1'u64 ), toF( 0x0000000000000bc2'u64 ), toF( 0x0000000000000bc3'u64 ) ] , [ toF( 0x1cca33822243b88f'u64 ), toF( 0x1de46958562c9c1d'u64 ), toF( 0x9501d939cc917cca'u64 ), toF( 0x981e3ef87ed403d1'u64 ), toF( 0x9fb8495f3f848efb'u64 ), toF( 0x819cf03056591463'u64 ), toF( 0xfadef40263c675d9'u64 ), toF( 0xf1fcb3eeb9aa8f84'u64 ), toF( 0xf4bef3909fdab4d6'u64 ), toF( 0xb7e9c0c252fb1efa'u64 ), toF( 0x02d864a6f4ab3ae8'u64 ), toF( 0x17df8a3a999c87ba'u64 ) ] ) + , ( [ toF( 0x0000000000000bb8'u64 ), toF( 0x0000000000000bbf'u64 ), toF( 0x0000000000000bc6'u64 ), toF( 0x0000000000000bcd'u64 ), toF( 0x0000000000000bd4'u64 ), toF( 0x0000000000000bdb'u64 ), toF( 0x0000000000000be2'u64 ), toF( 0x0000000000000be9'u64 ), toF( 0x0000000000000bf0'u64 ), toF( 0x0000000000000bf7'u64 ), toF( 0x0000000000000bfe'u64 ), toF( 0x0000000000000c05'u64 ) ] , [ toF( 0xe550760256d2735f'u64 ), toF( 0xc8d8f90e653b7cfe'u64 ), toF( 0x29d3704422320f39'u64 ), toF( 0x9554bd6346791d64'u64 ), toF( 0x697808438566a459'u64 ), toF( 0xee7173ff28614ee6'u64 ), toF( 0xde7fe0b8f018d806'u64 ), toF( 0xa2c1d77fbb4cf118'u64 ), toF( 0x3311aa7507b56ed0'u64 ), toF( 0x61aff60cf1023ed3'u64 ), toF( 0xea0ad162819a9c24'u64 ), toF( 0xd8c5081fa1f99579'u64 ) ] ) + , ( [ toF( 0x0000000000000bb8'u64 ), toF( 0x0000000000000bcf'u64 ), toF( 0x0000000000000be6'u64 ), toF( 0x0000000000000bfd'u64 ), toF( 0x0000000000000c14'u64 ), toF( 0x0000000000000c2b'u64 ), toF( 0x0000000000000c42'u64 ), toF( 0x0000000000000c59'u64 ), toF( 0x0000000000000c70'u64 ), toF( 0x0000000000000c87'u64 ), toF( 0x0000000000000c9e'u64 ), toF( 0x0000000000000cb5'u64 ) ] , [ toF( 0xd881be2249a7bb71'u64 ), toF( 0x04580a06eb7b4e2e'u64 ), toF( 0x88871490c2dd0c74'u64 ), toF( 0x49bfde50468888a4'u64 ), toF( 0xa31df1a1b1d04539'u64 ), toF( 0x46a952037ad78fbb'u64 ), toF( 0x38a9122e2b050ea4'u64 ), toF( 0x095f361fc41c02c2'u64 ), toF( 0xf310102d58450156'u64 ), toF( 0x6c0915186d8ec014'u64 ), toF( 0xa64a2b5d64ddb3d8'u64 ), toF( 0xcd4d144e41080073'u64 ) ] ) + , ( [ toF( 0x0000000000000bb8'u64 ), toF( 0x0000000000000e52'u64 ), toF( 0x00000000000010ec'u64 ), toF( 0x0000000000001386'u64 ), toF( 0x0000000000001620'u64 ), toF( 0x00000000000018ba'u64 ), toF( 0x0000000000001b54'u64 ), toF( 0x0000000000001dee'u64 ), toF( 0x0000000000002088'u64 ), toF( 0x0000000000002322'u64 ), toF( 0x00000000000025bc'u64 ), toF( 0x0000000000002856'u64 ) ] , [ toF( 0xd81e096669bb3573'u64 ), toF( 0x8dab2f6aaa6b7cf0'u64 ), toF( 0xb9721fd0d916c85d'u64 ), toF( 0x975fb9b481ded728'u64 ), toF( 0xd85aba7b62df4f4d'u64 ), toF( 0x88ca8043e5b7bdc7'u64 ), toF( 0x010e80d9eb064a4b'u64 ), toF( 0x6aa0a9ffea6e6a3c'u64 ), toF( 0x0ff657302563a51d'u64 ), toF( 0xd8754db804352580'u64 ), toF( 0x1bb0e90883e68612'u64 ), toF( 0x47564efc5a108ce4'u64 ) ] ) + ] + + + diff --git a/tests/poseidon2/reference.nim b/tests/poseidon2/reference.nim deleted file mode 100644 index 5e66d11..0000000 --- a/tests/poseidon2/reference.nim +++ /dev/null @@ -1,5 +0,0 @@ - -# import poseidon2/types -# -# func add(x, y: F): F = -# (uint) \ No newline at end of file diff --git a/tests/poseidon2/testPermutation.nim b/tests/poseidon2/testPermutation.nim index d7ba1d3..de7b865 100644 --- a/tests/poseidon2/testPermutation.nim +++ b/tests/poseidon2/testPermutation.nim @@ -5,6 +5,8 @@ import std/unittest import poseidon2/types import poseidon2/permutation +import ./permTestCases + #------------------------------------------------------------------------------- const refInp: F12 = @@ -46,5 +48,13 @@ suite "permutation": var output = perm(input); check fromState(output) == refOut + test "more permutation tests": + var ok = true + for (xs,ys) in testcases_perm: + if permF12(xs) != ys: + ok = false + break + check ok + #-------------------------------------------------------------------------------