do RNG before proving
This commit is contained in:
parent
34c5b9044d
commit
f57af0519d
4 changed files with 18 additions and 22 deletions
|
@ -3,7 +3,6 @@
|
|||
use bincode::serialize;
|
||||
use ed25519_consensus::*;
|
||||
use mtcs_core::*;
|
||||
use rand::thread_rng;
|
||||
use rs_merkle::{algorithms::Sha256, Hasher, MerkleProof};
|
||||
sp1_zkvm::entrypoint!(main);
|
||||
|
||||
|
@ -11,7 +10,7 @@ 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 key: SigningKey = sp1_zkvm::io::read::<SigningKey>();
|
||||
let proof: Proof = sp1_zkvm::io::read::<Proof>();
|
||||
let merkle_data: MerkleData = sp1_zkvm::io::read::<MerkleData>();
|
||||
assert_eq!(
|
||||
|
@ -53,15 +52,16 @@ pub fn main() {
|
|||
let message = {
|
||||
let hashed_cycle = Sha256::hash(&serialize(&cycle).unwrap());
|
||||
// Generate a signing key and sign the message
|
||||
let sk = SigningKey::new(thread_rng());
|
||||
let sig = sk.sign(&bincode::serialize(&hashed_cycle).unwrap()[..]);
|
||||
|
||||
let vk_bytes: [u8; 32] = VerificationKey::from(&sk).into();
|
||||
let sig = key.sign(&bincode::serialize(&hashed_cycle).unwrap()[..]);
|
||||
|
||||
let vk_bytes: [u8; 32] = VerificationKey::from(&key).into();
|
||||
|
||||
(hashed_cycle, vk_bytes, sig)
|
||||
};
|
||||
|
||||
sp1_zkvm::io::commit(&message);
|
||||
println!("cryptography magic happening...")
|
||||
}
|
||||
// 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
|
||||
|
|
1
script/Cargo.lock
generated
1
script/Cargo.lock
generated
|
@ -2243,6 +2243,7 @@ dependencies = [
|
|||
"ed25519-consensus",
|
||||
"hex",
|
||||
"mtcs-core",
|
||||
"rand",
|
||||
"rs_merkle",
|
||||
"serde_json",
|
||||
"sp1-helper",
|
||||
|
|
|
@ -12,6 +12,7 @@ bincode = "1.3.3"
|
|||
hex = "0.4.3"
|
||||
serde_json = "1.0"
|
||||
ed25519-consensus = "2.1.0"
|
||||
rand = "0.8.5"
|
||||
|
||||
[build-dependencies]
|
||||
sp1-helper = { git = "https://github.com/succinctlabs/sp1.git" }
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
// 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 ed25519_consensus::*;
|
||||
use mtcs_core::*;
|
||||
use rand::thread_rng;
|
||||
use rs_merkle::{algorithms::Sha256 as MerkleSha256, Hasher, MerkleTree};
|
||||
use std::fs;
|
||||
use std::time::SystemTime;
|
||||
|
@ -17,9 +16,6 @@ fn main() {
|
|||
|
||||
println!("generating guest inputs...");
|
||||
// For example:
|
||||
let key: Vec<u8> = "passw0rdpassw0rdpassw0rdpassw0rd".as_bytes().to_vec();
|
||||
|
||||
let secret = PrivateKey { key };
|
||||
let cycle_data: String = fs::read_to_string("../cycle.json").unwrap();
|
||||
|
||||
let all_obligation_data: String = fs::read_to_string("../obligations.json").unwrap();
|
||||
|
@ -50,7 +46,6 @@ fn main() {
|
|||
|
||||
let bytes = merkle_proof.to_bytes();
|
||||
|
||||
let key: PrivateKey = secret;
|
||||
let proof: Proof = Proof {
|
||||
bytes: bytes.as_slice().try_into().unwrap(),
|
||||
};
|
||||
|
@ -60,7 +55,7 @@ fn main() {
|
|||
indexes: indexes.try_into().unwrap(),
|
||||
len,
|
||||
};
|
||||
|
||||
let key = SigningKey::new(thread_rng());
|
||||
let mut stdin = SP1Stdin::new();
|
||||
let client = ProverClient::new();
|
||||
|
||||
|
@ -70,8 +65,6 @@ fn main() {
|
|||
stdin.write(&proof);
|
||||
stdin.write(&aux);
|
||||
|
||||
println!("generating proof...");
|
||||
|
||||
let mut proof = client.prove(ELF, stdin).expect("proving failed");
|
||||
|
||||
println!("proof generation completed!");
|
||||
|
@ -80,18 +73,19 @@ fn main() {
|
|||
client.verify(ELF, &proof).expect("verification failed");
|
||||
println!("verification completed!");
|
||||
|
||||
println!("validating digital signature...");
|
||||
|
||||
let (hash, verification_key, sign): &([u8; 32], VerificationKey, Signature) =
|
||||
&proof.public_values.read();
|
||||
// let read_values: ([u8; 32], Signature) = pub_values.read();
|
||||
let sig_verify = verification_key.verify(sign, hash).is_ok();
|
||||
assert!(sig_verify);
|
||||
let end_time = SystemTime::now();
|
||||
let difference = end_time
|
||||
.duration_since(start_time)
|
||||
.expect("Clock may have gone backwards");
|
||||
println!("Total time: {difference:?}");
|
||||
println!("Total prover time: {difference:?}");
|
||||
|
||||
println!("validating digital signature...");
|
||||
|
||||
let (hash, verification_key, sign): &([u8; 32], VerificationKey, Signature) =
|
||||
&proof.public_values.read();
|
||||
|
||||
let sig_verify = verification_key.verify(sign, hash).is_ok();
|
||||
assert!(sig_verify);
|
||||
|
||||
proof
|
||||
.save("proof-with-io.json")
|
||||
|
|
Loading…
Reference in a new issue