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

[EraVM] Implement __system_request_slice_fallback #557

Merged

Conversation

vladimirradosavljevic
Copy link
Contributor

@vladimirradosavljevic vladimirradosavljevic commented May 21, 2024

This implementation is similar to __system_request, but without the initial 4 bytes for the signature, and returns a whole slice.

Copy link

github-actions bot commented May 21, 2024

Benchmark results:

╔═╡ Size (-%) ╞════════════════╡ All M3B3 ╞═╗
║ Mean                                0.001 ║
║ Best                                3.113 ║
║ Worst                              -0.387 ║
║ Total                               0.002 ║
╠═╡ Cycles (-%) ╞══════════════╡ All M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.058 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════════════╡ All M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.047 ║
║ Worst                              -0.012 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════════════╡ All MzB3 ╞═╗
║ Mean                                0.000 ║
║ Best                                5.594 ║
║ Worst                              -3.347 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════════════╡ All MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                               18.911 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════════════╡ All MzB3 ╞═╣
║ Mean                                0.001 ║
║ Best                               48.690 ║
║ Worst                              -0.047 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞═══╡ EVMInterpreter M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs/gas ╞══════╡ EVMInterpreter M3B3 ╞═╣
║ ADD                                67.667 ║
║ MUL                                39.400 ║
║ SUB                                67.667 ║
║ DIV                                47.800 ║
║ SDIV                               64.600 ║
║ MOD                                46.600 ║
║ SMOD                               62.200 ║
║ ADDMOD                             39.000 ║
║ MULMOD                             36.000 ║
║ EXP                                 9.283 ║
║ SIGNEXTEND                         45.400 ║
║ LT                                 71.667 ║
║ GT                                 71.667 ║
║ SLT                                95.667 ║
║ SGT                                93.667 ║
║ EQ                                 71.667 ║
║ ISZERO                             63.333 ║
║ AND                                65.667 ║
║ OR                                 67.667 ║
║ XOR                                67.667 ║
║ NOT                                59.333 ║
║ BYTE                               75.667 ║
║ SHL                                73.667 ║
║ SHR                                71.667 ║
║ SAR                                89.667 ║
║ SGT                                93.667 ║
║ SHA3                               27.139 ║
║ ADDRESS                            91.000 ║
║ BALANCE                            73.180 ║
║ ORIGIN                           2852.000 ║
║ CALLER                             91.000 ║
║ CALLVALUE                          91.000 ║
║ CALLDATALOAD                       61.667 ║
║ CALLDATASIZE                       91.500 ║
║ CALLDATACOPY                       57.889 ║
║ CODESIZE                           88.500 ║
║ CODECOPY                          108.667 ║
║ GASPRICE                         2846.000 ║
║ EXTCODESIZE                         5.149 ║
║ EXTCODECOPY                         4.667 ║
║ RETURNDATASIZE                     89.000 ║
║ RETURNDATACOPY                     55.889 ║
║ EXTCODEHASH                         2.687 ║
║ BLOCKHASH                         244.450 ║
║ COINBASE                         2849.000 ║
║ TIMESTAMP                        2843.000 ║
║ NUMBER                           2843.000 ║
║ PREVRANDAO                       2843.000 ║
║ GASLIMIT                         2849.000 ║
║ CHAINID                          2837.000 ║
║ SELFBALANCE                       640.200 ║
║ BASEFEE                          2840.000 ║
║ POP                                79.000 ║
║ MLOAD                              43.667 ║
║ MSTORE                             44.333 ║
║ MSTORE8                            47.111 ║
║ SLOAD                               5.766 ║
║ SSTORE                              0.621 ║
║ JUMP                               37.333 ║
║ JUMPI                              32.818 ║
║ PC                                 91.500 ║
║ MSIZE                             101.000 ║
║ GAS                                85.500 ║
║ JUMPDEST                          122.000 ║
║ PUSH0                              88.500 ║
║ PUSH1                              75.333 ║
║ PUSH2                              91.667 ║
║ PUSH4                             150.333 ║
║ PUSH5                             170.667 ║
║ PUSH6                             191.000 ║
║ PUSH7                             211.333 ║
║ PUSH8                             231.667 ║
║ PUSH9                             252.000 ║
║ PUSH10                            272.333 ║
║ PUSH11                            290.667 ║
║ PUSH12                            313.000 ║
║ PUSH13                            333.333 ║
║ PUSH14                            343.333 ║
║ PUSH15                            392.667 ║
║ PUSH16                            413.000 ║
║ PUSH17                            433.333 ║
║ PUSH18                            453.667 ║
║ PUSH19                            474.000 ║
║ PUSH20                            494.333 ║
║ PUSH21                            514.667 ║
║ PUSH22                            535.000 ║
║ PUSH23                            555.333 ║
║ PUSH24                            575.667 ║
║ PUSH25                            596.000 ║
║ PUSH26                            616.333 ║
║ PUSH27                            636.667 ║
║ PUSH28                            657.000 ║
║ PUSH29                            677.333 ║
║ PUSH30                            681.333 ║
║ PUSH31                            758.667 ║
║ PUSH32                            779.000 ║
║ DUP1                               61.333 ║
║ DUP2                               65.333 ║
║ DUP3                               65.333 ║
║ DUP4                               65.333 ║
║ DUP5                               65.333 ║
║ DUP6                               65.333 ║
║ DUP7                               65.333 ║
║ DUP8                               65.333 ║
║ DUP9                               65.333 ║
║ DUP10                              65.333 ║
║ DUP11                              65.333 ║
║ DUP12                              65.333 ║
║ DUP13                              63.333 ║
║ DUP14                              65.333 ║
║ DUP15                              65.333 ║
║ DUP16                              65.333 ║
║ SWAP1                              66.000 ║
║ SWAP2                              66.000 ║
║ SWAP3                              66.000 ║
║ SWAP4                              66.000 ║
║ SWAP5                              66.000 ║
║ SWAP6                              66.000 ║
║ SWAP7                              66.000 ║
║ SWAP8                              66.000 ║
║ SWAP9                              66.000 ║
║ SWAP10                             66.000 ║
║ SWAP11                             64.000 ║
║ SWAP12                             66.000 ║
║ SWAP13                             66.000 ║
║ SWAP14                             66.000 ║
║ SWAP15                             66.000 ║
║ SWAP16                             66.000 ║
║ CREATE                              5.046 ║
║ CALL                               56.371 ║
║ RETURN                                inf ║
║ DELEGATECALL                       52.286 ║
║ STATICCALL                         53.248 ║
║ CREATE2                             7.067 ║
║ REVERT                                inf ║
╠═╡ Ergs/gas (-%) ╞═╡ EVMInterpreter M3B3 ╞═╣
╚═══════════════════════════════════════════╝

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

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

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

