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

Zk server compatibility #221

Merged
merged 60 commits into from
Sep 4, 2024
Merged

Zk server compatibility #221

merged 60 commits into from
Sep 4, 2024

Conversation

gianbelinche
Copy link
Contributor

@gianbelinche gianbelinche commented Sep 3, 2024

This PR makes the neccessary changes on era vm to be compatible with zksync-era

Related to:
lambdaclass/zksync-era#253
lambdaclass/era-compiler-tester#24

MarcosNicolau and others added 30 commits August 13, 2024 15:45
Fixes decommit opcode, which was not account for if the code had already been decommitted
Adds mandated gass, handles decommit cost err, and fixes the params of mimic call
MarcosNicolau and others added 13 commits August 26, 2024 16:13
* Add vm statistics

* Add tracking of precompiles cycles

* Add storage and decommit cycles

* Make opcode variant pub

* Add cycles counter

* Update zksync-era submodule

* Address clippy warnings

* Update era-compiler-tester submodule

* Update zksync-era submodule

* Fix initial value read in storage_changes

* Expose opcode variants

* Update zksync-era submodule

* Address review comments
@jrchatruc jrchatruc marked this pull request as ready for review September 3, 2024 14:28
Copy link
Contributor

@MarcosNicolau MarcosNicolau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link

github-actions bot commented Sep 3, 2024

Ergs comparison results:

