Skip to content
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

Boojum integration #47

Merged
merged 126 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 77 commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
3e247eb
Fix: replaced hardhat run with ts-node (#18)
agolajko Sep 15, 2023
675be2e
Automatically runs license scan in all subdirectories with yarn.lock.…
yorik Sep 15, 2023
b14b9a6
Add FOS Templates (#20)
shahar4 Sep 16, 2023
6ce20c2
Merge branch 'main' into release-optimized-plonk-verifier
StanislavBreadless Sep 18, 2023
848bff9
Merge branch 'dev' into release-optimized-plonk-verifier
StanislavBreadless Sep 18, 2023
06e8353
boojum integration
StanislavBreadless Sep 18, 2023
d166d18
use optimized verifier
StanislavBreadless Sep 18, 2023
6d02695
chore(*): foundry init EVM-216
benceharomi Aug 9, 2023
aab9246
feat(foundry): test:foundry command added EVM-216
benceharomi Aug 9, 2023
85b2ed0
chore(foundry): remappings.txt added EVM-216
benceharomi Aug 9, 2023
5b2e0b3
feat(hardhat): solpp task created EVM-216
benceharomi Aug 9, 2023
b108f5d
test(foundry): UnsafeBytes test added EVM-216
benceharomi Aug 9, 2023
152b924
test(foundry): AllowList test added EVM-216
benceharomi Aug 11, 2023
81c587a
chore(tests): missing license identifiers EVM-216
benceharomi Aug 11, 2023
ac1b59b
chore(DiamondCutTest): renamed to DiamondCutTestContract EVM-216
benceharomi Aug 14, 2023
14e25e3
test(foundry): DiamondCut test added EVM-216
benceharomi Aug 15, 2023
b8020dd
test(foundry): Executor test Part-1 EVM-216
benceharomi Aug 17, 2023
3e7f3df
test(foundry): Executor test Part-2 EVM-216
benceharomi Aug 18, 2023
88016cb
test(foundry): a bit more randomness EVM-216
benceharomi Aug 18, 2023
0ef682b
fix(executor-test): fix after upgrade changes EVM-216
benceharomi Aug 22, 2023
0fc3388
test(foundry): Executor test Part-3 EVM-216
benceharomi Aug 23, 2023
a9d43fa
test(foundry): Executor test Part-4 EVM-216
benceharomi Aug 23, 2023
1f58257
test(foundry): Executor test Part-5 EVM-216
benceharomi Sep 4, 2023
2a0f601
chore(tests): renamed to follow foundry convention EVM-216
benceharomi Sep 5, 2023
38fb066
chore(test/foundry): directory organised EVM-216
benceharomi Sep 5, 2023
5a43248
test(Utils): packBatchTimestampAndBlockTimestamp and randomBytes32 EV…
benceharomi Sep 11, 2023
f2af121
test(Executing): less duplication EVM-216
benceharomi Sep 11, 2023
2e5ebfe
test(Committing): too long storage changes tests EVM-216
benceharomi Sep 11, 2023
5a86465
test(unit_tests): remove migrated hardhat tests EVM-216
benceharomi Sep 11, 2023
9ff25fc
chore(AllowList/Permission): test file renamed EVM-216
benceharomi Sep 11, 2023
17f62ba
lint(test): test formatting/linting scripts added EVM-216
benceharomi Sep 18, 2023
be3593d
lint(test): test files formatted/linted EVM-216
benceharomi Sep 18, 2023
df9bfb0
ci(ci.yml): foundry testing added EVM-216
benceharomi Sep 18, 2023
950b354
chore(test): explicit imports EVM-216
benceharomi Sep 18, 2023
536fb4b
chore(test): solidity 0.8.13 -> 0.8.17 EVM-216
benceharomi Sep 18, 2023
1a6d864
include full input
StanislavBreadless Sep 18, 2023
d1df4ec
fmt
StanislavBreadless Sep 19, 2023
0f706ff
fix unit tests
StanislavBreadless Sep 19, 2023
f76e807
Regenerate verifier with new VKs (#30)
ly0va Sep 20, 2023
82d1823
fix formatting
StanislavBreadless Sep 20, 2023
8f4bca8
port most of the fixes
StanislavBreadless Sep 25, 2023
9d577f5
fix weth init
StanislavBreadless Sep 25, 2023
9bd2411
Rename block -> batch where appropriate (#33)
StanislavBreadless Sep 27, 2023
3dd33b9
Non recursive L1 verifier mode (#37)
olesHolem Sep 27, 2023
6a2dfb6
Optimize Validator timelock
vladbochok Sep 27, 2023
4796b68
Block -> Batch
vladbochok Sep 27, 2023
fc3cc60
Merge branch 'dev' into bh-EVM-216-move-l1-tests-to-foundry
benceharomi Sep 27, 2023
c2dc75a
Merge branch 'dev' into boojum-integration
benceharomi Sep 27, 2023
008b905
Merge branch 'boojum-integration' into bh-EVM-216-move-l1-tests-to-fo…
benceharomi Sep 27, 2023
bac3d57
port fixes to boojum
StanislavBreadless Sep 27, 2023
46abc2a
fix tests and compilation
StanislavBreadless Sep 27, 2023
814dea6
provide security contact
StanislavBreadless Sep 27, 2023
b061351
update Verifer.sol to latest
akash-chandrakar Sep 27, 2023
6e1db7a
Merge branch 'boojum-integration' into vb-implement-optimisations-for…
vladbochok Sep 27, 2023
8faf111
Fix system logs processing (#44)
StanislavBreadless Sep 27, 2023
b520592
test(foundry): Executor tests updated to work with new changes
benceharomi Sep 28, 2023
b56680d
Merge remote-tracking branch 'origin/boojum-integration' into bh-EVM-…
benceharomi Sep 28, 2023
c50f533
Prettier
vladbochok Sep 28, 2023
5ee02b0
Fix tests
vladbochok Sep 28, 2023
24fb56b
Fix lints
vladbochok Sep 28, 2023
024971a
Remove redundant tests & fix l2 upgrade test
vladbochok Sep 28, 2023
6101b93
Merge pull request #26 from matter-labs/bh-EVM-216-move-l1-tests-to-f…
vladbochok Sep 28, 2023
b432a99
Merge branch 'boojum-integration' into vb-implement-optimisations-for…
vladbochok Sep 28, 2023
66cbe30
Increase number of allowed warnings
vladbochok Sep 28, 2023
0c46159
Merge pull request #43 from matter-labs/vb-implement-optimisations-fo…
vladbochok Sep 28, 2023
41681a7
Fix issue with finalizing withdrawal on WETH bridge
vladbochok Sep 28, 2023
6eeb34b
Merge pull request #48 from matter-labs/vb-fix-weth-bridge-issue
vladbochok Sep 28, 2023
f8d9390
decrease tx encoding space as it is now consumed by l1 messenger (#46)
StanislavBreadless Sep 28, 2023
3444e03
fix test
StanislavBreadless Sep 28, 2023
0a2b9cc
Merge pull request #50 from matter-labs/sb-fix-unit-tests
vladbochok Sep 28, 2023
f6664e5
update executor facet docs
koloz193 Sep 28, 2023
36cc7df
Merge pull request #51 from matter-labs/zk-doc-update
koloz193 Sep 28, 2023
d0502f6
Implement governance mechanism with timelock and security council (#42)
vladbochok Sep 28, 2023
e172af7
test(DiamondCut): selectors moved to Utils
benceharomi Sep 28, 2023
6771bf5
test(Bridge): l1WethBridge tests added
benceharomi Sep 28, 2023
e3a21db
lint(test): lints removed
benceharomi Sep 28, 2023
ff2faa7
fix(test): gettersFacet selectors fix
benceharomi Sep 28, 2023
7b88360
Merge branch 'boojum-integration' into update-verifier-to-fix-snark
StanislavBreadless Sep 28, 2023
5e04f88
test(L1WethBridge): fix -> admin added to diamondInit
benceharomi Sep 28, 2023
d16d19a
Merge branch 'boojum-integration' into update-verifier-to-fix-snark
StanislavBreadless Sep 29, 2023
a0da7f1
chore(getGettersSelectors): unnecessary return duplicate removed
benceharomi Sep 29, 2023
12a2fd7
Update template to include VK_RECURSIVE_FLAG_SLOT
akash-chandrakar Sep 29, 2023
092edee
update template
akash-chandrakar Sep 29, 2023
ef15f18
Add unit-tests for WETH token and WETH bridge
ly0va Sep 30, 2023
7bd6063
Add CI for L2 contracts
ly0va Sep 30, 2023
0bbbe0a
Fix workflow file
ly0va Sep 30, 2023
4d3f73f
Add tests for Governance
vladbochok Sep 30, 2023
e4df32a
fix(tests): Restore tests for executing operation twice
vladbochok Sep 30, 2023
68e3ebf
Merge branch 'boojum-integration' into vb-add-tests-for-governance
vladbochok Sep 30, 2023
7cecea9
fix(tests): Fix coverage in Foundry tests
vladbochok Oct 1, 2023
7b457ee
fix(contracts): Remove unused variable
vladbochok Oct 1, 2023
6e17064
Merge pull request #55 from matter-labs/vb-fix-foundry-coverage
vladbochok Oct 1, 2023
33d8e29
Update ethereum/test/foundry/unit/concrete/Governance/Executing.t.sol
vladbochok Oct 1, 2023
581ecd6
Update ethereum/test/foundry/unit/concrete/Governance/Authorization.t…
vladbochok Oct 1, 2023
a8a6c8c
Use [email protected] in CI
ly0va Oct 1, 2023
110a051
Add negative testcase for fallback()
ly0va Oct 1, 2023
c5b9f82
Add test for failed execution of operation
vladbochok Oct 1, 2023
ee2e7b6
Refactoring
vladbochok Oct 1, 2023
f7fb805
Add tests on reentrancy
vladbochok Oct 1, 2023
e6af6db
Add testcases for receive/fallback functions
vladbochok Oct 1, 2023
98441cc
100% Governance coverage + refactoring
vladbochok Oct 1, 2023
38de922
Fix warning in Validator timelock
vladbochok Oct 1, 2023
f6956df
Descrease number or allowed warnings
vladbochok Oct 1, 2023
2d18251
Merge pull request #56 from matter-labs/vb-remove-redundant-veriable
vladbochok Oct 1, 2023
046a0af
Merge branch 'vb-add-tests-for-governance' of https://github.com/matt…
vladbochok Oct 1, 2023
bf1d435
Fix review
vladbochok Oct 1, 2023
d8085ac
Merge pull request #53 from matter-labs/lyova-l2-contracts-unit-tests
vladbochok Oct 2, 2023
c1fd4bc
Shift public input by 4 bytes (#57)
StanislavBreadless Oct 2, 2023
33bcd51
Merge pull request #54 from matter-labs/vb-add-tests-for-governance
vladbochok Oct 2, 2023
b1f0af0
Update OMEGA
ly0va Oct 3, 2023
74b1e54
Fix non-recursive verifier test
ly0va Oct 3, 2023
dcd55e1
Update recursive verifier test
ly0va Oct 3, 2023
c6a76cd
Change OMEGA in the template
ly0va Oct 3, 2023
aca7475
Merge pull request #52 from matter-labs/update-verifier-to-fix-snark
ly0va Oct 3, 2023
6536730
Add CI check for generated verifier
ly0va Oct 3, 2023
89f3070
Fix rust in CI
ly0va Oct 3, 2023
239b243
Merge pull request #58 from matter-labs/lyova-add-ci-verifier-check
ly0va Oct 3, 2023
ee1139d
Updated snark wrapper verification key
mm-zk Oct 3, 2023
aa7a4e3
renamed file back
mm-zk Oct 3, 2023
b2e6601
Fixed issue with public key derivation added tests
mm-zk Oct 4, 2023
3489d2f
Fix lint
ly0va Oct 4, 2023
a39c50d
Rename executor test so that it's run with 'yarn test'
ly0va Oct 4, 2023
4706f71
Updated snark wrapper verification key (#60)
mm-zk Oct 4, 2023
36f239d
newline
mm-zk Oct 4, 2023
6930125
Merge branch 'boojum-integration' into mmzk_1003_v2_tests
mm-zk Oct 4, 2023
0bd80df
Merge pull request #61 from matter-labs/mmzk_1003_v2_tests
ly0va Oct 4, 2023
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
45 changes: 44 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
ethereum/cache
ethereum/typechain

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

Expand Down Expand Up @@ -103,3 +103,46 @@ jobs:

- name: Run tests
run: yarn test --no-compile

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

defaults:
run:
working-directory: ethereum

steps:
- name: Checkout the repository
uses: actions/checkout@v3
with:
submodules: "recursive"

- name: "Install Foundry"
uses: "foundry-rs/foundry-toolchain@v1"

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16.15.1
cache: yarn
cache-dependency-path: ethereum/yarn.lock

- name: Install yarn
run: npm install -g yarn

- name: Install dependencies
run: yarn install

- name: Restore artifacts cache
uses: actions/cache/restore@v3
with:
fail-on-cache-miss: true
key: artifacts-${{ github.sha }}
path: |
ethereum/artifacts
ethereum/cache
ethereum/typechain

- name: Run tests
run: forge test
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ethereum/lib/forge-std"]
path = ethereum/lib/forge-std
url = https://github.com/foundry-rs/forge-std
10 changes: 5 additions & 5 deletions SystemConfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"L2_TX_MAX_GAS_LIMIT": 80000000,
"MAX_PUBDATA_PER_BLOCK": 110000,
"MAX_PUBDATA_PER_BATCH": 110000,
"PRIORITY_TX_MAX_PUBDATA": 99000,
"FAIR_L2_GAS_PRICE": 500000000,
"L1_GAS_PER_PUBDATA_BYTE": 17,
"BLOCK_OVERHEAD_L2_GAS": 1200000,
"BLOCK_OVERHEAD_L1_GAS": 1000000,
"MAX_TRANSACTIONS_IN_BLOCK": 1024,
"BOOTLOADER_TX_ENCODING_SPACE": 485225,
"BATCH_OVERHEAD_L2_GAS": 1200000,
"BATCH_OVERHEAD_L1_GAS": 1000000,
"MAX_TRANSACTIONS_IN_BATCH": 1024,
"BOOTLOADER_TX_ENCODING_SPACE": 273132,
"L1_TX_INTRINSIC_L2_GAS": 167157,
"L1_TX_INTRINSIC_PUBDATA": 88,
"L1_TX_MIN_L2_GAS_BASE": 173484,
Expand Down
118 changes: 70 additions & 48 deletions docs/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ See the [documentation](https://era.zksync.io/docs/dev/fundamentals/rollups.html
- **Governor** - a privileged address that controls the upgradability of the network and sets other privileged
addresses.
- **Security council** - an address of the Gnosis multisig with the trusted owners that can decrease upgrade timelock.
- **Validator/Operator** - a privileged address that can commit/verify/execute L2 blocks.
- **Validator/Operator** - a privileged address that can commit/verify/execute L2 batches.
- **L2 batch (or just batch)** - An aggregation of multiple L2 blocks. Note, that while the API operates on L2 blocks, the prove system operates on batches, which represent a single proved VM execution, which typically contains multiple L2 blocks.
- **Facet** - implementation contract. The word comes from the EIP-2535.
- **Gas** - a unit that measures the amount of computational effort required to execute specific operations on the
zkSync Era network.
Expand All @@ -43,9 +44,9 @@ even an upgrade system is a separate facet that can be replaced.

One of the differences from the reference implementation is access freezability. Each of the facets has an associated
parameter that indicates if it is possible to freeze access to the facet. Privileged actors can freeze the **diamond**
(not a specific facet!) and all facets with the marker `isFreezable` should be inaccessible until the governor unfreezes
the diamond. Note that it is a very dangerous thing since the diamond proxy can freeze the upgrade system and then the
diamond will be frozen forever.
(not a specific facet!) and all facets with the marker `isFreezable` should be inaccessible until the governor or its owner
unfreezes the diamond. Note that it is a very dangerous thing since the diamond proxy can freeze the upgrade system and then
the diamond will be frozen forever.

#### DiamondInit

Expand All @@ -55,41 +56,33 @@ diamond constructor and is not saved in the diamond as a facet.
Implementation detail - function returns a magic value just like it is designed in
[EIP-1271](https://eips.ethereum.org/EIPS/eip-1271), but the magic value is 32 bytes in size.

#### DiamondCutFacet

These smart contracts manage the freezing/unfreezing and upgrades of the diamond proxy. That being said, the contract
must never be frozen.

Currently, freezing and unfreezing are implemented as access control functions. It is fully controlled by the governor
but can be changed later. The governor can call `freezeDiamond` to freeze the diamond and `unfreezeDiamond` to restore
it.

Another purpose of `DiamondCutFacet` is to upgrade the facets. The upgrading is split into 2-3 phases:

- `proposeTransparentUpgrade`/`proposeShadowUpgrade` - propose an upgrade with visible/hidden parameters.
- `cancelUpgradeProposal` - cancel the upgrade proposal.
- `securityCouncilUpgradeApprove` - approve the upgrade by the security council.
- `executeUpgrade` - finalize the upgrade.

The upgrade itself characterizes by three variables:

- `facetCuts` - a set of changes to the facets (adding new facets, removing facets, and replacing them).
- pair `(address _initAddress, bytes _calldata)` for initializing the upgrade by making a delegate call to
`_initAddress` with `_calldata` inputs.

#### GettersFacet

Separate facet, whose only function is providing `view` and `pure` methods. It also implements
[diamond loupe](https://eips.ethereum.org/EIPS/eip-2535#diamond-loupe) which makes managing facets easier.
This contract must never be frozen.

#### GovernanceFacet
#### AdminFacet

Controls changing the privileged addresses such as governor and validators or one of the system parameters (L2
bootloader bytecode hash, verifier address, verifier parameters, etc).
bootloader bytecode hash, verifier address, verifier parameters, etc), and it also manages the freezing/unfreezing and execution of
upgrades in the diamond proxy.

#### Governance

This contract manages operations (calls with preconditions) for governance tasks. The contract allows for operations to be scheduled,
executed, and canceled with appropriate permissions and delays. It is used for managing and coordinating upgrades and changes in all
zkSync Era governed contracts.

Each upgrade consists of two steps:

- Upgrade Proposal - The governor can schedule upgrades in two different manners:
- Fully transparent data. All implementation contracts and migration contracts are known to the community. The governor must wait
for the timelock to execute the upgrade.
- Shadow upgrade. The governor only shows the commitment for the upgrade. The upgrade can be executed only with security council
approval without timelock.
- Upgrade execution - perform the upgrade that was proposed.

At the current stage, the governor has permission to instantly change the key system parameters with `GovernanceFacet`.
Later such functionality will be removed and changing system parameters will be possible only via Diamond upgrade (see
_DiamondCutFacet_).

#### MailboxFacet

Expand Down Expand Up @@ -143,11 +136,11 @@ burn the funds on L2, allowing the user to reclaim them through the `finalizeEth
L2 -> L1 communication, in contrast to L1 -> L2 communication, is based only on transferring the information, and not on
the transaction execution on L1.

From the L2 side, there is a special zkEVM opcode that saves `l2ToL1Log` in the L2 block. A validator will send all
`l2ToL1Logs` when sending an L2 block to the L1 (see `ExecutorFacet`). Later on, users will be able to both read their
From the L2 side, there is a special zkEVM opcode that saves `l2ToL1Log` in the L2 batch. A validator will send all
`l2ToL1Logs` when sending an L2 batch to the L1 (see `ExecutorFacet`). Later on, users will be able to both read their
`l2ToL1logs` on L1 and _prove_ that they sent it.

From the L1 side, for each L2 block, a Merkle root with such logs in leaves is calculated. Thus, a user can provide
From the L1 side, for each L2 batch, a Merkle root with such logs in leaves is calculated. Thus, a user can provide
Merkle proof for each `l2ToL1Logs`.

_NOTE_: For each executed L1 -> L2 transaction, the system program necessarily sends an L2 -> L1 log. To verify the
Expand All @@ -164,24 +157,43 @@ this trick:

#### ExecutorFacet

A contract that accepts L2 blocks, enforces data availability and checks the validity of zk-proofs.
A contract that accepts L2 batches, enforces data availability and checks the validity of zk-proofs.

The state transition is divided into three stages:

- `commitBlocks` - check L2 block timestamp, process the L2 logs, save data for a block, and prepare data for zk-proof.
- `proveBlocks` - validate zk-proof.
- `executeBlocks` - finalize the state, marking L1 -> L2 communication processing, and saving Merkle tree with L2 logs.
- `commitBatches` - check L2 batch timestamp, process the L2 logs, save data for a batch, and prepare data for zk-proof.
- `proveBatches` - validate zk-proof.
- `executeBatches` - finalize the state, marking L1 -> L2 communication processing, and saving Merkle tree with L2 logs.

When a block is committed, we process L2 -> L1 logs. Here are the invariants that are expected there:
Each L2 -> L1 system log will have a key that is part of the following:
```solidity
enum SystemLogKey {
L2_TO_L1_LOGS_TREE_ROOT_KEY,
TOTAL_L2_TO_L1_PUBDATA_KEY,
STATE_DIFF_HASH_KEY,
PACKED_BATCH_AND_L2_BLOCK_TIMESTAMP_KEY,
PREV_BATCH_HASH_KEY,
CHAINED_PRIORITY_TXN_HASH_KEY,
NUMBER_OF_LAYER_1_TXS_KEY,
EXPECTED_SYSTEM_CONTRACT_UPGRADE_TX_HASH_KEY
}
```

- The only L2 -> L1 log from the `L2_SYSTEM_CONTEXT_ADDRESS`, with the `key == l2BlockTimestamp` and
`value == l2BlockHash`.
- Several (or none) logs from the `L2_KNOWN_CODE_STORAGE_ADDRESS` with the `key == bytecodeHash`, where bytecode is
marked as a known factory dependency.
- Several (or none) logs from the `L2_BOOTLOADER_ADDRESS` with the `key == canonicalTxHash` where `canonicalTxHash` is a
hash of processed L1 -> L2 transaction.
- Several (of none) logs from the `L2_TO_L1_MESSENGER` with the `value == hashedMessage` where `hashedMessage` is a hash
of an arbitrary-length message that is sent from L2
When a batch is committed, we process L2 -> L1 system logs. Here are the invariants that are expected there:

- In a given batch there will be either 7 or 8 system logs. The 8th log is only required for a protocol upgrade.
- There will be a single log for each key that is containted within `SystemLogKey`
- Three logs from the `L2_TO_L1_MESSENGER` with keys:
- `L2_TO_L1_LOGS_TREE_ROOT_KEY`
- `TOTAL_L2_TO_L1_PUBDATA_KEY`
- `STATE_DIFF_HASH_KEY`
- Two logs from `L2_SYSTEM_CONTEXT_SYSTEM_CONTRACT_ADDR` with keys:
- `PACKED_BATCH_AND_L2_BLOCK_TIMESTAMP_KEY`
- `PREV_BATCH_HASH_KEY`
- Two or three logs from `L2_BOOTLOADER_ADDRESS` with keys:
- `CHAINED_PRIORITY_TXN_HASH_KEY`
- `NUMBER_OF_LAYER_1_TXS_KEY`
- `EXPECTED_SYSTEM_CONTRACT_UPGRADE_TX_HASH_KEY`
- None logs from other addresses (may be changed in the future).

#### Bridges
Expand Down Expand Up @@ -230,13 +242,23 @@ the L1 recipient.
#### ValidatorTimelock

An intermediate smart contract between the validator EOA account and the zkSync smart contract. Its primary purpose is
to provide a trustless means of delaying block execution without modifying the main zkSync contract. zkSync actively
to provide a trustless means of delaying batch execution without modifying the main zkSync contract. zkSync actively
monitors the chain activity and reacts to any suspicious activity by freezing the chain. This allows time for
investigation and mitigation before resuming normal operations.

It is a temporary solution to prevent any significant impact of the validator hot key leakage, while the network is in
the Alpha stage.

This contract consists of four main functions `commitBatches`, `proveBatches`, `executeBatches`, and `revertBatches`, that
can be called only by the validator.

When the validator calls `commitBatches`, the same calldata will be propogated to the zkSync contract (`DiamondProxy` through
`call` where it invokes the `ExecutorFacet` through `delegatecall`), and also a timestamp is assigned to these batches to track
the time these batches are commited by the validator to enforce a delay between committing and execution of batches. Then, the
validator can prove the already commited batches regardless of the mentioned timestamp, and again the same calldata (related
to the `proveBatches` function) will be propogated to the zkSync contract. After, the `delay` is elapsed, the validator
is allowed to call `executeBatches` to propogate the same calldata to zkSync contract.

#### Allowlist

The auxiliary contract controls the permission access list. It is used in bridges and diamond proxies to control which
Expand Down
2 changes: 2 additions & 0 deletions ethereum/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/typechain
node_modules
./contracts/DS_Store
/artifacts-forge
/cache-forge
31 changes: 16 additions & 15 deletions ethereum/contracts/bridge/L1ERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import "../common/ReentrancyGuard.sol";
import "../vendor/AddressAliasHelper.sol";

/// @author Matter Labs
/// @custom:security-contact [email protected]
/// @notice Smart contract that allows depositing ERC20 tokens from Ethereum to zkSync Era
/// @dev It is standard implementation of ERC20 Bridge that can be used as a reference
/// for any other custom token bridges.
Expand All @@ -33,7 +34,7 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, AllowListed, ReentrancyGua
/// @dev zkSync smart contract that is used to operate with L2 via asynchronous L2 <-> L1 communication
IZkSync internal immutable zkSync;

/// @dev A mapping L2 block number => message number => flag
/// @dev A mapping L2 batch number => message number => flag
/// @dev Used to indicate that zkSync L2 -> L1 message was already processed
mapping(uint256 => mapping(uint256 => bool)) public isWithdrawalFinalized;

Expand Down Expand Up @@ -247,24 +248,24 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, AllowListed, ReentrancyGua
/// @param _depositSender The address of the deposit initiator
/// @param _l1Token The address of the deposited L1 ERC20 token
/// @param _l2TxHash The L2 transaction hash of the failed deposit finalization
/// @param _l2BlockNumber The L2 block number where the deposit finalization was processed
/// @param _l2BatchNumber The L2 batch number where the deposit finalization was processed
/// @param _l2MessageIndex The position in the L2 logs Merkle tree of the l2Log that was sent with the message
/// @param _l2TxNumberInBlock The L2 transaction number in a block, in which the log was sent
/// @param _l2TxNumberInBatch The L2 transaction number in a batch, in which the log was sent
/// @param _merkleProof The Merkle proof of the processing L1 -> L2 transaction with deposit finalization
function claimFailedDeposit(
address _depositSender,
address _l1Token,
bytes32 _l2TxHash,
uint256 _l2BlockNumber,
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
uint16 _l2TxNumberInBlock,
uint16 _l2TxNumberInBatch,
bytes32[] calldata _merkleProof
) external nonReentrant senderCanCallFunction(allowList) {
bool proofValid = zkSync.proveL1ToL2TransactionStatus(
_l2TxHash,
_l2BlockNumber,
_l2BatchNumber,
_l2MessageIndex,
_l2TxNumberInBlock,
_l2TxNumberInBatch,
_merkleProof,
TxStatus.Failure
);
Expand All @@ -284,34 +285,34 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, AllowListed, ReentrancyGua
}

/// @notice Finalize the withdrawal and release funds
/// @param _l2BlockNumber The L2 block number where the withdrawal was processed
/// @param _l2BatchNumber The L2 batch number where the withdrawal was processed
/// @param _l2MessageIndex The position in the L2 logs Merkle tree of the l2Log that was sent with the message
/// @param _l2TxNumberInBlock The L2 transaction number in a block, in which the log was sent
/// @param _l2TxNumberInBatch The L2 transaction number in the batch, in which the log was sent
/// @param _message The L2 withdraw data, stored in an L2 -> L1 message
/// @param _merkleProof The Merkle proof of the inclusion L2 -> L1 message about withdrawal initialization
function finalizeWithdrawal(
uint256 _l2BlockNumber,
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
uint16 _l2TxNumberInBlock,
uint16 _l2TxNumberInBatch,
bytes calldata _message,
bytes32[] calldata _merkleProof
) external nonReentrant senderCanCallFunction(allowList) {
require(!isWithdrawalFinalized[_l2BlockNumber][_l2MessageIndex], "pw");
require(!isWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex], "pw");

L2Message memory l2ToL1Message = L2Message({
txNumberInBlock: _l2TxNumberInBlock,
txNumberInBatch: _l2TxNumberInBatch,
sender: l2Bridge,
data: _message
});

(address l1Receiver, address l1Token, uint256 amount) = _parseL2WithdrawalMessage(l2ToL1Message.data);
// Preventing the stack too deep error
{
bool success = zkSync.proveL2MessageInclusion(_l2BlockNumber, _l2MessageIndex, l2ToL1Message, _merkleProof);
bool success = zkSync.proveL2MessageInclusion(_l2BatchNumber, _l2MessageIndex, l2ToL1Message, _merkleProof);
require(success, "nq");
}

isWithdrawalFinalized[_l2BlockNumber][_l2MessageIndex] = true;
isWithdrawalFinalized[_l2BatchNumber][_l2MessageIndex] = true;
// Withdraw funds
IERC20(l1Token).safeTransfer(l1Receiver, amount);

Expand Down
Loading
Loading