╔═╡ Size (-%) ╞══════════╡ Real life M3B3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞════════╡ Real life M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞══════════╡ Real life M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.026 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

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

@vladimirradosavljevic vladimirradosavljevic force-pushed the vr-cpr-1710-add-a-version-of-system_request-without-signature branch from 00abe12 to c43bcd8 Compare May 21, 2024 13:53
@vladimirradosavljevic
Copy link
Contributor Author

Since we disabled CSE in GVN and NewGVN, running EraVMCSE later in the pipeline should fix these degradations.

Copy link
Collaborator

@hedgar2017 hedgar2017 left a comment

Choose a reason for hiding this comment

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

Oh lawd, sorry, I was slightly wrong about this @__system_request_fallback!

It must return the pointer it receives from the underlying call, that is system_request_result_abi_data, since the call returns not a single value, but the whole slice!

Let's also rename it to @__system_request_slice_fallback, as we may have all 4 combinations in the future.

This implementation is similar to __system_request, but
without the initial 4 bytes for the signature, and returns
a whole slice.

Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
…_request, __system_request_slice_fallback and __sha3

Currently, calls to these functions are combined.

Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
@vladimirradosavljevic vladimirradosavljevic force-pushed the vr-cpr-1710-add-a-version-of-system_request-without-signature branch from c43bcd8 to a8961c8 Compare May 22, 2024 09:04
@vladimirradosavljevic
Copy link
Contributor Author

Oh lawd, sorry, I was slightly wrong about this @__system_request_fallback!

It must return the pointer it receives from the underlying call, that is system_request_result_abi_data, since the call returns not a single value, but the whole slice!

Let's also rename it to @__system_request_slice_fallback, as we may have all 4 combinations in the future.

Done. Changed the name to @__system_request_slice_fallback and this function returns whole slice (system_request_result_abi_data).

@vladimirradosavljevic vladimirradosavljevic changed the title [EraVM] Implement __system_request_fallback [EraVM] Implement __system_request_slice_fallback May 22, 2024
Copy link
Collaborator

@hedgar2017 hedgar2017 left a comment

Choose a reason for hiding this comment

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

Thanks!
Please merge.

…t_slice_fallback and __sha3

CSE of these calls should be only done in EraVMCSE pass.

Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
Since we disabled CSE of some calls in GVN and NewGVN, run
this pass to do the CSE. Also, don't do the CSE of the
__system_request in case signature has changed after
some optimizations.

Signed-off-by: Vladimir Radosavljevic <vr@matterlabs.dev>
@akiramenai akiramenai force-pushed the vr-cpr-1710-add-a-version-of-system_request-without-signature branch from a8961c8 to 1cefc11 Compare May 22, 2024 19:34
@akiramenai
Copy link
Collaborator

Only changed comments, so merging.

@akiramenai akiramenai merged commit cf85cf2 into main May 22, 2024
3 of 5 checks passed
@akiramenai akiramenai deleted the vr-cpr-1710-add-a-version-of-system_request-without-signature branch May 22, 2024 19:34
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.

3 participants