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
zkvm: question: how to push predicate to Program? #218
Comments
Thanks so much for your question, @SoraSuegami ! A good place to look for reference on how to build some basic zkvm programs right now is the unit tests. To push a Predicate onto the program stack, you construct a Predicate (which you've already done!) and push that as data.
In terms of setting the anchor, the anchor is a field that's managed internally by the VM. We update the anchor on the Finally, in terms of the program you've written — awesome work thus far! I left some inline comments in a few places. fn main() {
// Right now, we never actually use this verify_key, so
// I think we can skip this section. Also, you can use the
// helper VerificationKey::from_secret(&Scalar) to make a
// verification key from random Scalar
let mut rng = rand::thread_rng();
let range = 0..31;
let mut randoms:[u8;32] = [0;32];
for i in range {
randoms[i] = rng.gen();
}
let ristretto = CompressedRistretto(randoms);
let verify_key = zkvm::VerificationKey(ristretto);
let bp_gens = BulletproofGens::new(64, 1);
let pc_gens = PedersenGens::default();
// This program looks great! We do need to add a `nonce` instruction
// to set the anchor, so we'll need to generate a nonce predicate +
// dummy block ID, push those to the stack and call `nonce` and `signtx`
let program1 = zkvm::Program::build(|prog:&mut zkvm::Program|{prog.push(123).r#const().push(123).r#const().eq().verify()});
// For this program in particular, we may not need a program Predicate
// Those are meant to be satisfied using the `call` VM instruction, for
// protecting a contract with some program that must be successfully run
// before continuing.
let pred = zkvm::Predicate::Program(program1.clone());
let op = pred.prove_program_predicate(&bytecode(&program1));
// Similarly, we can combine program1 and program2 here!
let program2 = zkvm::Program::build(|prog:&mut zkvm::Program|{prog.push(0).push(op).nonce()});
let tx_header = zkvm::TxHeader{version:0,mintime:0,maxtime:9999999999};
// The only signature we verify inside the transaction is from the nonce,
// so here we should only need to sign with the nonce Predicate's private key.
let privkey = Scalar::random(&mut rand::thread_rng());
// nit: it may be easier to define the signing function inline in the call to build_tx
let sign_fn = |transcript:&mut Transcript, verification_keys:&Vec<zkvm::VerificationKey>|{
let mut trans = transcript;
zkvm::Signature::sign_single(&mut trans, privkey)
};
let (tx,_,_) = zkvm::Prover::build_tx(program2,tx_header,&bp_gens,sign_fn).unwrap();
let verified = zkvm::Verifier::verify_tx(tx,&bp_gens).unwrap();
} Let me know if that all makes sense or if you have any more questions! |
I truly appreciate your courteous reply!
I understood I can push Predicate to the program and Predicate::Key is used to set Anchor. |
That's great to hear! Thanks so much for your interest. For the time being, we're more focused on development of zkvm itself but having more robust SDKs and tools is definitely something we're interested in working on a little bit down the pipeline :) |
It seems to me that a tool to compile wasm (webassembly) into opcodes in zkvm is very useful for developers. |
Hey @SoraSuegami — having zkvm work with wasm would be great! For right now, we're still developing & changing the zkvm internals a lot. We'll definitely keep that in mind, and would love to have your contributions when we get closer to having zkvm be stable enough to start building out those interfaces :) |
Hello. I am a beginner of Rust.
I'm interested in your zkvm and trying to make a simple example that proves two pushed data are equal.
I'd like to ask you how to push predicate to the program and set Anchor.
This is the code I wrote.
Running this code, I got error message, "the trait
std::convert::From<zkvm::point_ops::PointOp>
is not implemented forzkvm::scalar_witness::ScalarWitness
".As far as I saw Instructions in the ZkVM specification, however, no opcode can push predicates or PointOp of predicates to the stack.
I would appreciate it if you could share how to push predicate to the program and set Anchor.
The text was updated successfully, but these errors were encountered: