@@ -73,9 +73,11 @@ BC_PUSH_WARNING(NO_ARRAY_INDEXING)
7373// ----------------------------------------------------------------------------
7474
7575#if defined(HAVE_ULTRAFAST)
76-
76+
77+ // TODO: pass cancel.
7778template <typename Batch>
78- data_chunk batch_verify (const std::span<Batch>& batch, bool ) NOEXCEPT
79+ data_chunk batch_verify (const stopper& /* cancel */ ,
80+ const std::span<Batch>& batch) NOEXCEPT
7981{
8082 // OOM is unrecoverable.
8183 static thread_local ufsecp::lbtc::Controller context{ UFSECP_LBTC_AUTO };
@@ -103,7 +105,8 @@ data_chunk batch_verify(const std::span<Batch>& batch, bool) NOEXCEPT
103105#else
104106
105107template <typename Batch>
106- data_chunk batch_verify (const std::span<Batch>& batch, bool ) NOEXCEPT
108+ data_chunk batch_verify (const stopper& cancel,
109+ const std::span<Batch>& batch) NOEXCEPT
107110{
108111 constexpr auto policy = poolstl::execution::par;
109112
@@ -115,6 +118,7 @@ data_chunk batch_verify(const std::span<Batch>& batch, bool) NOEXCEPT
115118 data_chunk results (batch.size ());
116119 std::for_each (policy, it.cbegin (), it.cend (), [&](size_t row) NOEXCEPT
117120 {
121+ if (cancel) return ;
118122 results.at (row) = to_int<uint8_t >(verify_signature (batch[row]));
119123 });
120124
@@ -159,7 +163,7 @@ inline bool has_valid_path(uint8_t m_sigs, uint8_t n_keys,
159163
160164// Trivial single signature correlation.
161165template <typename Batch>
162- links_t to_links (const data_chunk& out,
166+ links_t to_links (const stopper& cancel, const data_chunk& out,
163167 const std::span<const Batch>& in) NOEXCEPT
164168{
165169 BC_ASSERT (out.size () == in.size ());
@@ -174,6 +178,8 @@ links_t to_links(const data_chunk& out,
174178 std::for_each (poolstl::execution::par, it.cbegin (), it.cend (),
175179 [&](size_t row) NOEXCEPT
176180 {
181+ if (cancel) return ;
182+
177183 // Failure is *extremely* rare, so this is very efficient.
178184 if (!to_bool (out.at (row)))
179185 {
@@ -188,8 +194,8 @@ links_t to_links(const data_chunk& out,
188194// Specialized threshold correlation.
189195// O(n) over the sig set, ~100 bytes of stack, no heap.
190196template <>
191- links_t to_links<threshold::batch>(const data_chunk& out ,
192- const threshold::batch::span& in) NOEXCEPT
197+ links_t to_links<threshold::batch>(const stopper& cancel ,
198+ const data_chunk& out, const threshold::batch::span& in) NOEXCEPT
193199{
194200 BC_ASSERT (out.size () == in.size ());
195201
@@ -200,6 +206,9 @@ links_t to_links<threshold::batch>(const data_chunk& out,
200206 links_t fails{};
201207 for (auto index = one; index <= in.size (); ++index)
202208 {
209+ if (cancel)
210+ return {};
211+
203212 // Find the start of the next group (or end).
204213 if ((index != in.size ()) &&
205214 (in[index].id == in[group].id ) &&
@@ -225,8 +234,8 @@ links_t to_links<threshold::batch>(const data_chunk& out,
225234// Specialized multisig correlation.
226235// O(n) over the sig set, ~100 bytes of stack, no heap.
227236template <>
228- links_t to_links<multisig::batch>(const data_chunk& out,
229- const multisig::batch::span& in) NOEXCEPT
237+ links_t to_links<multisig::batch>(const stopper& cancel,
238+ const data_chunk& out, const multisig::batch::span& in) NOEXCEPT
230239{
231240 BC_ASSERT (out.size () == in.size ());
232241
@@ -237,6 +246,9 @@ links_t to_links<multisig::batch>(const data_chunk& out,
237246 links_t fails{};
238247 for (auto index = one; index <= in.size (); ++index)
239248 {
249+ if (cancel)
250+ return {};
251+
240252 // Find the start of the next group (or end).
241253 if ((index != in.size ()) &&
242254 (in[index].id == in[group].id ) &&
@@ -271,84 +283,84 @@ BC_POP_WARNING()
271283// ----------------------------------------------------------------------------
272284// static/protected
273285
274- data_chunk schnorr::batch::evaluate (const schnorr::batch::span& batch ,
275- bool turbo ) NOEXCEPT
286+ data_chunk schnorr::batch::evaluate (const stopper& cancel ,
287+ const schnorr::batch::span& batch ) NOEXCEPT
276288{
277- return batch_verify (batch, turbo );
289+ return batch_verify (cancel, batch );
278290}
279291
280- data_chunk threshold::batch::evaluate (const threshold::batch::span& batch ,
281- bool turbo ) NOEXCEPT
292+ data_chunk threshold::batch::evaluate (const stopper& cancel ,
293+ const threshold::batch::span& batch ) NOEXCEPT
282294{
283- return batch_verify (batch, turbo );
295+ return batch_verify (cancel, batch );
284296}
285297
286- data_chunk ecdsa::batch::evaluate (const ecdsa::batch::span& batch ,
287- bool turbo ) NOEXCEPT
298+ data_chunk ecdsa::batch::evaluate (const stopper& cancel ,
299+ const ecdsa::batch::span& batch ) NOEXCEPT
288300{
289- return batch_verify (batch, turbo );
301+ return batch_verify (cancel, batch );
290302}
291303
292- data_chunk multisig::batch::evaluate (const multisig::batch::span& batch ,
293- bool turbo ) NOEXCEPT
304+ data_chunk multisig::batch::evaluate (const stopper& cancel ,
305+ const multisig::batch::span& batch ) NOEXCEPT
294306{
295- return batch_verify (batch, turbo );
307+ return batch_verify (cancel, batch );
296308}
297309
298310// correlate
299311// ----------------------------------------------------------------------------
300312// static/protected
301313
302- links_t schnorr::batch::correlate (const data_chunk& out ,
303- const schnorr::batch::span& in) NOEXCEPT
314+ links_t schnorr::batch::correlate (const stopper& cancel ,
315+ const data_chunk& out, const schnorr::batch::span& in) NOEXCEPT
304316{
305- return to_links (out, in);
317+ return to_links (cancel, out, in);
306318}
307319
308- links_t threshold::batch::correlate (const data_chunk& out ,
309- const threshold::batch::span& in) NOEXCEPT
320+ links_t threshold::batch::correlate (const stopper& cancel ,
321+ const data_chunk& out, const threshold::batch::span& in) NOEXCEPT
310322{
311- return to_links (out, in);
323+ return to_links (cancel, out, in);
312324}
313325
314- links_t ecdsa::batch::correlate (const data_chunk& out ,
315- const ecdsa::batch::span& in) NOEXCEPT
326+ links_t ecdsa::batch::correlate (const stopper& cancel ,
327+ const data_chunk& out, const ecdsa::batch::span& in) NOEXCEPT
316328{
317- return to_links (out, in);
329+ return to_links (cancel, out, in);
318330}
319331
320- links_t multisig::batch::correlate (const data_chunk& out ,
321- const multisig::batch::span& in) NOEXCEPT
332+ links_t multisig::batch::correlate (const stopper& cancel ,
333+ const data_chunk& out, const multisig::batch::span& in) NOEXCEPT
322334{
323- return to_links (out, in);
335+ return to_links (cancel, out, in);
324336}
325337
326338// verify
327339// ----------------------------------------------------------------------------
328340// static/public
329341
330- links_t schnorr::batch::verify (const schnorr::batch::span& batch ,
331- bool turbo ) NOEXCEPT
342+ links_t schnorr::batch::verify (const stopper& cancel ,
343+ const schnorr::batch::span& batch ) NOEXCEPT
332344{
333- return correlate (evaluate (batch, turbo ), batch);
345+ return correlate (cancel, evaluate (cancel, batch ), batch);
334346}
335347
336- links_t threshold::batch::verify (const threshold::batch::span& batch ,
337- bool turbo ) NOEXCEPT
348+ links_t threshold::batch::verify (const stopper& cancel ,
349+ const threshold::batch::span& batch ) NOEXCEPT
338350{
339- return correlate (evaluate (batch, turbo ), batch);
351+ return correlate (cancel, evaluate (cancel, batch ), batch);
340352}
341353
342- links_t ecdsa::batch::verify (const ecdsa::batch::span& batch ,
343- bool turbo ) NOEXCEPT
354+ links_t ecdsa::batch::verify (const stopper& cancel ,
355+ const ecdsa::batch::span& batch ) NOEXCEPT
344356{
345- return correlate (evaluate (batch, turbo ), batch);
357+ return correlate (cancel, evaluate (cancel, batch ), batch);
346358}
347359
348- links_t multisig::batch::verify (const multisig::batch::span& batch ,
349- bool turbo ) NOEXCEPT
360+ links_t multisig::batch::verify (const stopper& cancel ,
361+ const multisig::batch::span& batch ) NOEXCEPT
350362{
351- return correlate (evaluate (batch, turbo ), batch);
363+ return correlate (cancel, evaluate (cancel, batch ), batch);
352364}
353365
354366} // namespace system
0 commit comments