[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor] 43/77: hs_pow_solve: use equix_solve more efficiently
This is an automated email from the git hooks/post-receive script.
dgoulet pushed a commit to branch main
in repository tor.
commit 557eb814863285986039699ce92c6c4f11ee7426
Author: Micah Elizabeth Scott <beth@xxxxxxxxxxxxxx>
AuthorDate: Wed Mar 1 16:46:25 2023 -0800
hs_pow_solve: use equix_solve more efficiently
This was apparently misinterpreting "zero solutions" as an error
instead of just moving on to the next nonce. Additionally, equix
could have been returning up to 8 solutions and we would only
give one of those a chance to succeed.
Signed-off-by: Micah Elizabeth Scott <beth@xxxxxxxxxxxxxx>
---
src/feature/hs/hs_pow.c | 61 ++++++++++++++++++++-----------------------------
1 file changed, 25 insertions(+), 36 deletions(-)
diff --git a/src/feature/hs/hs_pow.c b/src/feature/hs/hs_pow.c
index 2e94f9bced..3c02a4851e 100644
--- a/src/feature/hs/hs_pow.c
+++ b/src/feature/hs/hs_pow.c
@@ -146,46 +146,35 @@ hs_pow_solve(const hs_pow_desc_params_t *pow_params,
challenge = build_equix_challenge(pow_params->seed, nonce, effort);
ctx = equix_alloc(EQUIX_CTX_SOLVE);
- equix_solution solution[EQUIX_MAX_SOLS];
+ equix_solution solutions[EQUIX_MAX_SOLS];
- /* We'll do a maximum of the nonce size iterations here which is the maximum
- * number of nonce we can try in an attempt to find a valid solution. */
log_notice(LD_REND, "Solving proof of work (effort %u)", effort);
- for (uint64_t i = 0; i < UINT64_MAX; i++) {
- /* Calculate S = equix_solve(C || N || E) */
- if (!equix_solve(ctx, challenge, HS_POW_CHALLENGE_LEN, solution)) {
- ret = -1;
- goto end;
- }
- const equix_solution *sol = &solution[0];
-
- equix_result result = equix_verify(ctx, challenge,
- HS_POW_CHALLENGE_LEN, sol);
- if (result != EQUIX_OK) {
- /* Go again with a new nonce. */
- increment_and_set_nonce(&nonce, challenge);
- continue;
- }
-
- /* Validate the challenge against the solution. */
- if (validate_equix_challenge(challenge, sol, effort)) {
- /* Store the nonce N. */
- pow_solution_out->nonce = nonce;
- /* Store the effort E. */
- pow_solution_out->effort = effort;
- /* We only store the first 4 bytes of the seed C. */
- pow_solution_out->seed_head = get_uint32(pow_params->seed);
- /* Store the solution S */
- memcpy(&pow_solution_out->equix_solution, sol,
- sizeof(pow_solution_out->equix_solution));
-
- /* Indicate success and we are done. */
- ret = 0;
- break;
+ for (;;) {
+ /* Calculate solutions to S = equix_solve(C || N || E), */
+ int count = equix_solve(ctx, challenge, HS_POW_CHALLENGE_LEN, solutions);
+ for (int i = 0; i < count; i++) {
+ const equix_solution *sol = &solutions[i];
+
+ /* Check an Equi-X solution against the effort threshold */
+ if (validate_equix_challenge(challenge, sol, effort)) {
+ /* Store the nonce N. */
+ pow_solution_out->nonce = nonce;
+ /* Store the effort E. */
+ pow_solution_out->effort = effort;
+ /* We only store the first 4 bytes of the seed C. */
+ pow_solution_out->seed_head = get_uint32(pow_params->seed);
+ /* Store the solution S */
+ memcpy(&pow_solution_out->equix_solution, sol,
+ sizeof(pow_solution_out->equix_solution));
+
+ /* Indicate success and we are done. */
+ ret = 0;
+ goto end;
+ }
}
- /* Did not pass the R * E <= UINT32_MAX check. Increment the nonce and
- * try again. */
+ /* No solutions for this nonce and/or none that passed the effort
+ * threshold, increment and try again. */
increment_and_set_nonce(&nonce, challenge);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits