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

[DO NOT MERGE]: EVM emulator #1142

Draft
wants to merge 202 commits into
base: release-v25-protocol-defense
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 197 commits
Commits
Show all changes
202 commits
Select commit Hold shift + click to select a range
2ff4e59
Add Evm Equivalence support
jrchatruc Aug 7, 2024
dfadb34
Merge branch 'dev' into evm-equivalence-yul-new
jrchatruc Aug 8, 2024
aa30514
fmt
jrchatruc Aug 9, 2024
04f5920
Update support for evm simulator with latest changes
IAvecilla Aug 9, 2024
7487de0
Revert solidity version update
IAvecilla Aug 12, 2024
fb58ebb
Update solidity contracts version
IAvecilla Aug 12, 2024
90e7043
Calculate evm simulator address from compiled file when deploying
IAvecilla Aug 12, 2024
6b78beb
Comment out assert in bootloader to deploy evm contracts
IAvecilla Aug 14, 2024
7cce99c
Remove solhint line added by mistake
IAvecilla Aug 15, 2024
8eeffba
Update contracts to emit events on evm deployment
IAvecilla Aug 16, 2024
c662106
Merge remote-tracking branch 'origin/dev' into evm-equivalence-yul-new
IAvecilla Aug 19, 2024
be47154
Fix typos
IAvecilla Aug 19, 2024
207320e
Update tests and delete todos
IAvecilla Aug 20, 2024
3ee830c
Merge remote-tracking branch 'origin/dev' into evm-equivalence-yul-new
IAvecilla Aug 20, 2024
6a9d835
Remove evm constants contract
IAvecilla Aug 20, 2024
cb3ad25
Remove asserts from bootloader (#26)
gianbelinche Aug 20, 2024
81dd19a
Merge remote-tracking branch 'origin/dev' into evm-equivalence-yul-new
IAvecilla Aug 20, 2024
7d8300b
Remove old contracts constants not longer used
IAvecilla Aug 21, 2024
e6b7a83
Fix some typos and outdated comments
IAvecilla Aug 21, 2024
4ba25a3
Add interface for evm gas manager
IAvecilla Aug 21, 2024
668bcac
Simplify check for warm slots in evm gas manager
IAvecilla Aug 21, 2024
2c59ee8
Check nonce equals zero for evm deploy
IAvecilla Aug 21, 2024
fbc8f8f
Fix trivial lint checks
IAvecilla Aug 21, 2024
ef1affd
Disable some solidity hints for conflicting system contracts
IAvecilla Aug 21, 2024
b1c7e00
Fix most of the l1 contracts foundry tests
IAvecilla Aug 21, 2024
e37175d
Change test hashes
gianbelinche Aug 21, 2024
cd2babb
Fix hardhat tests
gianbelinche Aug 22, 2024
0dd4a0b
Merge branch 'dev' into evm-equivalence-yul-new
IAvecilla Aug 22, 2024
2f1181f
Use modifier in evm gas manager to only modify callstack by system env
IAvecilla Aug 22, 2024
e4e8605
Merge branch 'dev' into evm-equivalence-yul-new
IAvecilla Aug 23, 2024
59834ab
Fix lint errores
IAvecilla Aug 23, 2024
1117c05
Fix typos
IAvecilla Aug 23, 2024
2579d68
Fix another typo
IAvecilla Aug 23, 2024
0ecbe61
Check for the `to` address to be zero when dispatching to createEVM o…
jrchatruc Aug 23, 2024
0ac4617
Fix format
IAvecilla Aug 26, 2024
9cd43a2
Update lock file
IAvecilla Aug 26, 2024
6bdc843
Fix compiler version for compile yul script
IAvecilla Aug 27, 2024
7f6da78
Delete debug logs
IAvecilla Aug 27, 2024
ca6b3cb
Download solc compiler when not found in cache
IAvecilla Aug 27, 2024
ad52dd8
Fix lint errors
IAvecilla Aug 27, 2024
01c0bd5
Update contracts hashes
IAvecilla Aug 27, 2024
1d36192
Remove download compiler step since old hardhat version already does it
IAvecilla Aug 27, 2024
5774d9e
Update system contract hashes
IAvecilla Aug 27, 2024
4d15c5e
Get the original lock file from dev to mantain correct versions
IAvecilla Aug 27, 2024
0922be9
Update system contracts hashes
IAvecilla Aug 27, 2024
0a17e16
Add evm simulatro bytecode hash to the test deployer
IAvecilla Aug 27, 2024
a420bf4
Merge branch 'dev' into evm-equivalence-yul-new
IAvecilla Aug 28, 2024
8e0aa26
Update evm interpreter contract to make sys calls when required
IAvecilla Aug 29, 2024
2d95a3b
Add modifier for functions that need to be called only by sys calls
IAvecilla Aug 29, 2024
f3af763
Update increment nonce function to yield unauthorized error
IAvecilla Aug 29, 2024
75f9287
Fix lint errors
IAvecilla Aug 29, 2024
d56209b
Update system contracts hashes
IAvecilla Aug 29, 2024
dc1a608
Merge branch 'dev' into evm-equivalence-yul-new
IAvecilla Aug 29, 2024
8b5b296
Implement restriction to allow limiting chain admin in power (#699)
StanislavBreadless Sep 5, 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
ef33539
lint
StanislavBreadless Sep 6, 2024
b653ac8
Merge pull request #778 from matter-labs/sb-merge-main-to-dev
StanislavBreadless Sep 6, 2024
5e6211a
Add preprocess script and template files
jrchatruc Sep 10, 2024
d1f5c40
Merge branch 'dev' into evm-equivalence-yul-new
IAvecilla Sep 10, 2024
fe5d5f5
Move evm interpreter files for preprocessing to a new directory
IAvecilla Sep 10, 2024
4d005d3
Bring missing system contract changes
jrchatruc Sep 10, 2024
99bcbb4
Format
jrchatruc Sep 10, 2024
8aa9cdb
Fix lints and codespells
jrchatruc Sep 10, 2024
e017b4e
More lints
jrchatruc Sep 10, 2024
0671291
Fix contract hashes
jrchatruc Sep 10, 2024
0f1383a
Fix foundry L1 tests
jrchatruc Sep 10, 2024
cc3b2ac
chore: merge main (#790)
kelemeno Sep 10, 2024
361d19a
Revert fetch deployed code len optimization (#31)
jrchatruc Sep 11, 2024
220e983
[EVM-Equivalence-YUL] Optimize EvmGasManager (#30)
0xVolosnikov Sep 12, 2024
32c05a1
[EVM-Equivalence-YUL] Fix overflow checks (#29)
IAvecilla Sep 13, 2024
1722402
Fix l1 hardhat test adding evm simulator code hash
IAvecilla Sep 16, 2024
2edbd69
fix: Revert consumeEvmFrame EvmGasManager optimization (#32)
0xVolosnikov Sep 17, 2024
62e0e04
chore: Initial cleanup in EvmInterpreter (#33)
0xVolosnikov Sep 23, 2024
6f791dd
Fix EVM branch in getCodeHash (#34)
0xVolosnikov Sep 23, 2024
966dc12
Optimize EvmGasManager
0xVolosnikov Sep 25, 2024
a0448c9
Make EvmGasManager methods payable
0xVolosnikov Sep 25, 2024
ea5a158
Use custom errors and optimize call inside EvmGasManager
0xVolosnikov Sep 25, 2024
0b6175e
Prettier run
0xVolosnikov Sep 25, 2024
4b55877
Implement return opcode hotfix
0xVolosnikov Sep 26, 2024
d76a8d1
Merge branch 'evm-vv-optimize-gasmanager' into evm-equivalence-yul-new
0xVolosnikov Sep 27, 2024
7827bf3
chore: Rename interpreter to emulator (#846)
0xVolosnikov Oct 9, 2024
1e375d1
fix(EVM): Fix accessed accounts behavior according to EVM (#865)
0xVolosnikov Oct 14, 2024
bf7f955
feat: Update zksolc for system contracts (#830)
0xVolosnikov Oct 18, 2024
59f45ba
chore(EVM): Update from dev (#947)
0xVolosnikov Oct 18, 2024
418b4a9
feat(EVM-emulator): add support for propagating LLVM options (#858)
vladimirradosavljevic Oct 18, 2024
f33c653
feat(EVM-emulator): Optimize deployment of EVM contracts (#827)
0xVolosnikov Oct 18, 2024
a3fc4b0
feat(EVM): Implement EvmGasManager in yul (#943)
0xVolosnikov Oct 18, 2024
a3254c8
fix: Fix bootloader bytecode loading after new `zksolc` version (#949)
0xVolosnikov Oct 18, 2024
91bc660
fix(EVM): Fix scripts (#950)
0xVolosnikov Oct 18, 2024
8bc5e7a
fix(EVM): Fix known code storage (#953)
0xVolosnikov Oct 21, 2024
e542fdf
feat(EVM): Add Identity precompile (#956)
0xVolosnikov Oct 21, 2024
1c3c818
fix(EVM): Refactor calls (#958)
0xVolosnikov Oct 22, 2024
31465df
feat(EVM): Compiler based optimizations (#959)
0xVolosnikov Oct 22, 2024
28ab977
chore(EVM): Move unused opcodes to template (#960)
0xVolosnikov Oct 22, 2024
daba783
chore(EVM): Simplify system calls in emulator (#961)
0xVolosnikov Oct 22, 2024
ddaad7d
feat(EVM): Switch EVM emulation in ContractDeployer constructor (#962)
0xVolosnikov Oct 22, 2024
2f3f35d
chore(EVM): Merge dev (#966)
0xVolosnikov Oct 23, 2024
4420755
chore(EVM): Cleanup in contracts (#967)
0xVolosnikov Oct 23, 2024
2dfa07d
fix(EVM): Optional EVM support during chain creation (#969)
0xVolosnikov Oct 23, 2024
5140326
feat(EVM): Simplify warm/cold storage model for "small" slots (#971)
0xVolosnikov Oct 24, 2024
c60db61
chore(EVM): Cleanup in emulator (#972)
0xVolosnikov Oct 24, 2024
ee5ad27
chore(EVM): Use returndatacopy in emulator internal static calls (#973)
0xVolosnikov Oct 24, 2024
e24cd09
Preprocess emulator
0xVolosnikov Oct 24, 2024
8b136ae
fix(EVM): Panic instead of reverts in case of critical errors (#974)
0xVolosnikov Oct 24, 2024
14bdfb0
fix(EVM): Fix panics in create/create2 (#975)
0xVolosnikov Oct 24, 2024
6dca1d4
Simplify create flow
0xVolosnikov Oct 24, 2024
b4cfe57
fix(EVM): Increase deployment nonce for EVM contracts even if creatio…
0xVolosnikov Oct 24, 2024
6ff7adc
fix(EVM): Fix semantic tests (#977)
0xVolosnikov Oct 24, 2024
a3305ee
fix(EVM): Prepare fixed CREATE implementation (#993)
0xVolosnikov Oct 25, 2024
2fb5df4
Fix(EVM): Fix keccak gas charge flow (#996)
0xVolosnikov Oct 25, 2024
9555afc
fix(EVM): Fix precompiles gas flow (#998)
0xVolosnikov Oct 25, 2024
781f9fd
fix(EVM): Fix ecPairing dynamic gas cost (#1003)
0xVolosnikov Oct 25, 2024
988d476
fix(EVM): Fix gas stipends (#1005)
0xVolosnikov Oct 25, 2024
17698ed
fix(EVM): Fix MCOPY gas cost (#1006)
0xVolosnikov Oct 25, 2024
e9819ec
fix(EVM): Fix EXP gas cost flow (#1007)
0xVolosnikov Oct 25, 2024
7b8cecc
fix(EVM): Make contract creation consistent with Geth implementation …
0xVolosnikov Oct 26, 2024
f6809c0
fix(EVM): Fix expand memory (#1002)
0xVolosnikov Oct 26, 2024
101646f
fix(EVM): Update max posible mem to 4 MB (#1009)
0xVolosnikov Oct 26, 2024
11176dc
fix(EVM): Fix gas in EVM constructor (#1012)
0xVolosnikov Oct 26, 2024
cc88802
fix(EVM): Fix stipends (#1014)
0xVolosnikov Oct 26, 2024
9135b56
fix(EVM): Cache fixed context values (#1015)
0xVolosnikov Oct 26, 2024
b50f361
Fix(EVM): Not revert caller frame in CREATE if balance insufficient (…
0xVolosnikov Oct 26, 2024
e0fb26d
fix(EVM): Fix stipend for transfers (#1019)
0xVolosnikov Oct 26, 2024
e1eb15b
fix(EVM): Remove gas calculation logic for unsupported precompiles; d…
0xVolosnikov Oct 27, 2024
c7a1f38
Feat(EVM): Use different memory layouts for constructor and deployed …
0xVolosnikov Oct 27, 2024
646a408
fix(EVM): Fix bytecode read operations (#1024)
0xVolosnikov Oct 27, 2024
5d6830c
fea(EVM): Optimize JUMP gas charge (#1025)
0xVolosnikov Oct 27, 2024
8981dec
chore(EVM): Cleanup (#1026)
0xVolosnikov Oct 27, 2024
488fced
fix(EVM): Fix emulator memory layout (#1004)
0xVolosnikov Oct 27, 2024
b631015
Chore(EVM): Cleanup (#1027)
0xVolosnikov Oct 27, 2024
0ae124a
fix(EVM): Fx SSTORE gas model (#1028)
0xVolosnikov Oct 27, 2024
a40ebe1
feat(EVM): Optimize EXTCODEHASH (#1029)
0xVolosnikov Oct 27, 2024
bb4443d
fix(EVM): Fix TODOs in KnownCodesStorage (#1030)
0xVolosnikov Oct 27, 2024
146aa34
fix(EVM): Warm origin and sender accounts (#1036)
0xVolosnikov Oct 28, 2024
3cb65f6
feat(EVM): Simplify returngas from constructor (#1037)
0xVolosnikov Oct 28, 2024
82aa1a2
fix(EVM): Fix TODOs in EvmGasManager (#1038)
0xVolosnikov Oct 28, 2024
96e989f
fix(EVM): Fix zknative calls (#1034)
0xVolosnikov Oct 28, 2024
6f1c55d
chore(EVM): Cleanup in contract deployer (#1039)
0xVolosnikov Oct 28, 2024
520a858
chore(EVM): Update hashes (#1040)
0xVolosnikov Oct 28, 2024
df1c554
fix(EVM): Fix panics on invalid opcodes (#1041)
0xVolosnikov Oct 28, 2024
cf476b1
fix(EVM): Implement resetEVMFrame function (#1051)
0xVolosnikov Oct 30, 2024
19a6872
fix(EVM): Change gas model (#1047)
0xVolosnikov Oct 30, 2024
7a4a895
feat(EVM): Optimize extcodecopy (#1046)
0xVolosnikov Oct 30, 2024
397092d
fix(EVM): Fix data copy corner cases (#1053)
0xVolosnikov Oct 30, 2024
42954fd
chore(EVM): Suppress sendtransfer zksolc error (#1067)
0xVolosnikov Nov 18, 2024
38a8bb8
chore: Tooling fixes in contracts (#1068)
0xVolosnikov Nov 18, 2024
7a2f587
chore(EVM): Merge dev (#1069)
0xVolosnikov Nov 18, 2024
df328ca
merge release v25 into dev (#1072)
koloz193 Nov 19, 2024
a3ccf98
feat(system-contracts): remove unecessary methods from L2BaseToken.so…
thomas-nguy Nov 19, 2024
f8b2651
readd hash check (#1074)
koloz193 Nov 20, 2024
4407bf4
chore(EVM): Merge dev (#1073)
0xVolosnikov Nov 20, 2024
ff6225a
Merge branch 'dev' into evm-emulator/merge-dev
0xVolosnikov Nov 20, 2024
ca3f135
Fix hashes
0xVolosnikov Nov 20, 2024
2af36d8
Merge pull request #1075 from matter-labs/evm-emulator/merge-dev
0xVolosnikov Nov 20, 2024
d1d4391
feat: Bump zksolc to 1.5.7 (#1076)
0xVolosnikov Nov 20, 2024
c5ff569
Merge branch 'dev' into evm-emulator/merge-dev
0xVolosnikov Nov 20, 2024
348e84a
Merge pull request #1077 from matter-labs/evm-emulator/merge-dev
0xVolosnikov Nov 20, 2024
a4c8e64
feat(EVM): Cleanup in system contracts (#1103)
0xVolosnikov Nov 29, 2024
7e242cf
fix(EVM): Change deploy flow for EIP712 transactions (#1106)
0xVolosnikov Dec 2, 2024
0c00649
feat(EVM): Remove reserved field usage for EVM deploy using custom tx…
0xVolosnikov Dec 6, 2024
5ec8486
feat(EVM): Return evm gas used in external create methods (#1130)
0xVolosnikov Dec 6, 2024
c6f1c7b
Merge branch 'release-v25-protocol-defense' into test-branch/evm-emul…
0xVolosnikov Dec 6, 2024
77983ce
chore(EVM): Merge V25 release branch (#1132)
0xVolosnikov Dec 6, 2024
a1405dc
Merge pull request #1133 from matter-labs/evm-emulator/merge-v25-release
0xVolosnikov Dec 6, 2024
93888b5
fix(EVM): Fix dev merge artifact (#1138)
0xVolosnikov Dec 10, 2024
933e1d5
fix(EVM): Fx l1 foundry deploy scripts (#1139)
0xVolosnikov Dec 10, 2024
ed6f4d1
fix(EVM) Fix config parsing in L1 foundry deploy script (#1140)
0xVolosnikov Dec 10, 2024
44bd426
fix(EVM): Add static MCOPY cost (#1081)
0xVolosnikov Nov 27, 2024
8e8323d
fix(EVM): Cleanup in checkMemIsAccessible (#1082)
0xVolosnikov Nov 27, 2024
ef91e52
fix(EVM): Simplify OP_PC (#1084)
0xVolosnikov Nov 27, 2024
b649f5f
fix(EVM): Do not charge additionally for EraVM decommit (#1086)
0xVolosnikov Nov 27, 2024
5db2a30
fix(EVM): Fix stack overflow check (#1085)
0xVolosnikov Nov 27, 2024
ba50e19
fix(EVM): Add stack overflow check in dup (#1087)
0xVolosnikov Nov 27, 2024
30d56ad
fix(EVM): Fix SSTORE warmth check (#1089)
0xVolosnikov Nov 27, 2024
6fe1257
fix(EVM): Fix CALL in static context (#1091)
0xVolosnikov Nov 27, 2024
1818626
fix(EVM): Fix calls to contract being created (#1093)
0xVolosnikov Nov 27, 2024
12efa1c
fix(EVM): Wrap access to calldata to prevent out-of-bounds EraVM pani…
0xVolosnikov Nov 28, 2024
07f43d0
fix(EVM): Zero out frame gas left for underpaid precompiles (#1101)
0xVolosnikov Nov 28, 2024
c74c6ec
fix(EVM): Fix panics on insufficient balance in calls (#1108)
0xVolosnikov Dec 2, 2024
5869331
fix(EVM): Fix DUP1 underflow check (#1110)
0xVolosnikov Dec 2, 2024
55367f5
fix(EVM): Update LLVM options after fixes (#1112)
0xVolosnikov Dec 3, 2024
70d1de8
fix(EVM): Do not check memory boundaries if size is zero (#1114)
0xVolosnikov Dec 4, 2024
37874c7
fi(EVM): Fix EXTCODECOPY zeroing offset (#1115)
0xVolosnikov Dec 4, 2024
6a76d76
fix(EVM): Cleanup address bytes in EXTCODECOPY (#1116)
0xVolosnikov Dec 4, 2024
2bdc565
fix(EVM): Use raw calls to precompiles (#1118)
0xVolosnikov Dec 5, 2024
3299faa
fix(EVM): Make DELEGATECALL behavior closer to EVM (3) (#1120)
0xVolosnikov Dec 5, 2024
483b099
fix(EVM): Handle corner case of KECCAK with 0 size (#1121)
0xVolosnikov Dec 5, 2024
d61e38d
fix(EVM): Make fetchDeployedCode more robust (2) (#1123)
0xVolosnikov Dec 6, 2024
47b2ddd
fix(EVM): Increase max allowed memory (2) (#1124)
0xVolosnikov Dec 6, 2024
c4c964b
fix(EVM): Implement EXTCODEHASH in emulator (#1125)
0xVolosnikov Dec 6, 2024
921b3e3
fix(EVM): Add stipends for calls to zkVM contracts (#1126)
0xVolosnikov Dec 6, 2024
ef80122
fix(EVM): Make CREATE flow equivalent to EVM (#1127)
0xVolosnikov Dec 6, 2024
b61406b
Handle Empty.sol as empty account
0xVolosnikov Dec 8, 2024
72bbed0
Do not call precompiles if not enough gas provided
0xVolosnikov Dec 8, 2024
daf7022
fix(EVM): Fix logs implementation (2) (#1137)
0xVolosnikov Dec 9, 2024
fe838fc
feat(EVM): Enable EVM emulator using service call (#1141)
0xVolosnikov Dec 16, 2024
e7aa3a9
fix(EVM): Simplify and optimize out-of-bounds truncation in `CODECOPY…
0xVolosnikov Dec 18, 2024
c396c03
fix(EVM): Store unpadded EVM bytecode length in versioned bytecode ha…
0xVolosnikov Dec 19, 2024
0419d3e
fix(EVM): Add overflow checks in `JUMP` and `JUMPI` opcodes (#1159)
0xVolosnikov Dec 20, 2024
684c072
fix(EVM): Handle calldata-related opcodes in constructor (#1160)
0xVolosnikov Dec 20, 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
36 changes: 35 additions & 1 deletion .github/workflows/system-contracts-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
- name: Install rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly-2023-04-17
toolchain: nightly-2024-08-01

- name: Restore artifacts cache
uses: actions/cache/restore@v3
Expand Down Expand Up @@ -143,3 +143,37 @@ jobs:
- name: Print output logs of era_test_node
if: always()
run: cat era_test_node.log

check-hashes:
needs: [build]
runs-on: ubuntu-latest

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

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 18.18.0
cache: yarn

- name: Install dependencies
run: yarn

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

- name: Check hashes
run: yarn sc calculate-hashes:check
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ l1-contracts/script-config/*
l1-contracts/script-out/*
!l1-contracts/script-out/.gitkeep
*.timestamp
l1-contracts/test/foundry/l1/integration/deploy-scripts/script-out/*
l1-contracts/zkout/*
2 changes: 2 additions & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ l1-contracts/lib
l1-contracts/node_modules
l1-contracts/contracts/dev-contracts
l1-contracts/test
l1-contracts/deploy-scripts

# l1-contracts-foundry
l1-contracts-foundry/cache
Expand All @@ -16,6 +17,7 @@ l1-contracts-foundry/lib
# l2-contracts
l2-contracts/cache-zk
l2-contracts/node_modules
l2-contracts/contracts/dev-contracts

# system-contracts
system-contracts/contracts/openzeppelin
Expand Down
22 changes: 16 additions & 6 deletions l1-contracts/contracts/bridge/L1SharedBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {ETH_TOKEN_ADDRESS, TWO_BRIDGES_MAGIC_VALUE} from "../common/Config.sol";
import {IBridgehub, L2TransactionRequestTwoBridgesInner, L2TransactionRequestDirect} from "../bridgehub/IBridgehub.sol";
import {IGetters} from "../state-transition/chain-interfaces/IGetters.sol";
import {L2_BASE_TOKEN_SYSTEM_CONTRACT_ADDR} from "../common/L2ContractAddresses.sol";
import {Unauthorized, ZeroAddress, SharedBridgeValueAlreadySet, SharedBridgeKey, NoFundsTransferred, ZeroBalance, ValueMismatch, TokensWithFeesNotSupported, NonEmptyMsgValue, L2BridgeNotSet, TokenNotSupported, DepositIncorrectAmount, EmptyDeposit, DepositExists, AddressAlreadyUsed, InvalidProof, DepositDoesNotExist, InsufficientChainBalance, SharedBridgeValueNotSet, WithdrawalAlreadyFinalized, WithdrawFailed, L2WithdrawalMessageWrongLength, InvalidSelector, SharedBridgeBalanceMismatch, SharedBridgeValueNotSet} from "../common/L1ContractErrors.sol";
import {Unauthorized, ZeroAddress, SharedBridgeValueAlreadySet, SharedBridgeKey, NoFundsTransferred, ZeroBalance, ValueMismatch, TokensWithFeesNotSupported, NonEmptyMsgValue, L2BridgeNotSet, TokenNotSupported, DepositIncorrectAmount, EmptyDeposit, DepositExists, AddressAlreadyUsed, InvalidProof, DepositDoesNotExist, InsufficientChainBalance, SharedBridgeValueNotSet, WithdrawalAlreadyFinalized, WithdrawFailed, L2WithdrawalMessageWrongLength, InvalidSelector, SharedBridgeBalanceMismatch, SharedBridgeValueNotSet, NotPendingAdmin, L2BridgeAlreadySet} from "../common/L1ContractErrors.sol";

/// @author Matter Labs
/// @custom:security-contact [email protected]
Expand Down Expand Up @@ -130,7 +130,9 @@ contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Ownable2StepUpgrade

/// @notice Checks that the message sender is either the owner or admin.
modifier onlyOwnerOrAdmin() {
require(msg.sender == owner() || msg.sender == admin, "ShB not owner or admin");
if (msg.sender != owner() && msg.sender != admin) {
revert Unauthorized(msg.sender);
}
_;
}

Expand Down Expand Up @@ -174,7 +176,9 @@ contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Ownable2StepUpgrade
/// @notice Accepts transfer of admin rights. Only pending admin can accept the role.
function acceptAdmin() external {
address currentPendingAdmin = pendingAdmin;
require(msg.sender == currentPendingAdmin, "ShB not pending admin"); // Only proposed by current admin address can claim the admin rights
if (msg.sender != currentPendingAdmin) {
revert NotPendingAdmin();
}

address previousAdmin = admin;
admin = currentPendingAdmin;
Expand Down Expand Up @@ -276,8 +280,12 @@ contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Ownable2StepUpgrade
/// @param _chainId The chain ID for which the l2Bridge address is being initialized.
/// @param _l2BridgeAddress The address of the L2 bridge contract.
function initializeChainGovernance(uint256 _chainId, address _l2BridgeAddress) external onlyOwnerOrAdmin {
require(l2BridgeAddress[_chainId] == address(0), "ShB: l2 bridge already set");
require(_l2BridgeAddress != address(0), "ShB: l2 bridge 0");
if (l2BridgeAddress[_chainId] != address(0)) {
revert L2BridgeAlreadySet(_chainId);
}
if (_l2BridgeAddress == address(0)) {
revert ZeroAddress();
}
l2BridgeAddress[_chainId] = _l2BridgeAddress;
}

Expand All @@ -287,7 +295,9 @@ contract L1SharedBridge is IL1SharedBridge, ReentrancyGuard, Ownable2StepUpgrade
/// @param _chainId The chain ID for which the l2Bridge address is being initialized.
/// @param _l2BridgeAddress The address of the L2 bridge contract.
function reinitializeChainGovernance(uint256 _chainId, address _l2BridgeAddress) external onlyOwner {
require(l2BridgeAddress[_chainId] != address(0), "ShB: l2 bridge not yet set");
if (l2BridgeAddress[_chainId] == address(0)) {
revert L2BridgeNotSet(_chainId);
}
l2BridgeAddress[_chainId] = _l2BridgeAddress;
}

Expand Down
26 changes: 26 additions & 0 deletions l1-contracts/contracts/common/L1ContractErrors.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;

// 0x5ecf2d7a
error AccessToFallbackDenied(address target, address invoker);
// 0x3995f750
error AccessToFunctionDenied(address target, bytes4 selector, address invoker);
// 0x6c167909
error OnlySelfAllowed();
// 0x52e22c98
error RestrictionWasNotPresent(address restriction);
// 0xf126e113
error RestrictionWasAlreadyPresent(address restriction);
// 0x3331e9c0
error CallNotAllowed(bytes call);
// 0x59e1b0d2
error ChainZeroAddress();
// 0xff4bbdf1
error NotAHyperchain(address chainAddress);
// 0xa3decdf3
error NotAnAdmin(address expected, address actual);
// 0xf6fd7071
error RemovingPermanentRestriction();
// 0xfcb9b2e1
error UnallowedImplementation(bytes32 implementationHash);
// 0x1ff9d522
error AddressAlreadyUsed(address addr);
// 0x86bb51b8
Expand Down Expand Up @@ -115,6 +137,8 @@ error InvalidValue();
error L2BridgeNotDeployed(uint256 chainId);
// 0xff8811ff
error L2BridgeNotSet(uint256 chainId);
// 0x685577fa
error L2BridgeAlreadySet(uint256 chainId);
// 0xcb5e4247
error L2BytecodeHashMismatch(bytes32 expected, bytes32 provided);
// 0xfb5c22e6
Expand Down Expand Up @@ -171,6 +195,8 @@ error NonZeroAddress(address);
error NotEnoughGas();
// 0xdd7e3621
error NotInitializedReentrancyGuard();
// 0x058d9a1b
error NotPendingAdmin();
// 0xf3ed9dfa
error OnlyEraSupported();
// 0x1a21feed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ contract CustomUpgradeTest is BaseZkSyncUpgrade {
(uint32 newMinorVersion, bool isPatchOnly) = _setNewProtocolVersion(_proposedUpgrade.newProtocolVersion);
_upgradeL1Contract(_proposedUpgrade.l1ContractsUpgradeCalldata);
_upgradeVerifier(_proposedUpgrade.verifier, _proposedUpgrade.verifierParams);
_setBaseSystemContracts(_proposedUpgrade.bootloaderHash, _proposedUpgrade.defaultAccountHash, isPatchOnly);
_setBaseSystemContracts(
_proposedUpgrade.bootloaderHash,
_proposedUpgrade.defaultAccountHash,
_proposedUpgrade.evmEmulatorHash,
isPatchOnly
);

bytes32 txHash;
txHash = _setL2SystemContractUpgrade(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ contract ExecutorProvingTest is ExecutorFacet {
return _processL2Logs(_newBatch, _expectedSystemContractUpgradeTxHash);
}

/// Sets the DefaultAccount Hash and Bootloader Hash.
function setHashes(bytes32 l2DefaultAccountBytecodeHash, bytes32 l2BootloaderBytecodeHash) external {
/// Sets the DefaultAccount Hash, Bootloader Hash and EVM emulator Hash.
function setHashes(
bytes32 l2DefaultAccountBytecodeHash,
bytes32 l2BootloaderBytecodeHash,
bytes32 l2EvmEmulatorBytecode
) external {
s.l2DefaultAccountBytecodeHash = l2DefaultAccountBytecodeHash;
s.l2BootloaderBytecodeHash = l2BootloaderBytecodeHash;
s.l2EvmEmulatorBytecodeHash = l2EvmEmulatorBytecode;
s.zkPorterIsAvailable = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pragma solidity 0.8.24;

import {IGovernance} from "../../governance/IGovernance.sol";
import {Call} from "../../governance/Common.sol";

contract ReenterGovernance {
// add this to be excluded from coverage report
Expand All @@ -12,7 +13,7 @@ contract ReenterGovernance {

// Store call, predecessor and salt separately,
// because Operation struct can't be stored on storage.
IGovernance.Call call;
Call call;
bytes32 predecessor;
bytes32 salt;

Expand Down Expand Up @@ -45,7 +46,7 @@ contract ReenterGovernance {
fallback() external payable {
if (!alreadyReentered) {
alreadyReentered = true;
IGovernance.Call[] memory calls = new IGovernance.Call[](1);
Call[] memory calls = new Call[](1);
calls[0] = call;
IGovernance.Operation memory op = IGovernance.Operation({
calls: calls,
Expand Down
13 changes: 13 additions & 0 deletions l1-contracts/contracts/governance/Common.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.24;

/// @dev Represents a call to be made during multicall.
/// @param target The address to which the call will be made.
/// @param value The amount of Ether (in wei) to be sent along with the call.
/// @param data The calldata to be executed on the `target` address.
struct Call {
address target;
uint256 value;
bytes data;
}
1 change: 1 addition & 0 deletions l1-contracts/contracts/governance/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.24;

import {Ownable2Step} from "@openzeppelin/contracts-v4/access/Ownable2Step.sol";
import {IGovernance} from "./IGovernance.sol";
import {Call} from "./Common.sol";
import {ZeroAddress, Unauthorized, OperationMustBeReady, OperationMustBePending, OperationExists, InvalidDelay, PreviousOperationNotExecuted} from "../common/L1ContractErrors.sol";

/// @author Matter Labs
Expand Down
12 changes: 2 additions & 10 deletions l1-contracts/contracts/governance/IGovernance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// We use a floating point pragma here so it can be used within other projects that interact with the ZKsync ecosystem without using our exact pragma version.
pragma solidity ^0.8.21;

import {Call} from "./Common.sol";

/// @title Governance contract interface
/// @author Matter Labs
/// @custom:security-contact [email protected]
Expand All @@ -18,16 +20,6 @@ interface IGovernance {
Done
}

/// @dev Represents a call to be made during an operation.
/// @param target The address to which the call will be made.
/// @param value The amount of Ether (in wei) to be sent along with the call.
/// @param data The calldata to be executed on the `target` address.
struct Call {
address target;
uint256 value;
bytes data;
}

/// @dev Defines the structure of an operation that Governance executes.
/// @param calls An array of `Call` structs, each representing a call to be made during the operation.
/// @param predecessor The hash of the predecessor operation, that should be executed before this operation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {IDiamondInit} from "./chain-interfaces/IDiamondInit.sol";
import {IExecutor} from "./chain-interfaces/IExecutor.sol";
import {IStateTransitionManager, StateTransitionManagerInitializeData, ChainCreationParams} from "./IStateTransitionManager.sol";
import {ISystemContext} from "./l2-deps/ISystemContext.sol";
import {AllowedBytecodeTypes} from "./l2-deps/AllowedBytecodeTypes.sol";
import {IZkSyncHyperchain} from "./chain-interfaces/IZkSyncHyperchain.sol";
import {FeeParams} from "./chain-deps/ZkSyncHyperchainStorage.sol";
import {L2_SYSTEM_CONTEXT_SYSTEM_CONTRACT_ADDR, L2_FORCE_DEPLOYER_ADDR} from "../common/L2ContractAddresses.sol";
Expand Down Expand Up @@ -322,8 +323,15 @@ contract StateTransitionManager is IStateTransitionManager, ReentrancyGuard, Own
/// registration

/// @dev we have to set the chainId at genesis, as blockhashzero is the same for all chains with the same chainId
function _setChainIdUpgrade(uint256 _chainId, address _chainContract) internal {
bytes memory systemContextCalldata = abi.encodeCall(ISystemContext.setChainId, (_chainId));
function _setChainConfigurationUpgrade(
uint256 _chainId,
AllowedBytecodeTypes _allowedBytecodeTypesMode,
address _chainContract
) internal {
bytes memory systemContextCalldata = abi.encodeCall(
ISystemContext.setChainConfiguration,
(_chainId, uint256(_allowedBytecodeTypesMode))
);
uint256[] memory uintEmptyArray;
bytes[] memory bytesEmptyArray;

Expand Down Expand Up @@ -356,6 +364,7 @@ contract StateTransitionManager is IStateTransitionManager, ReentrancyGuard, Own
factoryDeps: bytesEmptyArray,
bootloaderHash: bytes32(0),
defaultAccountHash: bytes32(0),
evmEmulatorHash: bytes32(0),
verifier: address(0),
verifierParams: VerifierParams({
recursionNodeLevelVkHash: bytes32(0),
Expand Down Expand Up @@ -395,26 +404,32 @@ contract StateTransitionManager is IStateTransitionManager, ReentrancyGuard, Own
/// @param _baseToken the base token address used to pay for gas fees
/// @param _sharedBridge the shared bridge address, used as base token bridge
/// @param _admin the chain's admin address
/// @param _diamondCut the diamond cut data that initializes the chains Diamond Proxy
/// @param _inputData the input data for chain creation
function createNewChain(
uint256 _chainId,
address _baseToken,
address _sharedBridge,
address _admin,
bytes calldata _diamondCut
bytes calldata _inputData
) external onlyBridgehub {
if (getHyperchain(_chainId) != address(0)) {
// Hyperchain already registered
return;
}

// check not registered
(bytes memory _diamondCut, AllowedBytecodeTypes allowedBytecodeTypesMode) = abi.decode(
_inputData,
(bytes, AllowedBytecodeTypes)
);
Diamond.DiamondCutData memory diamondCut = abi.decode(_diamondCut, (Diamond.DiamondCutData));

// check input
bytes32 cutHashInput = keccak256(_diamondCut);
if (cutHashInput != initialCutHash) {
revert HashMismatch(initialCutHash, cutHashInput);
{
// check input
bytes32 cutHashInput = keccak256(_diamondCut);
if (cutHashInput != initialCutHash) {
revert HashMismatch(initialCutHash, cutHashInput);
}
}

// construct init data
Expand Down Expand Up @@ -444,8 +459,8 @@ contract StateTransitionManager is IStateTransitionManager, ReentrancyGuard, Own

_registerNewHyperchain(_chainId, hyperchainAddress);

// set chainId in VM
_setChainIdUpgrade(_chainId, hyperchainAddress);
// set chain configuration: chainId in VM and allowed bytecode types
_setChainConfigurationUpgrade(_chainId, allowedBytecodeTypesMode, hyperchainAddress);
}

/// @dev This internal function is used to register a new hyperchain in the system.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ contract DiamondInit is ZkSyncHyperchainBase, IDiamondInit {
s.__DEPRECATED_verifierParams = _initializeData.verifierParams;
s.l2BootloaderBytecodeHash = _initializeData.l2BootloaderBytecodeHash;
s.l2DefaultAccountBytecodeHash = _initializeData.l2DefaultAccountBytecodeHash;
s.l2EvmEmulatorBytecodeHash = _initializeData.l2EvmEmulatorBytecodeHash;
s.priorityTxMaxGasLimit = _initializeData.priorityTxMaxGasLimit;
s.feeParams = _initializeData.feeParams;
s.blobVersionedHashRetriever = _initializeData.blobVersionedHashRetriever;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ struct ZkSyncHyperchainStorage {
/// @notice Bytecode hash of default account (bytecode for EOA).
/// @dev Used as an input to zkp-circuit.
bytes32 l2DefaultAccountBytecodeHash;
/// @notice Bytecode hash of evm emulator.
/// @dev Used as an input to zkp-circuit.
bytes32 l2EvmEmulatorBytecodeHash;
/// @dev Indicates that the porter may be touched on L2 transactions.
/// @dev Used as an input to zkp-circuit.
bool zkPorterIsAvailable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,13 +600,13 @@ contract ExecutorFacet is ZkSyncHyperchainBase, IExecutor {

function _batchMetaParameters() internal view returns (bytes memory) {
bytes32 l2DefaultAccountBytecodeHash = s.l2DefaultAccountBytecodeHash;
bytes32 l2EvmEmulatorBytecodeHash = s.l2EvmEmulatorBytecodeHash;
return
abi.encodePacked(
s.zkPorterIsAvailable,
s.l2BootloaderBytecodeHash,
l2DefaultAccountBytecodeHash,
// VM 1.5.0 requires us to pass the EVM simulator code hash. For now it is the same as the default account.
l2DefaultAccountBytecodeHash
l2EvmEmulatorBytecodeHash
);
}

Expand Down
Loading
Loading