Skip to content

Conversation

@b-j-roberts
Copy link
Collaborator

@b-j-roberts b-j-roberts commented Dec 4, 2025

Summary

Optimizes the Equihash proof-of-work validation for ZK prover efficiency. Restructures validation to minimize Cairo steps while maintaining full security guarantees equivalent to the reference implementation.

Current savings estimate: 40,277,059 steps -> 859,899 steps ( ~98% )

Key Optimizations/Changes

  • Blake2b cairo1 implementation -> Blake2b opcode: Enabled via blake2b feature flag, so cairo1 impl is used by default
  • Blake2b Base Hasher Caching: Pre-computes first compression block (128 bytes of 140-byte header) once, clones for each of 512 leaf hashes
  • U32-Optimized Nodes: Stores 20-bit collision elements as Array<u32> instead of Array<u8>, eliminating expand_array byte manipulation
  • O(n) Uniqueness Check: Replaces O(n²) pairwise distinct_indices with Schwartz-Zippel permutation verification using prover-provided sorted hint
  • Reduced intermediate byte arrays, type conversions, and redundant parsing/checks throughout the equihash implementation

How to Test

Using cairo1 blake2b

   cd packages/client
   ../../scripts/data/integration_tests.sh

Using blake2b opcode

  1. Clone & build zoro-proving-stack ( See zoro-proving-stack for more info )
git clone --recursive https://github.com/Ztarknet/zoro-proving-stack.git
cd zoro-proving-stack
./setup.sh

make scarb-build
  1. Run the test with custom scarb version
   cd packages/client
   SCARB=/path/to/scarb/target/debug/scarb ../../scripts/data/integration_tests.sh --features=blake2b

@b-j-roberts b-j-roberts force-pushed the brandon/equihash-optimizations branch from c66f95f to 641b1a8 Compare December 9, 2025 08:20
@b-j-roberts b-j-roberts marked this pull request as ready for review December 9, 2025 08:45
result = {
"chain_state": format_chain_state(initial_chain_state),
"blocks": formatted_blocks,
"expected": format_chain_state(chain_state),
"sorted_indices_hints": sorted_indices_hints,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would need to change that in the assumevalid crate as well (preparing args)

@b-j-roberts b-j-roberts force-pushed the brandon/equihash-optimizations branch from e49f1c9 to 314b66c Compare December 9, 2025 20:34
@b-j-roberts b-j-roberts changed the title Optimizations: Equihash (WIP) Optimizations: Equihash & Feats: Assumevalid + SPV Dec 17, 2025
@b-j-roberts b-j-roberts merged commit 522f979 into main Dec 17, 2025
2 checks passed
@b-j-roberts b-j-roberts deleted the brandon/equihash-optimizations branch December 17, 2025 16:10
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.

4 participants