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

Zksync era integration tests #208

Merged
merged 30 commits into from
Aug 27, 2024
Merged

Conversation

MarcosNicolau
Copy link
Contributor

This pr introduces several changes and fixes to the vm:

  • Fixes Contex(IncrementTxNumber) opcode: it was not clearing the transient storage.
  • Fixes the decommit opcode: it was not accounting if the contract had already been decommitted.
  • Various fixes to the farcall opcode: adds mandated gas, handles decommit cost err, and fixes the params of mimic call
  • Fix gas return on reverts and panics: on far_calls we were not supposed to add the evm_interpreter stipend gas to the new frame.
  • Implements external rollbacks: this type of rollbacks are only called from the bootloader and they create a snapshot of the whole vm(execution and whole state).

All of this changes have been made to finish the integration with the bootloader. See here.

src/execution.rs Show resolved Hide resolved
src/op_handlers/far_call.rs Show resolved Hide resolved
src/op_handlers/ret.rs Outdated Show resolved Hide resolved
src/rollbacks.rs Show resolved Hide resolved
src/state.rs Show resolved Hide resolved
src/op_handlers/ret.rs Outdated Show resolved Hide resolved
@@ -50,6 +51,23 @@ pub struct Execution {
pub use_hooks: bool,
Copy link
Member

Choose a reason for hiding this comment

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

If you extract the program, then the ExecutionSnapshot becomes just a clone of this. Maybe we could move the program out and turn ExecutionSnapshot in a simple wrapper?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I thought of that as well, but I didn't want to change the vm initial struct tbh. If you consider this change to be worth it, I'll go ahead and make the appropriate changes. I would prefer to leave it for a later general code refactor thou, but you call the shots!! 😉.

src/state.rs Outdated
Comment on lines 309 to 310
pub struct FullStateSnapshot {
pub internal_snapshot: StateSnapshot,
Copy link
Contributor

Choose a reason for hiding this comment

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

FullStateSnapshot and StateSnapshot are named in a confusing way IMO, maybe renaming StateSnapshot to InternalStateSnapshot is a bit better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that names can be a bit confusing, I've added some new comments, and renamed FullStateSnapshot to ExternalStateSnapshot. Tell me if you think that is clearer 😁.

Copy link
Contributor

@juan518munoz juan518munoz 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
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.

Let's discuss some things.

src/op_handlers/ret.rs Outdated Show resolved Hide resolved
src/op_handlers/ret.rs Outdated Show resolved Hide resolved
src/rollbacks.rs Show resolved Hide resolved
src/rollbacks.rs Show resolved Hide resolved
src/state.rs Outdated Show resolved Hide resolved
src/state.rs Outdated Show resolved Hide resolved
self.decommitted_hashes.map.insert(hash);
self.storage.borrow_mut().decommit(hash)
pub fn decommit(&mut self, hash: U256) -> (Option<Vec<U256>>, bool) {
let was_decommitted = !self.decommitted_hashes.map.insert(hash);
Copy link
Contributor

Choose a reason for hiding this comment

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

What we're doing here, Exactly? A bit confused since we're mixing Option + Bool. Let's discus this a bit.

Copy link
Contributor Author

@MarcosNicolau MarcosNicolau Aug 26, 2024

Choose a reason for hiding this comment

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

When decommiting, we want to know whether the hash has already been decommited or not to calculate refunds and decommit costs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a comment clarifying this then.

src/state.rs Outdated Show resolved Hide resolved
src/state.rs Show resolved Hide resolved
src/state.rs Show resolved Hide resolved
@MarcosNicolau
Copy link
Contributor Author

I’ve removed the cache for the initial storage to reduce confusion. We can consider re-adding it later if necessary.

Copy link

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                              100.000 ║
║ Best                              100.000 ║
║ Worst                               0.000 ║
║ Total                             100.000 ║
╚═══════════════════════════════════════════╝

╔═╡ 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                              100.000 ║
║ Best                              100.000 ║
║ Worst                               0.000 ║
║ Total                             100.000 ║
╠═╡ Ergs/gas ╞══════╡ EVMInterpreter M3B3 ╞═╣
║ ADD                                 0.000 ║
║ MUL                                 0.000 ║
║ SUB                                 0.000 ║
║ DIV                                 0.000 ║
║ SDIV                                0.000 ║
║ MOD                                 0.000 ║
║ SMOD                                0.000 ║
║ ADDMOD                              0.000 ║
║ MULMOD                              0.000 ║
║ EXP                                 0.000 ║
║ SIGNEXTEND                          0.000 ║
║ LT                                  0.000 ║
║ GT                                  0.000 ║
║ SLT                                 0.000 ║
║ SGT                                 0.000 ║
║ EQ                                  0.000 ║
║ ISZERO                              0.000 ║
║ AND                                 0.000 ║
║ OR                                  0.000 ║
║ XOR                                 0.000 ║
║ NOT                                 0.000 ║
║ BYTE                                0.000 ║
║ SHL                                 0.000 ║
║ SHR                                 0.000 ║
║ SAR                                 0.000 ║
║ SGT                                 0.000 ║
║ SHA3                                0.000 ║
║ ADDRESS                             0.000 ║
║ BALANCE                             0.000 ║
║ ORIGIN                              0.000 ║
║ CALLER                              0.000 ║
║ CALLVALUE                           0.000 ║
║ CALLDATALOAD                        0.000 ║
║ CALLDATASIZE                        0.000 ║
║ CALLDATACOPY                        0.000 ║
║ CODESIZE                            0.000 ║
║ CODECOPY                            0.000 ║
║ GASPRICE                            0.000 ║
║ EXTCODESIZE                         0.000 ║
║ EXTCODECOPY                         0.000 ║
║ RETURNDATASIZE                      0.000 ║
║ RETURNDATACOPY                      0.000 ║
║ EXTCODEHASH                         0.000 ║
║ BLOCKHASH                           0.000 ║
║ COINBASE                            0.000 ║
║ TIMESTAMP                           0.000 ║
║ NUMBER                              0.000 ║
║ PREVRANDAO                          0.000 ║
║ GASLIMIT                            0.000 ║
║ CHAINID                             0.000 ║
║ SELFBALANCE                         0.000 ║
║ BASEFEE                             0.000 ║
║ POP                                 0.000 ║
║ MLOAD                               0.000 ║
║ MSTORE                              0.000 ║
║ MSTORE8                             0.000 ║
║ SLOAD                               0.000 ║
║ SSTORE                              0.000 ║
║ JUMP                                0.000 ║
║ JUMPI                               0.000 ║
║ PC                                  0.000 ║
║ MSIZE                               0.000 ║
║ GAS                                 0.000 ║
║ JUMPDEST                            0.000 ║
║ PUSH0                               0.000 ║
║ PUSH1                               0.000 ║
║ PUSH2                               0.000 ║
║ PUSH4                               0.000 ║
║ PUSH5                               0.000 ║
║ PUSH6                               0.000 ║
║ PUSH7                               0.000 ║
║ PUSH8                               0.000 ║
║ PUSH9                               0.000 ║
║ PUSH10                              0.000 ║
║ PUSH11                              0.000 ║
║ PUSH12                              0.000 ║
║ PUSH13                              0.000 ║
║ PUSH14                              0.000 ║
║ PUSH15                              0.000 ║
║ PUSH16                              0.000 ║
║ PUSH17                              0.000 ║
║ PUSH18                              0.000 ║
║ PUSH19                              0.000 ║
║ PUSH20                              0.000 ║
║ PUSH21                              0.000 ║
║ PUSH22                              0.000 ║
║ PUSH23                              0.000 ║
║ PUSH24                              0.000 ║
║ PUSH25                              0.000 ║
║ PUSH26                              0.000 ║
║ PUSH27                              0.000 ║
║ PUSH28                              0.000 ║
║ PUSH29                              0.000 ║
║ PUSH30                              0.000 ║
║ PUSH31                              0.000 ║
║ PUSH32                              0.000 ║
║ DUP1                                0.000 ║
║ DUP2                                0.000 ║
║ DUP3                                0.000 ║
║ DUP4                                0.000 ║
║ DUP5                                0.000 ║
║ DUP6                                0.000 ║
║ DUP7                                0.000 ║
║ DUP8                                0.000 ║
║ DUP9                                0.000 ║
║ DUP10                               0.000 ║
║ DUP11                               0.000 ║
║ DUP12                               0.000 ║
║ DUP13                               0.000 ║
║ DUP14                               0.000 ║
║ DUP15                               0.000 ║
║ DUP16                               0.000 ║
║ SWAP1                               0.000 ║
║ SWAP2                               0.000 ║
║ SWAP3                               0.000 ║
║ SWAP4                               0.000 ║
║ SWAP5                               0.000 ║
║ SWAP6                               0.000 ║
║ SWAP7                               0.000 ║
║ SWAP8                               0.000 ║
║ SWAP9                               0.000 ║
║ SWAP10                              0.000 ║
║ SWAP11                              0.000 ║
║ SWAP12                              0.000 ║
║ SWAP13                              0.000 ║
║ SWAP14                              0.000 ║
║ SWAP15                              0.000 ║
║ SWAP16                              0.000 ║
║ CALL                                0.000 ║
║ STATICCALL                          0.000 ║
║ DELEGATECALL                        0.000 ║
║ CREATE                              0.000 ║
║ CREATE2                             0.000 ║
║ RETURN                              0.000 ║
║ REVERT                              0.000 ║
╠═╡ Ergs/gas (-%) ╞═╡ EVMInterpreter M3B3 ╞═╣
║ ADD                               100.000 ║
║ MUL                               100.000 ║
║ SUB                               100.000 ║
║ DIV                               100.000 ║
║ SDIV                              100.000 ║
║ MOD                               100.000 ║
║ SMOD                              100.000 ║
║ ADDMOD                            100.000 ║
║ MULMOD                            100.000 ║
║ EXP                               100.000 ║
║ SIGNEXTEND                        100.000 ║
║ LT                                100.000 ║
║ GT                                100.000 ║
║ SLT                               100.000 ║
║ SGT                               100.000 ║
║ EQ                                100.000 ║
║ ISZERO                            100.000 ║
║ AND                               100.000 ║
║ OR                                100.000 ║
║ XOR                               100.000 ║
║ NOT                               100.000 ║
║ BYTE                              100.000 ║
║ SHL                               100.000 ║
║ SHR                               100.000 ║
║ SAR                               100.000 ║
║ SGT                               100.000 ║
║ SHA3                              100.000 ║
║ ADDRESS                           100.000 ║
║ BALANCE                           100.000 ║
║ ORIGIN                            100.000 ║
║ CALLER                            100.000 ║
║ CALLVALUE                         100.000 ║
║ CALLDATALOAD                      100.000 ║
║ CALLDATASIZE                      100.000 ║
║ CALLDATACOPY                      100.000 ║
║ CODESIZE                          100.000 ║
║ CODECOPY                          100.000 ║
║ GASPRICE                          100.000 ║
║ EXTCODESIZE                       100.000 ║
║ EXTCODECOPY                       100.000 ║
║ RETURNDATASIZE                    100.000 ║
║ RETURNDATACOPY                    100.000 ║
║ EXTCODEHASH                       100.000 ║
║ BLOCKHASH                         100.000 ║
║ COINBASE                          100.000 ║
║ TIMESTAMP                         100.000 ║
║ NUMBER                            100.000 ║
║ PREVRANDAO                        100.000 ║
║ GASLIMIT                          100.000 ║
║ CHAINID                           100.000 ║
║ SELFBALANCE                       100.000 ║
║ BASEFEE                           100.000 ║
║ POP                               100.000 ║
║ MLOAD                             100.000 ║
║ MSTORE                            100.000 ║
║ MSTORE8                           100.000 ║
║ SLOAD                             100.000 ║
║ SSTORE                            100.000 ║
║ JUMP                              100.000 ║
║ JUMPI                             100.000 ║
║ PC                                100.000 ║
║ MSIZE                             100.000 ║
║ GAS                               100.000 ║
║ JUMPDEST                          100.000 ║
║ PUSH0                             100.000 ║
║ PUSH1                             100.000 ║
║ PUSH2                             100.000 ║
║ PUSH4                             100.000 ║
║ PUSH5                             100.000 ║
║ PUSH6                             100.000 ║
║ PUSH7                             100.000 ║
║ PUSH8                             100.000 ║
║ PUSH9                             100.000 ║
║ PUSH10                            100.000 ║
║ PUSH11                            100.000 ║
║ PUSH12                            100.000 ║
║ PUSH13                            100.000 ║
║ PUSH14                            100.000 ║
║ PUSH15                            100.000 ║
║ PUSH16                            100.000 ║
║ PUSH17                            100.000 ║
║ PUSH18                            100.000 ║
║ PUSH19                            100.000 ║
║ PUSH20                            100.000 ║
║ PUSH21                            100.000 ║
║ PUSH22                            100.000 ║
║ PUSH23                            100.000 ║
║ PUSH24                            100.000 ║
║ PUSH25                            100.000 ║
║ PUSH26                            100.000 ║
║ PUSH27                            100.000 ║
║ PUSH28                            100.000 ║
║ PUSH29                            100.000 ║
║ PUSH30                            100.000 ║
║ PUSH31                            100.000 ║
║ PUSH32                            100.000 ║
║ DUP1                              100.000 ║
║ DUP2                              100.000 ║
║ DUP3                              100.000 ║
║ DUP4                              100.000 ║
║ DUP5                              100.000 ║
║ DUP6                              100.000 ║
║ DUP7                              100.000 ║
║ DUP8                              100.000 ║
║ DUP9                              100.000 ║
║ DUP10                             100.000 ║
║ DUP11                             100.000 ║
║ DUP12                             100.000 ║
║ DUP13                             100.000 ║
║ DUP14                             100.000 ║
║ DUP15                             100.000 ║
║ DUP16                             100.000 ║
║ SWAP1                             100.000 ║
║ SWAP2                             100.000 ║
║ SWAP3                             100.000 ║
║ SWAP4                             100.000 ║
║ SWAP5                             100.000 ║
║ SWAP6                             100.000 ║
║ SWAP7                             100.000 ║
║ SWAP8                             100.000 ║
║ SWAP9                             100.000 ║
║ SWAP10                            100.000 ║
║ SWAP11                            100.000 ║
║ SWAP12                            100.000 ║
║ SWAP13                            100.000 ║
║ SWAP14                            100.000 ║
║ SWAP15                            100.000 ║
║ SWAP16                            100.000 ║
║ CALL                              100.000 ║
║ STATICCALL                        100.000 ║
║ DELEGATECALL                      100.000 ║
║ CREATE                            100.000 ║
║ CREATE2                           100.000 ║
║ RETURN                            100.000 ║
║ REVERT                            100.000 ║
╚═══════════════════════════════════════════╝

@MarcosNicolau MarcosNicolau merged commit 817d0f3 into main Aug 27, 2024
187 of 188 checks passed
@MarcosNicolau MarcosNicolau deleted the zksync-era-integration-tests branch August 27, 2024 20:08
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.

4 participants