Skip to main content

Cache

type Cache: {
"canWrite": boolean;
"debug": boolean;
"read": undefined | Uint8Array;
"write": void;
};

Interface for storing and retrieving values, for caching. read() and write() can just throw errors on failure.

The data that will be passed to the cache for writing is exhaustively described by the CacheHeader type. It represents one of the following:

  • The SRS. This is a deterministic lists of curve points (one per curve) that needs to be generated just once, to be used for polynomial commitments.
  • Lagrange basis commitments. Similar to the SRS, this will be created once for every power-of-2 circuit size.
  • Prover and verifier keys for every compiled circuit.

Per smart contract or ZkProgram, several different keys are created:

  • a step prover key (step-pk) and verification key (step-vk) for every method.
  • a wrap prover key (wrap-pk) and verification key (wrap-vk) for the entire contract.

Type declaration

canWrite

canWrite: boolean;

Indicates whether the cache is writable.

debug?

optional debug: boolean;

If debug is toggled, read() and write() errors are logged to the console.

By default, cache errors are silent, because they don't necessarily represent an error condition, but could just be a cache miss, or file system permissions incompatible with writing data.

read()

Read a value from the cache.

Parameters

header: CacheHeader

A small header to identify what is read from the cache.

Returns

undefined | Uint8Array

write()

Write a value to the cache.

Parameters

header: CacheHeader

A small header to identify what is written to the cache. This will be used by read() to retrieve the data.

value: Uint8Array

The value to write to the cache, as a byte array.

Returns

void

Source

lib/proof-system/cache.ts:31