You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
1.9 KiB

  1. package poseidon
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. const prime uint64 = 18446744069414584321
  7. func TestPoseidonHash(t *testing.T) {
  8. b0 := uint64(0)
  9. b1 := uint64(1)
  10. bm1 := prime - 1
  11. bM := prime
  12. h, err := Hash([NROUNDSF]uint64{b0, b0, b0, b0, b0, b0, b0, b0}, [CAPLEN]uint64{b0, b0, b0, b0})
  13. assert.Nil(t, err)
  14. assert.Equal(t,
  15. [CAPLEN]uint64{
  16. 4330397376401421145,
  17. 14124799381142128323,
  18. 8742572140681234676,
  19. 14345658006221440202,
  20. }, h,
  21. )
  22. h, err = Hash([NROUNDSF]uint64{b1, b1, b1, b1, b1, b1, b1, b1}, [CAPLEN]uint64{b1, b1, b1, b1})
  23. assert.Nil(t, err)
  24. assert.Equal(t,
  25. [CAPLEN]uint64{
  26. 16428316519797902711,
  27. 13351830238340666928,
  28. 682362844289978626,
  29. 12150588177266359240,
  30. }, h,
  31. )
  32. h, err = Hash([NROUNDSF]uint64{b1, b1, b1, b1, b1, b1, b1, b1}, [CAPLEN]uint64{b1, b1, b1, b1})
  33. assert.Nil(t, err)
  34. assert.Equal(t,
  35. [CAPLEN]uint64{
  36. 16428316519797902711,
  37. 13351830238340666928,
  38. 682362844289978626,
  39. 12150588177266359240,
  40. }, h,
  41. )
  42. h, err = Hash(
  43. [NROUNDSF]uint64{bm1, bm1, bm1, bm1, bm1, bm1, bm1, bm1},
  44. [CAPLEN]uint64{bm1, bm1, bm1, bm1},
  45. )
  46. assert.Nil(t, err)
  47. assert.Equal(t,
  48. [CAPLEN]uint64{
  49. 13691089994624172887,
  50. 15662102337790434313,
  51. 14940024623104903507,
  52. 10772674582659927682,
  53. }, h,
  54. )
  55. h, err = Hash([NROUNDSF]uint64{bM, bM, bM, bM, bM, bM, bM, bM}, [CAPLEN]uint64{b0, b0, b0, b0})
  56. assert.Nil(t, err)
  57. assert.Equal(t,
  58. [CAPLEN]uint64{
  59. 4330397376401421145,
  60. 14124799381142128323,
  61. 8742572140681234676,
  62. 14345658006221440202,
  63. }, h,
  64. )
  65. h, err = Hash([NROUNDSF]uint64{
  66. uint64(923978),
  67. uint64(235763497586),
  68. uint64(9827635653498),
  69. uint64(112870),
  70. uint64(289273673480943876),
  71. uint64(230295874986745876),
  72. uint64(6254867324987),
  73. uint64(2087),
  74. }, [CAPLEN]uint64{b0, b0, b0, b0})
  75. assert.Nil(t, err)
  76. assert.Equal(t,
  77. [CAPLEN]uint64{
  78. 1892171027578617759,
  79. 984732815927439256,
  80. 7866041765487844082,
  81. 8161503938059336191,
  82. }, h,
  83. )
  84. }