Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: nested proof verification #494

Merged
merged 19 commits into from
Apr 16, 2024
Merged
61 changes: 39 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"derive",
"eval",
"helper",
"primitives",
"prover",
"recursion/circuit",
"recursion/compiler",
Expand Down Expand Up @@ -33,7 +34,7 @@ p3-field = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-commit = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-matrix = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-baby-bear = { git = "https://github.com/Plonky3/Plonky3.git", features = [
"nightly-features",
"nightly-features",
], branch = "sp1" }
p3-util = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-challenger = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
Expand Down
3 changes: 2 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ p3-uni-stark = { workspace = true }
p3-util = { workspace = true }
rrs-lib = { git = "https://github.com/GregAC/rrs.git" }
sp1-derive = { path = "../derive" }
sp1-zkvm = { path = "../zkvm/entrypoint" }
sp1-primitives = { path = "../primitives" }

anyhow = "1.0.79"
arrayref = "0.3.6"
Expand Down Expand Up @@ -71,6 +71,7 @@ rayon-scan = "0.1.1"
criterion = "0.5.1"
num = { version = "0.4.1", features = ["rand"] }
rand = "0.8.5"
sp1-zkvm = { path = "../zkvm/entrypoint" }

[features]
debug = []
Expand Down
26 changes: 21 additions & 5 deletions core/src/air/public_values.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use arrayref::array_ref;
use core::fmt::Debug;
use core::mem::size_of;
use std::iter::once;
Expand All @@ -16,12 +15,19 @@ pub const SP1_PROOF_NUM_PV_ELTS: usize = size_of::<PublicValues<Word<u8>, u8>>()
/// The number of 32 bit words in the SP1 proof's commited value digest.
pub const PV_DIGEST_NUM_WORDS: usize = 8;

pub const POSEIDON_NUM_WORDS: usize = 8;

/// The PublicValues struct is used to store all of a shard proof's public values.
#[derive(Serialize, Deserialize, Clone, Copy, Default, Debug)]
pub struct PublicValues<W, T> {
/// The hash of all the bytes that the guest program has written to public values.
pub committed_value_digest: [W; PV_DIGEST_NUM_WORDS],

/// The hash of all deferred proofs that have been witnessed in the VM. It will be rebuilt in
/// recursive verification as the proofs get verified. The hash itself is a rolling poseidon2
/// hash of each proof+vkey hash and the previous hash which is initially zero.
pub deferred_proofs_digest: [W; POSEIDON_NUM_WORDS],

/// The shard number.
pub shard: T,

Expand All @@ -43,6 +49,11 @@ impl PublicValues<u32, u32> {
.committed_value_digest
.iter()
.flat_map(|w| Word::<F>::from(*w).into_iter())
.chain(
self.deferred_proofs_digest
.iter()
.flat_map(|w| Word::<F>::from(*w).into_iter()),
)
.chain(once(F::from_canonical_u32(self.shard)))
.chain(once(F::from_canonical_u32(self.start_pc)))
.chain(once(F::from_canonical_u32(self.next_pc)))
Expand All @@ -61,7 +72,7 @@ impl PublicValues<u32, u32> {
}
}

impl<T: Clone> PublicValues<Word<T>, T> {
impl<T: Clone + Debug> PublicValues<Word<T>, T> {
/// Convert a vector of field elements into a PublicValues struct.
pub fn from_vec(data: Vec<T>) -> Self {
let mut iter = data.iter().cloned();
Expand All @@ -71,6 +82,11 @@ impl<T: Clone> PublicValues<Word<T>, T> {
committed_value_digest.push(Word::from_iter(&mut iter));
}

let mut deferred_proofs_digest = Vec::new();
for _ in 0..POSEIDON_NUM_WORDS {
deferred_proofs_digest.push(Word::from_iter(&mut iter));
}

// Collecting the remaining items into a tuple. Note that it is only getting the first
// four items, as the rest would be padded values.
let remaining_items = iter.collect_vec();
Expand All @@ -84,8 +100,8 @@ impl<T: Clone> PublicValues<Word<T>, T> {
};

Self {
committed_value_digest: array_ref![committed_value_digest, 0, PV_DIGEST_NUM_WORDS]
.clone(),
committed_value_digest: committed_value_digest.try_into().unwrap(),
deferred_proofs_digest: deferred_proofs_digest.try_into().unwrap(),
shard: shard.to_owned(),
start_pc: start_pc.to_owned(),
next_pc: next_pc.to_owned(),
Expand Down Expand Up @@ -113,7 +129,7 @@ mod tests {
fn test_public_values_digest_num_words_consistency_zkvm() {
assert_eq!(
public_values::PV_DIGEST_NUM_WORDS,
sp1_zkvm::PV_DIGEST_NUM_WORDS
sp1_zkvm::syscalls::PV_DIGEST_NUM_WORDS
);
}
}
Loading
Loading