diff --git a/singer/src/instructions.rs b/singer/src/instructions.rs index 9936281e7..bb87d3b2c 100644 --- a/singer/src/instructions.rs +++ b/singer/src/instructions.rs @@ -87,6 +87,9 @@ pub(crate) fn construct_instruction_circuits( 0x91 => SwapInstruction::<2>::construct_circuits(challenges), 0x93 => SwapInstruction::<4>::construct_circuits(challenges), 0xF3 => ReturnInstruction::construct_circuits(challenges), + + // RISC-V iSA + 0x33 => RVAddInstruction::construct_circuits(challenges), _ => Ok(vec![]), // TODO: Add more instructions. } } diff --git a/singer/src/instructions/riscv_add.rs b/singer/src/instructions/riscv_add.rs index 5666ec5d3..854346991 100644 --- a/singer/src/instructions/riscv_add.rs +++ b/singer/src/instructions/riscv_add.rs @@ -336,60 +336,65 @@ mod test { ); } - // fn bench_add_instruction_helper(instance_num_vars: usize) { - // let chip_challenges = ChipChallenges::default(); - // let circuit_builder = - // SingerCircuitBuilder::::new(chip_challenges).expect("circuit builder failed"); - // let mut singer_builder = SingerGraphBuilder::::new(); - - // let mut rng = test_rng(); - // let size = RVAddInstruction::phase0_size(); - // let phase0: CircuitWiresIn = vec![LayerWitness { - // instances: (0..(1 << instance_num_vars)) - // .map(|_| { - // (0..size) - // .map(|_| E::BaseField::random(&mut rng)) - // .collect_vec() - // }) - // .collect_vec(), - // }]; - - // let real_challenges = vec![E::random(&mut rng), E::random(&mut rng)]; - - // let timer = Instant::now(); - - // let _ = RVAddInstruction::construct_graph_and_witness( - // &mut singer_builder.graph_builder, - // &mut singer_builder.chip_builder, - // &circuit_builder.insts_circuits[>::OPCODE as - // usize], vec![phase0], - // &real_challenges, - // 1 << instance_num_vars, - // &SingerParams::default(), - // ) - // .expect("gkr graph construction failed"); - - // let (graph, wit) = singer_builder.graph_builder.finalize_graph_and_witness(); - - // println!( - // "RVAddInstruction::construct_graph_and_witness, instance_num_vars = {}, time = {}", - // instance_num_vars, - // timer.elapsed().as_secs_f64() - // ); - - // let point = vec![E::random(&mut rng), E::random(&mut rng)]; - // let target_evals = graph.target_evals(&wit, &point); - - // let mut prover_transcript = &mut Transcript::new(b"Singer"); - - // let timer = Instant::now(); - // let _ = GKRGraphProverState::prove(&graph, &wit, &target_evals, &mut prover_transcript, - // 1) .expect("prove failed"); println!( "RVAddInstruction::prove, instance_num_vars = {}, time - // = {}", instance_num_vars, timer.elapsed().as_secs_f64() ); - // } - - // #[test] - // fn bench_add_instruction() { - // bench_add_instruction_helper::(10); - // } + fn bench_add_instruction_helper(instance_num_vars: usize) { + let chip_challenges = ChipChallenges::default(); + let circuit_builder = + SingerCircuitBuilder::::new(chip_challenges).expect("circuit builder failed"); + let mut singer_builder = SingerGraphBuilder::::new(); + + let mut rng = test_rng(); + let size = RVAddInstruction::phase0_size(); + let phase0: CircuitWiresIn = vec![LayerWitness { + instances: (0..(1 << instance_num_vars)) + .map(|_| { + (0..size) + .map(|_| E::BaseField::random(&mut rng)) + .collect_vec() + }) + .collect_vec(), + }]; + + let real_challenges = vec![E::random(&mut rng), E::random(&mut rng)]; + + let timer = Instant::now(); + + let _ = RVAddInstruction::construct_graph_and_witness( + &mut singer_builder.graph_builder, + &mut singer_builder.chip_builder, + &circuit_builder.insts_circuits[>::OPCODE as usize], + vec![phase0], + &real_challenges, + 1 << instance_num_vars, + &SingerParams::default(), + ) + .expect("gkr graph construction failed"); + + let (graph, wit) = singer_builder.graph_builder.finalize_graph_and_witness(); + + println!( + "RVAddInstruction::construct_graph_and_witness, instance_num_vars = {}, time = {}", + instance_num_vars, + timer.elapsed().as_secs_f64() + ); + + let point = vec![E::random(&mut rng), E::random(&mut rng)]; + let target_evals = graph.target_evals(&wit, &point); + + let mut prover_transcript = &mut Transcript::new(b"Singer"); + + let timer = Instant::now(); + let _ = GKRGraphProverState::prove(&graph, &wit, &target_evals, &mut prover_transcript, 1) + .expect("prove failed"); + println!( + "RVAddInstruction::prove, instance_num_vars = {}, time + = {}", + instance_num_vars, + timer.elapsed().as_secs_f64() + ); + } + + #[test] + fn bench_add_instruction() { + bench_add_instruction_helper::(10); + } }