-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
115 lines (104 loc) · 3.92 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#![allow(dead_code, unused_imports)]
struct ConsoleLogger;
use chrono::Local;
use log::{Level, Metadata, Record};
use pprof::protos::Message;
use pprof::ProfilerGuard;
use std::fs::File;
use std::io::Write;
pub mod channel;
pub mod fields;
pub mod fri;
pub mod merkle;
pub mod stark;
pub mod tables;
pub mod univariate_polynomial;
pub mod vm;
pub use crate::fields::{Field, FieldElement};
pub use crate::fri::FriDomain;
pub use crate::stark::{prove, verify_proof};
pub use crate::tables::derive_omicron;
pub use crate::tables::Table;
pub use crate::vm::VirtualMachine;
static CONSOLE_LOGGER: ConsoleLogger = ConsoleLogger;
impl log::Log for ConsoleLogger {
fn enabled(&self, metadata: &Metadata) -> bool {
metadata.level() <= Level::Debug
}
fn log(&self, record: &Record) {
if self.enabled(record.metadata()) {
println!(
"{} [{}] {}:{} - {}",
Local::now().format("%Y-%m-%dT%H:%M:%S"),
record.level(),
record.module_path().unwrap(),
record.line().unwrap(),
record.args()
);
}
}
fn flush(&self) {}
}
fn main() {
// std::env::set_var("RAYON_NUM_THREADS", "1024");
env_logger::init();
let guard = ProfilerGuard::new(1).unwrap();
let field = Field(18446744069414584321);
let vm = VirtualMachine::new(field);
let generator = field.generator().pow((1 << 32) - 1);
let order = 1 << 32;
// let code = "++>+-[+--]++.".to_string();
// let code = "++>+++++[<+>-]++++++++[<++++++>-]<.".to_string();
let code = "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.".to_string();
// let code = "+++++++++++>+>>>>++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>+<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-<-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<-]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<+>>[-]]<<<<<<<]>>>>>[++++++++++++++++++++++++++++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++++++++++++++++++++++++++++++++++++++++++++++.[-]<<<<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<[-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]".to_string();
let program = vm.compile(code);
let (running_time, input_symbols, _output_symbols) =
vm.run(&program, "1121231241223".to_string());
log::info!("Running time: {}", running_time);
let (processor_matrix, memory_matrix, instruction_matrix, input_matrix, output_matrix) =
vm.simulate(&program, "1121231241223".to_string());
assert_eq!(running_time as usize, processor_matrix.len());
let offset = FieldElement::one(field);
let expansion_f = 1;
let num_queries = 64;
let v: &[&[Vec<FieldElement>]] = &[
&processor_matrix,
&memory_matrix,
&instruction_matrix,
&input_matrix,
&output_matrix,
];
let (degree_bound, compressed_proof, tp, tm, tins, ti, to, fri_d) =
prove(v, input_symbols, field, offset, expansion_f, num_queries);
let maximum_random_int =
((degree_bound + 1) * expansion_f as u128 - expansion_f as u128) as u64;
let _domain = FriDomain::new(
offset,
derive_omicron(generator, order, (degree_bound + 1) * expansion_f as u128),
(degree_bound + 1) * expansion_f as u128,
);
verify_proof(
num_queries,
maximum_random_int,
expansion_f,
field,
&fri_d,
&compressed_proof,
tp,
tins,
tm,
ti,
to,
degree_bound as usize,
);
match guard.report().build() {
Ok(report) => {
let mut file = File::create("profile.pb").unwrap();
let profile = report.pprof().unwrap();
let mut content = Vec::new();
profile.write_to_vec(&mut content).unwrap();
file.write_all(&content).unwrap();
}
Err(_) => {}
};
}