Being a provable programming language, Cairo allows generating STARK proofs for the validity of its execution, which can then be verified onchain to guarantee their correctness. SHARP (SHARed Prover) is a powerful system designed to generate a unified STARK proof for multiple Cairo programs and verify it on Ethereum. Leveraging the exponential asymmetry of the STARK protocol, this allows applications to share the cost of verifying proofs onchain with other applications, as well as “break down” their computations into several smaller computations without increasing costs.For Starknet, this results in sending only a single proof per multiple blocks to Ethereum, and paying for its onchain verification only with respect to their relatize share in it.
Since its inception, SHARP has undergone a handful of efficiency upgrades, with the most powerful being the shift from a linear to a recursive model.In the linear model, SHARP waited for enough programs to “fill up” a proof, and only then started the proving process for the whole bundle of programs.In the recursive model, SHARP proves each statement upon its arrival, and instead of verifying it onchain, it verifies it offchain using a verifier program written in Cairo. Each two such verifications are then aggregated together and sent back to SHARP and the Cairo verifier, restarting the process. This continues recursively, with each new proof being sent to the Cairo verifier until a trigger is reached. At this point, the last proof in the series is sent to the Solidity verifier on Ethereum.At first glance, recursive proofs may seem more complex and time-consuming. However, there are several benefits to this approach:
Parallelization: Recursive proofs enable work parallelization, reducing user latency and improving SHARP efficiency
Cheaper onchain costs: Parallelization enables SHARP to create larger proofs, which in turn result in reduced onchain costs
Lower cloud costs: Since each job is smaller, the required memory for processing is reduced, resulting in lower cloud costs
Cairo support: Recursive proofs only require support in Cairo, without the need to add support to the onchain verifiers
SHARP’s onchain verifiers is a set of multiple smart contracts responsible for verifying STARK proofs generated by SHARP, the key of which are:
GpsStatementVerifier, which serves as the primary verifier contract and relies on smaller verifier contracts that contain specific verification logic.
For future enhancements or adjustments, a Proxy and CallProxy contracts are used allow seamless updates to the GpsStatementVerifier without compromising its foundational logic.
MemoryPageFactRegistry, which maintains hashes of the proven programs’ memory pages, primarily used to register outputs for data availability