The source code of the benchmark has been published.
It uses the following solidity code for the “Fibonacci-100k (u128)” benchmark:
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.2 <0.9.0;
contract MyFib {
function fib(uint128 n) external pure returns (uint128 b) {
if (n == 0) {
return 0;
}
uint128 a = 1;
b = 1;
for (uint128 i = 2; i < n; i++) {
uint128 c = (a + b) % 170141183460469231731687303715884105727;
a = b;
b = c;
}
return b;
}
}
Using this as the evaluation of the EVM interpreter performance comparing with Rust equivalent has number of issues:
- It looks the solidity program has been compiled with optimizations disabled. I’m getting the same number of bytes (671) of the runtime bytecode compiling locally as in the bytecode used in the benchmark. The optimized version is 138 bytes shorter.
- Usage of
uint128
instead ofuint256
makes it unnecessarily slower for no reason. - The checked arithmetic is used unnecessarily. Switching to unchecked variant removes another 181 bytes from the bytecode comparing with the optimized version.
- The expression like
(a + b) % 170141183460469231731687303715884105727
can be implemented with a singleADDMOD
instruction.