Skip to content

Commit e5ac805

Browse files
authored
feat: suggest passing argument from cli (#87)
1 parent caede0a commit e5ac805

File tree

7 files changed

+102
-2
lines changed

7 files changed

+102
-2
lines changed

examples/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ go build hello.go
1616
* Split the ELF hello into segments. Note that the flag `BLOCK_NO` is only necessary for minigeth.
1717

1818
```
19-
BASEDIR=test-vectors RUST_LOG=info ELF_PATH=test-vectors/hello BLOCK_NO=13284491 SEG_OUTPUT=/tmp/output SEG_SIZE=262144 \
19+
BASEDIR=test-vectors RUST_LOG=info ELF_PATH=test-vectors/hello BLOCK_NO=13284491 SEG_OUTPUT=/tmp/output SEG_SIZE=262144 ARGS="" \
2020
cargo run --release --example zkmips split
2121
```
2222

examples/zkmips.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ fn split_elf_into_segs() {
3333
let seg_path = env::var("SEG_OUTPUT").expect("Segment output path is missing");
3434
let seg_size = env::var("SEG_SIZE").unwrap_or(format!("{SEGMENT_STEPS}"));
3535
let seg_size = seg_size.parse::<_>().unwrap_or(SEGMENT_STEPS);
36+
let args = env::var("ARGS").unwrap_or("".to_string());
3637

3738
let data = fs::read(elf_path).expect("could not read file");
3839
let file =
3940
ElfBytes::<AnyEndian>::minimal_parse(data.as_slice()).expect("opening elf file failed");
4041
let (mut state, _) = State::load_elf(&file);
4142
state.patch_go(&file);
42-
state.patch_stack("");
43+
state.patch_stack(&args);
4344

4445
let block_path = get_block_path(&basedir, &block_no, "");
4546
state.load_input(&block_path);

src/mips_emulator/tests.rs

+99
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,103 @@ mod tests {
133133

134134
instrumented_state.split_segment(true, OUTPUT);
135135
}
136+
137+
#[test]
138+
fn test_execute_app() {
139+
let path = PathBuf::from("./test-vectors/test_local_app");
140+
let data = fs::read(path).expect("could not read file");
141+
let file =
142+
ElfBytes::<AnyEndian>::minimal_parse(data.as_slice()).expect("opening elf file failed");
143+
let (mut state, _) = State::load_elf(&file);
144+
145+
state.patch_go(&file);
146+
state.patch_stack("");
147+
148+
let mut instrumented_state = InstrumentedState::new(state, String::from(""));
149+
150+
let mut step_number = 0;
151+
loop {
152+
if instrumented_state.state.exited {
153+
break;
154+
}
155+
instrumented_state.step();
156+
step_number += 1;
157+
}
158+
println!("total steps {}", step_number);
159+
}
160+
161+
#[test]
162+
fn test_execute_nested_fib() {
163+
let path = PathBuf::from("./test-vectors/fib");
164+
let data = fs::read(path).expect("could not read file");
165+
let file =
166+
ElfBytes::<AnyEndian>::minimal_parse(data.as_slice()).expect("opening elf file failed");
167+
let (mut state, _) = State::load_elf(&file);
168+
169+
state.patch_go(&file);
170+
state.patch_stack("");
171+
172+
let mut instrumented_state = InstrumentedState::new(state, String::from(""));
173+
174+
let mut step_number = 0usize;
175+
loop {
176+
if instrumented_state.state.exited {
177+
break;
178+
}
179+
instrumented_state.step();
180+
step_number += 1;
181+
}
182+
183+
println!("total steps {}", step_number);
184+
}
185+
186+
#[test]
187+
fn test_execute_fib() {
188+
let path = PathBuf::from("./test-vectors/fib2");
189+
let data = fs::read(path).expect("could not read file");
190+
let file =
191+
ElfBytes::<AnyEndian>::minimal_parse(data.as_slice()).expect("opening elf file failed");
192+
let (mut state, _) = State::load_elf(&file);
193+
194+
state.patch_go(&file);
195+
state.patch_stack("");
196+
197+
let mut instrumented_state = InstrumentedState::new(state, String::from(""));
198+
199+
let mut step_number = 0usize;
200+
loop {
201+
if instrumented_state.state.exited {
202+
break;
203+
}
204+
instrumented_state.step();
205+
step_number += 1;
206+
}
207+
208+
println!("total steps {}", step_number);
209+
}
210+
211+
#[test]
212+
fn test_execute_simple_add() {
213+
let path = PathBuf::from("./test-vectors/simpleArith");
214+
let data = fs::read(path).expect("could not read file");
215+
let file =
216+
ElfBytes::<AnyEndian>::minimal_parse(data.as_slice()).expect("opening elf file failed");
217+
let (mut state, _) = State::load_elf(&file);
218+
219+
state.patch_go(&file);
220+
state.patch_stack("");
221+
222+
let mut instrumented_state = InstrumentedState::new(state, String::from(""));
223+
224+
let mut step_number = 0usize;
225+
loop {
226+
if instrumented_state.state.exited {
227+
break;
228+
}
229+
instrumented_state.step();
230+
step_number += 1;
231+
}
232+
233+
println!("total steps {}", step_number);
234+
}
136235
}

test-vectors/fib

1.87 MB
Binary file not shown.

test-vectors/fib2

1.87 MB
Binary file not shown.

test-vectors/simpleArith

1.87 MB
Binary file not shown.

test-vectors/test_local_app

17.8 MB
Binary file not shown.

0 commit comments

Comments
 (0)