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

feat: exex connection, read() macro #7

Merged
merged 12 commits into from
Oct 18, 2024
Merged

feat: exex connection, read() macro #7

merged 12 commits into from
Oct 18, 2024

Conversation

rkdud007
Copy link
Member

@rkdud007 rkdud007 commented Oct 15, 2024

this PR target for exex connection initalization & minimal compliance example ( not full sophisticate logic ) - and tried to evaluate what UX is required for hdp-sp1, what additional macros are required.

read() macro

now we have client.write(v) method on DataProcessorClient and the value passed as v will be captured in program with hdp::read() macro. Reasoning behind is again, we need to abstract behavior of online mode and zkvm mode. v will be just assigned as value during online mode through stdio pipeline. during zkvm mode, v will be deliver to zkvm program via SP1Stdin. and this macro is abstracting this two behaviors in conditional compilation.

let hdp_read_fn = quote! {
mod hdp {
use serde::{Serialize, de::DeserializeOwned};
cfg_if::cfg_if! {
if #[cfg(target_os = "zkvm")] {
pub fn read<T: DeserializeOwned>() -> T {
sp1_zkvm::io::read::<T>()
}
} else {
use std::io::{self, Read};
use std::fmt::Debug;
pub fn read<T: DeserializeOwned + Debug>() -> T {
let stdin = io::stdin();
let mut reader = stdin.lock();
let deserialized_value: T = bincode::deserialize_from(&mut reader).expect("Failed to deserialize input");
deserialized_value
}
}
}
}
};

exex connection with hdp-sp1

For compilance example, exex need to pass block_number and potentially some context related transaction ( for now simplicity i just passed tx length) to the hdp program. So base on the ability given by read() macro above, exex will keep stream dynamic values into hdp program that DataProcessorClient abstracted running online -> zkvm mode.

ExExNotification::ChainCommitted { new } => {
info!(committed_chain = ?new.range(), "Received commit");
let block = new.block(new.tip().block.hash()).unwrap();
let block_number = block.number;
let transaction_length = block.body.transactions.len() as u64;
let mut client = DataProcessorClient::new();
client.write(block_number);
client.write(transaction_length);
let (proof, vk) = client.prove("../program".into()).unwrap();
client.verify(&proof, &vk).expect("failed to verify proof");

@rkdud007 rkdud007 changed the title bump: 1.81.0 feat: exex connection Oct 17, 2024
@rkdud007 rkdud007 marked this pull request as ready for review October 18, 2024 12:58
@rkdud007 rkdud007 changed the title feat: exex connection feat: exex connection, read() macro Oct 18, 2024
@rkdud007 rkdud007 requested a review from Okm165 October 18, 2024 13:54
Copy link
Collaborator

@Okm165 Okm165 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rkdud007 rkdud007 merged commit 876ffa9 into main Oct 18, 2024
1 check passed
@rkdud007 rkdud007 deleted the pia/compliance branch October 18, 2024 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants