diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..f84a5bc3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,65 @@ +name: CI + +on: + merge_group: + push: + branches: [ main ] + pull_request: + branches: [ '**' ] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + compile: + name: Compile + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Rustup toolchain install + uses: dtolnay/rust-toolchain@stable + with: + toolchain: ${{ env.RUST_VERSION }} + + - name: Run cargo check + run: cargo check --workspace --all-features --all-targets + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install stable toolchain + uses: dtolnay/rust-toolchain@stable + with: + toolchain: ${{ env.RUST_VERSION }} + components: rustfmt, clippy + + - name: Run cargo fmt + run: cargo fmt --all -- --check + + # - name: Run clippy + # run: cargo clippy --workspace --all-features --benches --examples --tests -- -D warnings + + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: ${{ env.RUST_VERSION }} + components: clippy + + - name: Install testing tools + uses: taiki-e/install-action@v2 + with: + tool: cargo-nextest + + - name: Run tests + run: cargo nextest run --workspace --all-features --no-capture diff --git a/src/lib.rs b/src/lib.rs index 82608b9c..1d19b00f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,14 +17,12 @@ pub fn run_program(bin_path: &str) -> U256 { let program = std::fs::read(bin_path).unwrap(); let encoded = String::from_utf8(program.to_vec()).unwrap(); - let bin = hex::decode(encoded[2..].to_owned()).unwrap(); + let bin = hex::decode(&encoded[2..]).unwrap(); let mut program_code = vec![]; for raw_opcode_slice in bin.chunks(8) { let mut raw_opcode_bytes: [u8; 8] = [0; 8]; - for i in 0..8 { - raw_opcode_bytes[i] = raw_opcode_slice[i]; - } + raw_opcode_bytes.copy_from_slice(&raw_opcode_slice[..8]); let raw_opcode_u64 = u64::from_be_bytes(raw_opcode_bytes); let opcode = Opcode::from_raw_opcode(raw_opcode_u64, &opcode_table); @@ -76,5 +74,5 @@ pub fn run_program(bin_path: &str) -> U256 { vm.current_frame.pc += 1; } - vm.current_frame.storage.get(&U256::zero()).unwrap().clone() + *vm.current_frame.storage.get(&U256::zero()).unwrap() } diff --git a/src/opcode.rs b/src/opcode.rs index 5e653c2f..d1ebefc1 100644 --- a/src/opcode.rs +++ b/src/opcode.rs @@ -58,7 +58,7 @@ impl Opcode { let imm0: u16 = ((raw_op & 0xffff00000000) >> 32) as u16; let imm1: u16 = ((raw_op & 0xffff000000000000) >> 48) as u16; - let opcode = Opcode { + Self { variant: opcode_zksync.opcode, src0_operand_type: opcode_zksync.src0_operand_type, dst0_operand_type: opcode_zksync.dst0_operand_type, @@ -68,11 +68,9 @@ impl Opcode { src1_index: second_four_bits(src0_and_1_index), dst0_index: first_four_bits(dst0_and_1_index), dst1_index: second_four_bits(dst0_and_1_index), - imm0: imm0, - imm1: imm1, - }; - - return opcode; + imm0, + imm1, + } } } diff --git a/src/state.rs b/src/state.rs index 675418b8..0be2e3b0 100644 --- a/src/state.rs +++ b/src/state.rs @@ -43,7 +43,7 @@ impl VMState { return self.registers[(index - 1) as usize]; } - return U256::zero(); + U256::zero() } pub fn set_register(&mut self, index: u8, value: U256) { diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 7ae154d3..6bfd89e9 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -4,6 +4,6 @@ use u256::U256; #[test] fn test_add() { let bin_path = "./program_artifacts/add.artifacts/add.yul.zbin"; - let result = run_program(&bin_path); + let result = run_program(bin_path); assert_eq!(result, U256::from_dec_str("3").unwrap()); }