Modified inputs reading method
This commit is contained in:
parent
1682124af2
commit
d6044e493b
@ -1,6 +1,7 @@
|
||||
use equivalence_proof_statements::{EquivalencePrivate, EquivalencePublic};
|
||||
use risc0_zkvm::Receipt;
|
||||
use thiserror::Error;
|
||||
use crypto_bigint::{Encoding};
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
@ -8,12 +9,18 @@ pub enum Error {
|
||||
ProofError(#[from] anyhow::Error),
|
||||
}
|
||||
|
||||
pub fn prove(equivalence_public: EquivalencePublic, equivalence_private: EquivalencePrivate) -> Result<Receipt, Error> {
|
||||
pub fn prove(equivalence_public: EquivalencePublic,equivalence_private: EquivalencePrivate) -> Result<Receipt, Error> {
|
||||
|
||||
let mut buffer : Vec<u8> = vec![];
|
||||
buffer.append(&mut Vec::from(equivalence_public.da_commitment));
|
||||
buffer.append(&mut Vec::from(equivalence_public.y_0.to_be_bytes()));
|
||||
for i in 0..equivalence_private.coefficients.len() {
|
||||
buffer.append(&mut Vec::from(equivalence_private.coefficients[i].to_be_bytes()));
|
||||
}
|
||||
|
||||
|
||||
let env = risc0_zkvm::ExecutorEnv::builder()
|
||||
.write(&equivalence_public)
|
||||
.unwrap()
|
||||
.write(&equivalence_private)
|
||||
.unwrap()
|
||||
.write_slice(&buffer)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
/// Proof of Equivalence
|
||||
use equivalence_proof_statements::{EquivalencePrivate, EquivalencePublic};
|
||||
use risc0_zkvm::guest::env;
|
||||
use sha2::{Digest, Sha256};
|
||||
use crypto_bigint::{U256, impl_modulus, const_residue, modular::constant_mod::ResidueParams, Encoding};
|
||||
use crypto_bigint::{U256, impl_modulus, const_residue, modular::constant_mod::ResidueParams};
|
||||
|
||||
const BLOB_SIZE: usize = 2048;
|
||||
const COMMITMENT_SIZE: usize = 48;
|
||||
const SCALAR_SIZE: usize = 32;
|
||||
|
||||
impl_modulus!(
|
||||
Fr,
|
||||
@ -20,12 +21,12 @@ fn mul_mod(a: U256, b: U256) -> U256 {
|
||||
|
||||
fn main() {
|
||||
let start_start = env::cycle_count();
|
||||
let public_inputs: EquivalencePublic = env::read();
|
||||
|
||||
let EquivalencePrivate {
|
||||
coefficients,
|
||||
} = env::read();
|
||||
let private_inputs = EquivalencePrivate { coefficients };
|
||||
let mut inputs = vec![0u8;COMMITMENT_SIZE+SCALAR_SIZE+BLOB_SIZE*32];
|
||||
env::read_slice(&mut inputs);
|
||||
let da_commitment = inputs[0..COMMITMENT_SIZE].to_vec();
|
||||
let y_0 = U256::from_be_slice(& inputs[COMMITMENT_SIZE..COMMITMENT_SIZE+SCALAR_SIZE].to_vec());
|
||||
|
||||
let end = env::cycle_count();
|
||||
eprintln!("inputs load: {}", end - start_start);
|
||||
|
||||
@ -38,10 +39,8 @@ fn main() {
|
||||
//compute random point
|
||||
let start = env::cycle_count();
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(public_inputs.da_commitment.clone());
|
||||
for i in 0..BLOB_SIZE {
|
||||
hasher.update(private_inputs.coefficients[i].to_be_bytes());
|
||||
}
|
||||
hasher.update(da_commitment.clone());
|
||||
hasher.update(inputs[COMMITMENT_SIZE+SCALAR_SIZE..COMMITMENT_SIZE+SCALAR_SIZE+BLOB_SIZE*32].to_vec());
|
||||
let x_0 : [u8; 32] = hasher.finalize().into();
|
||||
let end = env::cycle_count();
|
||||
eprintln!("draw random point: {}", end - start);
|
||||
@ -54,22 +53,24 @@ fn main() {
|
||||
eprintln!("evaluation point conversion from u8: {}", end - start);
|
||||
|
||||
let start = env::cycle_count();
|
||||
let mut evaluation = private_inputs.coefficients[BLOB_SIZE-1];
|
||||
//load coefficient and evaluate polynomial with Horner method
|
||||
let mut evaluation = U256::from_be_slice(&inputs[SCALAR_SIZE+COMMITMENT_SIZE+32*(BLOB_SIZE-1)..SCALAR_SIZE+COMMITMENT_SIZE+32*BLOB_SIZE].to_vec());
|
||||
for i in 1..BLOB_SIZE {
|
||||
let mul = mul_mod(evaluation, bls_point);
|
||||
evaluation = private_inputs.coefficients[BLOB_SIZE-1-i].add_mod(&mul, &modulus);
|
||||
evaluation = U256::from_be_slice(&inputs[SCALAR_SIZE+COMMITMENT_SIZE+32*(BLOB_SIZE-1-i)..SCALAR_SIZE+COMMITMENT_SIZE+32*(BLOB_SIZE-i)].to_vec()).add_mod(&mul, &modulus);
|
||||
}
|
||||
let end = env::cycle_count();
|
||||
eprintln!("point evaluation: {}", end - start);
|
||||
|
||||
|
||||
let start = env::cycle_count();
|
||||
assert_eq!(evaluation, public_inputs.y_0);
|
||||
assert_eq!(evaluation, y_0);
|
||||
let end = env::cycle_count();
|
||||
eprintln!("last assertion: {}", end - start);
|
||||
|
||||
let start = env::cycle_count();
|
||||
env::commit(&public_inputs);
|
||||
env::commit(&da_commitment);
|
||||
env::commit(&y_0);
|
||||
let end_end = env::cycle_count();
|
||||
eprintln!("public input: {}", end_end - start);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user