### Setup Universal Parameters for Varuna SNARK Source: https://context7.com/vicsn/snarkvm-btc-balance-verification/llms.txt Initializes the Universal Reference String (URS) for the Varuna SNARK proof system. This setup is crucial for generating proofs and verifying them, requiring parameters like the number of constraints, variables, and non-zero entries. The output is UniversalParams suitable for proving and verification. ```rust use zprize::api; // Setup with circuit size parameters // Parameters: num_constraints, num_variables, num_non_zero let urs = api::setup(1000, 1000, 1000); // The max_degree is computed internally: // max_degree = AHPForR1CS::max_degree(1000, 1000, 1000) // Returns UniversalParams for proving and verification ``` -------------------------------- ### Bash: Running SnarkVM Performance Benchmarks Source: https://context7.com/vicsn/snarkvm-btc-balance-verification/llms.txt Provides bash commands to execute performance benchmarks for the SnarkVM circuit. It shows how to run the default benchmark and customize concurrency levels. The benchmarks test different message sizes and report timing statistics using Criterion, saving results to `target/criterion/`. ```bash # Run default benchmark (100-byte messages, 10 samples) cargo bench # Run with custom concurrency level MAX_CON=20 cargo bench # The benchmark suite tests: # - Small messages (100 bytes) # - Medium messages (1,000 bytes) - commented out # - Large messages (50,000 bytes) - commented out # # Each benchmark: # 1. Generates signatures # 2. Compiles circuit once # 3. Runs prove_and_verify multiple times # 4. Reports timing statistics via Criterion # # Results are saved to target/criterion/ with HTML reports ``` -------------------------------- ### Rust: End-to-End Signature Prove and Verify Workflow Source: https://context7.com/vicsn/snarkvm-btc-balance-verification/llms.txt Demonstrates the complete workflow for proving and verifying batched ECDSA signatures using SnarkVM. It includes generating test data, setting up universal parameters, compiling the circuit, and processing signatures in concurrent chunks. The function `prove_and_verify` handles the batched processing. ```rust use zprize::{api, console, prove_and_verify}; fn main() { // Parameters let num_signatures = 10; let msg_len = 100; let max_concurrent = 10; // Process 10 signatures at a time // Generate test data let tuples = console::generate_signatures(msg_len, num_signatures); // Setup universal parameters let urs = api::setup(1000, 1000, 1000); // Compile circuit for this message length let (pk, vk) = api::compile(&urs, msg_len); // Prove and verify all signatures // Processes signatures in chunks of max_concurrent prove_and_verify(&urs, &pk, &vk, &tuples, max_concurrent); println!("Successfully proved and verified {} signatures", num_signatures); } ``` -------------------------------- ### Compile ECDSA Circuit for Key Generation Source: https://context7.com/vicsn/snarkvm-btc-balance-verification/llms.txt Compiles the ECDSA verification circuit to generate proving and verifying keys. This process involves setting up the URS first and then compiling the circuit for a specified message length. The compilation also provides detailed constraint statistics. ```rust use zprize::api; // First setup the URS let urs = api::setup(1000, 1000, 1000); // Compile circuit for 100-byte messages let msg_len = 100; let (pk, vk) = api::compile(&urs, msg_len); // The compile function internally: // 1. Generates a sample message and signature // 2. Runs the circuit in compile mode // 3. Prints constraint statistics: // - num_constraints: total constraints in circuit // - num_public: public input count // - num_private: private witness count // - num_non_zeros: non-zero entries in R1CS matrix // Returns (CircuitProvingKey, CircuitVerifyingKey) ``` -------------------------------- ### Generate Zero-Knowledge Proof for ECDSA Signatures Source: https://context7.com/vicsn/snarkvm-btc-balance-verification/llms.txt Generates a zero-knowledge proof for a batch of ECDSA signature verifications. This involves setting up the URS, compiling the circuit, generating test signatures, and then using the `prove` API to create a single batch proof using Varuna V2. ```rust use zprize::api; use zprize::console; // Setup and compilation let urs = api::setup(1000, 1000, 1000); let msg_len = 100; let (pk, vk) = api::compile(&urs, msg_len); // Generate signatures to prove let tuples = console::generate_signatures(msg_len, 5); // Generate proof for all tuples in batch let proof = api::prove(&urs, &pk, tuples); // The prove function: // 1. Spawns parallel threads for each signature // 2. Runs the circuit for each (pubkey, msg, sig) tuple // 3. Collects all assignments // 4. Generates a single batch proof using Varuna V2 // Returns varuna::Proof ``` -------------------------------- ### Rust: Emulated Field Operations for secp256k1 Source: https://context7.com/vicsn/snarkvm-btc-balance-verification/llms.txt Details the implementation of emulated field operations in Rust, enabling secp256k1's 256-bit field arithmetic within SnarkVM's Bls12_377 circuit field (253-bit) using limb decomposition. It demonstrates creating field elements from `BigUint`, performing multiplication and addition, and enforcing equality constraints, ensuring operations stay within the field modulus. ```rust use zprize::emulated_field::{EmulatedField, secp256k1_Fp, secp256k1_Fr}; use num_bigint::BigUint; use snarkvm_circuit_environment::Mode; // secp256k1 base field (for curve points) // p = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F // secp256k1 scalar field (for private keys/signatures) // Fr = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 // Create emulated field element from BigUint let value = BigUint::from(12345u64); let limb_bytes = 11; // 88 bits per limb (3 limbs total = 264 bits) let field_elem = EmulatedField::from_BigUint( &value, limb_bytes, Mode::Private, secp256k1_Fp ); // Arithmetic operations let a = EmulatedField::from_BigUint(&BigUint::from(100u64), 11, Mode::Private, secp256k1_Fp); let b = EmulatedField::from_BigUint(&BigUint::from(200u64), 11, Mode::Private, secp256k1_Fp); // Multiplication: a*b = q*p + r (with range constraints) let product = a.mul(&b); // Addition/Subtraction let sum = a.add(&b); // Enforce equality constraint EmulatedField::enforce_eq(&a, &a); // Each operation maintains limb-wise constraints to prevent overflow // and ensures results stay within the emulated field modulus ``` -------------------------------- ### Keccak256 Hashing in Circuit (Rust) Source: https://context7.com/vicsn/snarkvm-btc-balance-verification/llms.txt Computes the Keccak256 hash of message bytes within a zero-knowledge circuit. It prepares message bytes as field elements, uses a Keccak256 hasher, and outputs a 32-byte hash. Dependencies include 'zprize' and 'snarkvm_circuit'. The circuit implements the full Keccak-f[1600] permutation. ```rust use zprize::keccak256::Keccak256; use snarkvm_circuit::Field; use snarkvm_circuit_environment::{Circuit as Env, Mode, Zero}; type F = Field; // Prepare message as field elements (1 byte per field element) let msg = vec![0u8, 1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8]; let msg_fields: Vec = msg.iter().map(|b| { let field_val = snarkvm_console::types::Field::from_u8(*b); F::new(Mode::Public, field_val) }).collect(); // Initialize Keccak256 hasher let mut hasher = Keccak256::new(); // Input message bytes hasher.input(&msg_fields); // Get 32-byte hash result let mut hash = vec![F::zero(); 32]; hasher.result(&mut hash.as_mut_slice()); // Hash is in big-endian, reverse for little-endian hash.reverse(); // The circuit implements full Keccak-f[1600] permutation with: // - 24 rounds of theta, rho, pi, chi, iota transformations // - Sponge construction with rate 136 bytes (1088 bits) // - All operations constrained in circuit using lookup tables // Result can be used for ECDSA message hash (first 32 bytes) ``` -------------------------------- ### Verify Zero-Knowledge Proof of ECDSA Signatures Source: https://context7.com/vicsn/snarkvm-btc-balance-verification/llms.txt Verifies a zero-knowledge proof for a batch of ECDSA signatures. This function requires the URS, verifying key, the original signature tuples, and the generated proof. It reconstructs public inputs and utilizes the VarunaSNARK::verify_batch function for V2 protocol verification, asserting the result. ```rust use zprize::api; use zprize::console; // Setup, compile, and prove let urs = api::setup(1000, 1000, 1000); let msg_len = 100; let (pk, vk) = api::compile(&urs, msg_len); let tuples = console::generate_signatures(msg_len, 5); let proof = api::prove(&urs, &pk, tuples.clone()); // Verify the proof api::verify_proof(&urs, &vk, &tuples, &proof); // The verify_proof function: // 1. Reconstructs public inputs from tuples // 2. Creates keys_to_inputs mapping // 3. Calls VarunaSNARK::verify_batch with V2 protocol // 4. Asserts verification result is true (panics on failure) ``` -------------------------------- ### Elliptic Curve Point Operations (Rust) Source: https://context7.com/vicsn/snarkvm-btc-balance-verification/llms.txt Performs secp256k1 elliptic curve arithmetic using emulated fields within zero-knowledge circuits. It includes operations for creating points from coordinates, verifying points on the curve, and scalar multiplication using windowed exponentiation. Dependencies include 'zprize' and 'num_bigint'. ```rust use zprize::ecc_secp256k1::Affine; use zprize::emulated_field::{EmulatedField, secp256k1_Fp, secp256k1_Fr}; use num_bigint::BigUint; use snarkvm_circuit_environment::Mode; // Get the secp256k1 generator point G let G = Affine::G(); // G.x = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798 // G.y = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8 // Create point from coordinates let x = BigUint::parse_bytes(b"79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 16).unwrap(); let y = BigUint::parse_bytes(b"483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", 16).unwrap(); let point = Affine::from_xy(&x, &y, Mode::Private, secp256k1_Fp); // Verify point is on curve: y^2 = x^3 + 7 let y_squared = point.y.mul(&point.y); let x_cubed = point.x.mul(&point.x.mul(&point.x)); let seven = EmulatedField::from_BigUint(&BigUint::from(7u64), 11, Mode::Private, secp256k1_Fp); let rhs = x_cubed.add(&seven); EmulatedField::enforce_eq(&y_squared, &rhs); // Scalar multiplication with windowed exponentiation // Computes: scalar1*point1 + scalar2*point2 (for ECDSA verification) let scalar1 = EmulatedField::from_BigUint(&BigUint::from(12345u64), 11, Mode::Private, secp256k1_Fr); let scalar2 = EmulatedField::from_BigUint(&BigUint::from(67890u64), 11, Mode::Private, secp256k1_Fr); let result = Affine::scalarMulExp_win(&scalar1, &G, &scalar2, &point); // Uses windowing optimization to reduce constraint count ``` -------------------------------- ### Rust: Circuit ECDSA Verification Function Source: https://context7.com/vicsn/snarkvm-btc-balance-verification/llms.txt Implements the core circuit function `verify_one` in Rust for verifying a single ECDSA signature. It uses emulated field arithmetic and elliptic curve operations within SnarkVM's circuit environment. This function takes public key, signature, and message as inputs and performs Keccak256 hashing, scalar field operations, and point addition on the secp256k1 curve. ```rust use zprize::circuit::{ECDSAPublicKey, ECDSASignature, Message, verify_one}; use zprize::console; use snarkvm_circuit_environment::Mode; // Generate test signature let msg_bytes = vec![0u8; 100]; let (pubkey, sig) = console::sample_pubkey_sig(&msg_bytes); // Create circuit inputs (Mode::Public for public inputs) let msg = Message::new(Mode::Public, msg_bytes.clone()); let public_key = ECDSAPublicKey::new(Mode::Public, pubkey); let signature = ECDSASignature::new(Mode::Public, sig); // Run verification circuit (compile_mode = false for proving) verify_one(public_key, signature, msg, false); // The verify_one function: // 1. Keccak256 hashes the message // 2. Extracts r, s from signature using emulated field arithmetic // 3. Computes s^-1 mod secp256k1_Fr // 4. Validates public key is on secp256k1 curve: y^2 = x^3 + 7 // 5. Performs scalar multiplication: h*s^-1*G + r*s^-1*PK // 6. Enforces result.x == r (ECDSA verification equation) // All operations use emulated fields to handle 256-bit secp256k1 operations ``` -------------------------------- ### Generate Test ECDSA Signatures Source: https://context7.com/vicsn/snarkvm-btc-balance-verification/llms.txt Creates tuples of (public_key, message, signature) for testing the zero-knowledge proof system. This function generates a specified number of signatures for messages of a given length, ensuring all generated signatures are valid. ```rust use zprize::console; // Generate 10 signatures with 100-byte messages let msg_len = 100; let num = 10; let tuples = console::generate_signatures(msg_len, num); // Each tuple contains: // - VerifyingKey: secp256k1 ECDSA public key // - Vec: message bytes (random, but set to zeros in this implementation) // - Signature: secp256k1 ECDSA signature // All signatures are automatically verified before being returned // Example iteration: for (public_key, msg, signature) in &tuples { println!("Public key: {:?}", public_key); println!("Message length: {}", msg.len()); println!("Signature r,s: {:?}", signature); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.