Skip to content

Reuse multiply scratch and check exponents four bits at a time - #1

Open
OverActiveBladderSystem wants to merge 2 commits into
mainfrom
OABS-verifier-scratch-and-4bit-window
Open

OverActiveBladderSystem wants to merge 2 commits into
mainfrom
OABS-verifier-scratch-and-4bit-window

Conversation

@OverActiveBladderSystem

Copy link
Copy Markdown
Owner

Two changes in the proof checker.

qfb_nucomp in src/nucomp.h still creates and frees GMP temporaries on every call. Pull request 298 already stopped doing that in qfb_nudupl, the square, by keeping those temporaries for the life of the thread. This applies that same pattern to the multiply. The ordered swap still returns before any scratch value is used, and each thread has its own scratch, including the two threads in ParallelProver.

Pull request 298 is merged on main, and it is not in any release. The published release is still 1.1.14. A full_node gets that code only after a new chiavdf release is tagged and a chia-blockchain release installs it, which is why the square speedup is not in the checker people are running today.

FastPowFormNucomp in src/proof_common.h still walks the exponent one bit at a time. This builds x^1 through x^15 and consumes the exponent four bits at a time. The coefficient a is reduced when it passes half the discriminant size, including after a window multiply, and the function still does one full reduction before returning. Exponent 0 still returns the identity. A zero digit skips the multiply.

The multiply is the other hot call, about 260 times per piece, and it was still paying to create and free temporaries on every entry. A fixed 5-bit window was slower on a 264-bit exponent. A sliding window saved about 0.11 ms, which is inside the noise of one block, because squaring is still most of the remaining time. Those were left out.

Same build, one proof piece, generic math library, Windows x64: main without this patch was 5.209 ms, and this patch was 4.562 ms, about 12 percent. The proof bytes from the old one-bit check and from this four-bit check were identical, and both checks accepted them. The checks used the iteration counts of the software timelord and of the program that prepares proofs for an ASIC, and they ran on this PC. No ASIC hardware was used. The ASIC chip does not call these functions. A one-byte change in a known proof still fails.

This pull request alone, on the same build as current main, is the 12 percent above. The larger figures need more than these two files, and none of them are in the 1.1.14 release.

On this Windows PC, against the released 1.1.14 checker with the generic math library, the same proofs gave:

  • Current main plus this patch, still on the generic library: about 27.5 percent. That includes pull request 298, this patch, and the compiler used to build this copy. The released 1.1.14 checker was not rebuilt with that compiler.
  • That same patched build with the AVX2 math library loaded: about 40.2 percent. Block by block the middle of that span was about 40 percent, and individual blocks fell between 36.4 and 42.1 percent.

The AVX2 library is selected by pull request 423, together with mpir_gc_x64 pull request 5. That change is not in this branch. Linux releases use GMP, so they do not get that Windows library swap. They would get pull request 298 and this patch only after a chiavdf release is tagged and a chia-blockchain release installs it.

The multiply keeps one scratch per thread. MSVC link-time optimization
miscompiles that function when it is inlined, so it stays out of line there.
Exponents under 64 bits use the one-bit walk. Longer exponents use the
four-bit walk. The tests compare both with the older multiply.
@OverActiveBladderSystem
OverActiveBladderSystem force-pushed the OABS-verifier-scratch-and-4bit-window branch from 2361791 to d4cb718 Compare October 19, 2026 21:58
The review asked to drop the debug print, include vdf_new.h directly
in the regression test, and either fill the unused table slot with the
identity or assert that it is never read. Filling the slot slowed the
short mix by about 26 percent, so the slot stays unused and an assert
guards the read.

The shallow-copy sites now say they share limb storage with the source
form. The MSVC noinline comment now says that moving the scratch into
another file does not stop the link-time miscompile.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant