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.

107 lines
2.1 KiB

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