Skip to content

Commit

Permalink
Fix fast 1-weso parameter approximation, for massive speedup
Browse files Browse the repository at this point in the history
The "fast" 1-Wesolowski prover inadvertently mixed up parameters in the
call to ApproximateParameter.

ApproximateParameter's signature has L followed by K:

    void ApproximateParameters(uint64_t T, uint32_t& L, uint32_t& K)

However, the 1-Weso calls used K followed by L:

    ApproximateParameters(num_iterations, k, l);

While this typo does not affect the correctness of the created 1-Weso
proof, this causes 1-Weso proving to be _much_ slower than necessary. In
isolated testing, the 1-Weso proof generation is up to 10x slower.

Funnily enough, the "slow" VDF impl (in `src/provers_slow.h`) uses a
separate 1-Weso prover implementation which _doesn't_ suffer from this
bug, thus making the "slow" VDF impl faster than the "fast" overall.

To be clear: the fixed bug _only_ affects the _performance_ (not the
correctness!) of computing 1-Weso proofs (thus, blueboxing) using the
"fast" implementation. Regular software timelords (N-Weso), hardware
(ASIC) timelords, and the "slow" bluebox implementation are unaffected.

The speedup can be observed/tested by running `src/1weso_test.cpp`:

    $ hyperfine --warmup 5 "./1weso_test.orig" "./1weso_test.fixed"
    Benchmark 1: ./1weso_test.orig
      Time (mean ± σ):     17.250 s ±  1.153 s    [User: 23.946 s, System: 0.037 s]
      Range (min … max):   15.582 s … 18.372 s    10 runs

    Benchmark 2: ./1weso_test.fixed
      Time (mean ± σ):      8.746 s ±  0.010 s    [User: 14.651 s, System: 0.029 s]
      Range (min … max):    8.733 s …  8.765 s    10 runs

    Summary
      ./1weso_test.fixed ran
        1.97 ± 0.13 times faster than ./1weso_test.orig
  • Loading branch information
xearl4 committed Aug 27, 2024
1 parent e0194a7 commit d462153
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class OneWesolowskiCallback: public WesolowskiCallback {
uint32_t k, l;
this->wanted_iter = wanted_iter;
if (wanted_iter >= (1 << 16)) {
ApproximateParameters(wanted_iter, k, l);
ApproximateParameters(wanted_iter, l, k);
} else {
k = 10;
l = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/provers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OneWesolowskiProver : public Prover {
{
this->intermediates = intermediates;
if (num_iterations >= (1 << 16)) {
ApproximateParameters(num_iterations, k, l);
ApproximateParameters(num_iterations, l, k);
} else {
k = 10;
l = 1;
Expand Down

0 comments on commit d462153

Please sign in to comment.