Skip to content

Commit 8263e14

Browse files
authored
feat: lower the log level (#157)
* replace debug! with trace * replace debug! with trace * update wasmer version to remove the wasmer's info level log * refact: remove redunction code in generate witness * refact: remove redunction code in generate witness * refact: remove redunction code in generate witness * refact: remove redunction code in generate witness * fmt * another try * fmt
1 parent 9161453 commit 8263e14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+360
-656
lines changed

algebraic/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ num-traits = "0.2.8"
2222
serde = { version = "1.0", features = [ "derive" ] }
2323
serde_json = { version = "1.0", features = [ "arbitrary_precision" ] }
2424
hex = "*"
25-
wasmer = { version = "2.0", default-features = false }
25+
wasmer = { version = "3.3.0", default-features = false }
2626
thiserror="1.0"
2727
fnv = { version = "1.0.3", default-features = false }
2828
num = { version = "0.4.0" }

algebraic/src/reader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ pub fn load_witness_from_bin_reader<E: ScalarEngine, R: Read>(mut reader: R) ->
9999
return Err(EigenError::from("Invalid file header".to_string()));
100100
}
101101
let version = reader.read_u32::<LittleEndian>()?;
102-
log::debug!("wtns version {}", version);
102+
log::trace!("wtns version {}", version);
103103
if version > 2 {
104104
return Err(EigenError::from("unsupported file version".to_string()));
105105
}
@@ -126,7 +126,7 @@ pub fn load_witness_from_bin_reader<E: ScalarEngine, R: Read>(mut reader: R) ->
126126
return Err(EigenError::from("invalid curve prime".to_string()));
127127
}
128128
let witness_len = reader.read_u32::<LittleEndian>()?;
129-
log::debug!("witness len {}", witness_len);
129+
log::trace!("witness len {}", witness_len);
130130
let sec_type = reader.read_u32::<LittleEndian>()?;
131131
if sec_type != 2 {
132132
return Err(EigenError::from("invalid section type".to_string()));

algebraic/src/witness/circom.rs

Lines changed: 78 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,132 @@
11
// copied and modified by https://github.com/arkworks-rs/circom-compat/blob/master/src/witness/circom.rs
22
use crate::errors::Result;
3-
use wasmer::{Function, Instance, Value};
3+
use wasmer::{Function, Instance, Store, Value};
44

55
#[derive(Clone, Debug)]
66
pub struct Wasm(Instance);
77

8-
pub trait CircomBase {
9-
fn init(&self, sanity_check: bool) -> Result<()>;
10-
fn func(&self, name: &str) -> &Function;
11-
fn get_ptr_witness_buffer(&self) -> Result<u32>;
12-
fn get_ptr_witness(&self, w: u32) -> Result<u32>;
13-
fn get_signal_offset32(
14-
&self,
15-
p_sig_offset: u32,
16-
component: u32,
17-
hash_msb: u32,
18-
hash_lsb: u32,
19-
) -> Result<()>;
20-
fn set_signal(&self, c_idx: u32, component: u32, signal: u32, p_val: u32) -> Result<()>;
21-
fn get_u32(&self, name: &str) -> Result<u32>;
22-
// Only exists natively in Circom2, hardcoded for Circom
23-
fn get_version(&self) -> Result<u32>;
24-
}
25-
26-
pub trait Circom {
27-
fn get_field_num_len32(&self) -> Result<u32>;
28-
fn get_raw_prime(&self) -> Result<()>;
29-
fn read_shared_rw_memory(&self, i: u32) -> Result<u32>;
30-
fn write_shared_rw_memory(&self, i: u32, v: u32) -> Result<()>;
31-
fn set_input_signal(&self, hmsb: u32, hlsb: u32, pos: u32) -> Result<()>;
32-
fn get_witness(&self, i: u32) -> Result<()>;
33-
fn get_witness_size(&self) -> Result<u32>;
34-
}
35-
36-
impl Circom for Wasm {
37-
fn get_field_num_len32(&self) -> Result<u32> {
38-
self.get_u32("getFieldNumLen32")
8+
impl Wasm {
9+
pub(crate) fn get_field_num_len32(&self, store: &mut Store) -> Result<u32> {
10+
self.get_u32(store, "getFieldNumLen32")
3911
}
4012

41-
fn get_raw_prime(&self) -> Result<()> {
13+
pub(crate) fn get_raw_prime(&self, store: &mut Store) -> Result<()> {
4214
let func = self.func("getRawPrime");
43-
func.call(&[])?;
15+
func.call(store, &[])?;
4416
Ok(())
4517
}
4618

47-
fn read_shared_rw_memory(&self, i: u32) -> Result<u32> {
19+
pub(crate) fn read_shared_rw_memory(&self, store: &mut Store, i: u32) -> Result<u32> {
4820
let func = self.func("readSharedRWMemory");
49-
let result = func.call(&[i.into()])?;
21+
let result = func.call(store, &[i.into()])?;
5022
Ok(result[0].unwrap_i32() as u32)
5123
}
5224

53-
fn write_shared_rw_memory(&self, i: u32, v: u32) -> Result<()> {
25+
pub(crate) fn write_shared_rw_memory(&self, store: &mut Store, i: u32, v: u32) -> Result<()> {
5426
let func = self.func("writeSharedRWMemory");
55-
func.call(&[i.into(), v.into()])?;
27+
func.call(store, &[i.into(), v.into()])?;
5628
Ok(())
5729
}
5830

59-
fn set_input_signal(&self, hmsb: u32, hlsb: u32, pos: u32) -> Result<()> {
31+
pub(crate) fn set_input_signal(
32+
&self,
33+
store: &mut Store,
34+
hmsb: u32,
35+
hlsb: u32,
36+
pos: u32,
37+
) -> Result<()> {
6038
let func = self.func("setInputSignal");
61-
func.call(&[hmsb.into(), hlsb.into(), pos.into()])?;
39+
func.call(store, &[hmsb.into(), hlsb.into(), pos.into()])?;
6240
Ok(())
6341
}
6442

65-
fn get_witness(&self, i: u32) -> Result<()> {
43+
pub(crate) fn get_witness(&self, store: &mut Store, i: u32) -> Result<()> {
6644
let func = self.func("getWitness");
67-
func.call(&[i.into()])?;
45+
func.call(store, &[i.into()])?;
6846
Ok(())
6947
}
7048

71-
fn get_witness_size(&self) -> Result<u32> {
72-
self.get_u32("getWitnessSize")
49+
pub(crate) fn get_witness_size(&self, store: &mut Store) -> Result<u32> {
50+
self.get_u32(store, "getWitnessSize")
7351
}
74-
}
7552

76-
impl CircomBase for Wasm {
77-
fn init(&self, sanity_check: bool) -> Result<()> {
53+
pub(crate) fn init(&self, store: &mut Store, sanity_check: bool) -> Result<()> {
7854
let func = self.func("init");
79-
func.call(&[Value::I32(sanity_check as i32)])?;
55+
func.call(store, &[Value::I32(sanity_check as i32)])?;
8056
Ok(())
8157
}
8258

83-
fn get_ptr_witness_buffer(&self) -> Result<u32> {
84-
self.get_u32("getWitnessBuffer")
85-
}
86-
87-
fn get_ptr_witness(&self, w: u32) -> Result<u32> {
88-
let func = self.func("getPWitness");
89-
let res = func.call(&[w.into()])?;
90-
91-
Ok(res[0].unwrap_i32() as u32)
92-
}
93-
94-
fn get_signal_offset32(
95-
&self,
96-
p_sig_offset: u32,
97-
component: u32,
98-
hash_msb: u32,
99-
hash_lsb: u32,
100-
) -> Result<()> {
101-
let func = self.func("getSignalOffset32");
102-
func.call(&[
103-
p_sig_offset.into(),
104-
component.into(),
105-
hash_msb.into(),
106-
hash_lsb.into(),
107-
])?;
108-
109-
Ok(())
110-
}
111-
112-
fn set_signal(&self, c_idx: u32, component: u32, signal: u32, p_val: u32) -> Result<()> {
113-
let func = self.func("setSignal");
114-
func.call(&[c_idx.into(), component.into(), signal.into(), p_val.into()])?;
115-
116-
Ok(())
117-
}
59+
// pub(crate) fn get_ptr_witness_buffer(&self, store: &mut Store) -> Result<u32> {
60+
// self.get_u32(store, "getWitnessBuffer")
61+
// }
62+
63+
// pub(crate) fn get_ptr_witness(&self, store: &mut Store, w: u32) -> Result<u32> {
64+
// let func = self.func( "getPWitness");
65+
// let res = func.call(store, &[w.into()])?;
66+
//
67+
// Ok(res[0].unwrap_i32() as u32)
68+
// }
69+
70+
// pub(crate) fn get_signal_offset32(
71+
// &self,
72+
// store: &mut Store,
73+
// p_sig_offset: u32,
74+
// component: u32,
75+
// hash_msb: u32,
76+
// hash_lsb: u32,
77+
// ) -> Result<()> {
78+
// let func = self.func( "getSignalOffset32");
79+
// func.call(
80+
// store,
81+
// &[
82+
// p_sig_offset.into(),
83+
// component.into(),
84+
// hash_msb.into(),
85+
// hash_lsb.into(),
86+
// ],
87+
// )?;
88+
//
89+
// Ok(())
90+
// }
91+
//
92+
// pub(crate) fn set_signal(
93+
// &self,
94+
// store: &mut Store,
95+
// c_idx: u32,
96+
// component: u32,
97+
// signal: u32,
98+
// p_val: u32,
99+
// ) -> Result<()> {
100+
// let func = self.func( "setSignal");
101+
// func.call(
102+
// store,
103+
// &[c_idx.into(), component.into(), signal.into(), p_val.into()],
104+
// )?;
105+
//
106+
// Ok(())
107+
// }
118108

119109
// Default to version 1 if it isn't explicitly defined
120-
fn get_version(&self) -> Result<u32> {
110+
pub(crate) fn get_version(&self, store: &mut Store) -> Result<u32> {
121111
match self.0.exports.get_function("getVersion") {
122-
Ok(func) => Ok(func.call(&[])?[0].unwrap_i32() as u32),
112+
Ok(func) => Ok(func.call(store, &[])?[0].unwrap_i32() as u32),
123113
Err(_) => Ok(1),
124114
}
125115
}
126116

127-
fn get_u32(&self, name: &str) -> Result<u32> {
117+
pub(crate) fn get_u32(&self, store: &mut Store, name: &str) -> Result<u32> {
128118
let func = self.func(name);
129-
let result = func.call(&[])?;
119+
let result = func.call(store, &[])?;
130120
Ok(result[0].unwrap_i32() as u32)
131121
}
132122

133-
fn func(&self, name: &str) -> &Function {
123+
pub(crate) fn func(&self, name: &str) -> &Function {
134124
self.0
135125
.exports
136126
.get_function(name)
137127
.unwrap_or_else(|_| panic!("function {} not found", name))
138128
}
139-
}
140129

141-
impl Wasm {
142130
pub fn new(instance: Instance) -> Self {
143131
Self(instance)
144132
}

0 commit comments

Comments
 (0)