Skip to main content

Overview

The BigInt inline provides optimized 256-bit × 256-bit multiplication with 512-bit output. This is essential for cryptographic operations involving large integers, such as elliptic curve arithmetic and RSA operations.

API Reference

bigint256_mul()

Performs 256-bit × 256-bit multiplication.

Parameters

  • lhs: First 256-bit operand as 4 u64 limbs (little-endian)
  • rhs: Second 256-bit operand as 4 u64 limbs (little-endian)

Returns

  • [u64; 8]: 512-bit result as 8 u64 limbs (little-endian)

bigint256_mul_inline()

Low-level unsafe interface to the multiplication instruction.

Safety Requirements

  • All pointers must be valid and 8-byte aligned
  • a and b must point to at least 32 bytes of readable memory
  • result must point to at least 64 bytes of writable memory
  • Memory regions may overlap (result can alias a or b)

Usage Examples

Basic Multiplication

Modular Arithmetic

RSA Modular Exponentiation (Component)

Elliptic Curve Point Scalar Multiplication Helper

Implementation Details

Custom Instruction

  • BIGINT256_MUL (funct3=0x00, funct7=0x04): Performs 256×256→512 multiplication

Limb Representation

Numbers are represented in little-endian limb order:

Multiplication Algorithm

The inline performs schoolbook multiplication:
Each output limb rᵢ includes contributions from all aⱼ × bₖ where j + k = i, plus carries from lower limbs.

Memory Layout

  • Input operands: 32 bytes each (4 × 64-bit limbs)
  • Output: 64 bytes (8 × 64-bit limbs)
  • Alignment: 8-byte (u64) alignment required

Constants

Performance Characteristics

  • Cycle count: ~10-20x reduction compared to pure Rust implementation
  • Proving overhead: Minimal additional constraints
  • Throughput: Optimized for single 256×256 multiplication

Integration with Curve Libraries

The BigInt inline is used internally by: For most use cases, prefer the high-level curve APIs which handle modular reduction automatically.

Comparison with Software Implementation

Pure Rust 256×256 multiplication typically requires:
  • 16 64×64→128 multiplications
  • Carry propagation logic
  • ~100-200 RISC-V instructions
The inline reduces this to a single custom instruction.

Feature Flags

  • host: Enables reference implementation for host-side execution
    • Guest code: Compile WITHOUT this feature
    • Prover code: Compile WITH this feature

Source Code Location

Advanced Usage

Using Raw Pointers

For zero-copy operations:

Overlapping Memory

The inline supports in-place operations:

See Also