@@ -51,16 +51,18 @@ BOOST_AUTO_TEST_SUITE(proof_of_knowledge_test_suite)
51
51
using poseidon = nil::crypto3::hashes::poseidon<policy>;
52
52
using pow_type = nil::crypto3::zk::commitments::field_proof_of_work<poseidon, field_type>;
53
53
54
- const integral_type expected_mask = integral_type ( 0xFF80000000000000 ) << (field_type::modulus_bits - 64 ) ;
54
+ std:: size_t grinding_bits = 9 ;
55
55
nil::crypto3::zk::transcript::fiat_shamir_heuristic_sequential<poseidon> transcript;
56
56
auto old_transcript_1 = transcript, old_transcript_2 = transcript;
57
57
58
- auto result = pow_type::generate (transcript, 9 );
59
- BOOST_ASSERT (pow_type::verify (old_transcript_1, result, 9 ));
58
+ auto result = pow_type::generate (transcript, grinding_bits );
59
+ BOOST_ASSERT (pow_type::verify (old_transcript_1, result, grinding_bits ));
60
60
61
61
// manually reimplement verify to ensure that changes in implementation didn't break it
62
62
old_transcript_2 (result);
63
63
auto chal = old_transcript_2.template challenge <field_type>();
64
+ const integral_type expected_mask = integral_type ( (1 << grinding_bits) - 1 ) << (field_type::modulus_bits - grinding_bits);
65
+
64
66
BOOST_ASSERT ((integral_type (chal.data ) & expected_mask) == 0 );
65
67
66
68
using hard_pow_type = nil::crypto3::zk::commitments::field_proof_of_work<poseidon, field_type>;
@@ -70,28 +72,26 @@ BOOST_AUTO_TEST_SUITE(proof_of_knowledge_test_suite)
70
72
71
73
BOOST_AUTO_TEST_CASE (pow_basic_test) {
72
74
using keccak = nil::crypto3::hashes::keccak_1600<512 >;
73
- const std::uint32_t mask = 0xFFFFF000 ;
75
+
76
+ const std::uint32_t grinding_bits = 20 ;
77
+ const uint64_t expected_mask = (1 << grinding_bits) - 1 ;
78
+
74
79
using pow_type = nil::crypto3::zk::commitments::proof_of_work<keccak, std::uint32_t >;
75
80
76
81
nil::crypto3::zk::transcript::fiat_shamir_heuristic_sequential<keccak> transcript;
77
82
auto old_transcript_1 = transcript, old_transcript_2 = transcript;
78
83
79
- auto result = pow_type::generate (transcript, mask );
80
- BOOST_ASSERT (pow_type::verify (old_transcript_1, result, mask ));
84
+ auto result = pow_type::generate (transcript, grinding_bits );
85
+ BOOST_ASSERT (pow_type::verify (old_transcript_1, result, grinding_bits ));
81
86
82
87
// manually reimplement verify to ensure that changes in implementation didn't break it
83
- std::array<std::uint8_t , 4 > bytes;
84
- bytes[0 ] = std::uint8_t ((result & 0xFF000000 ) >> 24 );
85
- bytes[1 ] = std::uint8_t ((result & 0x00FF0000 ) >> 16 );
86
- bytes[2 ] = std::uint8_t ((result & 0x0000FF00 ) >> 8 );
87
- bytes[3 ] = std::uint8_t (result & 0x000000FF );
88
- old_transcript_2 (bytes);
88
+ old_transcript_2 (pow_type::int_be (result));
89
89
auto chal = old_transcript_2.template int_challenge <std::uint32_t >();
90
- BOOST_ASSERT ((chal & mask ) == 0 );
90
+ BOOST_ASSERT ( (chal & expected_mask ) == 0 );
91
91
92
92
// check that random stuff doesn't pass verify
93
93
using hard_pow_type = nil::crypto3::zk::commitments::proof_of_work<keccak, std::uint32_t >;
94
- BOOST_ASSERT (!hard_pow_type::verify (old_transcript_1, result, mask ));
94
+ BOOST_ASSERT (!hard_pow_type::verify (old_transcript_1, result, grinding_bits ));
95
95
}
96
96
97
97
BOOST_AUTO_TEST_SUITE_END ()
0 commit comments