program works but script doesn't

This commit is contained in:
Ajinkya Kulkarni 2024-04-15 18:48:42 +02:00
parent a78bdf589d
commit e9b276de83
11 changed files with 4576 additions and 0 deletions

16
.gitignore vendored Normal file
View file

@ -0,0 +1,16 @@
# Cargo build
**/target
# Cargo config
.cargo
# Profile-guided optimization
/tmp
pgo-data.profdata
# MacOS nuisances
.DS_Store
# Proofs
**/proof-with-pis.json
**/proof-with-io.json

9
core/Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "mtcs-core"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }

43
core/src/lib.rs Normal file
View file

@ -0,0 +1,43 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct PrivateKey {
pub key: Vec<u8>,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct Proof {
pub bytes: Vec<u8>,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct MerkleData {
pub merkle_root: [u8; 32],
pub indexes: Vec<usize>,
pub len: usize,
}
pub type Address = [u8; 20];
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct Obligation {
pub from: Address,
pub to: Address,
pub value: u8,
pub salt: [u8; 32],
}
pub type ObligationList = Vec<Obligation>;
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct Cycle {
pub setoff: u8,
pub size: usize,
pub obligations: ObligationList,
}
// #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
// pub struct SignedCommit {
// pub message: Digest,
// pub sign: Digest,
// }

505
program/Cargo.lock generated Normal file
View file

@ -0,0 +1,505 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "anyhow"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247"
[[package]]
name = "base16ct"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf"
[[package]]
name = "base64ct"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
[[package]]
name = "bincode"
version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
dependencies = [
"serde",
]
[[package]]
name = "bitvec"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c"
dependencies = [
"funty",
"radium",
"tap",
"wyz",
]
[[package]]
name = "block-buffer"
version = "0.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
dependencies = [
"generic-array",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "const-oid"
version = "0.9.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8"
[[package]]
name = "cpufeatures"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504"
dependencies = [
"libc",
]
[[package]]
name = "crypto-bigint"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76"
dependencies = [
"generic-array",
"rand_core",
"subtle",
"zeroize",
]
[[package]]
name = "crypto-common"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [
"generic-array",
"typenum",
]
[[package]]
name = "der"
version = "0.7.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0"
dependencies = [
"const-oid",
"zeroize",
]
[[package]]
name = "digest"
version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"const-oid",
"crypto-common",
"subtle",
]
[[package]]
name = "ecdsa"
version = "0.16.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca"
dependencies = [
"der",
"digest",
"elliptic-curve",
"rfc6979",
"signature",
"spki",
]
[[package]]
name = "elliptic-curve"
version = "0.13.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47"
dependencies = [
"base16ct",
"crypto-bigint",
"digest",
"ff",
"generic-array",
"group",
"pkcs8",
"rand_core",
"sec1",
"subtle",
"tap",
"zeroize",
]
[[package]]
name = "ff"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449"
dependencies = [
"bitvec",
"rand_core",
"subtle",
]
[[package]]
name = "funty"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
[[package]]
name = "generic-array"
version = "0.14.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
dependencies = [
"typenum",
"version_check",
"zeroize",
]
[[package]]
name = "getrandom"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "group"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63"
dependencies = [
"ff",
"rand_core",
"subtle",
]
[[package]]
name = "hmac"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
dependencies = [
"digest",
]
[[package]]
name = "k256"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b"
dependencies = [
"cfg-if",
"ecdsa",
"elliptic-curve",
"once_cell",
"sha2",
"signature",
]
[[package]]
name = "libc"
version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "libm"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058"
[[package]]
name = "mtcs-core"
version = "0.1.0"
dependencies = [
"serde",
]
[[package]]
name = "mtcs-sp1-program"
version = "0.1.0"
dependencies = [
"bincode",
"mtcs-core",
"rs_merkle",
"sp1-zkvm",
]
[[package]]
name = "once_cell"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "pkcs8"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7"
dependencies = [
"der",
"spki",
]
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [
"proc-macro2",
]
[[package]]
name = "radium"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "rfc6979"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2"
dependencies = [
"hmac",
"subtle",
]
[[package]]
name = "rs_merkle"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b241d2e59b74ef9e98d94c78c47623d04c8392abaf82014dfd372a16041128f"
dependencies = [
"sha2",
]
[[package]]
name = "sec1"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc"
dependencies = [
"base16ct",
"der",
"generic-array",
"pkcs8",
"subtle",
"zeroize",
]
[[package]]
name = "serde"
version = "1.0.197"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.197"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "sha2"
version = "0.10.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "signature"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de"
dependencies = [
"digest",
"rand_core",
]
[[package]]
name = "sp1-precompiles"
version = "0.1.0"
source = "git+https://github.com/succinctlabs/sp1.git#b5d5473c010ab0630102652146e16c014a1eddf6"
dependencies = [
"anyhow",
"bincode",
"cfg-if",
"getrandom",
"k256",
"rand",
"serde",
]
[[package]]
name = "sp1-zkvm"
version = "0.1.0"
source = "git+https://github.com/succinctlabs/sp1.git#b5d5473c010ab0630102652146e16c014a1eddf6"
dependencies = [
"bincode",
"cfg-if",
"getrandom",
"k256",
"libm",
"once_cell",
"rand",
"serde",
"sha2",
"sp1-precompiles",
]
[[package]]
name = "spki"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d"
dependencies = [
"base64ct",
"der",
]
[[package]]
name = "subtle"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
[[package]]
name = "syn"
version = "2.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "tap"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]]
name = "typenum"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wyz"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed"
dependencies = [
"tap",
]
[[package]]
name = "zeroize"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d"

11
program/Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[workspace]
[package]
version = "0.1.0"
name = "mtcs-sp1-program"
edition = "2021"
[dependencies]
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git" }
mtcs-core = {path = "../core"}
rs_merkle = "1.4.2"
bincode = "1.3.3"

58
program/src/main.rs Normal file
View file

@ -0,0 +1,58 @@
#![no_main]
use bincode::serialize;
use mtcs_core::*;
use rs_merkle::{algorithms::Sha256 as MerkleSha256, Hasher, MerkleProof};
sp1_zkvm::entrypoint!(main);
pub fn main() {
println!("reading inputs into guest...");
let cycle: Cycle = sp1_zkvm::io::read::<Cycle>();
let _secret: PrivateKey = sp1_zkvm::io::read::<PrivateKey>();
let proof: Proof = sp1_zkvm::io::read::<Proof>();
let merkle_data: MerkleData = sp1_zkvm::io::read::<MerkleData>();
assert_eq!(
cycle.size,
cycle.obligations.len(),
"cycle size does not match number of obligations"
);
assert!(
cycle.size > 2,
"invalid cycle, length is {}, should be atleast 3",
cycle.size
);
let mut leaves: Vec<[u8; 32]> = vec![];
println!("running validity checks...");
let from = &cycle.obligations.first().unwrap().from;
let to = &cycle.obligations.iter().fold(from, |acc, x| {
if &x.from == acc && &x.value >= &cycle.setoff {
leaves.push(MerkleSha256::hash(&serialize(&x).unwrap()));
&x.to
} else {
panic!("cycle invalid")
}
});
assert_eq!(&from, to);
let indexes = merkle_data.indexes;
let proof: MerkleProof<MerkleSha256> =
MerkleProof::<MerkleSha256>::try_from(proof.bytes).unwrap();
assert!(proof.verify(
merkle_data.merkle_root,
&indexes,
leaves.get(..).ok_or("couldn't fetch leaves").unwrap(),
merkle_data.len
));
println!("creating commitments for public data");
sp1_zkvm::io::commit(&cycle);
}
// TODO: for every edge involved in clearing, the total offsets of all cycles
// passing through that edge should be less than the value of that edge
// TODO:need to make sure that the same cycle doesn't appear
// twice in the same clearing epoch

3718
script/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

11
script/Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[workspace]
[package]
version = "0.1.0"
name = "mtcs-sp1-script"
edition = "2021"
[dependencies]
sp1-sdk = { git = "https://github.com/succinctlabs/sp1.git" }
[build-dependencies]
sp1-helper = { git = "https://github.com/succinctlabs/sp1.git" }

5
script/build.rs Normal file
View file

@ -0,0 +1,5 @@
use sp1_helper::build_program;
fn main() {
build_program("../program")
}

3
script/rust-toolchain Normal file
View file

@ -0,0 +1,3 @@
[toolchain]
channel = "nightly-2024-01-25"
components = ["llvm-tools", "rustc-dev"]

197
script/src/main.rs Normal file
View file

@ -0,0 +1,197 @@
// These constants represent the RISC-V ELF and the image ID generated by risc0-build.
// The ELF is used for proving and the ID is used for verification.
use bincode::serialize;
use methods::{PROVER_ELF, PROVER_ID};
use mtcs_core::*;
use rs_merkle::{algorithms::Sha256 as MerkleSha256, Hasher, MerkleTree};
use std::time::SystemTime;
use sp1_sdk::{SP1Prover, SP1Stdin, SP1Verifier};
const ELF: &[u8] = include_bytes!("../../program/elf/riscv32im-succinct-zkvm-elf");
fn main() {
// Initialize tracing. In order to view logs, run `RUST_LOG=info cargo run`
env_logger::init();
// An executor environment describes the configurations for the zkVM
// including program inputs.
// An default ExecutorEnv can be created like so:
// `let env = ExecutorEnv::builder().build().unwrap();`
// However, this `env` does not have any inputs.
//
// To add add guest input to the executor environment, use
// ExecutorEnvBuilder::write().
// To access this method, you'll need to use ExecutorEnv::builder(), which
// creates an ExecutorEnvBuilder. When you're done adding input, call
// ExecutorEnvBuilder::build().
let start_time = SystemTime::now();
println!("generating guest inputs...");
// For example:
let key: Vec<u8> = "passw0rdpassw0rdpassw0rdpassw0rd".as_bytes().to_vec();
let secret = PrivateKey { key };
let cycle: Cycle = Cycle {
setoff: 103,
size: 3,
obligations: vec![
Obligation {
from: hex::decode("9BA1Bcd88E99d6E1E03252A70A63FEa83Bf1208c")
.expect("Decoding failed")
.try_into()
.unwrap(),
to: hex::decode("6FF840eeeFFec0C35F52bB6031a9Ae34524a05b6")
.expect("Decoding failed")
.try_into()
.unwrap(),
value: 103,
salt: [
134, 104, 222, 91, 13, 97, 183, 43, 190, 29, 199, 203, 206, 17, 241, 117, 145,
238, 154, 201, 79, 48, 188, 175, 205, 156, 218, 223, 93, 208, 253, 13,
],
},
Obligation {
from: hex::decode("6FF840eeeFFec0C35F52bB6031a9Ae34524a05b6")
.expect("Decoding failed")
.try_into()
.unwrap(),
to: hex::decode("42cEDde51198D1773590311E2A340DC06B24cB37")
.expect("Decoding failed")
.try_into()
.unwrap(),
value: 197,
salt: [
47, 45, 177, 118, 3, 36, 136, 70, 238, 148, 143, 56, 140, 115, 20, 16, 235,
102, 188, 236, 119, 192, 25, 103, 197, 72, 237, 170, 40, 203, 125, 227,
],
},
Obligation {
from: hex::decode("42cEDde51198D1773590311E2A340DC06B24cB37")
.expect("Decoding failed")
.try_into()
.unwrap(),
to: hex::decode("9BA1Bcd88E99d6E1E03252A70A63FEa83Bf1208c")
.expect("Decoding failed")
.try_into()
.unwrap(),
value: 252,
salt: [
10, 136, 55, 248, 203, 115, 181, 120, 254, 162, 89, 219, 109, 241, 31, 169,
203, 202, 197, 34, 2, 240, 234, 36, 28, 103, 3, 184, 190, 156, 151, 252,
],
},
],
};
let all_obligations: Vec<Obligation> = vec![
Obligation {
from: hex::decode("9BA1Bcd88E99d6E1E03252A70A63FEa83Bf1208c")
.expect("Decoding failed")
.try_into()
.unwrap(),
to: hex::decode("6FF840eeeFFec0C35F52bB6031a9Ae34524a05b6")
.expect("Decoding failed")
.try_into()
.unwrap(),
value: 103,
salt: [
134, 104, 222, 91, 13, 97, 183, 43, 190, 29, 199, 203, 206, 17, 241, 117, 145, 238,
154, 201, 79, 48, 188, 175, 205, 156, 218, 223, 93, 208, 253, 13,
],
},
Obligation {
from: hex::decode("6FF840eeeFFec0C35F52bB6031a9Ae34524a05b6")
.expect("Decoding failed")
.try_into()
.unwrap(),
to: hex::decode("42cEDde51198D1773590311E2A340DC06B24cB37")
.expect("Decoding failed")
.try_into()
.unwrap(),
value: 197,
salt: [
47, 45, 177, 118, 3, 36, 136, 70, 238, 148, 143, 56, 140, 115, 20, 16, 235, 102,
188, 236, 119, 192, 25, 103, 197, 72, 237, 170, 40, 203, 125, 227,
],
},
Obligation {
from: hex::decode("42cEDde51198D1773590311E2A340DC06B24cB37")
.expect("Decoding failed")
.try_into()
.unwrap(),
to: hex::decode("9BA1Bcd88E99d6E1E03252A70A63FEa83Bf1208c")
.expect("Decoding failed")
.try_into()
.unwrap(),
value: 252,
salt: [
10, 136, 55, 248, 203, 115, 181, 120, 254, 162, 89, 219, 109, 241, 31, 169, 203,
202, 197, 34, 2, 240, 234, 36, 28, 103, 3, 184, 190, 156, 151, 252,
],
},
];
let mut indexes: Vec<usize> = Vec::new();
cycle.obligations.iter().for_each(|&i| {
let index = all_obligations.iter().position(|&x| x == i).unwrap();
indexes.push(index)
});
let leaves: Vec<[u8; 32]> = all_obligations
.iter()
.map(|x| MerkleSha256::hash(&serialize(&x).unwrap()[..]))
.collect();
let len = leaves.len();
let merkle_tree = MerkleTree::<MerkleSha256>::from_leaves(&leaves);
let merkle_root = merkle_tree.root().ok_or("could not find root").unwrap();
let merkle_proof = merkle_tree.proof(&indexes);
let bytes = merkle_proof.to_bytes();
let key: PrivateKey = secret;
let proof: Proof = Proof {
bytes: bytes.as_slice().try_into().unwrap(),
};
let aux: MerkleData = MerkleData {
merkle_root,
indexes: indexes.try_into().unwrap(),
len,
};
let mut stdin = SP1Stdin::new();
println!("writing inputs to guest...");
stdin.write(&cycle);
stdin.write(&key);
stdin.write(&proof);
stdin.write(&aux);
println!("generating proof...");
let mut proof = SP1Prover::prove(ELF, stdin).expect("proving failed");
println!("proof generation completed!");
println!("verifying receipt...");
SP1Verifier::verify(ELF, &proof).expect("verification failed");
println!("verification completed!");
let end_time = SystemTime::now();
let difference = end_time
.duration_since(start_time)
.expect("Clock may have gone backwards");
println!("Total time: {difference:?}");
proof
.save("proof-with-io.json")
.expect("saving proof failed");
println!("successfully generated and verified proof for the program!")
}