Skip to content

Commit

Permalink
[chore] update toolchain, gitignore; cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenfeizhang committed Mar 29, 2023
1 parent efec13b commit 47c39ba
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 279 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@
testdata

Cargo.lock

# local files
*.srs
*.log
*.snark
*.sol
*.pkey
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2022-10-28
nightly-2022-12-10
4 changes: 1 addition & 3 deletions snark-verifier/src/loader/evm/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ pub struct YulCode {

impl YulCode {
pub fn new() -> Self {
YulCode {
runtime: String::new(),
}
YulCode { runtime: String::new() }
}

pub fn code(&self, base_modulus: String, scalar_modulus: String) -> String {
Expand Down
13 changes: 4 additions & 9 deletions snark-verifier/src/loader/evm/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,10 @@ pub fn execute(deployment_code: Vec<u8>, calldata: Vec<u8>) -> (bool, u64, Vec<u
let debug = debug();
let caller = Address::from_low_u64_be(0xfe);

let mut evm = ExecutorBuilder::default()
.with_gas_limit(u64::MAX.into())
.set_debugger(debug)
.build();

let contract = evm
.deploy(caller, deployment_code.into(), 0.into())
.address
.unwrap();
let mut evm =
ExecutorBuilder::default().with_gas_limit(u64::MAX.into()).set_debugger(debug).build();

let contract = evm.deploy(caller, deployment_code.into(), 0.into()).address.unwrap();
let result = evm.call_raw(caller, contract, calldata.into(), 0.into());

let costs = result
Expand Down
92 changes: 23 additions & 69 deletions snark-verifier/src/loader/evm/test/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ impl Tui {
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend).unwrap();
terminal.hide_cursor().unwrap();
Tui {
debug_arena,
terminal,
key_buffer: String::new(),
current_step,
}
Tui { debug_arena, terminal, key_buffer: String::new(), current_step }
}

pub fn start(mut self) {
Expand Down Expand Up @@ -91,11 +86,8 @@ impl Tui {
let mut draw_memory: DrawMemory = DrawMemory::default();

let debug_call = &self.debug_arena;
let mut opcode_list: Vec<String> = debug_call[0]
.1
.iter()
.map(|step| step.pretty_opcode())
.collect();
let mut opcode_list: Vec<String> =
debug_call[0].1.iter().map(|step| step.pretty_opcode()).collect();
let mut last_index = 0;

let mut stack_labels = false;
Expand Down Expand Up @@ -385,12 +377,8 @@ impl Tui {
if let [op_pane, stack_pane, memory_pane] = Layout::default()
.direction(Direction::Vertical)
.constraints(
[
Constraint::Ratio(1, 3),
Constraint::Ratio(1, 3),
Constraint::Ratio(1, 3),
]
.as_ref(),
[Constraint::Ratio(1, 3), Constraint::Ratio(1, 3), Constraint::Ratio(1, 3)]
.as_ref(),
)
.split(app)[..]
{
Expand All @@ -412,14 +400,7 @@ impl Tui {
stack_labels,
draw_memory,
);
Tui::draw_memory(
f,
debug_steps,
current_step,
memory_pane,
mem_utf,
draw_memory,
);
Tui::draw_memory(f, debug_steps, current_step, memory_pane, mem_utf, draw_memory);
} else {
panic!("unable to create vertical panes")
}
Expand Down Expand Up @@ -536,15 +517,11 @@ impl Tui {
let prev_start = draw_memory.current_startline;
let abs_min_start = 0;
let abs_max_start = (opcode_list.len() as i32 - 1) - (height / 2);
let mut min_start = max(
current_step as i32 - height + extra_top_lines,
abs_min_start,
) as usize;
let mut min_start =
max(current_step as i32 - height + extra_top_lines, abs_min_start) as usize;

let mut max_start = max(
min(current_step as i32 - extra_top_lines, abs_max_start),
abs_min_start,
) as usize;
let mut max_start =
max(min(current_step as i32 - extra_top_lines, abs_max_start), abs_min_start) as usize;

if min_start > max_start {
std::mem::swap(&mut min_start, &mut max_start);
Expand All @@ -559,18 +536,11 @@ impl Tui {
}
draw_memory.current_startline = display_start;

let max_pc_len = debug_steps
.iter()
.fold(0, |max_val, val| val.pc.max(max_val))
.to_string()
.len();
let max_pc_len =
debug_steps.iter().fold(0, |max_val, val| val.pc.max(max_val)).to_string().len();

let mut add_new_line = |line_number| {
let bg_color = if line_number == current_step {
Color::DarkGray
} else {
Color::Reset
};
let bg_color = if line_number == current_step { Color::DarkGray } else { Color::Reset };

let line_number_format = if line_number == current_step {
let step: &DebugStep = &debug_steps[line_number];
Expand Down Expand Up @@ -598,9 +568,8 @@ impl Tui {
add_new_line(number);
}
add_new_line(opcode_list.len());
let paragraph = Paragraph::new(text_output)
.block(block_source_code)
.wrap(Wrap { trim: true });
let paragraph =
Paragraph::new(text_output).block(block_source_code).wrap(Wrap { trim: true });
f.render_widget(paragraph, area);
}

Expand All @@ -613,9 +582,8 @@ impl Tui {
draw_memory: &mut DrawMemory,
) {
let stack = &debug_steps[current_step].stack;
let stack_space = Block::default()
.title(format!("Stack: {}", stack.len()))
.borders(Borders::ALL);
let stack_space =
Block::default().title(format!("Stack: {}", stack.len())).borders(Borders::ALL);
let min_len = usize::max(format!("{}", stack.len()).len(), 2);

let indices_affected = stack_indices_affected(debug_steps[current_step].instruction.0);
Expand All @@ -626,9 +594,8 @@ impl Tui {
.enumerate()
.skip(draw_memory.current_stack_startline)
.map(|(i, stack_item)| {
let affected = indices_affected
.iter()
.find(|(affected_index, _name)| *affected_index == i);
let affected =
indices_affected.iter().find(|(affected_index, _name)| *affected_index == i);

let mut words: Vec<Span> = (0..32)
.into_iter()
Expand Down Expand Up @@ -667,9 +634,7 @@ impl Tui {
})
.collect();

let paragraph = Paragraph::new(text)
.block(stack_space)
.wrap(Wrap { trim: true });
let paragraph = Paragraph::new(text).block(stack_space).wrap(Wrap { trim: true });
f.render_widget(paragraph, area);
}

Expand All @@ -683,10 +648,7 @@ impl Tui {
) {
let memory = &debug_steps[current_step].memory;
let stack_space = Block::default()
.title(format!(
"Memory (max expansion: {} bytes)",
memory.effective_len()
))
.title(format!("Memory (max expansion: {} bytes)", memory.effective_len()))
.borders(Borders::ALL);
let memory = memory.data();
let max_i = memory.len() / 32;
Expand Down Expand Up @@ -773,9 +735,7 @@ impl Tui {
Spans::from(spans)
})
.collect();
let paragraph = Paragraph::new(text)
.block(stack_space)
.wrap(Wrap { trim: true });
let paragraph = Paragraph::new(text).block(stack_space).wrap(Wrap { trim: true });
f.render_widget(paragraph, area);
}
}
Expand Down Expand Up @@ -884,13 +844,7 @@ fn stack_indices_affected(op: u8) -> Vec<(usize, &'static str)> {
0xa0 => vec![(0, "offset"), (1, "length")],
0xa1 => vec![(0, "offset"), (1, "length"), (2, "topic")],
0xa2 => vec![(0, "offset"), (1, "length"), (2, "topic1"), (3, "topic2")],
0xa3 => vec![
(0, "offset"),
(1, "length"),
(2, "topic1"),
(3, "topic2"),
(4, "topic3"),
],
0xa3 => vec![(0, "offset"), (1, "length"), (2, "topic1"), (3, "topic2"), (4, "topic3")],
0xa4 => vec![
(0, "offset"),
(1, "length"),
Expand Down
6 changes: 1 addition & 5 deletions snark-verifier/src/loader/evm/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ pub fn compile_yul(code: &str) -> Vec<u8> {
.arg("-")
.spawn()
.unwrap();
cmd.stdin
.take()
.unwrap()
.write_all(code.as_bytes())
.unwrap();
cmd.stdin.take().unwrap().write_all(code.as_bytes()).unwrap();
let output = cmd.wait_with_output().unwrap().stdout;
let binary = *split_by_ascii_whitespace(&output).last().unwrap();
hex::decode(binary).unwrap()
Expand Down
Loading

0 comments on commit 47c39ba

Please sign in to comment.