/collatz-conjecture

RISC Zero implementation of the Collatz Conjecture for Hylé

Primary LanguageRustApache License 2.0Apache-2.0

Hylé example RISC Zero smart contract

This repository provides an example smart contract for Hylé, implementing the Collatz Conjecture.

Installing RISC Zero

Please refer to RiscZero's installation guide

Reproducible builds

RISC Zero provides using a docker setup. Simply run

cargo risczero build --manifest-path methods/guest/Cargo.toml

to build the smart contract.

The reproducible Image ID of this smart contract is currently 0x826d7874ef3935e5ee2d7d9ed54753791a8a1334ec02e2f7d6b63034013c4ae4

Running the smart contract

cargo run next X # Generate a proof of the transition from X to the next number in the collatz conjecture
# Or reproducibly
cargo run -- -r next X
cargo run reset X # Reset to X, assuming the current number is a 1
# Or reproducibly
cargo run -- -r reset X

Verifying locally

Install the Hylé RISC Zero verifier. You can then verify proofs using:

# The verifier currently expects no `0x` prefix. Pass data as base64 values.
cargo run -p risc0-verifier e413a0dcd0a82050d3f65b955a7a9a202f1464c4ceae4beea914ac8a13079f5d [path_to_proof] [initial_state] [final_state]

If the proof is malformed, or doesn't respect the rules of the smart contract, the verifier will return an error.

Verifying on Hylé

Follow the instructions on the Hylé documentation.