Skip to content

Commit

Permalink
Merge pull request #1832 from lambdaclass/evm-integration-tests-bench…
Browse files Browse the repository at this point in the history
…marks

[EVM-Equivalence-YUL] Gas integration tests
  • Loading branch information
jrchatruc authored May 22, 2024
2 parents 8108803 + c286f18 commit 21cb479
Show file tree
Hide file tree
Showing 11 changed files with 519 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ server_logs.txt

core/lib/storage/.env
/core/lib/multivm/benchmarks/*.csv
/core/tests/ts-integration/benchmarks/*.csv

.zcli-config.json

Expand Down
15 changes: 15 additions & 0 deletions core/tests/ts-integration/evm-contracts/CounterFallback.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.0;

contract CounterFallback {

function performCall() external {
uint256 value = 0;
value += 1;
}

fallback() external {
this.performCall();
}
}
19 changes: 19 additions & 0 deletions core/tests/ts-integration/evm-contracts/CreatorFallback.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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();
}
}
16 changes: 16 additions & 0 deletions core/tests/ts-integration/evm-contracts/GasCaller.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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;
}
}
141 changes: 141 additions & 0 deletions core/tests/ts-integration/evm-contracts/OpcodeTestFallback.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// 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();
}

}
124 changes: 124 additions & 0 deletions core/tests/ts-integration/evm-contracts/UniswapFallback.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.0;

interface IUniswapV2ERC20 {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint 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 (uint);

function balanceOf(address owner) external returns (uint);

function allowance(address owner, address spender) external returns (uint);

function approve(address spender, uint value) external returns (bool);

function transfer(address to, uint value) external returns (bool);

function transferFrom(
address from,
address to,
uint value
) external returns (bool);

function DOMAIN_SEPARATOR() external returns (bytes32);

function PERMIT_TYPEHASH() external pure returns (bytes32);

function nonces(address owner) external returns (uint);

function permit(
address owner,
address spender,
uint value,
uint deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
}

interface IUniswapV2Pair {
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(
address indexed sender,
uint amount0,
uint amount1,
address indexed to
);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);

function MINIMUM_LIQUIDITY() external pure returns (uint);

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 (uint);

function price1CumulativeLast() external returns (uint);

function kLast() external returns (uint);

function mint(address to) external returns (uint liquidity);

function burn(address to) external returns (uint amount0, uint amount1);

function swap(
uint amount0Out,
uint 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");
uint balance = uniswapPair2.balanceOf(alice_address);
//uniswapPair2.transfer(address(uniswapPair),balance);
//uniswapPair.burn(alice_address);
}
}
4 changes: 3 additions & 1 deletion core/tests/ts-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"ts-jest": "^29.0.1",
"ts-node": "^10.1.0",
"typescript": "^4.3.5",
"zksync-web3": "^0.15.5"
"zksync-web3": "^0.15.5",
"csv-parser": "^3.0.0",
"csv-writer": "^1.6.0"
}
}
1 change: 1 addition & 0 deletions core/tests/ts-integration/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export function getEVMArtifact(contractPath: string, contractName: string | unde
const artifact = JSON.parse(solc.compile(JSON.stringify(compilerParams))).contracts['contract'][
contractName.split('.')[0]
];

return artifact;
}

Expand Down
Loading

0 comments on commit 21cb479

Please sign in to comment.