diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8cc5c528..a0fa2f97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -612,6 +612,82 @@ jobs: working-directory: ${{ github.workspace }} run: make bench + benchmark-run: + name: Run benchmarks + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Fetch submodules + run: make submodules + + - name: Setup nodejs + yarn + uses: actions/setup-node@v4 + with: + node-version: 18.20.2 + cache-dependency-path: | + ${{ github.workspace }}/zksync-era/contracts-test-data/yarn.lock + ${{ github.workspace }}/zksync-era/contracts/l1-contracts/yarn.lock + ${{ github.workspace }}/zksync-era/contracts/l2-contracts/yarn.lock + ${{ github.workspace }}/zksync-era/contracts/system-contracts/yarn.lock + + - name: Build benchmark contracts + if: steps.contracts-cache.outputs.cache-hit != 'true' + id: bench-setup + run: make bench-setup + + - name: Fetch toolchain version from zksync-era + run: | + cd ${{ github.workspace }}/zksync-era + echo "ERA_TOOLCHAIN=$(head ./rust-toolchain)" >> $GITHUB_ENV + + - name: Rustup toolchain install + uses: dtolnay/rust-toolchain@nightly + with: + toolchain: ${{ env.ERA_TOOLCHAIN }} + + - uses: Swatinem/rust-cache@v2 + with: + workspaces: | + era_vm/zksync-era/core/tests/vm-benchmark + + - name: Zksync-era dependencies + uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: clang clang-tools build-essential librocksdb-dev + version: 1.0 + + - name: Check benchmarks build + run: | + cd ${{ github.workspace }}/zksync-era + cargo build --benches + + # Download previous benchmark result from cache (if exists) + - name: Download previous benchmark data + uses: actions/cache@v4 + with: + path: ./cache + key: main-${{ runner.os }}-benchmark + + # Run `github-action-benchmark` action + - name: Store benchmark result + uses: benchmark-action/github-action-benchmark@v1 + with: + # What benchmark tool the output.txt came from + tool: 'cargo' + # Where the output from the benchmark tool is stored + output-file-path: "${{github.workspace}}/output.txt" + # Where the previous data file is stored + external-data-json-path: ./cache/benchmark-data.json + # Workflow will fail when an alert happens + fail-on-alert: true + # GitHub API token to make a commit comment + github-token: ${{ secrets.GITHUB_TOKEN }} + # Enable alert commit comment + comment-on-alert: true + # Enable Job Summary for PRs + summary-always: true zksync_era_tests: runs-on: ubuntu-latest diff --git a/src/execution.rs b/src/execution.rs index 34af025b..fa96a665 100644 --- a/src/execution.rs +++ b/src/execution.rs @@ -415,20 +415,15 @@ impl Heap { } pub fn store(&mut self, address: u32, value: U256) { - let mut bytes: [u8; 32] = [0; 32]; - value.to_big_endian(&mut bytes); - for (i, item) in bytes.iter().enumerate() { - self.heap[address as usize + i] = *item; - } + let start = address as usize; + let end = start + 32; + value.to_big_endian(&mut self.heap[start..end]); } pub fn read(&self, address: u32) -> U256 { - let mut result = U256::zero(); - - for i in 0..32 { - result |= U256::from(self.heap[address as usize + (31 - i)]) << (i * 8); - } - result + let start = address as usize; + let end = start + 32; + U256::from_big_endian(&self.heap[start..end]) } pub fn expanded_read(&mut self, address: u32) -> (U256, u32) { @@ -445,24 +440,15 @@ impl Heap { let mut result = U256::zero(); for i in 0..32 { let addr = pointer.start + pointer.offset + (31 - i); - if addr < pointer.start + pointer.len { - result |= U256::from(self.heap[addr as usize]) << (i * 8); - } + result |= U256::from(self.heap[addr as usize]) << (i * 8); } result } pub fn read_unaligned_from_pointer(&self, pointer: &FatPointer) -> Result, HeapError> { - let mut result = Vec::new(); - let start = pointer.start + pointer.offset; - let finish = start + pointer.len; - for i in start..finish { - if i as usize >= self.heap.len() { - return Err(HeapError::ReadOutOfBounds); - } - result.push(self.heap[i as usize]); - } - Ok(result) + let start = (pointer.start + pointer.offset) as usize; + let finish = (start + pointer.len as usize).min(self.heap.len()); + Ok(self.heap[start..finish].into()) } pub fn len(&self) -> usize {