From c14fa5a2709545225a3c26e0b48fbcc613010a93 Mon Sep 17 00:00:00 2001 From: IAvecilla Date: Thu, 19 Sep 2024 12:58:16 -0300 Subject: [PATCH] Remove tests for the evm simulator --- .../evm-contracts/ConstructorRevert.sol | 11 - .../evm-contracts/CounterFallback.sol | 14 - .../evm-contracts/CounterWithParam.sol | 39 - .../ts-integration/evm-contracts/Creator.sol | 19 - .../evm-contracts/CreatorFallback.sol | 20 - .../ts-integration/evm-contracts/ERC20.sol | 78 -- .../evm-contracts/GasCaller.sol | 16 - .../evm-contracts/OpcodeTest.sol | 123 --- .../evm-contracts/OpcodeTestFallback.sol | 139 --- .../evm-contracts/ProxyCaller.sol | 25 - .../evm-contracts/SelfDestruct.sol | 13 - .../evm-contracts/UniswapFallback.sol | 125 --- .../tests/evm-contracts.test.ts | 828 ------------------ 13 files changed, 1450 deletions(-) delete mode 100644 core/tests/ts-integration/evm-contracts/ConstructorRevert.sol delete mode 100644 core/tests/ts-integration/evm-contracts/CounterFallback.sol delete mode 100644 core/tests/ts-integration/evm-contracts/CounterWithParam.sol delete mode 100644 core/tests/ts-integration/evm-contracts/Creator.sol delete mode 100644 core/tests/ts-integration/evm-contracts/CreatorFallback.sol delete mode 100644 core/tests/ts-integration/evm-contracts/ERC20.sol delete mode 100644 core/tests/ts-integration/evm-contracts/GasCaller.sol delete mode 100644 core/tests/ts-integration/evm-contracts/OpcodeTest.sol delete mode 100644 core/tests/ts-integration/evm-contracts/OpcodeTestFallback.sol delete mode 100644 core/tests/ts-integration/evm-contracts/ProxyCaller.sol delete mode 100644 core/tests/ts-integration/evm-contracts/SelfDestruct.sol delete mode 100644 core/tests/ts-integration/evm-contracts/UniswapFallback.sol delete mode 100644 core/tests/ts-integration/tests/evm-contracts.test.ts diff --git a/core/tests/ts-integration/evm-contracts/ConstructorRevert.sol b/core/tests/ts-integration/evm-contracts/ConstructorRevert.sol deleted file mode 100644 index 868e57edca7..00000000000 --- a/core/tests/ts-integration/evm-contracts/ConstructorRevert.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED - -pragma solidity >=0.7.0; - -contract ConstructorRevert { - uint256 value; - - constructor() { - revert("Failure string"); - } -} diff --git a/core/tests/ts-integration/evm-contracts/CounterFallback.sol b/core/tests/ts-integration/evm-contracts/CounterFallback.sol deleted file mode 100644 index c67dfec9459..00000000000 --- a/core/tests/ts-integration/evm-contracts/CounterFallback.sol +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED - -pragma solidity ^0.8.0; - -contract CounterFallback { - function performCall() external { - uint256 value = 0; - value += 1; - } - - fallback() external { - this.performCall(); - } -} diff --git a/core/tests/ts-integration/evm-contracts/CounterWithParam.sol b/core/tests/ts-integration/evm-contracts/CounterWithParam.sol deleted file mode 100644 index 714b4d665ae..00000000000 --- a/core/tests/ts-integration/evm-contracts/CounterWithParam.sol +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED - -pragma solidity >=0.7.0; - -contract CounterWithParam { - uint256 value; - - constructor(uint256 _startingValue) { - value = _startingValue; - } - - function increment(uint256 x) public { - value += x; - } - - function incrementWithRevertPayable(uint256 x, bool shouldRevert) public payable returns (uint256) { - return incrementWithRevert(x, shouldRevert); - } - - function incrementWithRevert(uint256 x, bool shouldRevert) public returns (uint256) { - value += x; - if (shouldRevert) { - revert("This method always reverts"); - } - return value; - } - - function set(uint256 x) public { - value = x; - } - - function get() public view returns (uint256) { - return value; - } - - function getBytes() public returns (bytes memory) { - return "Testing"; - } -} diff --git a/core/tests/ts-integration/evm-contracts/Creator.sol b/core/tests/ts-integration/evm-contracts/Creator.sol deleted file mode 100644 index 63a6f7e3b1d..00000000000 --- a/core/tests/ts-integration/evm-contracts/Creator.sol +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED - -pragma solidity >=0.7.0; - -contract Creation { - function blockNumber() external view returns (uint256) { - return block.number; - } -} - -contract Creator { - function create() external { - new Creation(); - } - - function getCreationRuntimeCode() external pure returns (bytes memory) { - return type(Creation).runtimeCode; - } -} diff --git a/core/tests/ts-integration/evm-contracts/CreatorFallback.sol b/core/tests/ts-integration/evm-contracts/CreatorFallback.sol deleted file mode 100644 index 30ebabd7cc7..00000000000 --- a/core/tests/ts-integration/evm-contracts/CreatorFallback.sol +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED - -pragma solidity >=0.7.0; - -contract Creation { - function blockNumber() external view returns (uint256) { - return block.number; - } -} - -contract CreatorFallback { - function performCall() external { - new Creation(); - type(Creation).runtimeCode; - } - - fallback() external { - this.performCall(); - } -} diff --git a/core/tests/ts-integration/evm-contracts/ERC20.sol b/core/tests/ts-integration/evm-contracts/ERC20.sol deleted file mode 100644 index 1b65e654180..00000000000 --- a/core/tests/ts-integration/evm-contracts/ERC20.sol +++ /dev/null @@ -1,78 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED - -pragma solidity >=0.7.0; - -contract ERC20 { - string public symbol; - string public name; - uint8 public decimals; - uint256 public totalSupply; - - mapping(address => uint256) balances; - mapping(address => mapping(address => uint256)) allowed; - - event Transfer(address indexed _from, address indexed _to, uint256 _value); - event Approval(address indexed _owner, address indexed _spender, uint256 _value); - - constructor() { - symbol = "TEST"; - name = "Test Coin"; - decimals = 18; - totalSupply = 1000000; - balances[msg.sender] = totalSupply; - emit Transfer(address(0), msg.sender, totalSupply); - } - - function balanceOf(address tokenOwner) public view returns (uint256 balance) { - return balances[tokenOwner]; - } - - function transfer(address to, uint256 tokens) public returns (bool success) { - balances[msg.sender] = safeSub(balances[msg.sender], tokens); - balances[to] = safeAdd(balances[to], tokens); - emit Transfer(msg.sender, to, tokens); - return true; - } - - function approve(address spender, uint256 tokens) public returns (bool success) { - allowed[msg.sender][spender] = tokens; - emit Approval(msg.sender, spender, tokens); - return true; - } - - function transferFrom( - address from, - address to, - uint256 tokens - ) public returns (bool success) { - balances[from] = safeSub(balances[from], tokens); - allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens); - balances[to] = safeAdd(balances[to], tokens); - emit Transfer(from, to, tokens); - return true; - } - - function allowance(address tokenOwner, address spender) public view returns (uint256 remaining) { - return allowed[tokenOwner][spender]; - } - - function safeAdd(uint256 a, uint256 b) internal pure returns (uint256 c) { - c = a + b; - require(c >= a); - } - - function safeSub(uint256 a, uint256 b) internal pure returns (uint256 c) { - require(b <= a); - c = a - b; - } - - function safeMul(uint256 a, uint256 b) internal pure returns (uint256 c) { - c = a * b; - require(a == 0 || c / a == b); - } - - function safeDiv(uint256 a, uint256 b) internal pure returns (uint256 c) { - require(b > 0); - c = a / b; - } -} diff --git a/core/tests/ts-integration/evm-contracts/GasCaller.sol b/core/tests/ts-integration/evm-contracts/GasCaller.sol deleted file mode 100644 index 25b56aa744d..00000000000 --- a/core/tests/ts-integration/evm-contracts/GasCaller.sol +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED - -pragma solidity ^0.8.0; - -contract GasCaller { - uint256 _resultGas; - - function callAndGetGas(address _to) external returns (uint256) { - uint256 startGas = gasleft(); - // Just doing a call to an address - (bool success, ) = _to.call(""); - require(success); - _resultGas = startGas - gasleft(); - return _resultGas; - } -} diff --git a/core/tests/ts-integration/evm-contracts/OpcodeTest.sol b/core/tests/ts-integration/evm-contracts/OpcodeTest.sol deleted file mode 100644 index 721339bd7ae..00000000000 --- a/core/tests/ts-integration/evm-contracts/OpcodeTest.sol +++ /dev/null @@ -1,123 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED - -pragma solidity ^0.8.0; - -contract OpcodeTest { - function execute() external { - uint256 loaded = 1; - uint256 tmp; - uint256 prevBlock = block.number - 1; - assembly { - loaded := add(loaded, 1) - loaded := mul(loaded, 2) - loaded := sub(loaded, 1) - loaded := div(loaded, 2) - loaded := sdiv(loaded, 2) - loaded := mod(loaded, 2) - // ADDMOD - // MULMOD - loaded := exp(loaded, 2) - loaded := signextend(loaded, 2) - tmp := lt(loaded, 2) - tmp := gt(loaded, 2) - tmp := slt(loaded, 2) - tmp := sgt(loaded, 2) - tmp := eq(loaded, 2) - tmp := iszero(tmp) - tmp := and(1, 1) - tmp := or(1, 1) - tmp := xor(1, 1) - tmp := not(tmp) - tmp := byte(tmp, 1) - tmp := shl(tmp, 1) - tmp := shr(tmp, 1) - tmp := sar(tmp, 1) - tmp := keccak256(0, 0x40) - tmp := address() - tmp := balance(0x00) - tmp := origin() - tmp := caller() - tmp := callvalue() - // CALLDATALOAD - tmp := calldatasize() - // CALLDATACOPY - tmp := codesize() - // CODECOPY - tmp := gasprice() - // EXTCODESIZE - // EXTCODECOPY - tmp := returndatasize() - // RETURNDATACOPY - // EXTCODEHASH - tmp := blockhash(prevBlock) - tmp := coinbase() - tmp := timestamp() - tmp := number() - tmp := prevrandao() - tmp := gaslimit() - tmp := chainid() - tmp := selfbalance() - tmp := basefee() - // POP - tmp := mload(1) - mstore(1024, 1) - mstore8(10242, 1) - tmp := sload(0) - sstore(0, 1) - // JUMP - // JUMPI - // PC - tmp := msize() - tmp := gas() - // JUMPDEST - // PUSH0...PUSH32 - // DUP1...DUP16 - // SWAP1...SWAP16 - // LOG0...LOG4 - // CREATE - // CALL - // CALLCODE - // RETURN - // DELEGATECALL - // CREATE2 - // STATICCALL - // REVERT - // INVALID - // selfdestruct(sender) - } - - // tmp = 0; - // tmp = 0x11; - // tmp = 0x2211; - // tmp = 0x332211; - // tmp = 0x44332211; - // tmp = 0x5544332211; - // tmp = 0x665544332211; - // tmp = 0x77665544332211; - // tmp = 0x8877665544332211; - // tmp = 0x998877665544332211; - // tmp = 0xaa998877665544332211; - // tmp = 0xbbaa998877665544332211; - // tmp = 0xccbbaa998877665544332211; - // tmp = 0xddccbbaa998877665544332211; - // tmp = 0xeeddccbbaa998877665544332211; - // tmp = 0xffeeddccbbaa998877665544332211; - // tmp = 0x11ffeeddccbbaa998877665544332211; - // tmp = 0x2211ffeeddccbbaa998877665544332211; - // tmp = 0x332211ffeeddccbbaa998877665544332211; - // tmp = 0x44332211ffeeddccbbaa998877665544332211; - // tmp = uint256(uint160(0x5544332211FFeeDDCcbbAa998877665544332211)); - // tmp = 0x665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x77665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x8877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x998877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0xff998877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x11ff998877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x2211ff998877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x332211ff998877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x44332211ff998877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x5544332211ff998877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x665544332211ff998877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x77665544332211ff998877665544332211ffeeddccbbaa998877665544332211; - } -} diff --git a/core/tests/ts-integration/evm-contracts/OpcodeTestFallback.sol b/core/tests/ts-integration/evm-contracts/OpcodeTestFallback.sol deleted file mode 100644 index 47f427a2733..00000000000 --- a/core/tests/ts-integration/evm-contracts/OpcodeTestFallback.sol +++ /dev/null @@ -1,139 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED - -pragma solidity ^0.8.0; - -contract OpcodeTestFallback { - function performCall() external { - uint256 loaded = 1; - uint256 tmp; - uint256 prevBlock = block.number - 1; - assembly { - loaded := add(loaded, 1) - loaded := mul(loaded, 2) - loaded := sub(loaded, 1) - loaded := div(loaded, 2) - loaded := sdiv(loaded, 2) - loaded := mod(loaded, 2) - // ADDMOD - // MULMOD - loaded := exp(loaded, 2) - loaded := signextend(loaded, 2) - tmp := lt(loaded, 2) - tmp := gt(loaded, 2) - tmp := slt(loaded, 2) - tmp := sgt(loaded, 2) - tmp := eq(loaded, 2) - tmp := iszero(tmp) - tmp := and(1, 1) - tmp := or(1, 1) - tmp := xor(1, 1) - tmp := not(tmp) - tmp := byte(tmp, 1) - tmp := shl(tmp, 1) - tmp := shr(tmp, 1) - tmp := sar(tmp, 1) - tmp := keccak256(0, 0x40) - tmp := address() - tmp := balance(0x00) - tmp := origin() - tmp := caller() - tmp := callvalue() - // CALLDATALOAD - tmp := calldatasize() - // CALLDATACOPY - tmp := codesize() - // CODECOPY - tmp := gasprice() - // EXTCODESIZE - // EXTCODECOPY - tmp := returndatasize() - // RETURNDATACOPY - // EXTCODEHASH - tmp := blockhash(prevBlock) - tmp := coinbase() - tmp := timestamp() - tmp := number() - tmp := prevrandao() - tmp := gaslimit() - tmp := chainid() - tmp := selfbalance() - tmp := basefee() - // POP - tmp := mload(1) - mstore(1024, 1) - mstore8(10242, 1) - tmp := sload(0) - sstore(0, 1) - // JUMP - // JUMPI - // PC - tmp := msize() - tmp := gas() - // JUMPDEST - // PUSH0...PUSH32 - // DUP1...DUP16 - // SWAP1...SWAP16 - // LOG0...LOG4 - // CREATE - // CALL - // CALLCODE - // RETURN - // DELEGATECALL - // CREATE2 - // STATICCALL - // REVERT - // INVALID - // selfdestruct(sender) - tmp := calldataload(0) - calldatacopy(10, 0, 1) - codecopy(10, 0, 1) - tmp := extcodesize(0) - extcodecopy(address(), 10, 0, 1) - returndatacopy(10, 0, 1) - pop(extcodehash(0)) - log0(0, 30) - log1(0, 30, 30) - log2(0, 30, 30, 30) - log3(0, 30, 30, 30, 30) - log4(0, 30, 30, 30, 30, 30) - } - - // tmp = 0; - // tmp = 0x11; - // tmp = 0x2211; - // tmp = 0x332211; - // tmp = 0x44332211; - // tmp = 0x5544332211; - // tmp = 0x665544332211; - // tmp = 0x77665544332211; - // tmp = 0x8877665544332211; - // tmp = 0x998877665544332211; - // tmp = 0xaa998877665544332211; - // tmp = 0xbbaa998877665544332211; - // tmp = 0xccbbaa998877665544332211; - // tmp = 0xddccbbaa998877665544332211; - // tmp = 0xeeddccbbaa998877665544332211; - // tmp = 0xffeeddccbbaa998877665544332211; - // tmp = 0x11ffeeddccbbaa998877665544332211; - // tmp = 0x2211ffeeddccbbaa998877665544332211; - // tmp = 0x332211ffeeddccbbaa998877665544332211; - // tmp = 0x44332211ffeeddccbbaa998877665544332211; - // tmp = uint256(uint160(0x5544332211FFeeDDCcbbAa998877665544332211)); - // tmp = 0x665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x77665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x8877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x998877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0xff998877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x11ff998877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x2211ff998877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x332211ff998877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x44332211ff998877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x5544332211ff998877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x665544332211ff998877665544332211ffeeddccbbaa998877665544332211; - // tmp = 0x77665544332211ff998877665544332211ffeeddccbbaa998877665544332211; - } - - fallback() external { - this.performCall(); - } -} diff --git a/core/tests/ts-integration/evm-contracts/ProxyCaller.sol b/core/tests/ts-integration/evm-contracts/ProxyCaller.sol deleted file mode 100644 index 379d7c7addc..00000000000 --- a/core/tests/ts-integration/evm-contracts/ProxyCaller.sol +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED - -pragma solidity >=0.7.0; - -interface ICounterWithParam { - function increment(uint256 x) external; - - function get() external view returns (uint256); - - function getBytes() external returns (bytes memory); -} - -contract ProxyCaller { - function executeIncrememt(address dest, uint256 x) external { - ICounterWithParam(dest).increment(x); - } - - function proxyGet(address dest) external view returns (uint256) { - return ICounterWithParam(dest).get(); - } - - function proxyGetBytes(address dest) external returns (bytes memory returnData) { - return ICounterWithParam(dest).getBytes(); - } -} diff --git a/core/tests/ts-integration/evm-contracts/SelfDestruct.sol b/core/tests/ts-integration/evm-contracts/SelfDestruct.sol deleted file mode 100644 index 12fec955590..00000000000 --- a/core/tests/ts-integration/evm-contracts/SelfDestruct.sol +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED - -pragma solidity >=0.7.0; - -contract SelfDestruct { - constructor() payable {} - - function destroy(address recipient) external { - assembly { - selfdestruct(recipient) - } - } -} diff --git a/core/tests/ts-integration/evm-contracts/UniswapFallback.sol b/core/tests/ts-integration/evm-contracts/UniswapFallback.sol deleted file mode 100644 index 0237b4be1ba..00000000000 --- a/core/tests/ts-integration/evm-contracts/UniswapFallback.sol +++ /dev/null @@ -1,125 +0,0 @@ -// SPDX-License-Identifier: UNLICENSED - -pragma solidity ^0.8.0; - -interface IUniswapV2ERC20 { - event Approval(address indexed owner, address indexed spender, uint256 value); - event Transfer(address indexed from, address indexed to, uint256 value); - - function name() external pure returns (string memory); - - function symbol() external pure returns (string memory); - - function decimals() external pure returns (uint8); - - function totalSupply() external returns (uint256); - - function balanceOf(address owner) external returns (uint256); - - function allowance(address owner, address spender) external returns (uint256); - - function approve(address spender, uint256 value) external returns (bool); - - function transfer(address to, uint256 value) external returns (bool); - - function transferFrom( - address from, - address to, - uint256 value - ) external returns (bool); - - function DOMAIN_SEPARATOR() external returns (bytes32); - - function PERMIT_TYPEHASH() external pure returns (bytes32); - - function nonces(address owner) external returns (uint256); - - function permit( - address owner, - address spender, - uint256 value, - uint256 deadline, - uint8 v, - bytes32 r, - bytes32 s - ) external; -} - -interface IUniswapV2Pair { - event Mint(address indexed sender, uint256 amount0, uint256 amount1); - event Burn(address indexed sender, uint256 amount0, uint256 amount1, address indexed to); - event Swap( - address indexed sender, - uint256 amount0In, - uint256 amount1In, - uint256 amount0Out, - uint256 amount1Out, - address indexed to - ); - event Sync(uint112 reserve0, uint112 reserve1); - - function MINIMUM_LIQUIDITY() external pure returns (uint256); - - function factory() external returns (address); - - function token0() external returns (address); - - function token1() external returns (address); - - function getReserves() - external - returns ( - uint112 reserve0, - uint112 reserve1, - uint32 blockTimestampLast - ); - - function price0CumulativeLast() external returns (uint256); - - function price1CumulativeLast() external returns (uint256); - - function kLast() external returns (uint256); - - function mint(address to) external returns (uint256 liquidity); - - function burn(address to) external returns (uint256 amount0, uint256 amount1); - - function swap( - uint256 amount0Out, - uint256 amount1Out, - address to, - bytes calldata data - ) external; - - function skim(address to) external; - - function sync() external; - - function initialize(address, address) external; -} - -contract UniswapFallback { - IUniswapV2Pair public uniswapPair; - IUniswapV2ERC20 public uniswapPair2; - address public alice_address; - - function setUniswapAddress(address _uniswap_address) public { - uniswapPair = IUniswapV2Pair(_uniswap_address); - uniswapPair2 = IUniswapV2ERC20(_uniswap_address); - } - - function setAliceAddress(address _alice_address) public { - alice_address = _alice_address; - } - - // Fallback function - fallback() external { - // Implement any logic you want the contract to perform when it receives Ether - // This function will be called when the contract receives Ether and no other function matches the call data - uniswapPair.mint(alice_address); - uniswapPair.swap(0, 5000, alice_address, "0x"); - uint256 balance = uniswapPair2.balanceOf(alice_address); - //uniswapPair2.transfer(address(uniswapPair),balance); - //uniswapPair.burn(alice_address); - } -} diff --git a/core/tests/ts-integration/tests/evm-contracts.test.ts b/core/tests/ts-integration/tests/evm-contracts.test.ts deleted file mode 100644 index 90eb0975f02..00000000000 --- a/core/tests/ts-integration/tests/evm-contracts.test.ts +++ /dev/null @@ -1,828 +0,0 @@ -/** - * Generic tests checking evm equivalence smart contract behavior. - * - * Note: if you are going to write multiple tests checking specific topic (e.g. `CREATE2` behavior or something like this), - * consider creating a separate suite. - * Let's try to keep only relatively simple and self-contained tests here. - */ - -import { TestMaster } from '../src'; -import { deployContract, getEVMArtifact, getEVMContractFactory, getTestContract } from '../src/helpers'; - -import * as ethers from 'ethers'; -import * as zksync from 'zksync-ethers'; - -const contracts = { - tester: getTestContract('TestEVMCreate'), - erc20: getTestContract('ERC20'), - uniswapV2Pair: getTestContract('UniswapV2Pair'), - uniswapV2Factory: getTestContract('UniswapV2Factory') -}; - -const artifacts = { - counter: getEVMArtifact('../evm-contracts/CounterWithParam.sol'), - proxyCaller: getEVMArtifact('../evm-contracts/ProxyCaller.sol'), - creator: getEVMArtifact('../evm-contracts/Creator.sol'), - erc20: getEVMArtifact('../evm-contracts/ERC20.sol'), - constructorRevert: getEVMArtifact('../evm-contracts/ConstructorRevert.sol'), - uniswapV2Pair: getEVMArtifact('../contracts/uniswap-v2/UniswapV2Factory.sol', 'UniswapV2Pair.sol'), - uniswapV2Factory: getEVMArtifact('../contracts/uniswap-v2/UniswapV2Factory.sol', 'UniswapV2Factory.sol'), - opcodeTest: getEVMArtifact('../evm-contracts/OpcodeTest.sol'), - selfDestruct: getEVMArtifact('../evm-contracts/SelfDestruct.sol'), - gasCaller: getEVMArtifact('../evm-contracts/GasCaller.sol'), - counterFallback: getEVMArtifact('../evm-contracts/CounterFallback.sol'), - uniswapFallback: getEVMArtifact('../evm-contracts/UniswapFallback.sol'), - creatorFallback: getEVMArtifact('../evm-contracts/CreatorFallback.sol'), - opcodeTestFallback: getEVMArtifact('../evm-contracts/OpcodeTestFallback.sol') -}; - -const initBytecode = '0x69602a60005260206000f3600052600a6016f3'; -const runtimeBytecode = '0x602a60005260206000f3'; - -let gasLimit = '0x01ffffff'; - -const logGasCosts = false; -describe('EVM equivalence contract', () => { - let testMaster: TestMaster; - let alice: zksync.Wallet; - - // Contracts shared in several tests. - let evmCreateTester: zksync.Contract; - let deployer: zksync.Contract; - - beforeAll(async () => { - testMaster = TestMaster.getInstance(__filename); - alice = testMaster.mainAccount(); - - evmCreateTester = await deployContract(alice, contracts.tester, []); - deployer = new zksync.Contract(zksync.utils.CONTRACT_DEPLOYER_ADDRESS, zksync.utils.CONTRACT_DEPLOYER, alice); - }); - - describe('Gas consumption', () => { - test("Should compare gas against counter fallback contract's call", async () => { - const gasCallerContract = await deploygasCallerContract(alice, artifacts.gasCaller); - - const counterContract = await deploygasCallerContract(alice, artifacts.counterFallback); - - let result = ( - await gasCallerContract.getFunction('callAndGetGas').staticCall(counterContract.getAddress()) - ).toString(); - - const expected_gas = '3617'; // Gas cost when run with solidity interpreter - expect(result).toEqual(expected_gas); - }); - - test("Should compare gas against creator fallback contract's call", async () => { - const gasCallerContract = await deploygasCallerContract(alice, artifacts.gasCaller); - - const creatorContract = await deploygasCallerContract(alice, artifacts.creatorFallback); - - let result = ( - await gasCallerContract.getFunction('callAndGetGas').staticCall(creatorContract.getAddress()) - ).toString(); - - const expected_gas = '70598'; // Gas cost when run with solidity interpreter - 3 (We have some changes that are needed) - expect(result).toEqual(expected_gas); - }); - }); - - describe('Contract creation', () => { - describe('Create from EOA', () => { - test('Should create evm contract from EOA and allow view and non-view calls', async () => { - const args = 1; - const factory = getEVMContractFactory(alice, artifacts.counter); - const contract = await factory.deploy(args); - await contract.deploymentTransaction()?.wait(); - await alice.provider.getTransactionReceipt( - contract.deploymentTransaction()?.hash ?? - (() => { - throw new Error('Deployment transaction has failed'); - })() - ); - - await assertCreatedCorrectly( - deployer, - await contract.getAddress(), - '0x' + artifacts.counter.evm.deployedBytecode.object - ); - - expect((await contract.getFunction('get').staticCall()).toString()).toEqual('1'); - await (await contract.getFunction('increment')(1)).wait(); - expect((await contract.getFunction('get').staticCall()).toString()).toEqual('2'); - }); - - test('Should create2 evm contract from ZKEVM contract', async () => { - const salt = ethers.randomBytes(32); - - const expectedAddress = ethers.getCreate2Address( - await evmCreateTester.getAddress(), - salt, - ethers.keccak256(initBytecode) - ); - - await (await evmCreateTester.create2(salt, initBytecode)).wait(); - - await assertCreatedCorrectly(deployer, expectedAddress, runtimeBytecode); - - try { - await (await evmCreateTester.create2(salt, initBytecode, { gasLimit })).wait(); - } catch (e) { - // Should fail - return; - } - throw 'Should fail to create2 the same contract with same salt twice'; - }); - - test('Should propegate revert in constructor', async () => { - const factory = getEVMContractFactory(alice, artifacts.constructorRevert); - const contract = await factory.deploy({ gasLimit }); - - let failReason; - - try { - await contract.deploymentTransaction()?.wait(); - } catch (e: any) { - failReason = e.reason; - } - - expect(failReason).toBe(null); - }); - - test('Should NOT create evm contract from EOA when `to` is address(0x0)', async () => { - const args = 1; - - const factory = getEVMContractFactory(alice, artifacts.counter); - const { data, ...rest } = await factory.getDeployTransaction(args); - const dep_transaction = { - ...rest, - to: '0x0000000000000000000000000000000000000000', - chainId: alice.provider._network.chainId, - data - }; - await (await alice.sendTransaction(dep_transaction)).wait(); - const expectedAddressCreate = ethers.getCreateAddress({ - from: alice.address, - nonce: await alice.getNonce() - }); - - await assertContractNotCreated(deployer, expectedAddressCreate); - }); - }); - }); - - describe('Inter-contract calls', () => { - test('Calls (read/write) between EVM contracts should work correctly', async () => { - const args = 1; - - const counterFactory = getEVMContractFactory(alice, artifacts.counter); - const counterContract = await counterFactory.deploy(args); - await counterContract.deploymentTransaction()?.wait(); - await alice.provider.getTransactionReceipt( - counterContract.deploymentTransaction()?.hash ?? - (() => { - throw new Error('Deployment transaction has failed'); - })() - ); - - const proxyCallerFactory = getEVMContractFactory(alice, artifacts.proxyCaller); - const proxyCallerContract = await proxyCallerFactory.deploy(); - await proxyCallerContract.deploymentTransaction()?.wait(); - await alice.provider.getTransactionReceipt( - proxyCallerContract.deploymentTransaction()?.hash ?? - (() => { - throw new Error('Deployment transaction has failed'); - })() - ); - - expect( - (await proxyCallerContract.getFunction('proxyGet')(await counterContract.getAddress())).toString() - ).toEqual('1'); - - await ( - await proxyCallerContract.getFunction('executeIncrememt')(await counterContract.getAddress(), 1) - ).wait(); - - expect( - (await proxyCallerContract.getFunction('proxyGet')(await counterContract.getAddress())).toString() - ).toEqual('2'); - - expect( - ( - await proxyCallerContract - .getFunction('proxyGetBytes') - .staticCall(await counterContract.getAddress()) - ).toString() - ).toEqual('0x54657374696e67'); - }); - - test('Create opcode works correctly', async () => { - const creatorFactory = getEVMContractFactory(alice, artifacts.creator); - const creatorContract = await creatorFactory.deploy(); - await creatorContract.deploymentTransaction()?.wait(); - - const nonce = 1; - - const runtimeBytecode = await creatorContract.getFunction('getCreationRuntimeCode')(); - - const expectedAddress = ethers.getCreateAddress({ - from: await creatorContract.getAddress(), - nonce - }); - - await (await creatorContract.getFunction('create')()).wait(); - - await assertCreatedCorrectly(deployer, expectedAddress, runtimeBytecode); - }); - - test('Should revert correctly', async () => { - const args = 1; - - const counterFactory = getEVMContractFactory(alice, artifacts.counter); - const counterContract = await counterFactory.deploy(args); - await counterContract.deploymentTransaction()?.wait(); - - let errorString; - - try { - await counterContract.getFunction('incrementWithRevert').staticCall(1, true); - } catch (e: any) { - errorString = e.reason; - } - - expect(errorString).toEqual('This method always reverts'); - }); - }); - - // NOTE: Gas cost comparisons should be done on a *fresh* chain that doesn't have e.g. bytecodes already published - describe('ERC20', () => { - let evmToken: ethers.BaseContract; - let nativeToken: zksync.Contract; - let userAccount: zksync.Wallet; - let deployLogged: boolean = false; - - beforeEach(async () => { - const erc20Factory = getEVMContractFactory(alice, artifacts.erc20); - evmToken = await erc20Factory.deploy(); - await evmToken.deploymentTransaction()?.wait(); - nativeToken = await deployContract(alice, contracts.erc20, []); - - userAccount = testMaster.newEmptyAccount(); - // Only log the first deployment - if (logGasCosts && !deployLogged) { - let native_hash = - nativeToken.deploymentTransaction()?.hash ?? - (() => { - throw new Error('Deployment transaction has failed'); - })(); - let native_transanction_receipt = - (await alice.provider.getTransactionReceipt(native_hash)) ?? - (() => { - throw new Error('Deployment transaction has failed'); - })(); - let evm_hash = - evmToken.deploymentTransaction()?.hash ?? - (() => { - throw new Error('Deployment transaction has failed'); - })(); - let evm_transanction_receipt = - (await alice.provider.getTransactionReceipt(evm_hash)) ?? - (() => { - throw new Error('Deployment transaction has failed'); - })(); - console.log('ERC20 native deploy gas: ' + native_transanction_receipt.gasUsed); - console.log('ERC20 evm deploy gas: ' + evm_transanction_receipt.gasUsed); - deployLogged = true; - } - await ( - await alice.sendTransaction({ - to: userAccount.address, - value: BigInt('0xffffffffffffff') - }) - ).wait(); - }); - - test('view functions should work', async () => { - const evmBalanceOfCost = await evmToken.getFunction('balanceOf').estimateGas(alice.address); - const nativeBalanceOfCost = await nativeToken.getFunction('balanceOf').estimateGas(alice.address); - if (logGasCosts) { - console.log('ERC20 native balanceOf gas: ' + nativeBalanceOfCost.toString()); - console.log('ERC20 evm balanceOf gas: ' + evmBalanceOfCost.toString()); - } - expect((await evmToken.getFunction('balanceOf')(alice.address)).toString()).toEqual('1000000'); - expect((await evmToken.getFunction('totalSupply')()).toString()).toEqual('1000000'); - expect((await evmToken.getFunction('balanceOf')(userAccount.address)).toString()).toEqual('0'); - }); - - test('transfer should work', async () => { - expect((await evmToken.getFunction('balanceOf')(alice.address)).toString()).toEqual('1000000'); - const evmTransferTx = await (await evmToken.getFunction('transfer')(userAccount.address, 100000)).wait(); - const nativeTransferTx = await (await nativeToken.transfer(userAccount.address, 100000)).wait(); - if (logGasCosts) { - console.log('ERC20 native transfer gas: ' + nativeTransferTx.gasUsed.toString()); - console.log('ERC20 evm transfer gas: ' + evmTransferTx.gasUsed.toString()); - } - - expect((await evmToken.getFunction('balanceOf')(alice.address)).toString()).toEqual('900000'); - expect((await evmToken.getFunction('balanceOf')(userAccount.address)).toString()).toEqual('100000'); - }); - - test('approve & transferFrom should work', async () => { - expect((await evmToken.getFunction('balanceOf')(alice.address)).toString()).toEqual('1000000'); - const evmApproveTx = await ( - await evmToken.connect(alice).getFunction('approve')(userAccount.getAddress(), 100000) - ).wait(); - const nativeApproveTx = await ( - await nativeToken.connect(alice).getFunction('approve')(userAccount.address, 100000) - ).wait(); - if (logGasCosts) { - console.log('ERC20 native approve gas: ' + nativeApproveTx.gasUsed.toString()); - console.log('ERC20 evm approve gas: ' + evmApproveTx.gasUsed.toString()); - } - - const evmTransferFromTx = await ( - await evmToken.connect(userAccount).getFunction('transferFrom')( - alice.address, - userAccount.address, - 100000 - ) - ).wait(); - const nativeTransferFromTx = await ( - await nativeToken.connect(userAccount).getFunction('transferFrom')( - alice.address, - userAccount.address, - 100000 - ) - ).wait(); - if (logGasCosts) { - console.log('ERC20 native transferFrom gas: ' + nativeTransferFromTx.gasUsed.toString()); - console.log('ERC20 evm transferFrom gas: ' + evmTransferFromTx.gasUsed.toString()); - } - - expect((await evmToken.getFunction('balanceOf')(alice.address)).toString()).toEqual('900000'); - expect((await evmToken.getFunction('balanceOf')(userAccount.address)).toString()).toEqual('100000'); - }); - }); - - // NOTE: Gas cost comparisons should be done on a *fresh* chain that doesn't have e.g. bytecodes already published - describe('Uniswap-v2', () => { - let evmToken1: ethers.BaseContract; - let evmToken2: ethers.BaseContract; - let evmUniswapFactory: ethers.BaseContract; - let nativeUniswapFactory: ethers.BaseContract; - let evmUniswapPair: ethers.BaseContract; - let nativeUniswapPair: ethers.BaseContract; - - let deployLogged: boolean = false; - const NEW_PAIR_TOPIC = '0x0d3648bd0f6ba80134a33ba9275ac585d9d315f0ad8355cddefde31afa28d0e9'; - - beforeEach(async () => { - const erc20Factory = getEVMContractFactory(alice, artifacts.erc20); - evmToken1 = await erc20Factory.deploy({ gasLimit }); - await evmToken1.deploymentTransaction()?.wait(); - evmToken2 = await erc20Factory.deploy(); - await evmToken2.deploymentTransaction()?.wait(); - - const evmUniswapFactoryFactory = getEVMContractFactory(alice, artifacts.uniswapV2Factory); - evmUniswapFactory = await evmUniswapFactoryFactory.deploy('0x0000000000000000000000000000000000000000'); - await evmUniswapFactory.deploymentTransaction()?.wait(); - - nativeUniswapFactory = await deployContract( - alice, - contracts.uniswapV2Factory, - ['0x0000000000000000000000000000000000000000'], - undefined, - { - customData: { - factoryDeps: [contracts.uniswapV2Pair.bytecode] - } - } - ); - - const evmPairReceipt = await ( - await evmUniswapFactory.getFunction('createPair')(evmToken1.getAddress(), evmToken2.getAddress()) - ).wait(); - - const nativePairReceipt = await ( - await nativeUniswapFactory.getFunction('createPair')(evmToken1.getAddress(), evmToken2.getAddress()) - ).wait(); - - const evmUniswapPairFactory = getEVMContractFactory(alice, artifacts.uniswapV2Pair); - const nativeUniswapPairFactory = new zksync.ContractFactory( - contracts.uniswapV2Pair.abi, - contracts.uniswapV2Pair.bytecode, - alice - ); - evmUniswapPair = evmUniswapPairFactory.attach( - ethers.AbiCoder.defaultAbiCoder().decode( - ['address', 'uint256'], - evmPairReceipt.logs.find((log: any) => log.topics[0] === NEW_PAIR_TOPIC).data - )[0] - ); - nativeUniswapPair = nativeUniswapPairFactory.attach( - ethers.AbiCoder.defaultAbiCoder().decode( - ['address', 'uint256'], - nativePairReceipt.logs.find((log: any) => log.topics[0] === NEW_PAIR_TOPIC).data - )[0] - ); - const token1IsFirst = (await evmUniswapPair.getFunction('token0')()).toString() === evmToken1.getAddress(); - if (!token1IsFirst) { - [evmToken1, evmToken2] = [evmToken2, evmToken1]; - } - await (await evmToken1.getFunction('transfer')(evmUniswapPair.getAddress(), 100000)).wait(); - await (await evmToken1.getFunction('transfer')(nativeUniswapPair.getAddress(), 100000)).wait(); - await (await evmToken2.getFunction('transfer')(evmUniswapPair.getAddress(), 100000)).wait(); - await (await evmToken2.getFunction('transfer')(nativeUniswapPair.getAddress(), 100000)).wait(); - - // Only log the first deployment - if (logGasCosts && !deployLogged) { - let native_hash = - nativeUniswapFactory.deploymentTransaction()?.hash ?? - (() => { - throw new Error('Deployment transaction has failed'); - })(); - let native_transanction_receipt = - (await alice.provider.getTransactionReceipt(native_hash)) ?? - (() => { - throw new Error('Deployment transaction has failed'); - })(); - let evm_hash = - evmUniswapFactory.deploymentTransaction()?.hash ?? - (() => { - throw new Error('Deployment transaction has failed'); - })(); - let evm_transanction_receipt = - (await alice.provider.getTransactionReceipt(evm_hash)) ?? - (() => { - throw new Error('Deployment transaction has failed'); - })(); - console.log('Uniswap Factory native deploy gas: ' + native_transanction_receipt.gasUsed); - console.log('Uniswap Factory evm deploy gas: ' + evm_transanction_receipt.gasUsed); - console.log('Uniswap Pair native create gas: ' + nativePairReceipt.gasUsed); - console.log('Uniswap Pair evm create gas: ' + evmPairReceipt.gasUsed); - deployLogged = true; - } - }); - - test('mint, swap, and burn should work', async () => { - const evmMintReceipt = await (await evmUniswapPair.getFunction('mint')(alice.address)).wait(); - const nativeMintReceipt = await (await nativeUniswapPair.getFunction('mint')(alice.address)).wait(); - - await (await evmToken1.getFunction('transfer')(evmUniswapPair.getAddress(), 10000)).wait(); - await (await evmToken1.getFunction('transfer')(nativeUniswapPair.getAddress(), 10000)).wait(); - const evmSwapReceipt = await ( - await evmUniswapPair.getFunction('swap')(0, 5000, alice.address, '0x') - ).wait(); - const nativeSwapReceipt = await ( - await nativeUniswapPair.getFunction('swap')(0, 5000, alice.address, '0x') - ).wait(); - - await ( - await evmUniswapPair.getFunction('transfer')( - evmUniswapPair.getAddress(), - (await evmUniswapPair.getFunction('balanceOf')(alice.address)).toString() - ) - ).wait(); - await ( - await nativeUniswapPair.getFunction('transfer')( - nativeUniswapPair.getAddress(), - (await nativeUniswapPair.getFunction('balanceOf')(alice.address)).toString() - ) - ).wait(); - const evmBurnReceipt = await (await evmUniswapPair.getFunction('burn')(alice.address)).wait(); - const nativeBurnReceipt = await (await nativeUniswapPair.getFunction('burn')(alice.address)).wait(); - expect(Number((await evmToken1.getFunction('balanceOf')(alice.address)).toString())).toBeGreaterThanOrEqual( - 990000 - ); - expect(Number((await evmToken2.getFunction('balanceOf')(alice.address)).toString())).toBeGreaterThanOrEqual( - 990000 - ); - - if (logGasCosts) { - console.log('UniswapV2Pair native mint gas: ' + nativeMintReceipt.gasUsed); - console.log('UniswapV2Pair evm mint gas: ' + evmMintReceipt.gasUsed); - console.log('UniswapV2Pair native swap gas: ' + nativeSwapReceipt.gasUsed); - console.log('UniswapV2Pair evm swap gas: ' + evmSwapReceipt.gasUsed); - console.log('UniswapV2Pair native burn gas: ' + nativeBurnReceipt.gasUsed); - console.log('UniswapV2Pair evm burn gas: ' + evmBurnReceipt.gasUsed); - } - }); - - test("Should compare gas against uniswap fallback contract's call", async () => { - const gasCallerFactory = getEVMContractFactory(alice, artifacts.gasCaller); - const gasCallerContract = await gasCallerFactory.deploy(); - await gasCallerContract.deploymentTransaction()?.wait(); - await alice.provider.getTransactionReceipt( - gasCallerContract.deploymentTransaction()?.hash ?? - (() => { - throw new Error('Deployment transaction has failed'); - })() - ); - - const uniswapContract = await deploygasCallerContract(alice, artifacts.uniswapFallback); - await (await uniswapContract.getFunction('setUniswapAddress')(evmUniswapPair.getAddress())).wait(); - await (await uniswapContract.getFunction('setAliceAddress')(alice.address)).wait(); - - await (await evmToken1.getFunction('transfer')(evmUniswapPair.getAddress(), 10000)).wait(); - await (await evmToken1.getFunction('transfer')(uniswapContract.getAddress(), 10000)).wait(); - - let result = ( - await gasCallerContract.getFunction('callAndGetGas').staticCall(uniswapContract.getAddress()) - ).toString(); - - const expected_gas = '165939'; // Gas cost when run with solidity interpreter - expect(result).toEqual(expected_gas); - }); - }); - - // NOTE: Gas cost comparisons should be done on a *fresh* chain that doesn't have e.g. bytecodes already published - // describe('Bulk opcode tests', () => { - // let opcodeTest: ethers.Contract; - // beforeEach(async () => { - // const opcodeTestFactory = getEVMContractFactory(alice, artifacts.opcodeTest); - // console.log(opcodeTestFactory.bytecode) - // opcodeTest = await opcodeTestFactory.deploy() - // }); - - // test('should successfully execute bulk opcode test', async () => { - // console.log(await deployer.evmCode(opcodeTest.address)) - // // const receipt = await (await opcodeTest.execute()).wait() - // }); - // }); - - afterAll(async () => { - await testMaster.deinitialize(); - if (logGasCosts) { - printCostData(); - } - }); -}); - -async function deploygasCallerContract(alice: zksync.Wallet, contract: any, ...args: Array) { - const counterFactory = getEVMContractFactory(alice, contract); - const counterContract = await counterFactory.deploy(...args); - await counterContract.waitForDeployment(); - await counterContract.deploymentTransaction()?.wait(); - let hash = counterContract.deploymentTransaction()?.hash; - if (hash == undefined) { - throw new Error('Deployment transaction has failed'); - } - await alice.provider.getTransactionReceipt(hash); - - return counterContract; -} - -async function assertStoredBytecodeHash( - deployer: zksync.Contract, - deployedAddress: string, - expectedStoredHash: string -): Promise { - const ACCOUNT_CODE_STORAGE_ADDRESS = '0x0000000000000000000000000000000000008002'; - let runner = - deployer.runner ?? - (() => { - throw new Error('Runner get failed'); - })(); - let provider = - runner.provider ?? - (() => { - throw new Error('Provider get failed'); - })(); - const storedCodeHash = await provider.getStorage( - ACCOUNT_CODE_STORAGE_ADDRESS, - ethers.zeroPadValue(deployedAddress, 32) - ); - - expect(storedCodeHash).toEqual(expectedStoredHash); -} - -async function assertCreatedCorrectly( - deployer: zksync.Contract, - deployedAddress: string, - expectedEVMBytecode: string -): Promise { - const expectedStoredHash = getSha256BlobHash(expectedEVMBytecode); - await assertStoredBytecodeHash(deployer, deployedAddress, expectedStoredHash); -} - -function getPaddedBytecode(bytes: ethers.BytesLike) { - const length = ethers.getBytes(bytes).length; - - const encodedLength = ethers.AbiCoder.defaultAbiCoder().encode(['uint256'], [length]); - - let paddedBytecode = encodedLength + ethers.toBeHex(ethers.toBigInt(bytes)).slice(2); - - // The length needs to be 32 mod 64. We use 64 mod 128, since - // we are dealing with a hexlified string - while ((paddedBytecode.length - 2) % 128 != 64) { - paddedBytecode += '0'; - } - - return paddedBytecode; -} - -// Returns the canonical code hash of -function getSha256BlobHash(bytes: ethers.BytesLike): string { - const paddedBytes = getPaddedBytecode(bytes); - - const hash = ethers.getBytes(ethers.sha256(paddedBytes)); - hash[0] = 2; - hash[1] = 0; - - // Length of the bytecode - const lengthInBytes = ethers.getBytes(paddedBytes).length; - hash[2] = Math.floor(lengthInBytes / 256); - hash[3] = lengthInBytes % 256; - - return ethers.toBeHex(ethers.toBigInt(hash)); -} - -async function assertContractNotCreated(deployer: zksync.Contract, deployedAddress: string): Promise { - assertStoredBytecodeHash(deployer, deployedAddress, ethers.ZeroHash); -} - -function printCostData() { - let costsDataString = ''; - - const averageOverhead = - overheadDataDump.length === 0 - ? undefined - : Math.floor(overheadDataDump.reduce((a: number, c: number) => a + c) / overheadDataDump.length); - const minOverhead = overheadDataDump.length === 0 ? undefined : Math.min(...overheadDataDump); - const maxOverhead = overheadDataDump.length === 0 ? undefined : Math.max(...overheadDataDump); - - costsDataString += 'Overhead\t' + averageOverhead + '\t' + minOverhead + '\t' + maxOverhead + '\n'; - - Object.keys(opcodeDataDump).forEach((opcode) => { - const opcodeString = '0x' + Number(opcode).toString(16).padStart(2, '0'); - const values = opcodeDataDump[opcode.toString()]; - if (values.length === 0) { - costsDataString += opcodeString + '\n'; - return; - } - const average = Math.floor(values.reduce((a: number, c: number) => a + c) / values.length); - const min = Math.min(...values); - const max = Math.max(...values); - - costsDataString += - opcodeString + - '\t' + - average + - '\t' + - (min === average ? '' : min) + - '\t' + - (max === average ? '' : max) + - '\n'; - }); - console.log(costsDataString); -} - -const overheadDataDump: Array = []; -const opcodeDataDump: any = {}; -[ - '0x0', - '0x1', - '0x2', - '0x3', - '0x4', - '0x5', - '0x6', - '0x7', - '0x8', - '0x9', - '0x0A', - '0x0B', - '0x10', - '0x11', - '0x12', - '0x13', - '0x14', - '0x15', - '0x16', - '0x17', - '0x18', - '0x19', - '0x1A', - '0x1B', - '0x1C', - '0x1D', - '0x20', - '0x30', - '0x31', - '0x32', - '0x33', - '0x34', - '0x35', - '0x36', - '0x37', - '0x38', - '0x39', - '0x3A', - '0x3B', - '0x3C', - '0x3D', - '0x3E', - '0x3F', - '0x40', - '0x41', - '0x42', - '0x43', - '0x44', - '0x45', - '0x46', - '0x47', - '0x48', - '0x50', - '0x51', - '0x52', - '0x53', - '0x54', - '0x55', - '0x56', - '0x57', - '0x58', - '0x59', - '0x5A', - '0x5B', - '0x5F', - '0x60', - '0x61', - '0x62', - '0x63', - '0x64', - '0x65', - '0x66', - '0x67', - '0x68', - '0x69', - '0x6A', - '0x6B', - '0x6C', - '0x6D', - '0x6E', - '0x6F', - '0x70', - '0x71', - '0x72', - '0x73', - '0x74', - '0x75', - '0x76', - '0x77', - '0x78', - '0x79', - '0x7A', - '0x7B', - '0x7C', - '0x7D', - '0x7E', - '0x7F', - '0x80', - '0x81', - '0x82', - '0x83', - '0x84', - '0x85', - '0x86', - '0x87', - '0x88', - '0x89', - '0x8A', - '0x8B', - '0x8C', - '0x8D', - '0x8E', - '0x8F', - '0x90', - '0x91', - '0x92', - '0x93', - '0x94', - '0x95', - '0x96', - '0x97', - '0x98', - '0x99', - '0x9A', - '0x9B', - '0x9C', - '0x9D', - '0x9E', - '0x9F', - '0xA0', - '0xA1', - '0xA2', - '0xA3', - '0xA4', - '0xF0', - '0xF1', - '0xF2', - '0xF3', - '0xF4', - '0xF5', - '0xFA', - '0xFD', - '0xFE', - '0xFF' -].forEach((key) => { - opcodeDataDump[Number(key).toString()] = []; -});