Skip to main content
Cryptographic inlines are custom instructions that replace computationally expensive RISC-V implementations of cryptographic primitives with efficient, constraint-native implementations. This optimization can provide 2-5x throughput improvements for cryptography-heavy programs.

Problem: Expensive RISC-V Execution

Proving RISC-V execution of cryptographic operations is inefficient:

Solution: Constraint-Native Primitives

Inlines replace the RISC-V trace with a pre-computed sequence of constraint-native operations:

Available Inlines

Jolt provides optimized inlines for common cryptographic primitives:

Hash Functions

SHA-256

  • Module: jolt-inlines/sha2
  • Operations: Block compression, initial compression
  • Speedup: ~10-15x vs. RISC-V

Keccak-256

  • Module: jolt-inlines/keccak256
  • Operations: Permutation function
  • Speedup: ~20-30x vs. RISC-V

BLAKE2b

  • Module: jolt-inlines/blake2
  • Operations: Compression function
  • Speedup: ~12-18x vs. RISC-V

BLAKE3

  • Module: jolt-inlines/blake3
  • Operations: Compression function
  • Speedup: ~12-18x vs. RISC-V

Elliptic Curve Operations

secp256k1

  • Module: jolt-inlines/secp256k1
  • Operations: Point multiplication, ECDSA
  • Speedup: ~50-100x vs. RISC-V

Grumpkin

  • Module: jolt-inlines/grumpkin
  • Operations: Curve arithmetic
  • Speedup: ~50-100x vs. RISC-V

Big Integer Arithmetic

BigInt Multiplication

  • Module: jolt-inlines/bigint
  • Operations: 256-bit multiplication
  • Speedup: ~5-10x vs. RISC-V

How Inlines Work

1. Custom Instruction Encoding

Inlines use RISC-V’s custom instruction extension space:

2. Sequence Builder

Each inline defines a sequence builder that generates the constraint-native operation sequence:

3. Tracer Integration

The tracer replaces custom instructions with the pre-computed sequence:

4. Witness Generation

The inline sequence generates compact witness data:

Performance Impact

SHA-256 Example

secp256k1 Example

End-to-End Impact

For a program that performs:
  • 100 SHA-256 blocks
  • 10 secp256k1 signatures
Without inlines:
  • SHA-256: 100,000 instructions
  • secp256k1: 500,000 instructions
  • Total: ~600,000 instructions
  • Proving time: ~60s
With inlines:
  • SHA-256: 8,000 instructions (inline sequences)
  • secp256k1: 5,000 instructions (inline sequences)
  • Other logic: ~10,000 instructions
  • Total: ~23,000 instructions
  • Proving time: ~12s
Result: ~5x end-to-end speedup

Creating Custom Inlines

To create a new inline for your application:

1. Define the Inline Module

2. Implement Sequence Builder

3. Register the Inline

4. Provide Guest API

Best Practices

When to Use Inlines

Good candidates:
  • Cryptographic primitives (hash, signatures, encryption)
  • Fixed computation patterns (no data-dependent branching)
  • High instruction count in RISC-V (>100 instructions)
  • Performance-critical operations
Poor candidates:
  • Simple operations (less than 10 instructions)
  • Data-dependent control flow
  • Operations that vary significantly based on input

Optimization Guidelines

  1. Minimize witness size: Each operation in the sequence adds to witness
  2. Use constraint-friendly operations: Prefer operations that map cleanly to R1CS constraints
  3. Avoid branches: Keep the sequence deterministic and fixed-length
  4. Test thoroughly: Verify correctness in both host and guest modes

References