╔═╡ Size (-%) ╞════════════════╡ All M3B3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Cycles (-%) ╞══════════════╡ All M3B3 ╞═╣
║ Mean                              100.000 ║
║ Best                              100.000 ║
║ Worst                               0.000 ║
║ Total                             100.000 ║
╠═╡ Ergs (-%) ╞════════════════╡ All M3B3 ╞═╣
║ Mean                                7.941 ║
║ Best                               57.093 ║
║ Worst                               0.000 ║
║ Total                               9.985 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════════════╡ All MzB3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Cycles (-%) ╞══════════════╡ All MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Ergs (-%) ╞════════════════╡ All MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Cycles (-%) ╞═══╡ EVMInterpreter M3B3 ╞═╣
║ Mean                              100.000 ║
║ Best                              100.000 ║
║ Worst                               0.000 ║
║ Total                             100.000 ║
╠═╡ Ergs (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╣
║ Mean                                7.941 ║
║ Best                               57.093 ║
║ Worst                               0.000 ║
║ Total                               9.985 ║
╠═╡ Ergs/gas ╞══════╡ EVMInterpreter M3B3 ╞═╣
║ ADD                                60.750 ║
║ MUL                                36.450 ║
║ SUB                                60.750 ║
║ DIV                                44.850 ║
║ SDIV                               59.250 ║
║ MOD                                43.650 ║
║ SMOD                               58.050 ║
║ ADDMOD                             34.156 ║
║ MULMOD                             34.156 ║
║ EXP                                 8.537 ║
║ SIGNEXTEND                         42.450 ║
║ LT                                 64.750 ║
║ GT                                 64.750 ║
║ SLT                                88.750 ║
║ SGT                                86.750 ║
║ EQ                                 64.750 ║
║ ISZERO                             56.417 ║
║ AND                                58.750 ║
║ OR                                 60.750 ║
║ XOR                                60.750 ║
║ NOT                                52.417 ║
║ BYTE                               66.750 ║
║ SHL                                64.750 ║
║ SHR                                62.750 ║
║ SAR                                80.750 ║
║ SGT                                86.750 ║
║ SHA3                               27.647 ║
║ ADDRESS                            81.000 ║
║ BALANCE                            34.496 ║
║ ORIGIN                            398.594 ║
║ CALLER                             81.000 ║
║ CALLVALUE                          81.000 ║
║ CALLDATALOAD                       54.750 ║
║ CALLDATASIZE                       81.125 ║
║ CALLDATACOPY                       66.231 ║
║ CODESIZE                           81.625 ║
║ CODECOPY                          142.241 ║
║ GASPRICE                          404.219 ║
║ EXTCODESIZE                         3.590 ║
║ EXTCODECOPY                         3.664 ║
║ RETURNDATASIZE                     76.500 ║
║ RETURNDATACOPY                     51.778 ║
║ EXTCODEHASH                         5.489 ║
║ BLOCKHASH                          49.197 ║
║ COINBASE                          401.594 ║
║ TIMESTAMP                         398.594 ║
║ NUMBER                            398.594 ║
║ PREVRANDAO                        398.594 ║
║ GASLIMIT                          404.594 ║
║ CHAINID                           398.594 ║
║ SELFBALANCE                       261.863 ║
║ BASEFEE                           395.594 ║
║ POP                                65.625 ║
║ MLOAD                              71.931 ║
║ MSTORE                             75.696 ║
║ MSTORE8                            83.539 ║
║ SLOAD                              14.891 ║
║ SSTORE                              4.039 ║
║ JUMP                               32.444 ║
║ JUMPI                              30.455 ║
║ PC                                 81.500 ║
║ MSIZE                              88.000 ║
║ GAS                                81.500 ║
║ JUMPDEST                          114.000 ║
║ PUSH0                              75.500 ║
║ PUSH1                              62.083 ║
║ PUSH2                              65.500 ║
║ PUSH4                              68.333 ║
║ PUSH5                              69.750 ║
║ PUSH6                              71.167 ║
║ PUSH7                              72.583 ║
║ PUSH8                              74.000 ║
║ PUSH9                              75.417 ║
║ PUSH10                             76.833 ║
║ PUSH11                             78.250 ║
║ PUSH12                             79.667 ║
║ PUSH13                             81.083 ║
║ PUSH14                             82.500 ║
║ PUSH15                             83.917 ║
║ PUSH16                             85.333 ║
║ PUSH17                             86.750 ║
║ PUSH18                             88.167 ║
║ PUSH19                             89.583 ║
║ PUSH20                             91.000 ║
║ PUSH21                             92.417 ║
║ PUSH22                             93.833 ║
║ PUSH23                             95.250 ║
║ PUSH24                             96.667 ║
║ PUSH25                             98.083 ║
║ PUSH26                             99.500 ║
║ PUSH27                            100.917 ║
║ PUSH28                            102.333 ║
║ PUSH29                            103.750 ║
║ PUSH30                            105.167 ║
║ PUSH31                            106.583 ║
║ PUSH32                            106.000 ║
║ DUP1                               54.417 ║
║ DUP2                               58.417 ║
║ DUP3                               58.417 ║
║ DUP4                               58.417 ║
║ DUP5                               58.417 ║
║ DUP6                               58.417 ║
║ DUP7                               58.417 ║
║ DUP8                               58.417 ║
║ DUP9                               56.417 ║
║ DUP10                              58.417 ║
║ DUP11                              58.417 ║
║ DUP12                              58.417 ║
║ DUP13                              58.417 ║
║ DUP14                              58.417 ║
║ DUP15                              58.417 ║
║ DUP16                              58.417 ║
║ SWAP1                              59.083 ║
║ SWAP2                              59.083 ║
║ SWAP3                              59.083 ║
║ SWAP4                              59.083 ║
║ SWAP5                              59.083 ║
║ SWAP6                              59.083 ║
║ SWAP7                              59.083 ║
║ SWAP8                              59.083 ║
║ SWAP9                              59.083 ║
║ SWAP10                             59.083 ║
║ SWAP11                             59.083 ║
║ SWAP12                             59.083 ║
║ SWAP13                             59.083 ║
║ SWAP14                             59.083 ║
║ SWAP15                             59.083 ║
║ SWAP16                             57.083 ║
║ CALL                               42.789 ║
║ STATICCALL                         42.749 ║
║ DELEGATECALL                       42.469 ║
║ CREATE                              3.737 ║
║ CREATE2                             5.144 ║
║ RETURN                              1.000 ║
║ REVERT                              1.000 ║
╠═╡ Ergs/gas (-%) ╞═╡ EVMInterpreter M3B3 ╞═╣
║ BALANCE                            53.121 ║
║ ORIGIN                             70.963 ║
║ GASPRICE                           70.673 ║
║ EXTCODESIZE                        29.684 ║
║ EXTCODECOPY                        29.233 ║
║ EXTCODEHASH                        33.981 ║
║ BLOCKHASH                          79.764 ║
║ COINBASE                           70.808 ║
║ TIMESTAMP                          70.963 ║
║ NUMBER                             70.963 ║
║ PREVRANDAO                         70.963 ║
║ GASLIMIT                           70.654 ║
║ CHAINID                            70.963 ║
║ SELFBALANCE                        59.692 ║
║ BASEFEE                            71.118 ║
║ SLOAD                              44.878 ║
║ SSTORE                             55.336 ║
║ CALL                               31.292 ║
║ STATICCALL                         31.312 ║
║ DELEGATECALL                       30.698 ║
║ CREATE                             31.944 ║
║ CREATE2                            33.582 ║
╚═══════════════════════════════════════════╝

Copy link
Contributor

@fkrause98 fkrause98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -82,6 +84,10 @@ pub fn add_l2_to_l1_message(
) -> Result<(), EraVmError> {
let key = vm_state.get_register(opcode.src0_index).value;
let value = vm_state.get_register(opcode.src1_index).value;
println!(
"L1 TO L2 regusters indexes {} {}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo here

src/execution.rs Outdated
Comment on lines 512 to 514
if addr >= self.heap.len() as u32 {
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done out of the loop, like this:

let start = pointer.start + offset;
let end = self.heap.len().min(start + 32);
for i in start..end {
    result |= U256::from(self.heap[addr as usize]) << (1 * 8);
}
result

Or quite possibly as a slice copy, if the U256 provides a byte representation.

@gianbelinche gianbelinche merged commit e2c56ac into main Sep 4, 2024
188 checks passed
@gianbelinche gianbelinche deleted the zk_server_compatibility branch September 4, 2024 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants