Skip to content

Commit

Permalink
supernova finish constaints done, add workaround to collect meta info…
Browse files Browse the repository at this point in the history
… from asm source
  • Loading branch information
hero78119 committed Aug 2, 2023
1 parent 5cb4029 commit e7268e8
Show file tree
Hide file tree
Showing 12 changed files with 463 additions and 124 deletions.
12 changes: 6 additions & 6 deletions ast/src/asm_analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct DegreeStatement {
pub degree: BigUint,
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum FunctionStatement<T> {
Assignment(AssignmentStatement<T>),
Instruction(InstructionStatement<T>),
Expand Down Expand Up @@ -74,28 +74,28 @@ impl<T> From<DebugDirective> for FunctionStatement<T> {
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct AssignmentStatement<T> {
pub start: usize,
pub lhs: Vec<String>,
pub using_reg: Option<String>,
pub rhs: Box<Expression<T>>,
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct InstructionStatement<T> {
pub start: usize,
pub instruction: String,
pub inputs: Vec<Expression<T>>,
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct LabelStatement {
pub start: usize,
pub name: String,
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct DebugDirective {
pub start: usize,
pub directive: crate::parsed::asm::DebugDirective,
Expand Down Expand Up @@ -130,7 +130,7 @@ impl<T> Machine<T> {
}
}

#[derive(Clone, Default)]
#[derive(Clone, Default, Debug)]
pub struct Rom<T> {
pub statements: Vec<FunctionStatement<T>>,
pub batches: Option<Vec<BatchMetadata>>,
Expand Down
15 changes: 11 additions & 4 deletions backend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ast::analyzed::Analyzed;
use ast::{analyzed::Analyzed, asm_analysis::Machine};
use number::FieldElement;
use std::io;
use strum::{Display, EnumString, EnumVariantNames};
Expand Down Expand Up @@ -107,13 +107,20 @@ impl ProverAggregationWithParams for Halo2AggregationBackend {
}

#[cfg(feature = "nova")]
impl ProverWithoutParams for NovaBackend {
fn prove<T: FieldElement>(
// TODO implement ProverWithoutParams, and remove dependent on main_machine
impl NovaBackend {
pub fn prove<T: FieldElement>(
pil: &Analyzed<T>,
main_machine: &Machine<T>,
fixed: Vec<(&str, Vec<T>)>,
witness: Vec<(&str, Vec<T>)>,
) -> Option<Proof> {
Some(nova::prove_ast_read_params(pil, fixed, witness));
Some(nova::prove_ast_read_params(
pil,
main_machine,
fixed,
witness,
));
Some(vec![])
}
}
3 changes: 2 additions & 1 deletion compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use json::JsonValue;
pub mod util;
mod verify;

use analysis::analyze;
// TODO should analyze be `pub`?
pub use analysis::analyze;
pub use backend::{Backend, Proof};
use number::write_polys_file;
use pil_analyzer::json_exporter;
Expand Down
1 change: 0 additions & 1 deletion number/src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{fmt, hash::Hash, ops::*};

use ark_ff::PrimeField;
use num_traits::{One, Zero};

use crate::{AbstractNumberType, DegreeType};
Expand Down
30 changes: 28 additions & 2 deletions powdr_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mod util;

use clap::{Parser, Subcommand};
use compiler::{compile_pil_or_asm, Backend};
use compiler::{analyze, compile_pil_or_asm, Backend};
use env_logger::{Builder, Target};
use log::LevelFilter;
use number::{Bn254Field, FieldElement, GoldilocksField};
Expand Down Expand Up @@ -188,6 +188,9 @@ enum Commands {
/// Input PIL file
file: String,

/// TODO retrive asm info from PIL
asm_file: String,

/// Directory to find the committed and fixed values
#[arg(short, long)]
#[arg(default_value_t = String::from("."))]
Expand Down Expand Up @@ -372,18 +375,41 @@ fn run_command(command: Commands) {
#[cfg(feature = "nova")]
Commands::ProveNova {
file,
asm_file,
dir,
params: _,
} => {
let pil = Path::new(&file);
let contents = fs::read_to_string(asm_file.clone()).unwrap();

let parsed = parser::parse_asm::<Bn254Field>(Some(&asm_file[..]), &contents[..])
.unwrap_or_else(|err| {
eprintln!("Error parsing .asm file:");
err.output_to_stderr();
panic!();
});
let analysed_asm = analyze(parsed).unwrap();

// retrieve instance of the Main state machine
let main = match analysed_asm.machines.len() {
// if there is a single machine, treat it as main
1 => analysed_asm.machines.values().next().unwrap().clone(),
// otherwise, find the machine called "Main"
_ => analysed_asm
.machines
.get("Main")
.expect("couldn't find a Main state machine")
.clone(),
};

let dir = Path::new(&dir);

let pil = compiler::analyze_pil::<Bn254Field>(pil);
let fixed = compiler::util::read_fixed(&pil, dir);
let witness = compiler::util::read_witness(&pil, dir);

// let params = fs::File::open(dir.join(params.unwrap())).unwrap();
NovaBackend::prove(&pil, fixed.0, witness.0);
NovaBackend::prove(&pil, &main, fixed.0, witness.0);

// TODO: this probably should be abstracted alway in a common backends API,
// // maybe a function "get_file_extension()".
Expand Down
Binary file modified zero_nova/commits.bin
Binary file not shown.
Binary file modified zero_nova/constants.bin
Binary file not shown.

0 comments on commit e7268e8

Please sign in to comment.