Skip to content

Commit

Permalink
Merge 9d0ffa4 into 9de1edc
Browse files Browse the repository at this point in the history
  • Loading branch information
kelemeno authored Oct 29, 2024
2 parents 9de1edc + 9d0ffa4 commit e14c496
Show file tree
Hide file tree
Showing 301 changed files with 16,873 additions and 2,897 deletions.
2 changes: 1 addition & 1 deletion .github/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ We truly appreciate efforts to discover and disclose security issues responsibly
## Vulnerabilities

If you'd like to report a security issue in the repositories of matter-labs organization, please proceed to our
[Bug Bounty Program on Immunefi](https://era.zksync.io/docs/reference/troubleshooting/audit-bug-bounty.html#bug-bounty-program).
[Bug Bounty Program on Immunefi](https://immunefi.com/bug-bounty/zksyncera/information/).

## Other Security Issues

Expand Down
39 changes: 20 additions & 19 deletions .github/workflows/codespell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,26 @@ name: Codespell
on: pull_request

jobs:
codespell:
runs-on: ubuntu-latest

steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: pip cache
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: ${{ runner.os }}-pip-

- name: Install prerequisites
run: sudo pip install -r ./.codespell/requirements.txt

- name: Spell check
run: codespell --config=./.codespell/.codespellrc
# TODO: fix codespell CI
# codespell:
# runs-on: ubuntu-latest

# steps:
# - name: Checkout the repository
# uses: actions/checkout@v4

# - name: pip cache
# uses: actions/cache@v4
# with:
# path: ~/.cache/pip
# key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
# restore-keys: ${{ runner.os }}-pip-

# - name: Install prerequisites
# run: sudo pip install -r ./.codespell/requirements.txt

# - name: Spell check
# run: codespell --config=./.codespell/.codespellrc

typos:
runs-on: ubuntu-latest
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/dead-links.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Check Dead Links in Markdown Files

on: pull_request

jobs:
check-dead-links:
name: Check Dead Links in Markdown Files
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Rust and Lychee
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
~/.cargo/bin/cargo install lychee
- name: Find and check markdown files
run: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
find . -type f -name "*.md" ! -path "*/node_modules/*" ! -path "*/openzeppelin*" ! -path "*/murky/*" -exec lychee --github-token $GITHUB_TOKEN {} +
66 changes: 35 additions & 31 deletions .github/workflows/l1-contracts-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ jobs:
- name: Lint
run: yarn lint:check

- name: Lint errors
run: yarn l1 errors-lint --check

test-foundry:
needs: [build, lint]
runs-on: ubuntu-latest
Expand Down Expand Up @@ -276,37 +279,38 @@ jobs:
- name: Run coverage
run: FOUNDRY_PROFILE=default yarn test:foundry && FOUNDRY_PROFILE=default yarn coverage:foundry --report summary --report lcov

# To ignore coverage for certain directories modify the paths in this step as needed. The
# below default ignores coverage results for the test and script directories. Alternatively,
# to include coverage in all directories, comment out this step. Note that because this
# filtering applies to the lcov file, the summary table generated in the previous step will
# still include all files and directories.
# The `--rc lcov_branch_coverage=1` part keeps branch info in the filtered report, since lcov
# defaults to removing branch info.
- name: Filter directories
run: |
sudo apt update && sudo apt install -y lcov
lcov --remove lcov.info 'test/*' 'contracts/dev-contracts/*' '../lib/forge-std/*' '../lib/murky/*' 'lib/*' '../lib/*' 'lib/' 'deploy-scripts/*' --output-file lcov.info --rc lcov_branch_coverage=1
# This step posts a detailed coverage report as a comment and deletes previous comments on
# each push. The below step is used to fail coverage if the specified coverage threshold is
# not met. The below step can post a comment (when it's `github-token` is specified) but it's
# not as useful, and this action cannot fail CI based on a minimum coverage threshold, which
# is why we use both in this way.
- name: Post coverage report
if: github.event_name == 'pull_request' # This action fails when ran outside of a pull request.
uses: romeovs/[email protected]
with:
delete-old-comments: true
lcov-file: ./l1-contracts/lcov.info
github-token: ${{ secrets.GITHUB_TOKEN }} # Adds a coverage summary comment to the PR.

- name: Verify minimum coverage
uses: zgosalvez/github-actions-report-lcov@v2
with:
coverage-files: ./l1-contracts/lcov.info
working-directory: l1-contracts
minimum-coverage: 85 # Set coverage threshold.
# TODO: for some reason filtering directories stopped working.
# # To ignore coverage for certain directories modify the paths in this step as needed. The
# # below default ignores coverage results for the test and script directories. Alternatively,
# # to include coverage in all directories, comment out this step. Note that because this
# # filtering applies to the lcov file, the summary table generated in the previous step will
# # still include all files and directories.
# # The `--rc lcov_branch_coverage=1` part keeps branch info in the filtered report, since lcov
# # defaults to removing branch info.
# - name: Filter directories
# run: |
# sudo apt update && sudo apt install -y lcov
# lcov --remove lcov.info 'test/*' 'contracts/dev-contracts/*' '../lib/forge-std/*' '../lib/murky/*' 'lib/*' '../lib/*' 'lib/' 'deploy-scripts/*' --output-file lcov.info --rc lcov_branch_coverage=1

# # This step posts a detailed coverage report as a comment and deletes previous comments on
# # each push. The below step is used to fail coverage if the specified coverage threshold is
# # not met. The below step can post a comment (when it's `github-token` is specified) but it's
# # not as useful, and this action cannot fail CI based on a minimum coverage threshold, which
# # is why we use both in this way.
# - name: Post coverage report
# if: github.event_name == 'pull_request' # This action fails when ran outside of a pull request.
# uses: romeovs/[email protected]
# with:
# delete-old-comments: true
# lcov-file: ./l1-contracts/lcov.info
# github-token: ${{ secrets.GITHUB_TOKEN }} # Adds a coverage summary comment to the PR.

# - name: Verify minimum coverage
# uses: zgosalvez/github-actions-report-lcov@v2
# with:
# coverage-files: ./l1-contracts/lcov.info
# working-directory: l1-contracts
# minimum-coverage: 85 # Set coverage threshold.

gas-report:
needs: [build, lint]
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/slither.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
rm -rf ./l1-contracts/contracts/state-transition/utils/
rm -rf ./l1-contracts/contracts/state-transition/Verifier.sol
rm -rf ./l1-contracts/contracts/state-transition/TestnetVerifier.sol
rm -rf ./l1-contracts/contracts/state-transition/chain-deps/GatewayCTMDeployer.sol
rm -rf ./l1-contracts/contracts/dev-contracts/test/VerifierTest.sol
rm -rf ./l1-contracts/contracts/dev-contracts/test/VerifierRecursiveTest.sol
Expand Down
59 changes: 30 additions & 29 deletions .github/workflows/system-contracts-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,35 +53,36 @@ jobs:
- name: Run lint
run: yarn lint:check

test-bootloader:
needs: [build, lint]
runs-on: ubuntu-latest

steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Install rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2023-04-17

- name: Restore artifacts cache
uses: actions/cache/restore@v3
with:
fail-on-cache-miss: true
key: artifacts-system-${{ github.sha }}
path: |
system-contracts/artifacts-zk
system-contracts/cache-zk
system-contracts/typechain
system-contracts/contracts-preprocessed
system-contracts/bootloader/build
- name: Run bootloader tests
run: |
cd system-contracts/bootloader/test_infra
cargo run
# FIXME: recover when used multivm is updated
# test-bootloader:
# needs: [build, lint]
# runs-on: ubuntu-latest

# steps:
# - name: Checkout the repository
# uses: actions/checkout@v4

# - name: Install rust
# uses: actions-rust-lang/setup-rust-toolchain@v1
# with:
# toolchain: nightly-2023-04-17

# - name: Restore artifacts cache
# uses: actions/cache/restore@v3
# with:
# fail-on-cache-miss: true
# key: artifacts-system-${{ github.sha }}
# path: |
# system-contracts/artifacts-zk
# system-contracts/cache-zk
# system-contracts/typechain
# system-contracts/contracts-preprocessed
# system-contracts/bootloader/build

# - name: Run bootloader tests
# run: |
# cd system-contracts/bootloader/test_infra
# cargo run

test-contracts:
needs: [build, lint]
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ There are many ways to contribute to the ZK Stack:
issues.
3. Resolve issues: either by showing an issue isn't a problem and the current state is ok as is or by fixing the problem
and opening a PR.
4. Report security issues, see [our security policy](./github/SECURITY.md).
4. Report security issues, see [our security policy](./.github/SECURITY.md).
5. [Join the team!](https://matterlabs.notion.site/Shape-the-future-of-Ethereum-at-Matter-Labs-dfb3b5a037044bb3a8006af2eb0575e0)

## Fixing issues
Expand All @@ -34,7 +34,7 @@ We aim to make it as easy as possible to contribute to the mission. This is stil
and suggestions here too. Some resources to help:

1. [In-repo docs aimed at developers](docs)
2. [ZKsync Era docs!](https://era.zksync.io/docs/)
2. [ZKsync Era docs!](https://docs.zksync.io/zk-stack)
3. Company links can be found in the [repo's readme](README.md)

## Code of Conduct
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ or re-auditing a single line of code. ZKsync Era also uses an LLVM-based compile
write smart contracts in C++, Rust and other popular languages.

This repository contains both L1 and L2 ZKsync smart contracts. For their description see the
[system overview](docs/Overview.md).
[system overview](docs/overview.md).

## Disclaimer

Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ We truly appreciate efforts to discover and disclose security issues responsibly
## Vulnerabilities

If you'd like to report a security issue in the repositories of matter-labs organization, please proceed to our
[Bug Bounty Program on Immunefi](https://era.zksync.io/docs/reference/troubleshooting/audit-bug-bounty.html#bug-bounty-program).
[Bug Bounty Program on Immunefi](https://immunefi.com/bug-bounty/zksyncera/information/).

## Other Security Issues

Expand Down
2 changes: 1 addition & 1 deletion SystemConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"L1_TX_DELTA_FACTORY_DEPS_PUBDATA": 64,
"L2_TX_INTRINSIC_GAS": 14070,
"L2_TX_INTRINSIC_PUBDATA": 0,
"MAX_NEW_FACTORY_DEPS": 32,
"MAX_NEW_FACTORY_DEPS": 64,
"MAX_GAS_PER_TRANSACTION": 80000000,
"KECCAK_ROUND_COST_GAS": 40,
"SHA256_ROUND_COST_GAS": 7,
Expand Down
34 changes: 25 additions & 9 deletions da-contracts/contracts/CalldataDA.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity 0.8.24;

// solhint-disable gas-custom-errors, reason-string
import {OperatorDAInputLengthTooSmall, InvalidNumberOfBlobs, InvalidBlobsHashes, InvalidL2DAOutputHash, OneBlobWithCalldata, PubdataInputTooSmall, PubdataLengthTooBig, InvalidPubdataHash} from "./DAContractsErrors.sol";

/// @dev Total number of bytes in a blob. Blob = 4096 field elements * 31 bytes per field element
/// @dev EIP-4844 defines it as 131_072 but we use 4096 * 31 within our circuits to always fit within a field element
Expand Down Expand Up @@ -44,26 +44,34 @@ abstract contract CalldataDA {
// - Then, there are linear hashes of the published blobs, 32 bytes each.

// Check that it accommodates enough pubdata for the state diff hash, hash of pubdata + the number of blobs.
require(_operatorDAInput.length >= BLOB_DATA_OFFSET, "too small");
if (_operatorDAInput.length < BLOB_DATA_OFFSET) {
revert OperatorDAInputLengthTooSmall(_operatorDAInput.length, BLOB_DATA_OFFSET);
}

stateDiffHash = bytes32(_operatorDAInput[:32]);
fullPubdataHash = bytes32(_operatorDAInput[32:64]);
blobsProvided = uint256(uint8(_operatorDAInput[64]));

require(blobsProvided <= _maxBlobsSupported, "invalid number of blobs");
if (blobsProvided > _maxBlobsSupported) {
revert InvalidNumberOfBlobs(blobsProvided, _maxBlobsSupported);
}

// Note that the API of the contract requires that the returned blobs linear hashes have length of
// the `_maxBlobsSupported`
blobsLinearHashes = new bytes32[](_maxBlobsSupported);

require(_operatorDAInput.length >= BLOB_DATA_OFFSET + 32 * blobsProvided, "invalid blobs hashes");
if (_operatorDAInput.length < BLOB_DATA_OFFSET + 32 * blobsProvided) {
revert InvalidBlobsHashes(_operatorDAInput.length, BLOB_DATA_OFFSET + 32 * blobsProvided);
}

_cloneCalldata(blobsLinearHashes, _operatorDAInput[BLOB_DATA_OFFSET:], blobsProvided);

uint256 ptr = BLOB_DATA_OFFSET + 32 * blobsProvided;

// Now, we need to double check that the provided input was indeed returned by the L2 DA validator.
require(keccak256(_operatorDAInput[:ptr]) == _l2DAValidatorOutputHash, "invalid l2 DA output hash");
if (keccak256(_operatorDAInput[:ptr]) != _l2DAValidatorOutputHash) {
revert InvalidL2DAOutputHash();
}

// The rest of the output was provided specifically by the operator
l1DaInput = _operatorDAInput[ptr:];
Expand All @@ -81,8 +89,12 @@ abstract contract CalldataDA {
uint256 _maxBlobsSupported,
bytes calldata _pubdataInput
) internal pure virtual returns (bytes32[] memory blobCommitments, bytes calldata _pubdata) {
require(_blobsProvided == 1, "one blob with calldata");
require(_pubdataInput.length >= BLOB_COMMITMENT_SIZE, "pubdata too small");
if (_blobsProvided != 1) {
revert OneBlobWithCalldata();
}
if (_pubdataInput.length < BLOB_COMMITMENT_SIZE) {
revert PubdataInputTooSmall(_pubdataInput.length, BLOB_COMMITMENT_SIZE);
}

// We typically do not know whether we'll use calldata or blobs at the time when
// we start proving the batch. That's why the blob commitment for a single blob is still present in the case of calldata.
Expand All @@ -91,8 +103,12 @@ abstract contract CalldataDA {

_pubdata = _pubdataInput[:_pubdataInput.length - BLOB_COMMITMENT_SIZE];

require(_pubdata.length <= BLOB_SIZE_BYTES, "cz");
require(_fullPubdataHash == keccak256(_pubdata), "wp");
if (_pubdata.length > BLOB_SIZE_BYTES) {
revert PubdataLengthTooBig(_pubdata.length, BLOB_SIZE_BYTES);
}
if (_fullPubdataHash != keccak256(_pubdata)) {
revert InvalidPubdataHash(_fullPubdataHash, keccak256(_pubdata));
}
blobCommitments[0] = bytes32(_pubdataInput[_pubdataInput.length - BLOB_COMMITMENT_SIZE:_pubdataInput.length]);
}

Expand Down
34 changes: 32 additions & 2 deletions da-contracts/contracts/DAContractsErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ pragma solidity ^0.8.21;

// 0x53dee67b
error PubdataCommitmentsEmpty();
// 0x7734c31a
error PubdataCommitmentsTooBig();
// 0x53e6d04d
error InvalidPubdataCommitmentsSize();
// 0xafd53e2f
Expand All @@ -17,3 +15,35 @@ error NonEmptyBlobVersionHash(uint256 index);
error PointEvalCallFailed(bytes);
// 0x4daa985d
error PointEvalFailed(bytes);

// 0xf4a3e629
error OperatorDAInputLengthTooSmall(uint256 operatorDAInputLength, uint256 blobDataOffset);

// 0xbeb96791
error InvalidNumberOfBlobs(uint256 blobsProvided, uint256 maxBlobsSupported);

// 0xcd384e46
error InvalidBlobsHashes(uint256 operatorDAInputLength, uint256 blobsProvided);

// 0xe9e79528
error InvalidL2DAOutputHash();

// 0x3db6e664
error OneBlobWithCalldata();

// 0x2dc9747d
error PubdataInputTooSmall(uint256 pubdataInputLength, uint256 blobCommitmentSize);

// 0x9044dff9
error PubdataLengthTooBig(uint256 pubdataLength, uint256 blobSizeBytes);

// 0x5513177c
error InvalidPubdataHash(bytes32 fullPubdataHash, bytes32 pubdata);

// 0xc771423e
error BlobCommitmentNotPublished();

// 0x5717f940
error InvalidPubdataSource(uint8 pubdataSource);
// 0x52595598
error ValL1DAWrongInputLength(uint256 inputLength, uint256 expectedLength);
Loading

0 comments on commit e14c496

Please sign in to comment.