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

feat: ZKChain and Gateway Upgrade Audit (#1052) #1147

Merged
merged 275 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
275 commits
Select commit Hold shift + click to select a range
fd4aebc
fix: zksync-ethers v5 dependency (#702)
benceharomi Aug 15, 2024
f1a8c2d
Kl/stmdt counterpart fix EVM-701 (#693)
kelemeno Aug 15, 2024
df1c5c8
fix: move hyperchain mapping EVM-709 (#704)
kelemeno Aug 16, 2024
acd603a
bridgehub small fixes, some cleanup
kelemeno Aug 16, 2024
ad92d47
Merge branch 'kl/sync-layer-reorg' of ssh://github.com/matter-labs/er…
kelemeno Aug 16, 2024
7d4b79c
fix: EVM-708 bridge fixes (#703)
kelemeno Aug 16, 2024
4c82e7d
Limitations for the l2 migrated chain (#707)
StanislavBreadless Aug 16, 2024
6d0ceb9
small fixes
kelemeno Aug 16, 2024
a738dc8
Merge branch 'kl/sync-layer-reorg' of ssh://github.com/matter-labs/er…
kelemeno Aug 16, 2024
c168183
more fixes
kelemeno Aug 16, 2024
a9a4646
typo
kelemeno Aug 16, 2024
ff10238
Stas issues
kelemeno Aug 16, 2024
d4bb8c5
removed unsued function + some changes
StanislavBreadless Aug 16, 2024
2a22e23
fixes
kelemeno Aug 16, 2024
590d207
fix some legacy methods
StanislavBreadless Aug 17, 2024
83cd458
fmt
StanislavBreadless Aug 17, 2024
42e7e0a
additional changes
StanislavBreadless Aug 18, 2024
aff1f4e
fmt
StanislavBreadless Aug 18, 2024
8099c0e
commented out code
StanislavBreadless Aug 19, 2024
ce27e0b
lint fix
StanislavBreadless Aug 19, 2024
ec64d85
should work
StanislavBreadless Aug 19, 2024
ea24b02
move some methods around
StanislavBreadless Aug 19, 2024
e58a3ee
fmt
StanislavBreadless Aug 19, 2024
d0a4401
remove useless change
StanislavBreadless Aug 19, 2024
ade586e
codespell
StanislavBreadless Aug 19, 2024
9e52539
router
StanislavBreadless Aug 19, 2024
8e59135
upd some files
StanislavBreadless Aug 19, 2024
859eed8
fix tests
StanislavBreadless Aug 19, 2024
568d65c
Merge remote-tracking branch 'origin/sb-sync-layer-reorg-stable-sync-…
StanislavBreadless Aug 19, 2024
a94a1b1
fmt
StanislavBreadless Aug 19, 2024
e7865bc
Merge pull request #712 from matter-labs/sb-sync-layer-reorg-stable-s…
StanislavBreadless Aug 19, 2024
9ebe7aa
fix lint
StanislavBreadless Aug 19, 2024
f105566
fix sys contracts tests
StanislavBreadless Aug 19, 2024
0640579
lint
StanislavBreadless Aug 19, 2024
ad726f7
fix
StanislavBreadless Aug 19, 2024
fa16bcb
fix
StanislavBreadless Aug 19, 2024
d50bf31
Merge pull request #714 from matter-labs/sb-fix-sl-stable
StanislavBreadless Aug 19, 2024
6a5dada
Merge branch 'sync-layer-stable' into sb-reduce-owner-footprint-on-ge…
StanislavBreadless Aug 19, 2024
1b8393b
fix check hashes
StanislavBreadless Aug 20, 2024
3de3430
Remove Base Token Address from Chain Registration (#700)
Raid5594 Aug 20, 2024
a91bc7a
Merge pull request #711 from matter-labs/sb-reduce-owner-footprint-on…
StanislavBreadless Aug 20, 2024
5853c3a
feat(consensus): add L2 registry contract (BFT-434) (#555) (#718)
pompon0 Aug 20, 2024
8f4aad4
Merge pull request #719 from matter-labs/sync-layer-stable
StanislavBreadless Aug 20, 2024
9b24cce
merge dev into the kl sync layer reorg
StanislavBreadless Aug 20, 2024
66e8494
fix sc build
StanislavBreadless Aug 20, 2024
47495d1
fix some lints
StanislavBreadless Aug 20, 2024
def5d47
fix lint
StanislavBreadless Aug 20, 2024
336e40c
Merge pull request #721 from matter-labs/sb-merge-dev-kl-reorg
StanislavBreadless Aug 20, 2024
fb536f2
fix chainRegistered
kelemeno Aug 20, 2024
21a10e0
gw fixes
StanislavBreadless Aug 20, 2024
86d2cc0
script fixes
kelemeno Aug 20, 2024
092d198
local zk fmt breaks...
kelemeno Aug 20, 2024
ed036a2
fmt
StanislavBreadless Aug 21, 2024
792d059
fix comment
StanislavBreadless Aug 21, 2024
7ef7a6d
fmt
StanislavBreadless Aug 21, 2024
739fabb
some contract fixes
kelemeno Aug 21, 2024
d7928ba
commented out code
kelemeno Aug 21, 2024
8b45eff
some more fixes
kelemeno Aug 21, 2024
95f5085
forgot await
kelemeno Aug 21, 2024
4d5cdc9
undo getL1ChainId, its async
kelemeno Aug 21, 2024
c1675c3
fix tests
StanislavBreadless Aug 21, 2024
96fa8e4
wip
StanislavBreadless Aug 21, 2024
c7b7123
foundry test fixes
kelemeno Aug 21, 2024
1e13d50
add a getAssetId function
kelemeno Aug 21, 2024
e7442e6
Merge pull request #725 from matter-labs/sb-some-gw-messaing-fixes
StanislavBreadless Aug 21, 2024
d29195b
first round of conflict resolution
StanislavBreadless Aug 21, 2024
9e19b5a
system contracts compile
StanislavBreadless Aug 21, 2024
a7a10ae
l2 contracts compile
StanislavBreadless Aug 21, 2024
ad7c0ad
Stas issue fixes
kelemeno Aug 21, 2024
d31866a
Merge branch 'kl/sync-layer-reorg' of ssh://github.com/matter-labs/er…
kelemeno Aug 21, 2024
3274507
fix remappings
Deniallugo Aug 21, 2024
37245fa
foundry test and small fixes
kelemeno Aug 21, 2024
a7e3d0a
linting
kelemeno Aug 21, 2024
daf396e
make l1 contracts compile
StanislavBreadless Aug 21, 2024
a59077c
script fix
kelemeno Aug 21, 2024
1d62e8e
foundry test are running
StanislavBreadless Aug 21, 2024
8a2d7c8
Merge branch 'kl/script-fixes' of ssh://github.com/matter-labs/era-co…
kelemeno Aug 21, 2024
391fa4d
fix: script fixes (#726)
kelemeno Aug 21, 2024
70a0660
Merge branch 'sync-layer-stable' of ssh://github.com/matter-labs/era-…
kelemeno Aug 21, 2024
2b2af24
foundry tests pass (though some were commented out)
StanislavBreadless Aug 21, 2024
d1b5149
Merge branch 'sync-layer-stable' of ssh://github.com/matter-labs/era-…
kelemeno Aug 21, 2024
00f7d8e
partial l1 test fix
StanislavBreadless Aug 21, 2024
446d391
Add admin role to shared bridge (#727)
StanislavBreadless Aug 21, 2024
94b2646
chore: Kl/merge-stable (#730)
kelemeno Aug 21, 2024
5ec24e2
Kl/merge-stable2 (#731)
kelemeno Aug 21, 2024
8421abc
forceDeploymetns data
kelemeno Aug 21, 2024
095a55a
bad merge
StanislavBreadless Aug 22, 2024
4e084b7
merge kl reorg branch
StanislavBreadless Aug 22, 2024
ab605b2
foundry tests pass
StanislavBreadless Aug 22, 2024
9e0c329
make more tests pass
StanislavBreadless Aug 22, 2024
377d0aa
fmt
StanislavBreadless Aug 22, 2024
9a168a6
Merge branch 'kl/sync-layer-reorg-dev' into kl/sync-layer-reorg-foundry
StanislavBreadless Aug 22, 2024
a80a667
message root fix
kelemeno Aug 22, 2024
4255c63
renaming and some fixes
kelemeno Aug 22, 2024
51d5dc4
lint
kelemeno Aug 22, 2024
f741346
wip
StanislavBreadless Aug 22, 2024
f617301
erc20 tests in foundry work
StanislavBreadless Aug 22, 2024
0d7ee23
aggregated root return value
kelemeno Aug 22, 2024
d2f83db
cover most of weth tsts
StanislavBreadless Aug 22, 2024
ebfb6d2
port the rest of the tests
StanislavBreadless Aug 22, 2024
c90c9f6
remove old tests
StanislavBreadless Aug 23, 2024
3c1b796
old proof support
StanislavBreadless Aug 23, 2024
6225350
unit tests
StanislavBreadless Aug 23, 2024
5e1ada2
fix lint
StanislavBreadless Aug 23, 2024
774ef90
fix comment
StanislavBreadless Aug 23, 2024
7931924
Merge pull request #736 from matter-labs/sb-support-old-proving-format
StanislavBreadless Aug 26, 2024
a4a2b06
add a few events for migration
StanislavBreadless Aug 26, 2024
e05866e
ensure that the STM has to be whitelisted before it is used
StanislavBreadless Aug 26, 2024
18f66ba
some fixes
StanislavBreadless Aug 26, 2024
7c8ef21
fix lint
StanislavBreadless Aug 26, 2024
9a3b546
rename event
StanislavBreadless Aug 26, 2024
b6d6c47
lint
StanislavBreadless Aug 26, 2024
e5b44c6
remove unused methods from validator timelock and executor
StanislavBreadless Aug 26, 2024
a478e2e
some more fixes
StanislavBreadless Aug 26, 2024
823ef65
Merge remote-tracking branch 'origin/sb-set-of-fixes-2' into sb-set-o…
StanislavBreadless Aug 26, 2024
3f17ff8
fix compile
StanislavBreadless Aug 26, 2024
caf4192
fix some more stuff
StanislavBreadless Aug 26, 2024
ae9add5
lint
StanislavBreadless Aug 26, 2024
dc1da58
migrate tests
StanislavBreadless Aug 26, 2024
60b7fc4
lint fix
StanislavBreadless Aug 26, 2024
2071f78
test
StanislavBreadless Aug 26, 2024
d5ecc4a
fmt
StanislavBreadless Aug 26, 2024
075eed8
Merge pull request #737 from matter-labs/sb-set-of-fixes-2
StanislavBreadless Aug 27, 2024
3a4fc67
make scripts work with the server
StanislavBreadless Aug 27, 2024
5cb5a03
sync with sync-layer-stable
StanislavBreadless Aug 27, 2024
d273ebf
fmt
StanislavBreadless Aug 27, 2024
95c501b
Merge pull request #744 from matter-labs/sb-port-kl/sync-layer-reorg
StanislavBreadless Aug 27, 2024
709bd86
Merge pull request #746 from matter-labs/sync-layer-stable
StanislavBreadless Aug 27, 2024
c82a950
sync with dev
StanislavBreadless Aug 28, 2024
7bcf8ac
sync with kl/sync-layer-reorg
StanislavBreadless Aug 28, 2024
a102e75
fix l1 tests
StanislavBreadless Aug 28, 2024
1dfc1ef
fmt
StanislavBreadless Aug 28, 2024
ad046e0
most of lints
StanislavBreadless Aug 28, 2024
4ac4e01
tmp: submodules work
StanislavBreadless Aug 28, 2024
d77b6a8
remove forge std
StanislavBreadless Aug 28, 2024
60935d3
remove l1-contracts/lib/murky
StanislavBreadless Aug 28, 2024
2c03a8d
remove mode subdmoules
StanislavBreadless Aug 28, 2024
f3e83dd
fix unit tests
StanislavBreadless Aug 28, 2024
8b025a4
fmt
StanislavBreadless Aug 28, 2024
60a1f7b
fix ci
StanislavBreadless Aug 28, 2024
f3a9481
fix spelling
StanislavBreadless Aug 28, 2024
fa4baf0
check hashes
StanislavBreadless Aug 28, 2024
6fa9393
better compare
StanislavBreadless Aug 28, 2024
8632559
correct address
StanislavBreadless Aug 28, 2024
2d92a68
comments
StanislavBreadless Aug 28, 2024
277d61d
fix addr
StanislavBreadless Aug 28, 2024
955979c
lint
StanislavBreadless Aug 28, 2024
10ec8ba
Merge pull request #749 from matter-labs/kl/sync-layer-reorg-dev
StanislavBreadless Aug 28, 2024
ac415e2
Merge pull request #753 from matter-labs/kl/sync-layer-reorg
StanislavBreadless Aug 28, 2024
03644e6
Merge branch 'kl/sync-layer-reorg' into kl/sync-layer-reorg-foundry
StanislavBreadless Aug 29, 2024
a557c01
upd workflow
StanislavBreadless Aug 29, 2024
487dd71
forge install: v2-testnet-contracts
StanislavBreadless Aug 29, 2024
4bac7cb
wip
StanislavBreadless Aug 29, 2024
1a2390c
forge install: @matterlabs/zksync-contracts
StanislavBreadless Aug 29, 2024
2d9ad08
using foundry deps
StanislavBreadless Aug 29, 2024
bc54d47
remove unneeded changes
StanislavBreadless Aug 29, 2024
e4689f0
wip
StanislavBreadless Aug 29, 2024
0a5e318
fix typo
StanislavBreadless Aug 29, 2024
6775587
install foundry zksync in ci
StanislavBreadless Aug 29, 2024
12cb8d0
fix lint
StanislavBreadless Aug 29, 2024
db7eafb
more efficient forge install
StanislavBreadless Aug 29, 2024
e70b722
fmt
StanislavBreadless Aug 29, 2024
e572c91
compile sc contracts also
StanislavBreadless Aug 29, 2024
dfd969c
Merge pull request #755 from matter-labs/kl/sync-layer-reorg-foundry
StanislavBreadless Aug 29, 2024
c905dd3
sync with stable
StanislavBreadless Aug 29, 2024
f17d7e1
Merge branch 'kl/sync-layer-reorg' into kl/migrate-back-from-gw
StanislavBreadless Aug 29, 2024
8affc3c
fix compile
StanislavBreadless Aug 29, 2024
adc2e76
Merge pull request #706 from matter-labs/kl/migrate-back-from-gw
StanislavBreadless Aug 29, 2024
3301a13
add ability to recover from failed migration (#715)
koloz193 Aug 29, 2024
de2cca7
sync with stable
StanislavBreadless Aug 29, 2024
464382e
fix compile
StanislavBreadless Aug 29, 2024
c05daf6
Fixed yarn clean - to remove zksync artifacts too
mm-zk Aug 30, 2024
262ee7e
Merge pull request #759 from matter-labs/mmzk_0830_fix_cleanup
StanislavBreadless Aug 30, 2024
989f2c1
L2 verifier support (#756)
StanislavBreadless Aug 30, 2024
d669a5f
Merge pull request #758 from matter-labs/sb-sync-sync-layer-stable
StanislavBreadless Aug 30, 2024
b212535
sync with kl sync layer reorg
StanislavBreadless Aug 30, 2024
840df35
fix comile
StanislavBreadless Aug 30, 2024
9fa2d66
fix lint
StanislavBreadless Aug 30, 2024
f469e7c
fix script
StanislavBreadless Aug 30, 2024
9d319e7
Merge branch 'sync-layer-stable' into kl/message-root-update
StanislavBreadless Aug 30, 2024
73ddd6d
Merge pull request #724 from matter-labs/kl/message-root-update
StanislavBreadless Aug 30, 2024
d368769
feat: Deploy ConsensusRegistry through L1 to L2 transaction (BFT-504)…
aakoshh Sep 2, 2024
3a1aecc
Fix token info upon migration (#760)
StanislavBreadless Sep 2, 2024
7f2c27a
Small PR to Fix "Ethers" and "ETH" encoding (#762)
Raid5594 Sep 3, 2024
78b0ce8
STM -> CTM
StanislavBreadless Sep 4, 2024
213f990
chore: Kl/merge-dev-sync-layer-stable (#763)
kelemeno Sep 4, 2024
249e012
Merge branch 'kl/sync-layer-reorg' into sb-rename-stm
StanislavBreadless Sep 4, 2024
28aadaa
migrate in script files as well
StanislavBreadless Sep 4, 2024
e8d47b4
l1 foundry test work
StanislavBreadless Sep 4, 2024
ae911bb
fix ts tests
StanislavBreadless Sep 4, 2024
b23bf7c
lint
StanislavBreadless Sep 4, 2024
566a54b
Resolve some of the leftover todos (#765)
StanislavBreadless Sep 5, 2024
9d1ce13
fix lib to remove it from coverage report
StanislavBreadless Sep 5, 2024
6fff2b1
sync with base
StanislavBreadless Sep 5, 2024
af14533
recalc hashes
StanislavBreadless Sep 5, 2024
aab2f77
toml file
StanislavBreadless Sep 5, 2024
3d6e02f
Set foundry optimizer_runs (#770)
perekopskiy Sep 5, 2024
42933cd
Merge pull request #766 from matter-labs/sb-rename-stm
StanislavBreadless Sep 5, 2024
4a062d0
Rename hyperchain -> ZK chain (#771)
StanislavBreadless Sep 5, 2024
8b5b296
Implement restriction to allow limiting chain admin in power (#699)
StanislavBreadless Sep 5, 2024
c95f623
sync with dev
StanislavBreadless Sep 6, 2024
93ed4dc
fix l1 compile
StanislavBreadless Sep 6, 2024
265166b
fix l1 foundry tests
StanislavBreadless Sep 6, 2024
1a23102
fix l2 compile
StanislavBreadless Sep 6, 2024
bd438c5
fix lint
StanislavBreadless Sep 6, 2024
99e9a0a
hopefully fix ci
StanislavBreadless Sep 6, 2024
2929483
hopefully fix ci 2
StanislavBreadless Sep 6, 2024
a1705ab
delete duplicated contract
StanislavBreadless Sep 6, 2024
6892ccc
Add admin permission to add custom base tokens (#776)
vladbochok Sep 6, 2024
b6c7130
merge main into dev
StanislavBreadless Sep 6, 2024
0fa0fa2
foundry tests pass
StanislavBreadless Sep 6, 2024
00ddc06
fix compile for registry
StanislavBreadless Sep 6, 2024
b6766b0
Merge pull request #777 from matter-labs/sb-merge-dev-kl-sync-layer-r…
StanislavBreadless Sep 6, 2024
ef33539
lint
StanislavBreadless Sep 6, 2024
dccc114
Remove most info from relayed L1->GW priority ops (#775)
StanislavBreadless Sep 6, 2024
b653ac8
Merge pull request #778 from matter-labs/sb-merge-main-to-dev
StanislavBreadless Sep 6, 2024
cb3c177
sync with reorg
StanislavBreadless Sep 6, 2024
23f5e3c
fmt
StanislavBreadless Sep 6, 2024
cb42ae4
Merge pull request #779 from matter-labs/sb-sync-reorg-with-stable
StanislavBreadless Sep 6, 2024
49868af
Change Executor.sol interface (#780)
vladbochok Sep 9, 2024
bebdefc
(feat): add tx filterer contract (#772)
Raid5594 Sep 10, 2024
f95beef
Ra/split asset router (#595)
Raid5594 Sep 10, 2024
8479868
chore: merge stable (#785)
kelemeno Sep 10, 2024
d1b7e16
Update l1-contracts/contracts/bridge/L1Nullifier.sol
kelemeno Sep 10, 2024
e741471
Update l1-contracts/contracts/bridge/asset-router/IL1AssetRouter.sol
kelemeno Sep 10, 2024
a42b991
fix: vlad issues (#788)
kelemeno Sep 10, 2024
2508f36
Recover some tests (#789)
StanislavBreadless Sep 10, 2024
b3564ef
Kl/chain balance fix (#786)
kelemeno Sep 10, 2024
1404dc0
Merge branch 'dev' of ssh://github.com/matter-labs/era-contracts into…
kelemeno Sep 10, 2024
cc3b2ac
chore: merge main (#790)
kelemeno Sep 10, 2024
8155711
Merge branch 'dev' of ssh://github.com/matter-labs/era-contracts into…
kelemeno Sep 10, 2024
c0d45fa
test fixes
kelemeno Sep 10, 2024
6de2963
Merge pull request #791 from matter-labs/kl/merge-dev
StanislavBreadless Sep 10, 2024
07d0462
Fixes (#792)
vladbochok Sep 11, 2024
1673186
sync head with base
StanislavBreadless Sep 11, 2024
eb3583a
delete unneeded files
StanislavBreadless Sep 11, 2024
e5727a0
Sync audit head with base (#797)
StanislavBreadless Sep 11, 2024
ef318e2
Merge pull request #798 from matter-labs/sb-sync-head-base
StanislavBreadless Sep 11, 2024
8208402
Better governance protection (audit) (#822)
StanislavBreadless Sep 26, 2024
f72d206
feat: ZKChain and Gateway Upgrade Audit (#1052)
Raid5594 Dec 12, 2024
7fff748
fix: CI + lint
Dec 13, 2024
dc477e0
fix: hardhat config
Dec 13, 2024
0f90c38
(fix): revert changes to CI
Dec 13, 2024
34af433
(fix): test lcov argument
Dec 13, 2024
360e9d1
fix ci
Dec 13, 2024
0810ca1
resolve merge conflicts
Dec 18, 2024
a70eae5
fixes
Dec 18, 2024
65a4db2
system contracts fix
Dec 18, 2024
2c2e16f
fixes
Dec 18, 2024
b3dc3ec
fix
Dec 18, 2024
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
26 changes: 11 additions & 15 deletions .github/workflows/l1-contracts-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ jobs:
- name: Build da-contracts artifacts
run: yarn da build:foundry

- name: Build l1 artifacts
run: yarn l1 build

- name: Create cache
uses: actions/cache/save@v3
with:
Expand Down Expand Up @@ -287,18 +284,17 @@ jobs:
- name: Run coverage
run: FOUNDRY_PROFILE=default yarn test:foundry && FOUNDRY_PROFILE=default yarn coverage:foundry --report summary --report lcov

# 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
# 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/bridge/asset-router/L1AssetRouter.sol' 'contracts/dev-contracts/*' '../lib/forge-std/*' '../lib/murky/*' 'lib/*' '../lib/*' 'lib/' --ignore-errors unused --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
Expand Down
13 changes: 3 additions & 10 deletions l1-contracts/contracts/bridge/L1ERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {IL1AssetRouter} from "./asset-router/IL1AssetRouter.sol";
import {L2ContractHelper} from "../common/libraries/L2ContractHelper.sol";
import {ReentrancyGuard} from "../common/ReentrancyGuard.sol";

import {EmptyDeposit, WithdrawalAlreadyFinalized, TokensWithFeesNotSupported, ETHDepositNotSupported, ApprovalFailed} from "../common/L1ContractErrors.sol";
import {EmptyDeposit, WithdrawalAlreadyFinalized, TokensWithFeesNotSupported, ETHDepositNotSupported} from "../common/L1ContractErrors.sol";
import {ETH_TOKEN_ADDRESS} from "../common/Config.sol";

/// @author Matter Labs
Expand Down Expand Up @@ -203,11 +203,7 @@ contract L1ERC20Bridge is IL1ERC20Bridge, ReentrancyGuard {
_l2TxGasPerPubdataByte: _l2TxGasPerPubdataByte,
_refundRecipient: _refundRecipient
});
// clearing approval
bool success = IERC20(_l1Token).approve(address(L1_ASSET_ROUTER), 0);
if (!success) {
revert ApprovalFailed();
}

depositAmount[msg.sender][_l1Token][l2TxHash] = _amount;
emit DepositInitiated({
l2DepositTxHash: l2TxHash,
Expand All @@ -227,10 +223,7 @@ contract L1ERC20Bridge is IL1ERC20Bridge, ReentrancyGuard {
function _approveFundsToAssetRouter(address _from, IERC20 _token, uint256 _amount) internal returns (uint256) {
uint256 balanceBefore = _token.balanceOf(address(this));
_token.safeTransferFrom(_from, address(this), _amount);
bool success = _token.approve(address(L1_ASSET_ROUTER), _amount);
if (!success) {
revert ApprovalFailed();
}
_token.forceApprove(address(L1_ASSET_ROUTER), _amount);
uint256 balanceAfter = _token.balanceOf(address(this));

return balanceAfter - balanceBefore;
Expand Down
14 changes: 7 additions & 7 deletions l1-contracts/contracts/bridge/L1Nullifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@ contract L1Nullifier is IL1Nullifier, ReentrancyGuard, Ownable2StepUpgradeable,
address baseToken = BRIDGE_HUB.baseToken(_chainId);
transferData = DataEncoding.encodeBridgeMintData({
_originalCaller: address(0),
_l2Receiver: l1Receiver,
_l1Token: baseToken,
_remoteReceiver: l1Receiver,
_originToken: baseToken,
_amount: amount,
_erc20Metadata: new bytes(0)
});
Expand All @@ -598,15 +598,15 @@ contract L1Nullifier is IL1Nullifier, ReentrancyGuard, Ownable2StepUpgradeable,
assetId = DataEncoding.encodeNTVAssetId(block.chainid, l1Token);
transferData = DataEncoding.encodeBridgeMintData({
_originalCaller: address(0),
_l2Receiver: l1Receiver,
_l1Token: l1Token,
_remoteReceiver: l1Receiver,
_originToken: l1Token,
_amount: amount,
_erc20Metadata: new bytes(0)
});
} else if (bytes4(functionSignature) == IAssetRouterBase.finalizeDeposit.selector) {
// The data is expected to be at least 36 bytes long to contain assetId.
if (_l2ToL1message.length < 36) {
revert WrongMsgLength(36, _l2ToL1message.length);
// The data is expected to be at least 68 bytes long to contain assetId.
if (_l2ToL1message.length < 68) {
revert WrongMsgLength(68, _l2ToL1message.length);
}
// slither-disable-next-line unused-return
(, offset) = UnsafeBytes.readUint256(_l2ToL1message, offset); // originChainId, not used for L2->L1 txs
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/contracts/bridge/L2WrappedBaseToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ contract L2WrappedBaseToken is ERC20PermitUpgradeable, IL2WrappedBaseToken, IBri
/// Always reverts instead of minting anything!
/// Note: Use `deposit`/`depositTo` methods instead.
// solhint-disable-next-line no-unused-vars
function bridgeMint(address _to, uint256 _amount) external override onlyBridge {
function bridgeMint(address _to, uint256 _amount) external view override onlyBridge {
revert BridgeMintNotImplemented();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ abstract contract AssetRouterBase is IAssetRouterBase, Ownable2StepUpgradeable,
Internal Functions
//////////////////////////////////////////////////////////////*/

function _setAssetHandler(bytes32 _assetId, address _assetHandlerAddress) internal {
assetHandlerAddress[_assetId] = _assetHandlerAddress;
emit AssetHandlerRegistered(_assetId, _assetHandlerAddress);
}

/// @dev send the burn message to the asset
/// @notice Forwards the burn request for specific asset to respective asset handler.
/// @param _chainId The chain ID of the ZK chain to which to deposit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ interface IAssetRouterBase {
bytes bridgeMintCalldata
);

event BridgehubWithdrawalInitiated(
uint256 chainId,
address indexed sender,
bytes32 indexed assetId,
bytes32 assetDataHash // Todo: What's the point of emitting hash?
);

event AssetHandlerRegisteredInitial(
bytes32 indexed assetId,
address indexed assetHandlerAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ interface IL1AssetRouter is IAssetRouterBase, IL1SharedBridgeLegacy {
bytes32 indexed additionalData
);

event LegacyDepositInitiated(
uint256 indexed chainId,
bytes32 indexed l2DepositTxHash,
address indexed from,
address to,
address l1Asset,
uint256 amount
);

/// @notice Initiates a deposit by locking funds on the contract and sending the request
/// of processing an L2 transaction where tokens would be minted.
/// @dev If the token is bridged for the first time, the L2 token contract will be deployed. Note however, that the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ interface IL2AssetRouter is IAssetRouterBase {
/// @dev Used to set the assetHandlerAddress for a given assetId.
/// @dev Will be used by ZK Gateway
function setAssetHandlerAddress(uint256 _originChainId, bytes32 _assetId, address _assetAddress) external;

/// @notice Function that allows native token vault to register itself as the asset handler for
/// a legacy asset.
/// @param _assetId The assetId of the legacy token.
function setLegacyTokenAssetHandler(bytes32 _assetId) external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

pragma solidity 0.8.24;

// solhint-disable reason-string, gas-custom-errors

import {IERC20} from "@openzeppelin/contracts-v4/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts-v4/token/ERC20/utils/SafeERC20.sol";

Expand Down
51 changes: 33 additions & 18 deletions l1-contracts/contracts/bridge/asset-router/L2AssetRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {IAssetRouterBase} from "./IAssetRouterBase.sol";
import {AssetRouterBase} from "./AssetRouterBase.sol";

import {IL2NativeTokenVault} from "../ntv/IL2NativeTokenVault.sol";
import {INativeTokenVault} from "../ntv/INativeTokenVault.sol";
import {IL2SharedBridgeLegacy} from "../interfaces/IL2SharedBridgeLegacy.sol";
import {IAssetHandler} from "../interfaces/IAssetHandler.sol";
import {IBridgedStandardToken} from "../interfaces/IBridgedStandardToken.sol";
Expand All @@ -19,7 +18,7 @@ import {AddressAliasHelper} from "../../vendor/AddressAliasHelper.sol";
import {L2_NATIVE_TOKEN_VAULT_ADDR, L2_BRIDGEHUB_ADDR} from "../../common/L2ContractAddresses.sol";
import {L2ContractHelper} from "../../common/libraries/L2ContractHelper.sol";
import {DataEncoding} from "../../common/libraries/DataEncoding.sol";
import {EmptyAddress, InvalidCaller, AmountMustBeGreaterThanZero, AssetIdNotSupported} from "../../common/L1ContractErrors.sol";
import {TokenNotLegacy, EmptyAddress, InvalidCaller, AmountMustBeGreaterThanZero, AssetIdNotSupported} from "../../common/L1ContractErrors.sol";

/// @author Matter Labs
/// @custom:security-contact [email protected]
Expand Down Expand Up @@ -69,6 +68,13 @@ contract L2AssetRouter is AssetRouterBase, IL2AssetRouter {
_;
}

modifier onlyNTV() {
if (msg.sender != L2_NATIVE_TOKEN_VAULT_ADDR) {
revert InvalidCaller(msg.sender);
}
_;
}

/// @dev Disable the initialization to prevent Parity hack.
/// @dev this contract is deployed in the L2GenesisUpgrade, and is meant as direct deployment without a proxy.
/// @param _l1AssetRouter The address of the L1 Bridge contract.
Expand Down Expand Up @@ -109,6 +115,12 @@ contract L2AssetRouter is AssetRouterBase, IL2AssetRouter {
_setAssetHandlerAddressThisChain(L2_NATIVE_TOKEN_VAULT_ADDR, _assetRegistrationData, _assetHandlerAddress);
}

function setLegacyTokenAssetHandler(bytes32 _assetId) external override onlyNTV {
// Note, that it is an asset handler, but not asset deployment tracker,
// which is located on L1.
_setAssetHandler(_assetId, L2_NATIVE_TOKEN_VAULT_ADDR);
}

/*//////////////////////////////////////////////////////////////
Receive transaction Functions
//////////////////////////////////////////////////////////////*/
Expand All @@ -131,26 +143,16 @@ contract L2AssetRouter is AssetRouterBase, IL2AssetRouter {
}

/*//////////////////////////////////////////////////////////////
LEGACY FUNCTIONS
INITIATTE DEPOSIT Functions
//////////////////////////////////////////////////////////////*/

/// @notice Initiates a withdrawal by burning funds on the contract and sending the message to L1
/// where tokens would be unlocked
/// @dev do not rely on this function, it will be deprecated in the future
/// @param _assetId The asset id of the withdrawn asset
/// @param _assetData The data that is passed to the asset handler contract
function withdraw(bytes32 _assetId, bytes memory _assetData) public override returns (bytes32) {
return _withdrawSender(_assetId, _assetData, msg.sender, true);
}

function withdrawToken(address _l2NativeToken, bytes memory _assetData) public returns (bytes32) {
bytes32 recordedAssetId = INativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR).assetId(_l2NativeToken);
uint256 recordedOriginChainId = INativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR).originChainId(recordedAssetId);
if (recordedOriginChainId == L1_CHAIN_ID) {
revert AssetIdNotSupported(recordedAssetId);
}
bytes32 assetId = _ensureTokenRegisteredWithNTV(_l2NativeToken);
return _withdrawSender(assetId, _assetData, msg.sender, true);
function withdraw(bytes32 _assetId, bytes calldata _assetData) external returns (bytes32) {
_withdrawSender(_assetId, _assetData, msg.sender, true);
}

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -313,16 +315,29 @@ contract L2AssetRouter is AssetRouterBase, IL2AssetRouter {
}

function _withdrawLegacy(address _l1Receiver, address _l2Token, uint256 _amount, address _sender) internal {
bytes32 assetId = DataEncoding.encodeNTVAssetId(L1_CHAIN_ID, l1TokenAddress(_l2Token));
bytes memory data = abi.encode(_amount, _l1Receiver);
address l1Address = l1TokenAddress(_l2Token);
if (l1Address == address(0)) {
revert TokenNotLegacy();
}
bytes32 assetId = DataEncoding.encodeNTVAssetId(L1_CHAIN_ID, l1Address);
bytes memory data = DataEncoding.encodeBridgeBurnData(_amount, _l1Receiver, _l2Token);
_withdrawSender(assetId, data, _sender, false);
}

/// @notice Legacy getL1TokenAddress.
/// @param _l2Token The address of token on L2.
/// @return The address of token on L1.
function l1TokenAddress(address _l2Token) public view returns (address) {
return IBridgedStandardToken(_l2Token).l1Address();
bytes32 assetId = IL2NativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR).assetId(_l2Token);
if (assetId == bytes32(0)) {
return address(0);
}
uint256 originChainId = IL2NativeTokenVault(L2_NATIVE_TOKEN_VAULT_ADDR).originChainId(assetId);
if (originChainId != L1_CHAIN_ID) {
return address(0);
}

return IBridgedStandardToken(_l2Token).originToken();
}

/// @notice Legacy function used for backward compatibility to return L2 wrapped token
Expand Down
29 changes: 20 additions & 9 deletions l1-contracts/contracts/bridge/interfaces/IL1Nullifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,6 @@ interface IL1Nullifier {

function nullifyChainBalanceByNTV(uint256 _chainId, address _token) external;

function finalizeWithdrawal(
uint256 _chainId,
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
uint16 _l2TxNumberInBatch,
bytes calldata _message,
bytes32[] calldata _merkleProof
) external;

/// @dev Withdraw funds from the initiated deposit, that failed when finalizing on L2.
/// @param _chainId The ZK chain id to which deposit was initiated.
/// @param _depositSender The address of the entity that initiated the deposit.
Expand All @@ -117,4 +108,24 @@ interface IL1Nullifier {
uint16 _l2TxNumberInBatch,
bytes32[] calldata _merkleProof
) external;

/// @notice Legacy function to finalize withdrawal via the same
/// interface as the old L1SharedBridge.
/// @dev Note, that we need to keep this interface, since the `L2AssetRouter`
/// will continue returning the previous address as the `l1SharedBridge`. The value
/// returned by it is used in the SDK for finalizing withdrawals.
/// @param _chainId The chain ID of the transaction to check
/// @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 _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 _chainId,
uint256 _l2BatchNumber,
uint256 _l2MessageIndex,
uint16 _l2TxNumberInBatch,
bytes calldata _message,
bytes32[] calldata _merkleProof
) external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@ pragma solidity 0.8.24;
/// @custom:security-contact [email protected]
interface IL1SharedBridgeLegacy {
function l2BridgeAddress(uint256 _chainId) external view returns (address);

event LegacyDepositInitiated(
uint256 indexed chainId,
bytes32 indexed l2DepositTxHash,
address indexed from,
address to,
address l1Asset,
uint256 amount
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

pragma solidity ^0.8.20;

import {UpgradeableBeacon} from "@openzeppelin/contracts-v4/proxy/beacon/UpgradeableBeacon.sol";

/// @author Matter Labs
/// @custom:security-contact [email protected]
interface IL2SharedBridgeLegacy {
Expand All @@ -14,8 +12,6 @@ interface IL2SharedBridgeLegacy {
uint256 amount
);

function l2TokenBeacon() external returns (UpgradeableBeacon);

function withdraw(address _l1Receiver, address _l2Token, uint256 _amount) external;

function l1TokenAddress(address _l2Token) external view returns (address);
Expand Down
3 changes: 1 addition & 2 deletions l1-contracts/contracts/bridge/ntv/IL1NativeTokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ pragma solidity 0.8.24;

import {IL1Nullifier} from "../interfaces/IL1Nullifier.sol";
import {INativeTokenVault} from "./INativeTokenVault.sol";
import {IL1AssetDeploymentTracker} from "../interfaces/IL1AssetDeploymentTracker.sol";

/// @title L1 Native token vault contract interface
/// @author Matter Labs
/// @custom:security-contact [email protected]
/// @notice The NTV is an Asset Handler for the L1AssetRouter to handle native tokens
// is IL1AssetHandler, IL1BaseTokenAssetHandler {
interface IL1NativeTokenVault is INativeTokenVault, IL1AssetDeploymentTracker {
interface IL1NativeTokenVault is INativeTokenVault {
/// @notice The L1Nullifier contract
function L1_NULLIFIER() external view returns (IL1Nullifier);

Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/contracts/bridge/ntv/L1NativeTokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ contract L1NativeTokenVault is IL1NativeTokenVault, IL1AssetHandler, NativeToken
bytes32,
address,
address _assetHandlerAddressOnCounterpart
) external view override onlyAssetRouter {
) external view onlyAssetRouter {
if (_assetHandlerAddressOnCounterpart != L2_NATIVE_TOKEN_VAULT_ADDR) {
revert WrongCounterpart();
}
Expand Down
Loading
Loading