Skip to main content

verifyRangeProof

Verifies if a revealed value (value) is consistent with a previously created range proof (proof).

This function allows you to check if someone's claim, like "The value was 42, and here's the proof it was between 0-100," is cryptographically valid.

Parameters

ParameterTypeDescription
valueint64_tThe revealed value to be verified.
secretconst String&The secret key originally used to create the proof.
proofconst RangeProof&The range proof structure generated by createRangeProof.

Return Value

  • bool: Returns true if the value and proof are consistent, false otherwise.

Example Code (main.cpp)

#include <Arduino.h>
#include "Infratic-lib.h" // Assume RangeProof 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=== verifyRangeProof Example ===");

// 1. First, create the proof
int64_t secretValue = 42;
int64_t minRange = 0;
int64_t maxRange = 100;
String mySecret = "rangeProofSecret123";
RangeProof proof;

if (!solana.createRangeProof(secretValue, minRange, maxRange, mySecret, proof)) {
Serial.println("❌ Test Failed: Could not create proof first.");
return;
}
Serial.println("Proof created for secret value '42' and range [0, 100].");

// 2. Successful Verification
Serial.println("\nTest 1: Verifying with the revealed value (42)...");
if (solana.verifyRangeProof(secretValue, mySecret, proof)) {
Serial.println("✅ SUCCESS: Value (42) is consistent with the proof!");
} else {
Serial.println("❌ ERROR: Verification failed.");
}

// 3. Failed Verification (Value outside the original range claimed)
Serial.println("\nTest 2: Verifying with an out-of-range value (101)...");
int64_t tamperedValue = 101;
if (solana.verifyRangeProof(tamperedValue, mySecret, proof)) {
Serial.println("❌ ERROR: Out-of-range value should not have verified!");
} else {
Serial.println("✅ SUCCESS: Out-of-range value (101) is inconsistent with the proof and was correctly rejected.");
}
}

void loop() {
// Can be left empty
}