verifyzkSNARKProof
Verifies a simplified zkSNARK proof generated by createzkSNARKProof.
This function checks if the provided proof is valid for the given expectedPublicInputs. If it returns true, it cryptographically confirms that the prover knew the secret inputs (privateData) that correctly produced the expectedPublicInputs when processed through the specified circuit, without revealing the secrets.
Parameters
| Parameter | Type | Description |
|---|---|---|
proof | const zkSNARKProof& | The zkSNARK proof structure to be verified. |
expectedPublicInputs | const std::vector<uint8_t>& | The public inputs that the proof should satisfy. |
Return Value
bool: Returnstrueif the proof is valid,falseotherwise.
Example Code (main.cpp)
#include <Arduino.h>
#include <vector>
#include "Infratic-lib.h" // Assume zkSNARKProof struct is defined here
// This function does not require network connectivity.
Infratic solana(""); // RPC URL not needed
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("\n=== verifyzkSNARKProof Example ===");
// 1. First, create a (hypothetical) proof
std::vector<uint8_t> privateData = { 0x03 }; // x = 3
std::vector<uint8_t> publicInputs = { 0x09 }; // result = 9
String circuit = "simple_square_circuit";
zkSNARKProof proof;
if (!solana.createzkSNARKProof(privateData, publicInputs, circuit, proof)) {
Serial.println("❌ Test Failed: Could not create proof first.");
return;
}
Serial.println("Proof created for 'x=3' (private) and 'result=9' (public).");
// 2. Successful Verification
Serial.println("\nTest 1: Verifying with expected public input (9)...");
std::vector<uint8_t> expectedPublicInputs = { 0x09 };
if (solana.verifyzkSNARKProof(proof, expectedPublicInputs)) {
Serial.println("✅ SUCCESS: Proof verified!");
} else {
Serial.println("❌ ERROR: Verification failed.");
}
// 3. Failed Verification (Incorrect Public Input)
Serial.println("\nTest 2: Verifying with incorrect public input (10)...");
std::vector<uint8_t> wrongPublicInputs = { 0x0A }; // 10
if (solana.verifyzkSNARKProof(proof, wrongPublicInputs)) {
Serial.println("❌ ERROR: Incorrect input should not have verified!");
} else {
Serial.println("✅ SUCCESS: Proof rejected due to inconsistent public input.");
}
}
void loop() {
// Can be left empty
}