Skip to content

Added scripts to update Rust version in Zisk-Rust repo #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,22 @@ jobs:
- name: Setup CI
uses: ./.github/actions/setup

- name: Install Rust Nightly
- name: Clean rust toolchain
run: |
rustup self uninstall -y || true
rm -rf ~/.rustup ~/.cargo

- name: Install rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
toolchain: stable
profile: minimal
components: rustfmt

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
toolchain: nightly
toolchain: stable
command: fmt
args: --all -- --check
env:
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/build_toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl BuildToolchainCmd {
repo_url,
"--depth=1",
"--single-branch",
"--branch=stable",
"--branch=zisk",
"zisk-rust",
])
.current_dir(&temp_dir)
Expand Down
8 changes: 4 additions & 4 deletions cli/src/commands/install_toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ impl InstallToolchainCmd {
if let Ok(entry) = entry {
let entry_path = entry.path();
let entry_name = entry_path.file_name().unwrap();
if entry_path.is_dir() &&
entry_name != "bin" &&
entry_name != "circuits" &&
entry_name != "toolchains"
if entry_path.is_dir()
&& entry_name != "bin"
&& entry_name != "circuits"
&& entry_name != "toolchains"
{
if let Err(err) = fs::remove_dir_all(&entry_path) {
println!("Failed to remove directory {:?}: {}", entry_path, err);
Expand Down
6 changes: 3 additions & 3 deletions core/src/elf2rom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ pub fn elf2rom(elf_file: String) -> Result<ZiskRom, Box<dyn Error>> {
// Add init data as a read/write memory section, initialized by code
// If the data is a writable memory section, add it to the ROM memory using Zisk
// copy instructions
if (section_header.sh_flags & SHF_WRITE as u64) != 0 &&
addr >= RAM_ADDR &&
addr + data.len() as u64 <= RAM_ADDR + RAM_SIZE
if (section_header.sh_flags & SHF_WRITE as u64) != 0
&& addr >= RAM_ADDR
&& addr + data.len() as u64 <= RAM_ADDR + RAM_SIZE
{
//println! {"elf2rom() new RW from={:x} length={:x}={}", addr, data.len(),
//data.len()};
Expand Down
26 changes: 13 additions & 13 deletions core/src/zisk_inst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,19 @@ impl ZiskInst {
/// Constructs a `flags`` bitmap made of combinations of fields of the Zisk instruction. This
/// field is used by the PIL to proof some of the operations.
pub fn get_flags(&self) -> u64 {
let flags: u64 = 1 |
(((self.a_src == SRC_IMM) as u64) << 1) |
(((self.a_src == SRC_MEM) as u64) << 2) |
(((self.a_src == SRC_STEP) as u64) << 3) |
(((self.b_src == SRC_IMM) as u64) << 4) |
(((self.b_src == SRC_MEM) as u64) << 5) |
((self.is_external_op as u64) << 6) |
((self.store_ra as u64) << 7) |
(((self.store == STORE_MEM) as u64) << 8) |
(((self.store == STORE_IND) as u64) << 9) |
((self.set_pc as u64) << 10) |
((self.m32 as u64) << 11) |
(((self.b_src == SRC_IND) as u64) << 12);
let flags: u64 = 1
| (((self.a_src == SRC_IMM) as u64) << 1)
| (((self.a_src == SRC_MEM) as u64) << 2)
| (((self.a_src == SRC_STEP) as u64) << 3)
| (((self.b_src == SRC_IMM) as u64) << 4)
| (((self.b_src == SRC_MEM) as u64) << 5)
| ((self.is_external_op as u64) << 6)
| ((self.store_ra as u64) << 7)
| (((self.store == STORE_MEM) as u64) << 8)
| (((self.store == STORE_IND) as u64) << 9)
| ((self.set_pc as u64) << 10)
| ((self.m32 as u64) << 11)
| (((self.b_src == SRC_IND) as u64) << 12);

flags
}
Expand Down
34 changes: 17 additions & 17 deletions emulator/src/emu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ impl MemBusHelpers {
[
MEMORY_LOAD_OP,
addr as u64,
MEM_STEP_BASE +
MAX_MEM_OPS_BY_MAIN_STEP * step +
MAX_MEM_OPS_BY_STEP_OFFSET * step_offset as u64,
MEM_STEP_BASE
+ MAX_MEM_OPS_BY_MAIN_STEP * step
+ MAX_MEM_OPS_BY_STEP_OFFSET * step_offset as u64,
bytes as u64,
mem_values[0],
mem_values[1],
Expand All @@ -59,9 +59,9 @@ impl MemBusHelpers {
[
MEMORY_STORE_OP,
addr as u64,
MEM_STEP_BASE +
MAX_MEM_OPS_BY_MAIN_STEP * step +
MAX_MEM_OPS_BY_STEP_OFFSET * step_offset as u64,
MEM_STEP_BASE
+ MAX_MEM_OPS_BY_MAIN_STEP * step
+ MAX_MEM_OPS_BY_STEP_OFFSET * step_offset as u64,
bytes as u64,
mem_values[0],
mem_values[1],
Expand Down Expand Up @@ -1343,9 +1343,9 @@ impl<'a> Emu<'a> {
}

// Log emulation step, if requested
if options.print_step.is_some() &&
(options.print_step.unwrap() != 0) &&
((self.ctx.inst_ctx.step % options.print_step.unwrap()) == 0)
if options.print_step.is_some()
&& (options.print_step.unwrap() != 0)
&& ((self.ctx.inst_ctx.step % options.print_step.unwrap()) == 0)
{
println!("step={}", self.ctx.inst_ctx.step);
}
Expand Down Expand Up @@ -1520,9 +1520,9 @@ impl<'a> Emu<'a> {
// Increment step counter
self.ctx.inst_ctx.step += 1;

if self.ctx.inst_ctx.end ||
((self.ctx.inst_ctx.step - self.ctx.last_callback_step) ==
self.ctx.callback_steps)
if self.ctx.inst_ctx.end
|| ((self.ctx.inst_ctx.step - self.ctx.last_callback_step)
== self.ctx.callback_steps)
{
// In run() we have checked the callback consistency with ctx.do_callback
let callback = callback.as_ref().unwrap();
Expand Down Expand Up @@ -1820,8 +1820,8 @@ impl<'a> Emu<'a> {
let b = [inst_ctx.b & 0xFFFFFFFF, (inst_ctx.b >> 32) & 0xFFFFFFFF];
let c = [inst_ctx.c & 0xFFFFFFFF, (inst_ctx.c >> 32) & 0xFFFFFFFF];

let addr1 = (inst.b_offset_imm0 as i64 +
if inst.b_src == SRC_IND { inst_ctx.a as i64 } else { 0 }) as u64;
let addr1 = (inst.b_offset_imm0 as i64
+ if inst.b_src == SRC_IND { inst_ctx.a as i64 } else { 0 }) as u64;

let jmp_offset1 = if inst.jmp_offset1 >= 0 {
F::from_canonical_u64(inst.jmp_offset1 as u64)
Expand Down Expand Up @@ -1899,9 +1899,9 @@ impl<'a> Emu<'a> {
m32: F::from_bool(inst.m32),
addr1: F::from_canonical_u64(addr1),
__debug_operation_bus_enabled: F::from_bool(
inst.op_type == ZiskOperationType::Arith ||
inst.op_type == ZiskOperationType::Binary ||
inst.op_type == ZiskOperationType::BinaryE,
inst.op_type == ZiskOperationType::Arith
|| inst.op_type == ZiskOperationType::Binary
|| inst.op_type == ZiskOperationType::BinaryE,
),
}
}
Expand Down
12 changes: 6 additions & 6 deletions emulator/src/emu_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ impl fmt::Display for EmuOptions {
impl EmuOptions {
/// Returns true if the configuration allows to emulate in fast mode, maximizing the performance
pub fn is_fast(&self) -> bool {
self.trace_steps.is_none() &&
(self.print_step.is_none() || (self.print_step.unwrap() == 0)) &&
self.trace.is_none() &&
!self.log_step &&
!self.verbose &&
!self.tracerv
self.trace_steps.is_none()
&& (self.print_step.is_none() || (self.print_step.unwrap() == 0))
&& self.trace.is_none()
&& !self.log_step
&& !self.verbose
&& !self.tracerv
}
}
28 changes: 14 additions & 14 deletions emulator/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,22 +185,22 @@ impl Stats {
output += &format!(" COST_STEP: {:02} sec\n", COST_STEP);

// Calculate some aggregated counters to be used in the logs
let total_mem_ops = self.mops.mread_na1 +
self.mops.mread_na2 +
self.mops.mread_a +
self.mops.mwrite_na1 +
self.mops.mwrite_na2 +
self.mops.mwrite_a;
let total_mem_align_steps = self.mops.mread_na1 +
self.mops.mread_na2 * 2 +
self.mops.mwrite_na1 * 2 +
self.mops.mwrite_na2 * 4;
let total_mem_ops = self.mops.mread_na1
+ self.mops.mread_na2
+ self.mops.mread_a
+ self.mops.mwrite_na1
+ self.mops.mwrite_na2
+ self.mops.mwrite_a;
let total_mem_align_steps = self.mops.mread_na1
+ self.mops.mread_na2 * 2
+ self.mops.mwrite_na1 * 2
+ self.mops.mwrite_na2 * 4;

let cost_mem = total_mem_ops as f64 * COST_MEM;
let cost_mem_align = self.mops.mread_na1 as f64 * COST_MEMA_R1 +
self.mops.mread_na2 as f64 * COST_MEMA_R2 +
self.mops.mwrite_na1 as f64 * COST_MEMA_W1 +
self.mops.mwrite_na2 as f64 * COST_MEMA_W2;
let cost_mem_align = self.mops.mread_na1 as f64 * COST_MEMA_R1
+ self.mops.mread_na2 as f64 * COST_MEMA_R2
+ self.mops.mwrite_na1 as f64 * COST_MEMA_W1
+ self.mops.mwrite_na2 as f64 * COST_MEMA_W2;

// Declare some total counters for the opcodes
let mut total_opcodes: u64 = 0;
Expand Down
18 changes: 10 additions & 8 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
reorder_imports = true
imports_granularity = "Crate"
use_small_heuristics = "Max"
comment_width = 100
wrap_comments = true
binop_separator = "Back"
trailing_comma = "Vertical"
trailing_semicolon = false
use_field_init_shorthand = true
format_code_in_doc_comments = true
doc_comment_code_block_width = 100

## Nightly options:
# imports_granularity = "Crate"
# comment_width = 100
# wrap_comments = true
# binop_separator = "Front"
# trailing_comma = "Vertical"
# trailing_semicolon = false
# format_code_in_doc_comments = true
# doc_comment_code_block_width = 100
16 changes: 8 additions & 8 deletions state-machines/arith/src/arith_full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@ impl ArithFullSM {
step,
opcode,
ZiskOperationType::Binary as u64,
aop.d[0] +
CHUNK_SIZE * aop.d[1] +
CHUNK_SIZE.pow(2) * (aop.d[2] + extension.0) +
CHUNK_SIZE.pow(3) * aop.d[3],
aop.b[0] +
CHUNK_SIZE * aop.b[1] +
CHUNK_SIZE.pow(2) * (aop.b[2] + extension.1) +
CHUNK_SIZE.pow(3) * aop.b[3],
aop.d[0]
+ CHUNK_SIZE * aop.d[1]
+ CHUNK_SIZE.pow(2) * (aop.d[2] + extension.0)
+ CHUNK_SIZE.pow(3) * aop.d[3],
aop.b[0]
+ CHUNK_SIZE * aop.b[1]
+ CHUNK_SIZE.pow(2) * (aop.b[2] + extension.1)
+ CHUNK_SIZE.pow(3) * aop.b[3],
)
.to_vec()]
} else {
Expand Down
Loading
Loading