Skip to main content

Overview

UntrustedAdvice<T> is a wrapper type that marks guest program inputs as untrusted advice. Unlike trusted advice, untrusted advice values must be verified within the zkVM to ensure correctness. This is the safer option for inputs that need to be validated as part of the proof.

Type Definition

pub struct UntrustedAdvice<T> {
    value: T,
}
value
T
The wrapped value provided as untrusted advice

Methods

new

Creates a new UntrustedAdvice wrapper around a value.
pub fn new(value: T) -> Self
value
T
required
The value to wrap as untrusted advice
Returns: A new UntrustedAdvice<T> instance Example:
use jolt_sdk::UntrustedAdvice;

let untrusted_value = UntrustedAdvice::new(42u64);

Trait Implementations

From<T>

Allows automatic conversion from any value T into UntrustedAdvice<T>.
impl<T> From<T> for UntrustedAdvice<T>
Example:
use jolt_sdk::UntrustedAdvice;

let untrusted: UntrustedAdvice<u64> = 42u64.into();

Deref

Provides automatic dereferencing to access the wrapped value.
impl<T> core::ops::Deref for UntrustedAdvice<T> {
    type Target = T;
}
Example:
use jolt_sdk::UntrustedAdvice;

let untrusted = UntrustedAdvice::new(42u64);
let value: u64 = *untrusted; // Dereferences to 42

Usage Example

use jolt_sdk::{UntrustedAdvice, check_advice};

#[jolt::provable]
fn verify_sorted_indices(data: Vec<u64>, indices: UntrustedAdvice<Vec<usize>>) -> bool {
    // Verify that the untrusted indices actually sort the data
    check_advice!(indices.len() == data.len());
    
    for i in 0..indices.len() - 1 {
        check_advice!(data[indices[i]] <= data[indices[i + 1]]);
    }
    
    true
}

fn main() {
    let data = vec![5, 2, 8, 1, 9];
    let sorted_indices = vec![3, 1, 0, 2, 4]; // Indices that sort the data
    
    let result = verify_sorted_indices(
        data,
        UntrustedAdvice::new(sorted_indices)
    );
    println!("Verified: {}", result);
}

When to Use

Use UntrustedAdvice<T> when:
  • The input comes from an external source and needs verification
  • You want to provide a hint or witness that will be checked within the zkVM
  • You need to verify properties of the input as part of the proof
  • You want to use the safer default for advice inputs
UntrustedAdvice is the recommended default for most use cases. Always verify untrusted advice using check_advice! or check_advice_eq! macros to ensure correctness.

Verification Macros

When working with untrusted advice, use these macros to verify correctness:
  • check_advice!(condition) - Asserts that a condition holds
  • check_advice_eq!(left, right) - Asserts that two values are equal
See the check_advice! macro documentation for more details.

See Also

Build docs developers (and LLMs) love