Skip to content

fix: cache uncompressed CRS after first decompression#22002

Merged
johnathan79717 merged 1 commit into
nextfrom
jh/cache-uncompressed-crs
Mar 25, 2026
Merged

fix: cache uncompressed CRS after first decompression#22002
johnathan79717 merged 1 commit into
nextfrom
jh/cache-uncompressed-crs

Conversation

@johnathan79717

Copy link
Copy Markdown
Contributor

Summary

  • After PR feat: SRS point compression - download 50% less CRS data #21112 switched CRS storage to compressed format (32 bytes/point), every CRS load decompresses from scratch. For 2^20 points in a browser that's ~4s on every page load; for 100M points on an 8-core native prover that's ~110s.
  • This PR makes compression a bandwidth-only optimization: after the first decompression, the uncompressed points (64 bytes/point) are cached and reused on subsequent loads.

Changes

C++ native (get_bn254_crs.cpp): Check for cached bn254_g1.dat (uncompressed) first. On cache miss, decompress from bn254_g1_compressed.dat and write the uncompressed cache. On download, cache both compressed and uncompressed.

C++ WASM (bbapi_srs.hpp/cpp): srsInitSrs auto-detects input format (32B vs 64B per point). When decompressing compressed input, it returns the uncompressed bytes in the response so the caller can cache them.

Browser (cached_net_crs.ts): Check IndexedDB for uncompressed g1Data first. Add cacheUncompressed() to persist after first decompression.

Node.js (crs/node/index.ts): Check bn254_g1.dat first, fall back to bn254_g1_compressed.dat. Add cacheUncompressed() to write uncompressed file.

Wiring (barretenberg/index.ts): initSRSChonk captures the srsInitSrs response and calls crs.cacheUncompressed() when uncompressed bytes are returned.

Test plan

  • C++ native: run bb with only compressed CRS on disk, verify it creates bn254_g1.dat and uses it on second run
  • WASM: ./scripts/run_test.sh bbapi/exception_handling.test.js passes (schema change)
  • WASM: ./scripts/run_test.sh barretenberg/blake2s.test.js passes (skipSrsInit)
  • Browser: first load downloads compressed, caches uncompressed in IDB; second load skips decompression

@johnathan79717 johnathan79717 added the ci-full Run all master checks. label Mar 25, 2026
@johnathan79717 johnathan79717 changed the base branch from merge-train/barretenberg to next March 25, 2026 15:44
@johnathan79717 johnathan79717 changed the base branch from next to merge-train/barretenberg March 25, 2026 15:48
@johnathan79717 johnathan79717 changed the base branch from merge-train/barretenberg to next March 25, 2026 15:51
@johnathan79717 johnathan79717 force-pushed the jh/cache-uncompressed-crs branch from 64211ff to ebd7c0b Compare March 25, 2026 15:52
@johnathan79717 johnathan79717 removed the ci-full Run all master checks. label Mar 25, 2026
@johnathan79717 johnathan79717 force-pushed the jh/cache-uncompressed-crs branch from ebd7c0b to bfec44a Compare March 25, 2026 16:13
@johnathan79717 johnathan79717 added this pull request to the merge queue Mar 25, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 25, 2026
@johnathan79717 johnathan79717 added this pull request to the merge queue Mar 25, 2026
@johnathan79717 johnathan79717 removed this pull request from the merge queue due to a manual request Mar 25, 2026
@johnathan79717 johnathan79717 added this pull request to the merge queue Mar 25, 2026
@johnathan79717 johnathan79717 removed this pull request from the merge queue due to a manual request Mar 25, 2026
@johnathan79717 johnathan79717 added this pull request to the merge queue Mar 25, 2026
Merged via the queue into next with commit 9fc5ddd Mar 25, 2026
23 checks passed
@johnathan79717 johnathan79717 deleted the jh/cache-uncompressed-crs branch March 25, 2026 18:50
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.

2 participants