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: Evm equivalence in yul #364

Closed
wants to merge 691 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
691 commits
Select commit Hold shift + click to select a range
ef4111f
Replace expression with already calculated variable
ManuelBilbao Apr 10, 2024
6658425
Charge gas on mload and mstore
ManuelBilbao Apr 10, 2024
59765af
Add mstore8 opcode
ManuelBilbao Apr 10, 2024
8cb0a5a
Charge gas on mstore8
ManuelBilbao Apr 10, 2024
4094115
Move memory expansion to function
ManuelBilbao Apr 10, 2024
b04c5a9
Add memory expansion function
jrchatruc Apr 10, 2024
3e79894
Improve legibility
ManuelBilbao Apr 12, 2024
97c0a4e
Fix exponent gas charge
ManuelBilbao Apr 12, 2024
72d2bb4
Refactor returndatacopy opcode
ManuelBilbao Apr 29, 2024
bd54bec
feat(blockenvironment-opcodes): Add opcodes
fborello-lambda Apr 11, 2024
30a966d
refactor(blockenvironment-opcodes): Remove blob opcodes
fborello-lambda Apr 12, 2024
67c4cc4
Start working on create opcode
ManuelBilbao Apr 15, 2024
40583b3
Get deployed address for create
ManuelBilbao Apr 15, 2024
9a059c8
Fix bytes encoding
ManuelBilbao Apr 15, 2024
779f325
Add sample init code
ManuelBilbao Apr 15, 2024
7b9c987
Add basic constructor code
jrchatruc Apr 16, 2024
6323174
Add correct bytecode when creating
jrchatruc Apr 16, 2024
ac9bddd
Fix isStatic check when constructor is called
jrchatruc Apr 16, 2024
e0a53ac
Remove logs
ManuelBilbao Apr 16, 2024
2bdca4a
Format code
ManuelBilbao Apr 16, 2024
d7dc722
Implement gas functions for constructor fallback
ManuelBilbao Apr 16, 2024
578993f
Use real calldata from user
ManuelBilbao Apr 16, 2024
831cece
Allow nonces greater than 128
ManuelBilbao Apr 16, 2024
47e4c11
Fix addresses masks
ManuelBilbao Apr 16, 2024
45915e2
Replicate create opcode on constructor
ManuelBilbao Apr 16, 2024
7cd0f73
Increment nonce after a create
ManuelBilbao Apr 16, 2024
58e73c6
Add more validations
ManuelBilbao Apr 17, 2024
6cf623e
Replicate create opcode on constructor
ManuelBilbao Apr 17, 2024
15c16dc
Refactor memory overflow check
ManuelBilbao Apr 17, 2024
884ca14
Add gas charge to create
ManuelBilbao Apr 17, 2024
c44dcda
Fix missing parameter and comma
ManuelBilbao Apr 17, 2024
7b363e1
Add warming to new address
ManuelBilbao Apr 17, 2024
1b23cb0
Fix warm return value
ManuelBilbao Apr 17, 2024
c0f7a6b
Add create2 opcode
ManuelBilbao Apr 17, 2024
35f3150
Add create2 opcode
ManuelBilbao Apr 17, 2024
9dda906
EVM implement CALL opcode (#21)
fborello-lambda Apr 18, 2024
07ffd2d
feat(keccak256-opcode): Add KECCAK256 opcode
fborello-lambda Apr 10, 2024
bbde71a
fix(keccak-opcode): syntax error
fborello-lambda Apr 11, 2024
0d237f1
Refactor extcodehash opcode
ManuelBilbao Apr 29, 2024
d7ff79b
Remove prints
gianbelinche Apr 29, 2024
e8cac11
feat(keccak-opcode): Add dynamicGas
fborello-lambda Apr 12, 2024
b8fe493
feat(environment3-opcodes): add OPs: CODESIZE CODECOPY GASPRICE
fborello-lambda Apr 11, 2024
f70331f
fix(codecopy): Fix memory_offset
fborello-lambda Apr 12, 2024
ace3b84
fix(op_codecopy): Fix dynamicGas calculation of codecopy
fborello-lambda Apr 15, 2024
bb10f39
fix(op_codecopy): Fix build
fborello-lambda Apr 15, 2024
ba25158
fix(op_codecopy): Fix multiplication factor
fborello-lambda Apr 15, 2024
1a84062
Add warm address
gianbelinche Apr 12, 2024
69b5c89
Fix compilation errors
gianbelinche Apr 15, 2024
61446ae
Add warm address
gianbelinche Apr 12, 2024
d85d050
Refactor memory opcodes
ManuelBilbao Apr 29, 2024
e501d14
Fix compilation errors
gianbelinche Apr 15, 2024
502f1a9
Fix compilation errors
gianbelinche Apr 15, 2024
7be406d
Initial implementations of return,revert,invalid and selfdestruct
gianbelinche Apr 15, 2024
5c69cf6
Add gas to revert and nonce to selfdestruct
gianbelinche Apr 16, 2024
c33d6b1
Add callcode op
gianbelinche Apr 16, 2024
72b2eb4
Add callcode
gianbelinche Apr 16, 2024
aadbd40
Comment unnecessary code
gianbelinche Apr 16, 2024
7489cb1
Remove callcode and selfdestruct
gianbelinche Apr 17, 2024
2713997
feat(byte_opcodes): Implement shl shr and sar
fborello-lambda Apr 15, 2024
d2a5378
feat(log0..4-opcodes): Implement log opcodes
fborello-lambda Apr 15, 2024
a105b5c
chore(log0..4): Remove TODOs
fborello-lambda Apr 17, 2024
6c14da6
Refactor addGasIfEvmRevert
gianbelinche Apr 17, 2024
b0d34a6
Reformat evm interpreter for preprocessor
gianbelinche Apr 18, 2024
b2d748a
Readd missing opcodes and functions
jrchatruc Apr 18, 2024
d19f078
Fix dynamic balance calculation
jrchatruc Apr 18, 2024
3ea6795
Fix yarn build
ManuelBilbao Apr 18, 2024
80ed43a
Format
ManuelBilbao Apr 18, 2024
650ebe4
Fix gas calculation
ManuelBilbao Apr 18, 2024
2535c14
Some fixes
jrchatruc Apr 19, 2024
8264da5
Add mload to temp variable storaging
gianbelinche Apr 19, 2024
24b1b3e
Fix CODECOPY opcode
ManuelBilbao Apr 19, 2024
eb7e616
Fix getNewAddress for CREATE opcode
ManuelBilbao Apr 19, 2024
a629186
Move gas inclusion on return to fallback only
ManuelBilbao Apr 19, 2024
8014f70
Fix memory overflow check on CREATE and CREATE2 opcodes
ManuelBilbao Apr 19, 2024
c48c2b6
feat(env4-opcodes): Add env4 opcodes
fborello-lambda Apr 22, 2024
0317ae4
feat(op-returndatacopy): Fix op-returndatacopy
fborello-lambda Apr 22, 2024
c05acda
fix(op-extcodesize): Fix op-extcodesize
fborello-lambda Apr 22, 2024
e74a4a3
chore(rm file): rm preprocessed
fborello-lambda Apr 22, 2024
a39ecfa
fix: change shl to shr in order to perform division correctly
fborello-lambda Apr 22, 2024
18064b5
fix(op-extcodesize): Fix op-extcodesize
fborello-lambda Apr 22, 2024
6ca6980
chore: fix comment
fborello-lambda Apr 22, 2024
8026296
test(op-call int tests): Integration tests
fborello-lambda Apr 22, 2024
df0a512
test(op-codecopy): Change implementation
fborello-lambda Apr 23, 2024
69d7ea9
test: wip
fborello-lambda Apr 23, 2024
a2a3210
test: wip
fborello-lambda Apr 23, 2024
d5c2716
fix(op-returndatacopy): fix integration tests
fborello-lambda Apr 23, 2024
726b746
chore: remove prints
fborello-lambda Apr 24, 2024
4c7fa9e
feat(op-extcodehash): Add extcodehash
fborello-lambda Apr 24, 2024
bdf6dec
wip(op-extcodehash)
fborello-lambda Apr 24, 2024
604cf3c
chore: rm conflicts
fborello-lambda Apr 25, 2024
d065531
Add delegatecall opcode
ManuelBilbao Apr 24, 2024
886734b
Fix syntax misslead errors
ManuelBilbao Apr 24, 2024
36c9429
Add missing instruction
ManuelBilbao Apr 24, 2024
b291617
Add isStatic check on sstore and create2 opcodes
ManuelBilbao Apr 24, 2024
6584585
Fix delegate call
jrchatruc Apr 25, 2024
b5ad7b6
Remove resolved comment
ManuelBilbao Apr 25, 2024
87e0f2a
feat(op-call): Add proper gas calculations
fborello-lambda Apr 22, 2024
f20191d
chore: fix comment
fborello-lambda Apr 22, 2024
43c11f9
Remove comments
jrchatruc Apr 24, 2024
ec6b179
Remove prints
jrchatruc Apr 25, 2024
4d29430
Fix broken stuff
jrchatruc Apr 29, 2024
3958de3
Refactor storage opcodes
ManuelBilbao Apr 29, 2024
d6de27e
Change dynamicGas comment to improve suggestions
ManuelBilbao Apr 29, 2024
c485e45
Refactor log opcodes
ManuelBilbao Apr 29, 2024
a205740
Reformat evm interpreter for preprocessor
gianbelinche Apr 18, 2024
d4030f0
Fix yarn build
ManuelBilbao Apr 18, 2024
3c17900
Fix gas calculation
ManuelBilbao Apr 18, 2024
a131ea5
Some fixes
jrchatruc Apr 19, 2024
d13391b
test(op-call int tests): Integration tests
fborello-lambda Apr 22, 2024
8223deb
feat(op-call): Add proper gas calculations
fborello-lambda Apr 22, 2024
f45f79f
Check if gas is enough
gianbelinche Apr 25, 2024
86134d3
Update check for zkevm gas
gianbelinche Apr 29, 2024
1d801f7
Resolve conflicts
gianbelinche Apr 29, 2024
ad9a0e4
Remove print
jrchatruc Apr 29, 2024
67ce4fc
Merge pull request #414 from lambdaclass/evm-not-enough-zkevm-gas
jrchatruc Apr 29, 2024
7f696dc
Reformat evm interpreter for preprocessor
gianbelinche Apr 18, 2024
16be6d7
Fix yarn build
ManuelBilbao Apr 18, 2024
9f6ec5f
Fix gas calculation
ManuelBilbao Apr 18, 2024
294878d
Some fixes
jrchatruc Apr 19, 2024
c6f4ea9
feat(op-call): Add proper gas calculations
fborello-lambda Apr 22, 2024
7c016d5
test(op-call int tests): Integration tests
fborello-lambda Apr 22, 2024
045f0e3
wip: gas cost for precompiles
fborello-lambda Apr 25, 2024
d1ea0de
feat(precompiles): Add gas calculation for precompiles
fborello-lambda Apr 26, 2024
8f613e9
fix(gas for precompiles): remove unused function parameter
fborello-lambda Apr 29, 2024
920160d
feat(call/delegatecall): add gas calculation for precompiles
fborello-lambda Apr 29, 2024
4e60c87
fix: gas calculation for precompiles
fborello-lambda Apr 29, 2024
7a10300
Fixes
jrchatruc Apr 29, 2024
3e9804b
Fix changes
gianbelinche Apr 29, 2024
1006a95
Fix conflicts
gianbelinche Apr 29, 2024
6d61cac
Remove unnecessary variable
gianbelinche Apr 30, 2024
a0b40c2
Merge pull request #423 from lambdaclass/evm-call-gas-fix
jrchatruc Apr 30, 2024
4161b94
Merge matter-labs/evm-equivalence-yul into lambdaclass/evm-yul-precom…
fborello-lambda Apr 30, 2024
e807875
chore: remove unused verbatim
fborello-lambda Apr 30, 2024
6c4ebf2
feat(gas for precompiles): add gas cost for precompiles
fborello-lambda Apr 30, 2024
ad9e0bb
chore: add missing function
fborello-lambda Apr 30, 2024
1838925
chore: fix conflicts
fborello-lambda Apr 30, 2024
ed7d227
Merge evm-equivalence-yul
ManuelBilbao Apr 30, 2024
cfae957
Fix codecopy gas
gianbelinche Apr 30, 2024
3c80cd2
Charge gas on iszero
ManuelBilbao Apr 30, 2024
0449739
Move static gas charge up on create opcode
ManuelBilbao Apr 30, 2024
332b2fb
Move static gas charge up on create2 opcode
ManuelBilbao Apr 30, 2024
537ac08
Push preprocessed contract
jrchatruc Apr 30, 2024
e433270
Add minimum gas consumption to call opcodes
ManuelBilbao Apr 30, 2024
1aeeff3
Merge branch 'evm-equivalence-yul' into yul-gas-charge-up
ManuelBilbao Apr 30, 2024
d1691f4
Merge pull request #420 from lambdaclass/evm-yul-precompiles
jrchatruc May 2, 2024
62a2573
Merge pull request #424 from lambdaclass/yul-gas-charge-up
jrchatruc May 2, 2024
37e8002
Merge branch 'evm-equivalence-yul' into evm-fix-codecopy-gas
jrchatruc May 2, 2024
8e765e4
Merge pull request #426 from lambdaclass/evm-fix-codecopy-gas
jrchatruc May 2, 2024
6c3602c
Fix delegateCall
jrchatruc May 2, 2024
2b3e3fb
Comment revert on getEvmGas until we figure out the details
jrchatruc May 2, 2024
d77b631
Fix memory expansion error
gianbelinche May 2, 2024
0a3812a
Fix sstore and sload gas
gianbelinche May 3, 2024
7330e55
Fix log2 gas
gianbelinche May 3, 2024
732838d
Fix expand memory dest
gianbelinche May 3, 2024
d115399
Merge pull request #445 from lambdaclass/evm-memory-expansion-fix
jrchatruc May 6, 2024
19b81f7
Bump bytecode length limit
fkrause98 May 16, 2024
fb88864
Optimize sload
gianbelinche May 17, 2024
beab207
Add push optimization
gianbelinche May 17, 2024
ffe55e3
Add extcodecpoy optimization
gianbelinche May 20, 2024
727f9d1
Add memoryExpansion optimization
gianbelinche May 20, 2024
3eb9691
Charge for zkEVM Contract Decommits
jrchatruc May 20, 2024
84b6a6a
Add readIp optimization
gianbelinche May 20, 2024
f592284
Add call optimizations
gianbelinche May 21, 2024
a306e77
Return keccak hash on evm contracts extcodehash
ManuelBilbao May 2, 2024
e5d9274
Change max evm bytecode length
gianbelinche May 6, 2024
9124b42
Change max evm bytecode length
gianbelinche May 7, 2024
7047533
Fix exp gas
gianbelinche May 7, 2024
83f8847
Run preprocessor
jrchatruc May 22, 2024
b4788f6
Merge pull request #479 from lambdaclass/sload-optimization
jrchatruc May 22, 2024
6079e4f
Fix integration tests error
gianbelinche May 22, 2024
3e58f35
Merge branch 'evm-equivalence-yul' into optimizations
gianbelinche May 22, 2024
f1817ef
Remove memCost function
gianbelinche May 27, 2024
63d1f43
Revert "Remove memCost function"
gianbelinche May 27, 2024
a702849
Remove memcost
gianbelinche May 27, 2024
a2b77bd
Merge pull request #488 from lambdaclass/optimizations
jrchatruc May 27, 2024
2954c3a
Merge branch 'evm-equivalence-yul' into yul-charge-decommit-fixed
jrchatruc Jun 5, 2024
ff2fe0f
Fix extcodecopy not storing on dest
gianbelinche Jun 7, 2024
c9d9883
Fix extcodecopy reverting con empty address
gianbelinche Jun 7, 2024
45d2c6d
Merge pull request #515 from lambdaclass/extcodecopy-fix
jrchatruc Jun 10, 2024
2e190af
Add check for overflow
gianbelinche Jun 11, 2024
a043c2b
Fix keccak
gianbelinche Jun 11, 2024
f44956b
Fix returndatacopy checks
gianbelinche Jun 11, 2024
7da9bc4
fix mload
gianbelinche Jun 11, 2024
ea6ce17
Fix return overflow checks
gianbelinche Jun 11, 2024
5879008
Fix compilation
gianbelinche Jun 11, 2024
f595f66
Add mcopy
gianbelinche Jun 12, 2024
ecc51e2
Changes to fix tests
jrchatruc Jun 19, 2024
6b3da03
Fix off by one errors in msize
jrchatruc Jun 24, 2024
559ee47
Add tload and tstore
jrchatruc Jun 25, 2024
126c052
Fix create checking balance incorrectly, revert tstore on static calls
jrchatruc Jun 25, 2024
f9b5bd0
Return gas on push stack reverts
jrchatruc Jun 26, 2024
34296da
Fix balance not truncating addresses to the first 20 bytes
jrchatruc Jun 26, 2024
0828191
Truncate addresses to first 20 bytes in extcodehash
jrchatruc Jun 26, 2024
fa8338b
Truncate addresses on delegatecall
jrchatruc Jun 26, 2024
78b698b
Fix extcodesize
jrchatruc Jun 26, 2024
26e3ea9
Pass stipend on EVM calls as the zkevm gas
jrchatruc Jun 28, 2024
34ee366
Copy zeroes in memory overflow for calldatacopy
IAvecilla Jun 28, 2024
3a09b39
Fix create unnecessary revert
gianbelinche Jul 2, 2024
61c0568
Revert with gas for pop stack operation
IAvecilla Jul 3, 2024
1a88e64
Properly charge cost per word and substract it instead of adding
jrchatruc Jul 3, 2024
420d9ea
Update preprocessed file
IAvecilla Jul 3, 2024
de9afeb
Handle test case of address 0 in extcodehash to match with solidity
IAvecilla Jul 3, 2024
c5766a0
Fix nonce not starting at 0
gianbelinche Jul 4, 2024
e730132
Merge pull request #527 from lambdaclass/fix-compiler-tester-bugs
jrchatruc Jul 5, 2024
f804728
Move loop processing in a function and mark it as noinline
vladimirradosavljevic Jul 8, 2024
58da68f
Add AlwaysInline to warmAddress
vladimirradosavljevic Jul 10, 2024
b2d7432
Combine checks for pop and push
vladimirradosavljevic Jul 8, 2024
c457c7b
Merge pull request #602 from vladimirradosavljevic/evm-equivalence-yu…
jrchatruc Jul 10, 2024
4bfcf68
Merge remote-tracking branch 'origin/evm-equivalence-yul' into nonce-…
jrchatruc Jul 10, 2024
0b58290
Go back to returning 0 evm gas when there's not enough zkevm gas
jrchatruc Jul 10, 2024
a252e10
Increment nonce on failed deployment only for EOAs
jrchatruc Jul 10, 2024
dc2e056
Merge pull request #609 from lambdaclass/increment-nonce-only-for-eoa…
jrchatruc Jul 11, 2024
c5425c6
Merge branch 'evm-equivalence-yul' into nonce-address-fix
jrchatruc Jul 11, 2024
398aeb4
Merge pull request #481 from matter-labs/yul-charge-decommit-fixed
jrchatruc Jul 29, 2024
7c7c6ff
Add NoInline to genericCreate
vladimirradosavljevic Jul 29, 2024
d270bf6
Sink instruction pointer increment to opcode handling
vladimirradosavljevic Jul 30, 2024
b126e8f
Fix pushStackItem argument in genericCreate
vladimirradosavljevic Jul 30, 2024
3695b24
Merge pull request #646 from vladimirradosavljevic/generic_create_noi…
jrchatruc Jul 30, 2024
97a8c94
Merge pull request #608 from lambdaclass/nonce-address-fix
jrchatruc Jul 31, 2024
5a3e3f5
Don't charge the regular cost of the call when calling precompiles
jrchatruc Aug 5, 2024
94967b9
Fix address code
gianbelinche Aug 12, 2024
8376204
Merge pull request #691 from lambdaclass/fix-new-semantic-tests
StanislavBreadless Aug 14, 2024
b19c855
Change consecutive mstore8 with immediate with mstore
vladimirradosavljevic Aug 13, 2024
413d637
Implement memset to zero
vladimirradosavljevic Aug 13, 2024
40d84fd
Implement memcpy function
vladimirradosavljevic Aug 13, 2024
e4175ac
Remove calls to mstore8 in OP_MCOPY and fix checks
vladimirradosavljevic Aug 15, 2024
1b2b0f9
Check offset overflow earlier in memory opcodes
0xVolosnikov Aug 15, 2024
462f011
Merge pull request #705 from matter-labs/vv-evm-interp-mem-overflow-c…
jrchatruc Aug 15, 2024
d272a7e
Remove pop push check
0xVolosnikov Aug 19, 2024
3d766a2
Use unchecked push in safe cases
0xVolosnikov Aug 19, 2024
6691c88
Execute JUMPDEST immediately after JUMP/JUMPI
0xVolosnikov Aug 19, 2024
c8bdc79
Merge pull request #713 from matter-labs/vv-optimize-jump
jrchatruc Aug 19, 2024
68a2c6a
Merge pull request #710 from matter-labs/vv-remove-pop-push-check
jrchatruc Aug 20, 2024
36c03ec
Merge pull request #689 from vladimirradosavljevic/remove_mstore8_calls
jrchatruc Aug 20, 2024
74767c1
Merge pull request #677 from lambdaclass/dont-charge-the-regular-cost…
jrchatruc Aug 20, 2024
77eb854
Remove TODOs
gianbelinche Aug 20, 2024
18d1d3a
Merge pull request #723 from lambdaclass/remove-todo
jrchatruc Aug 20, 2024
7356c2c
Use switch/case in calls
0xVolosnikov Aug 21, 2024
2611e61
Fix
0xVolosnikov Aug 21, 2024
fefa6ce
Optimize getNewAddress
0xVolosnikov Aug 21, 2024
7a98198
Add and use pushStackCheck
0xVolosnikov Aug 21, 2024
83d9aa7
Initial overflow checks remake
0xVolosnikov Aug 21, 2024
2c9b719
Merge branch 'evm-equivalence-yul' into vv-small-interpreter-optimiza…
0xVolosnikov Aug 21, 2024
5cdc5dd
Merge pull request #729 from matter-labs/vv-small-interpreter-optimiz…
jrchatruc Aug 23, 2024
944b6c9
Implement evmCodeHash without mapping (no need to keccak key)
0xVolosnikov Aug 28, 2024
89245ad
Simplify _fetchDeployedCodeLen
0xVolosnikov Aug 28, 2024
448bc97
Use _fetchDeployedCodeLen for both code types
0xVolosnikov Aug 28, 2024
253d370
[EVM-Equivalence-YUL] Restrict functions to only be called from inter…
gianbelinche Aug 29, 2024
2fe0652
Merge pull request #752 from matter-labs/vv-evm-simplify-fetchDeploye…
jrchatruc Aug 29, 2024
b022c9b
Merge pull request #751 from matter-labs/vv-evm-simplify-evmCodeHash
jrchatruc Aug 30, 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
2 changes: 1 addition & 1 deletion .github/workflows/system-contracts-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
- name: Use era-test-node for testing
uses: dutterbutter/era-test-node-action@v0.1.3
with:
releaseTag: v0.0.1-vm1.4.1
releaseTag: v0.0.1-vm1.5.0

- name: Install dependencies
run: yarn
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ tools/data/Verifier.sol
typechain/
yarn-debug.log*
yarn-error.log*
system-contracts/contracts/EvmInterpreterPreprocessed.yul
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ tools/data
l1-contracts/lib
system-contracts/contracts/openzeppelin
system-contracts/contracts/Constants.sol
system-contracts/artifacts-zk
system-contracts/cache-zk
system-contracts/contracts-preprocessed
l1-contracts/cache
l1-contracts/cache-forge
l1-contracts/artifacts
l1-contracts/artifacts-forge
1 change: 1 addition & 0 deletions .solhintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules

# l1-contracts
l1-contracts/cache
l1-contracts/cache-forge
l1-contracts/lib
l1-contracts/node_modules

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ library L2ContractHelper {
uint8 version = uint8(_bytecodeHash[0]);
require(version == 1 && _bytecodeHash[1] == bytes1(0), "zf"); // Incorrectly formatted bytecodeHash

require(_bytecodeLen(_bytecodeHash) % 2 == 1, "uy"); // Code length in words must be odd
require(bytecodeLen(_bytecodeHash) % 2 == 1, "uy"); // Code length in words must be odd
}

/// @notice Returns the length of the bytecode associated with the given hash.
/// @param _bytecodeHash The hash of the bytecode.
/// @return codeLengthInWords The length of the bytecode in words.
function _bytecodeLen(bytes32 _bytecodeHash) private pure returns (uint256 codeLengthInWords) {
function bytecodeLen(bytes32 _bytecodeHash) internal pure returns (uint256 codeLengthInWords) {
codeLengthInWords = uint256(uint8(_bytecodeHash[2])) * 256 + uint256(uint8(_bytecodeHash[3]));
}

Expand Down
53 changes: 41 additions & 12 deletions l1-contracts/contracts/zksync/facets/Executor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.20;

import {Base} from "./Base.sol";
import {COMMIT_TIMESTAMP_NOT_OLDER, COMMIT_TIMESTAMP_APPROXIMATION_DELTA, EMPTY_STRING_KECCAK, L2_TO_L1_LOG_SERIALIZE_SIZE, MAX_L2_TO_L1_LOGS_COMMITMENT_BYTES, PACKED_L2_BLOCK_TIMESTAMP_MASK, PUBLIC_INPUT_SHIFT, POINT_EVALUATION_PRECOMPILE_ADDR} from "../Config.sol";
import {IExecutor, L2_LOG_ADDRESS_OFFSET, L2_LOG_KEY_OFFSET, L2_LOG_VALUE_OFFSET, SystemLogKey, LogProcessingOutput, PubdataSource, BLS_MODULUS, PUBDATA_COMMITMENT_SIZE, PUBDATA_COMMITMENT_CLAIMED_VALUE_OFFSET, PUBDATA_COMMITMENT_COMMITMENT_OFFSET, MAX_NUMBER_OF_BLOBS} from "../interfaces/IExecutor.sol";
import {IExecutor, L2_LOG_ADDRESS_OFFSET, L2_LOG_KEY_OFFSET, L2_LOG_VALUE_OFFSET, SystemLogKey, LogProcessingOutput, PubdataSource, BLS_MODULUS, PUBDATA_COMMITMENT_SIZE, PUBDATA_COMMITMENT_CLAIMED_VALUE_OFFSET, PUBDATA_COMMITMENT_COMMITMENT_OFFSET, MAX_NUMBER_OF_BLOBS, TOTAL_BLOBS_IN_COMMITMENT} from "../interfaces/IExecutor.sol";
import {PriorityQueue, PriorityOperation} from "../libraries/PriorityQueue.sol";
import {UncheckedMath} from "../../common/libraries/UncheckedMath.sol";
import {UnsafeBytes} from "../../common/libraries/UnsafeBytes.sol";
Expand Down Expand Up @@ -451,7 +451,15 @@ contract ExecutorFacet is Base, IExecutor {
}

function _batchMetaParameters() internal view returns (bytes memory) {
return abi.encodePacked(s.zkPorterIsAvailable, s.l2BootloaderBytecodeHash, s.l2DefaultAccountBytecodeHash);
bytes32 l2DefaultAccountBytecodeHash = s.l2DefaultAccountBytecodeHash;
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
);
}

function _batchAuxiliaryOutput(
Expand All @@ -465,23 +473,44 @@ contract ExecutorFacet is Base, IExecutor {
bytes32 l2ToL1LogsHash = keccak256(_batch.systemLogs);

return
abi.encode(
abi.encodePacked(
l2ToL1LogsHash,
_stateDiffHash,
_batch.bootloaderHeapInitialContentsHash,
_batch.eventsQueueStateHash,
// for each blob we have:
// linear hash (hash of preimage from system logs) and
// output hash of blob commitments: keccak(versioned hash || opening point || evaluation value)
// These values will all be bytes32(0) when we submit pubdata via calldata instead of blobs.
// If we only utilize a single blob, _blobHash[1] and _blobCommitments[1] will be bytes32(0)
_blobHashes[0],
_blobCommitments[0],
_blobHashes[1],
_blobCommitments[1]
_encodeBlobAuxilaryOutput(_blobCommitments, _blobHashes)
);
}

/// @dev Encodes the commitment to blobs to be used in the auxiliary output of the batch commitment
/// @param _blobCommitments - the commitments to the blobs
/// @param _blobHashes - the hashes of the blobs
/// @param blobAuxOutputWords - The circuit commitment to the blobs split into 32-byte words
function _encodeBlobAuxilaryOutput(
bytes32[] memory _blobCommitments,
bytes32[] memory _blobHashes
) internal pure returns (bytes32[] memory blobAuxOutputWords) {
// These invariants should be checked by the caller of this function, but we double check
// just in case.
require(_blobCommitments.length == MAX_NUMBER_OF_BLOBS, "b10");
require(_blobHashes.length == MAX_NUMBER_OF_BLOBS, "b11");

// for each blob we have:
// linear hash (hash of preimage from system logs) and
// output hash of blob commitments: keccak(versioned hash || opening point || evaluation value)
// These values will all be bytes32(0) when we submit pubdata via calldata instead of blobs.
//
// For now, only up to 2 blobs are supported by the contract, while 16 are required by the circuits.
// All the unfilled blobs will have their commitment as 0, including the case when we use only 1 blob.

blobAuxOutputWords = new bytes32[](2 * TOTAL_BLOBS_IN_COMMITMENT);

for (uint i = 0; i < MAX_NUMBER_OF_BLOBS; i++) {
blobAuxOutputWords[i * 2] = _blobHashes[i];
blobAuxOutputWords[i * 2 + 1] = _blobCommitments[i];
}
}

/// @notice Returns the keccak hash of the ABI-encoded StoredBatchInfo
function _hashStoredBatchInfo(StoredBatchInfo memory _storedBatchInfo) internal pure returns (bytes32) {
return keccak256(abi.encode(_storedBatchInfo));
Expand Down
5 changes: 5 additions & 0 deletions l1-contracts/contracts/zksync/interfaces/IExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ uint256 constant PUBDATA_COMMITMENT_COMMITMENT_OFFSET = 48;
/// @dev Max number of blobs currently supported
uint256 constant MAX_NUMBER_OF_BLOBS = 2;

/// @dev The number of blobs that must be present in the commitment to a batch.
/// It represents the maximal number of blobs that circuits can support and can be larger
/// than the maximal number of blobs supported by the contract (`MAX_NUMBER_OF_BLOBS`).
uint256 constant TOTAL_BLOBS_IN_COMMITMENT = 16;

/// @title The interface of the zkSync Executor contract capable of processing events emitted in the zkSync protocol.
/// @author Matter Labs
/// @custom:security-contact security@matterlabs.dev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pragma solidity 0.8.20;
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";

import {IMailbox} from "../interfaces/IMailbox.sol";
import {L2ContractHelper} from "../../common/libraries/L2ContractHelper.sol";
import {TX_SLOT_OVERHEAD_L2_GAS, MEMORY_OVERHEAD_GAS, L1_TX_INTRINSIC_L2_GAS, L1_TX_DELTA_544_ENCODING_BYTES, L1_TX_DELTA_FACTORY_DEPS_L2_GAS, L1_TX_MIN_L2_GAS_BASE, L1_TX_INTRINSIC_PUBDATA, L1_TX_DELTA_FACTORY_DEPS_PUBDATA, MAX_GAS_PER_TRANSACTION} from "../Config.sol";

/// @title zkSync Library for validating L1 -> L2 transactions
Expand Down
75 changes: 65 additions & 10 deletions l1-contracts/scripts/deploy-erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as hardhat from "hardhat";

import "@nomiclabs/hardhat-ethers";
import { Command } from "commander";
import type { Contract } from "ethers";
import { Wallet } from "ethers";
import { parseEther } from "ethers/lib/utils";
import { web3Provider } from "./utils";
Expand All @@ -25,8 +26,64 @@ type Token = {

type TokenDescription = Token & {
implementation?: string;
contract?: Contract;
};

async function deployContracts(tokens: TokenDescription[], wallet: Wallet): Promise<number> {
let nonce = await wallet.getTransactionCount("pending");

for (const token of tokens) {
token.implementation = token.implementation || DEFAULT_ERC20;
const tokenFactory = await hardhat.ethers.getContractFactory(token.implementation, wallet);
const args = token.implementation !== "WETH9" ? [token.name, token.symbol, token.decimals] : [];

token.contract = await tokenFactory.deploy(...args, { gasLimit: 5000000, nonce: nonce++ });
}

await Promise.all(tokens.map(async (token) => token.contract.deployTransaction.wait()));

return nonce;
}

function getTestAddresses(): string[] {
return Array.from(
{ length: 10 },
(_, i) =>
Wallet.fromMnemonic(ethTestConfig.test_mnemonic as string, `m/44'/60'/0'/0/${i}`).connect(provider).address
);
}

function unwrapToken(token: TokenDescription): Token {
token.address = token.contract.address;

delete token.contract;
if (token.implementation) {
delete token.implementation;
}

return token;
}

async function mintTokens(tokens: TokenDescription[], wallet: Wallet, nonce: number): Promise<Token[]> {
const targetAddresses = [wallet.address, ...getTestAddresses()];

const results = [];
const promises = [];
for (const token of tokens) {
if (token.implementation !== "WETH9") {
for (const address of targetAddresses) {
const tx = await token.contract.mint(address, parseEther("3000000000"), { nonce: nonce++ });
promises.push(tx.wait());
}
}

results.push(unwrapToken(token));
}
await Promise.all(promises);

return results;
}

async function deployToken(token: TokenDescription, wallet: Wallet): Promise<Token> {
token.implementation = token.implementation || DEFAULT_ERC20;
const tokenFactory = await hardhat.ethers.getContractFactory(token.implementation, wallet);
Expand All @@ -36,12 +93,12 @@ async function deployToken(token: TokenDescription, wallet: Wallet): Promise<Tok

if (token.implementation !== "WETH9") {
await erc20.mint(wallet.address, parseEther("3000000000"));
}
for (let i = 0; i < 10; ++i) {
const testWallet = Wallet.fromMnemonic(ethTestConfig.test_mnemonic as string, "m/44'/60'/0'/0/" + i).connect(
provider
);
if (token.implementation !== "WETH9") {

for (let i = 0; i < 10; ++i) {
const testWallet = Wallet.fromMnemonic(ethTestConfig.test_mnemonic as string, "m/44'/60'/0'/0/" + i).connect(
provider
);

await erc20.mint(testWallet.address, parseEther("3000000000"));
}
}
Expand Down Expand Up @@ -90,15 +147,13 @@ async function main() {
.description("Adds a multiple tokens given in JSON format")
.action(async (tokens_json: string, cmd) => {
const tokens: Array<TokenDescription> = JSON.parse(tokens_json);
const result = [];

const wallet = cmd.privateKey
? new Wallet(cmd.privateKey, provider)
: Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/1").connect(provider);

for (const token of tokens) {
result.push(await deployToken(token, wallet));
}
const nonce = await deployContracts(tokens, wallet);
const result = await mintTokens(tokens, wallet, nonce);

console.log(JSON.stringify(result, null, 2));
});
Expand Down
46 changes: 35 additions & 11 deletions l1-contracts/test/foundry/unit/concrete/Utils/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ address constant L2_KNOWN_CODE_STORAGE_ADDRESS = 0x00000000000000000000000000000
address constant L2_TO_L1_MESSENGER = 0x0000000000000000000000000000000000008008;
address constant PUBDATA_PUBLISHER_ADDRESS = 0x0000000000000000000000000000000000008011;

uint256 constant MAX_NUMBER_OF_BLOBS = 2;
uint256 constant TOTAL_BLOBS_IN_COMMITMENT = 16;

library Utils {
function packBatchTimestampAndBlockTimestamp(
uint256 batchTimestamp,
Expand Down Expand Up @@ -193,7 +196,7 @@ library Utils {
function _batchMetaParameters() internal pure returns (bytes memory) {
// Used in __Executor_Shared.t.sol
bytes8 dummyHash = 0x1234567890123456;
return abi.encodePacked(false, bytes32(dummyHash), bytes32(dummyHash));
return abi.encodePacked(false, bytes32(dummyHash), bytes32(dummyHash), bytes32(dummyHash));
}

function _batchAuxiliaryOutput(
Expand All @@ -205,20 +208,41 @@ library Utils {
bytes32 l2ToL1LogsHash = keccak256(_batch.systemLogs);

return
abi.encode(
abi.encodePacked(
l2ToL1LogsHash,
_stateDiffHash,
_batch.bootloaderHeapInitialContentsHash,
_batch.eventsQueueStateHash,
// for each blob we have:
// linear hash (hash of preimage from system logs) and
// output hash of blob commitments: keccak(versioned hash || opening point || evaluation value)
// These values will all be bytes32(0) when we submit pubdata via calldata instead of blobs.
// If we only utilize a single blob, _blobHash[1] and _blobCommitments[1] will be bytes32(0)
_blobHashes[0],
_blobCommitments[0],
_blobHashes[1],
_blobCommitments[1]
_encodeBlobAuxilaryOutput(_blobCommitments, _blobHashes)
);
}

/// @dev Encodes the commitment to blobs to be used in the auxiliary output of the batch commitment
/// @param _blobCommitments - the commitments to the blobs
/// @param _blobHashes - the hashes of the blobs
/// @param blobAuxOutputWords - The circuit commitment to the blobs split into 32-byte words
function _encodeBlobAuxilaryOutput(
bytes32[] memory _blobCommitments,
bytes32[] memory _blobHashes
) internal pure returns (bytes32[] memory blobAuxOutputWords) {
// These invariants should be checked by the caller of this function, but we double check
// just in case.
require(_blobCommitments.length == MAX_NUMBER_OF_BLOBS, "b10");
require(_blobHashes.length == MAX_NUMBER_OF_BLOBS, "b11");

// for each blob we have:
// linear hash (hash of preimage from system logs) and
// output hash of blob commitments: keccak(versioned hash || opening point || evaluation value)
// These values will all be bytes32(0) when we submit pubdata via calldata instead of blobs.
//
// For now, only up to 2 blobs are supported by the contract, while 16 are required by the circuits.
// All the unfilled blobs will have their commitment as 0, including the case when we use only 1 blob.

blobAuxOutputWords = new bytes32[](2 * TOTAL_BLOBS_IN_COMMITMENT);

for (uint i = 0; i < MAX_NUMBER_OF_BLOBS; i++) {
blobAuxOutputWords[i * 2] = _blobHashes[i];
blobAuxOutputWords[i * 2 + 1] = _blobCommitments[i];
}
}
}
4 changes: 2 additions & 2 deletions l1-contracts/test/unit_tests/executor_proof.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe("Executor test", function () {
);
console.log("This block Commitment is : " + nextCommitment);
expect(nextCommitment, "Commitment computation failed").is.equal(
"0x38ba669c30ce03475c4139fdab5d43fd8edd78f50ee3e99101cc55ad29b6efb0"
"0xab2238ade1c47671daadd8859d3f40986daf53a9349716fca57e6679e5dc1ece"
);

const prevCommitment = "0x6ebf945305689a8c3ac993df7f002d41d311a762cd6bf39bb054ead8d1f54404";
Expand All @@ -66,6 +66,6 @@ describe("Executor test", function () {
// ignored.
recursionCircuitsSetVksHash: "0x05dc05911af0aee6a0950ee36dad423981cf05a58cfdb479109bff3c2262eaac",
});
expect(result.toHexString(), "").to.be.equal("0x3449f2e7025a7731ca98a7a232211f88ae4e5e8ae2ce41fd40866f7b");
expect(result.toHexString(), "").to.be.equal("0x23ef2434974fa8d0f7f7d29839aaa78fe767bf36edb3a5979d60a6b0");
});
});
Loading
Loading