@@ -46,22 +46,23 @@ BOOST_AUTO_TEST_CASE(modexpFermatTheorem)
46
46
bytes expected = fromHex (" 0000000000000000000000000000000000000000000000000000000000000001" );
47
47
BOOST_REQUIRE_EQUAL_COLLECTIONS (res.second .begin (), res.second .end (), expected.begin (), expected.end ());
48
48
}
49
- /*
50
- BOOST_AUTO_TEST_CASE(modexpTooLarge )
49
+
50
+ BOOST_AUTO_TEST_CASE (modexpZeroBase )
51
51
{
52
52
PrecompiledExecutor exec = PrecompiledRegistrar::executor (" modexp" );
53
53
54
54
bytes in = fromHex (
55
55
" 0000000000000000000000000000000000000000000000000000000000000000"
56
56
" 0000000000000000000000000000000000000000000000000000000000000020"
57
- "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff "
58
- "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe "
59
- "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd ");
57
+ " 0000000000000000000000000000000000000000000000000000000000000020 "
58
+ " fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e "
59
+ " fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f " );
60
60
auto res = exec (bytesConstRef (in.data (), in.size ()));
61
61
62
- BOOST_REQUIRE_EQUAL(res.first, false);
62
+ BOOST_REQUIRE (res.first );
63
+ bytes expected = fromHex (" 0000000000000000000000000000000000000000000000000000000000000000" );
64
+ BOOST_REQUIRE_EQUAL_COLLECTIONS (res.second .begin (), res.second .end (), expected.begin (), expected.end ());
63
65
}
64
- */
65
66
66
67
BOOST_AUTO_TEST_CASE (modexpExtraByteIgnored)
67
68
{
@@ -100,4 +101,120 @@ BOOST_AUTO_TEST_CASE(modexpRightPadding)
100
101
BOOST_REQUIRE_EQUAL_COLLECTIONS (res.second .begin (), res.second .end (), expected.begin (), expected.end ());
101
102
}
102
103
104
+ BOOST_AUTO_TEST_CASE (modexpMissingValues)
105
+ {
106
+ PrecompiledExecutor exec = PrecompiledRegistrar::executor (" modexp" );
107
+
108
+ bytes in = fromHex (
109
+ " 0000000000000000000000000000000000000000000000000000000000000001"
110
+ " 0000000000000000000000000000000000000000000000000000000000000002"
111
+ " 0000000000000000000000000000000000000000000000000000000000000020"
112
+ " 03" );
113
+ auto res = exec (bytesConstRef (in.data (), in.size ()));
114
+
115
+ BOOST_REQUIRE (res.first );
116
+ bytes expected = fromHex (" 0000000000000000000000000000000000000000000000000000000000000000" );
117
+ BOOST_REQUIRE_EQUAL_COLLECTIONS (res.second .begin (), res.second .end (), expected.begin (), expected.end ());
118
+ }
119
+
120
+ BOOST_AUTO_TEST_CASE (modexpEmptyValue)
121
+ {
122
+ PrecompiledExecutor exec = PrecompiledRegistrar::executor (" modexp" );
123
+
124
+ bytes in = fromHex (
125
+ " 0000000000000000000000000000000000000000000000000000000000000001"
126
+ " 0000000000000000000000000000000000000000000000000000000000000000"
127
+ " 0000000000000000000000000000000000000000000000000000000000000020"
128
+ " 03"
129
+ " 8000000000000000000000000000000000000000000000000000000000000000" );
130
+ auto res = exec (bytesConstRef (in.data (), in.size ()));
131
+
132
+ BOOST_REQUIRE (res.first );
133
+ bytes expected = fromHex (" 0000000000000000000000000000000000000000000000000000000000000001" );
134
+ BOOST_REQUIRE_EQUAL_COLLECTIONS (res.second .begin (), res.second .end (), expected.begin (), expected.end ());
135
+ }
136
+
137
+ BOOST_AUTO_TEST_CASE (modexpZeroPowerZero)
138
+ {
139
+ PrecompiledExecutor exec = PrecompiledRegistrar::executor (" modexp" );
140
+
141
+ bytes in = fromHex (
142
+ " 0000000000000000000000000000000000000000000000000000000000000001"
143
+ " 0000000000000000000000000000000000000000000000000000000000000001"
144
+ " 0000000000000000000000000000000000000000000000000000000000000020"
145
+ " 00"
146
+ " 00"
147
+ " 80" );
148
+ auto res = exec (bytesConstRef (in.data (), in.size ()));
149
+
150
+ BOOST_REQUIRE (res.first );
151
+ bytes expected = fromHex (" 0000000000000000000000000000000000000000000000000000000000000001" );
152
+ BOOST_REQUIRE_EQUAL_COLLECTIONS (res.second .begin (), res.second .end (), expected.begin (), expected.end ());
153
+ }
154
+
155
+ BOOST_AUTO_TEST_CASE (modexpZeroPowerZeroModZero)
156
+ {
157
+ PrecompiledExecutor exec = PrecompiledRegistrar::executor (" modexp" );
158
+
159
+ bytes in = fromHex (
160
+ " 0000000000000000000000000000000000000000000000000000000000000001"
161
+ " 0000000000000000000000000000000000000000000000000000000000000001"
162
+ " 0000000000000000000000000000000000000000000000000000000000000020"
163
+ " 00"
164
+ " 00"
165
+ " 00" );
166
+ auto res = exec (bytesConstRef (in.data (), in.size ()));
167
+
168
+ BOOST_REQUIRE (res.first );
169
+ bytes expected = fromHex (" 0000000000000000000000000000000000000000000000000000000000000000" );
170
+ BOOST_REQUIRE_EQUAL_COLLECTIONS (res.second .begin (), res.second .end (), expected.begin (), expected.end ());
171
+ }
172
+
173
+ BOOST_AUTO_TEST_CASE (modexpModLengthZero)
174
+ {
175
+ PrecompiledExecutor exec = PrecompiledRegistrar::executor (" modexp" );
176
+
177
+ bytes in = fromHex (
178
+ " 0000000000000000000000000000000000000000000000000000000000000001"
179
+ " 0000000000000000000000000000000000000000000000000000000000000001"
180
+ " 0000000000000000000000000000000000000000000000000000000000000000"
181
+ " 01"
182
+ " 01" );
183
+ auto res = exec (bytesConstRef (in.data (), in.size ()));
184
+
185
+ BOOST_REQUIRE (res.first );
186
+ BOOST_REQUIRE (res.second .empty ());
187
+ }
188
+
189
+ BOOST_AUTO_TEST_CASE (modexpCostFermatTheorem)
190
+ {
191
+ PrecompiledPricer cost = PrecompiledRegistrar::pricer (" modexp" );
192
+
193
+ bytes in = fromHex (
194
+ " 0000000000000000000000000000000000000000000000000000000000000001"
195
+ " 0000000000000000000000000000000000000000000000000000000000000020"
196
+ " 0000000000000000000000000000000000000000000000000000000000000020"
197
+ " 03"
198
+ " fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e"
199
+ " fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f" );
200
+ auto res = cost (bytesConstRef (in.data (), in.size ()));
201
+
202
+ BOOST_REQUIRE_EQUAL (static_cast <int >(res), 1638 );
203
+ }
204
+
205
+ BOOST_AUTO_TEST_CASE (modexpCostTooLarge)
206
+ {
207
+ PrecompiledPricer cost = PrecompiledRegistrar::pricer (" modexp" );
208
+
209
+ bytes in = fromHex (
210
+ " 0000000000000000000000000000000000000000000000000000000000000000"
211
+ " ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
212
+ " 0000000000000000000000000000000000000000000000000000000000000020"
213
+ " fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"
214
+ " fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd" );
215
+ auto res = cost (bytesConstRef (in.data (), in.size ()));
216
+
217
+ BOOST_REQUIRE (res == bigint{" 5928554968950589205686834432444820882087423214880796878820228301205152237564672" });
218
+ }
219
+
103
220
BOOST_AUTO_TEST_SUITE_END ()
0 commit comments