Skip to content

Commit

Permalink
clean a bit the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuang Wu authored and ShuangWu121 committed Sep 24, 2024
1 parent 5e1a653 commit 248de24
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 37 deletions.
43 changes: 14 additions & 29 deletions backend/src/stwo/circuit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ pub fn generate_stwo_trace<T>(witness: &[(String, Vec<T>)], log_n_instances: u32
})
})
.collect(); // Collect the flattened iterator into a Vec<PackedBaseField>.
println!("from generate stwo trace trace");
println!("{:?}", trace);
// println!("from generate stwo trace trace");
//println!("{:?}", trace);

let mut trace_stwo= (0..2)
.map(|_| Col::<SimdBackend, BaseField>::zeros(1 << 5))
Expand All @@ -149,7 +149,7 @@ pub fn generate_stwo_trace<T>(witness: &[(String, Vec<T>)], log_n_instances: u32

}

pub fn generate_parallel_stwo_trace_by_witness_repitition<T: Clone>(witness: &[(String, Vec<T>)], log_n_instances: u32
pub fn generate_parallel_stwo_trace_by_witness_repitition<T: Clone>(length: usize, witness: &[(String, Vec<T>)], log_n_instances: u32
)-> ColumnVec<CircleEvaluation<SimdBackend, BaseField, BitReversedOrder>> {

let trace: Vec<PackedBaseField> = witness
Expand Down Expand Up @@ -187,41 +187,26 @@ pub fn generate_parallel_stwo_trace_by_witness_repitition<T: Clone>(witness: &[(
.collect(); // Collect the flattened iterator into a Vec<PackedBaseField>


println!("from generate stwo trace trace");
println!("{:?}", trace);
// println!("from generate stwo trace trace");
// println!("{:?}", trace);

let mut trace_stwo= (0..6)//fibonacci length
let mut trace_stwo= (0..length)//fibonacci length
.map(|_| Col::<SimdBackend, BaseField>::zeros(1 << log_n_instances))
.collect_vec();


// column x
trace_stwo[0].data[0]= trace[0];
trace_stwo[0].data[1]= trace[1];

println!("from generate stwo trace trace 64 ......");
println!("{:?}", trace[64]);

println!("from generate stwo trace trace 65 ......");
println!("{:?}", trace[65]);

trace_stwo[1].data[0]= trace[64];
trace_stwo[1].data[1]= trace[65];
trace_stwo[0].data[0]= trace[0]; //x
trace_stwo[0].data[1]= trace[1]; //y

trace_stwo[2].data[0]= trace[66];
trace_stwo[2].data[1]= trace[67];

trace_stwo[3].data[0]= trace[68];
trace_stwo[3].data[1]= trace[69];

trace_stwo[4].data[0]= trace[70];
trace_stwo[4].data[1]= trace[71];

trace_stwo[5].data[0]= trace[72];
trace_stwo[5].data[1]= trace[73];
for i in 1..length {
trace_stwo[i].data[0] = trace[2*length + 2 * (i - 1)];
trace_stwo[i].data[1] = trace[2*length + 2 * (i - 1) + 1];
}

println!("from generate stwo trace trace_stwo repititions");
println!("{:?}", trace_stwo);
// println!("from generate stwo trace trace_stwo repititions");
// println!("{:?}", trace_stwo);

let domain = CanonicCoset::new(5).circle_domain();
trace_stwo
Expand Down
28 changes: 20 additions & 8 deletions backend/src/stwo/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ use stwo_prover::core::pcs::{CommitmentSchemeProver, CommitmentSchemeVerifier, P
use stwo_prover::core::poly::circle::{CanonicCoset, CircleEvaluation, PolyOps};
use stwo_prover::core::vcs::blake2_merkle::Blake2sMerkleChannel;




// We use two different EVM verifier libraries.
// 1. snark_verifier: supports single SNARK verification as well as aggregated proof verification.
// However the generated smart contract code size is often larger than the limit on Ethereum for complex VMs.
Expand Down Expand Up @@ -136,7 +139,7 @@ impl<F: FieldElement> StwoProver<F> {
) {

const LOG_N_INSTANCES: u32 = 5;
const FIB_SEQUENCE_LENGTH: usize=6;
const FIB_SEQUENCE_LENGTH: usize=262144;



Expand All @@ -160,12 +163,20 @@ impl<F: FieldElement> StwoProver<F> {
let circuit = PowdrCircuit::new(&self.analyzed)
.with_witgen_callback(witgen_callback)
.with_witness(witness);
print!("witness from powdr {:?}", witness );
// print!("witness from powdr {:?}", witness );

let fibonacci_y_length = witness
.iter()
.find(|(key, _)| key == "Fibonacci::y")
.map(|(_, values)| values.len())
.unwrap_or(0);



//let trace = generate_stwo_trace(witness,LOG_N_INSTANCES);
let trace=generate_parallel_stwo_trace_by_witness_repitition(witness, LOG_N_INSTANCES);
let trace=generate_parallel_stwo_trace_by_witness_repitition(fibonacci_y_length, witness, LOG_N_INSTANCES);

println!("this is from the generate stwo trace in repitition \n {:?}",generate_parallel_stwo_trace_by_witness_repitition(witness,LOG_N_INSTANCES));


let mut tree_builder = commitment_scheme.tree_builder();
tree_builder.extend_evals(trace);
Expand All @@ -186,10 +197,10 @@ impl<F: FieldElement> StwoProver<F> {

println!("created component!");

println!("component eval is like this \n {} ",component.log_n_rows);
// println!("component eval is like this \n {} ",component.log_n_rows);



let start = Instant::now();
let proof = stwo_prover::core::prover::prove::<SimdBackend, Blake2sMerkleChannel>(
&[&component],
prover_channel,
Expand All @@ -198,6 +209,9 @@ impl<F: FieldElement> StwoProver<F> {
.unwrap();

println!("proof generated!");
let duration = start.elapsed();

println!("proving time for fibo length of {:?} is {:?}",fibonacci_y_length, duration);

// Verify.
let verifier_channel = &mut Blake2sChannel::default();
Expand All @@ -209,8 +223,6 @@ impl<F: FieldElement> StwoProver<F> {
stwo_prover::core::prover::verify(&[&component], verifier_channel, commitment_scheme, proof).unwrap();



println!("{:?}", witness);



Expand Down

0 comments on commit 248de24

Please sign in to comment.