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

Benchmarks post verkle v06 #469

Closed
wants to merge 10 commits into from
29 changes: 29 additions & 0 deletions contracts/test/TestERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.12;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract TestERC20 is ERC20 {
uint8 private immutable __decimals;

constructor(uint8 _decimals) ERC20("TestERC20", "T20") {
_mint(msg.sender, 1000000000000000000000000);
__decimals = _decimals;
}

function decimals() public view override returns (uint8) {
return __decimals;
}

function sudoMint(address _to, uint256 _amount) external {
_mint(_to, _amount);
}

function sudoTransfer(address _from, address _to) external {
_transfer(_from, _to, balanceOf(_from));
}

function sudoApprove(address _from, address _to, uint256 _amount) external {
_approve(_from, _to, _amount);
}
}
48 changes: 44 additions & 4 deletions gascalc/1-simple-wallet.gas.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,55 @@
import { GasChecker } from './GasChecker'
import { GasCheckCollector, GasChecker } from './GasChecker'

context('simple account', function () {
this.timeout(60000)
const g = new GasChecker()

before(async function () {
await GasCheckCollector.init()
GasCheckCollector.inst.createJsonResult = true
})

it('simple 1', async function () {
await g.addTestRow({ title: 'simple', count: 1, diffLastGas: false })
await g.addTestRow({ title: 'simple - diff from previous', count: 2, diffLastGas: true })
await g.addTestRow({
title: 'simple',
count: 1,
diffLastGas: false,
dest: 'random',
destValue: 1,
destCallData: '0x',
skipAccountCreation: true
})
await g.addTestRow({
title: 'simple - diff',
count: 2,
diffLastGas: true,
dest: 'random',
destValue: 1,
destCallData: '0x',
skipAccountCreation: true
})
})

it('simple-create 1', async function () {
await g.addTestRow({
title: 'simple-create',
count: 1,
diffLastGas: false,
dest: 'random',
destValue: 1,
destCallData: '0x'
})
await g.addTestRow({
title: 'simple-create - diff',
count: 2,
diffLastGas: true,
dest: 'random',
destValue: 1,
destCallData: '0x'
})
})

it('simple 10', async function () {
it.skip('simple 10', async function () {
if (g.skipLong()) this.skip()
await g.addTestRow({ title: 'simple', count: 10, diffLastGas: false })
await g.addTestRow({ title: 'simple - diff from previous', count: 11, diffLastGas: true })
Expand Down
2 changes: 1 addition & 1 deletion gascalc/2-paymaster.gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { hexValue } from '@ethersproject/bytes'

const ethersSigner = ethers.provider.getSigner()

context('Minimal Paymaster', function () {
context.skip('Minimal Paymaster', function () {
this.timeout(60000)
const g = new GasChecker()

Expand Down
2 changes: 1 addition & 1 deletion gascalc/3-huge-tx-gas.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DefaultGasTestInfo, GasChecker } from './GasChecker'

context('huge tx - 5k', function () {
context.skip('huge tx - 5k', function () {
this.timeout(60000)
const huge = DefaultGasTestInfo.destCallData!.padEnd(10240, 'f')
const g = new GasChecker()
Expand Down
45 changes: 45 additions & 0 deletions gascalc/4-paymaster-postop.gas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { parseEther } from 'ethers/lib/utils'
import { TestPaymasterWithPostOp__factory } from '../typechain'
import { ethers } from 'hardhat'
import { GasChecker } from './GasChecker'
import { Create2Factory } from '../src/Create2Factory'
import { hexValue } from '@ethersproject/bytes'

const ethersSigner = ethers.provider.getSigner()

context.skip('Paymaster with PostOp', function () {
this.timeout(60000)
const g = new GasChecker()

let paymasterAddress: string

before(async () => {
const paymasterInit = hexValue(new TestPaymasterWithPostOp__factory(ethersSigner).getDeployTransaction(g.entryPoint().address).data!)
paymasterAddress = await new Create2Factory(ethers.provider, ethersSigner).deploy(paymasterInit, 0)
const paymaster = TestPaymasterWithPostOp__factory.connect(paymasterAddress, ethersSigner)
await paymaster.addStake(1, { value: 1 })
await g.entryPoint().depositTo(paymaster.address, { value: parseEther('10') })
})

it('paymaster with PostOp', async function () {
await g.addTestRow({ title: 'paymaster+postOp', count: 1, paymaster: paymasterAddress, diffLastGas: false })
await g.addTestRow({
title: 'paymaster+postOp with diff',
count: 2,
paymaster: paymasterAddress,
diffLastGas: true
})
})

it('paymaster with postOp 10', async function () {
if (g.skipLong()) this.skip()

await g.addTestRow({ title: 'paymaster+postOp', count: 10, paymaster: paymasterAddress, diffLastGas: false })
await g.addTestRow({
title: 'paymaster+postOp with diff',
count: 11,
paymaster: paymasterAddress,
diffLastGas: true
})
})
})
133 changes: 133 additions & 0 deletions gascalc/5-token-paymaster.gas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { parseEther } from 'ethers/lib/utils'
import {
TestERC20__factory, TestOracle2__factory,
TestUniswap__factory,
TestWrappedNativeToken__factory, TokenPaymaster,
TokenPaymaster__factory
} from '../typechain'
import { ethers } from 'hardhat'
import { GasCheckCollector, GasChecker } from './GasChecker'
import { Create2Factory } from '../src/Create2Factory'
import { hexValue } from '@ethersproject/bytes'
import {
OracleHelper as OracleHelperNamespace,
UniswapHelper as UniswapHelperNamespace
} from '../typechain/contracts/samples/TokenPaymaster'
import { BigNumber } from 'ethers'
import { createAccountOwner } from '../test/testutils'
// const ethersSigner = ethers.provider.getSigner()

context.skip('Token Paymaster', function () {
this.timeout(60000)
const g = new GasChecker()

let paymasterAddress: string
before(async () => {
await GasCheckCollector.init()
const globalSigner = ethers.provider.getSigner()
const create2Factory = new Create2Factory(ethers.provider, globalSigner)

const ethersSigner = createAccountOwner()
await globalSigner.sendTransaction({ to: ethersSigner.getAddress(), value: parseEther('10') })

const minEntryPointBalance = 1e17.toString()
const initialPriceToken = 100000000 // USD per TOK
const initialPriceEther = 500000000 // USD per ETH
const priceDenominator = BigNumber.from(10).pow(26)

const tokenInit = await new TestERC20__factory(ethersSigner).getDeployTransaction(6)
const tokenAddress = await create2Factory.deploy(tokenInit, 0)
const token = TestERC20__factory.connect(tokenAddress, ethersSigner)

const wethInit = await new TestWrappedNativeToken__factory(ethersSigner).getDeployTransaction()
const wethAddress = await create2Factory.deploy(wethInit, 0)
const testUniswapInit = await new TestUniswap__factory(ethersSigner).getDeployTransaction(wethAddress)
const testUniswapAddress = await create2Factory.deploy(testUniswapInit, 0)

const tokenPaymasterConfig: TokenPaymaster.TokenPaymasterConfigStruct = {
priceMaxAge: 86400,
refundPostopCost: 40000,
minEntryPointBalance,
priceMarkup: priceDenominator.mul(15).div(10) // +50%
}

const nativeAssetOracleInit = await new TestOracle2__factory(ethersSigner).getDeployTransaction(initialPriceEther, 8)
const nativeAssetOracleAddress = await create2Factory.deploy(nativeAssetOracleInit, 0, 10_000_000)
const tokenOracleInit = await new TestOracle2__factory(ethersSigner).getDeployTransaction(initialPriceToken, 8)
const tokenOracleAddress = await create2Factory.deploy(tokenOracleInit, 0, 10_000_000)

const oracleHelperConfig: OracleHelperNamespace.OracleHelperConfigStruct = {
cacheTimeToLive: 100000000,
maxOracleRoundAge: 0,
nativeOracle: nativeAssetOracleAddress,
nativeOracleReverse: false,
priceUpdateThreshold: priceDenominator.mul(2).div(10), // +20%
tokenOracle: tokenOracleAddress,
tokenOracleReverse: false,
tokenToNativeOracle: false
}

const uniswapHelperConfig: UniswapHelperNamespace.UniswapHelperConfigStruct = {
minSwapAmount: 1,
slippage: 5,
uniswapPoolFee: 3
}

const owner = await ethersSigner.getAddress()

const paymasterInit = hexValue(new TokenPaymaster__factory(ethersSigner).getDeployTransaction(
tokenAddress,
g.entryPoint().address,
wethAddress,
testUniswapAddress,
tokenPaymasterConfig,
oracleHelperConfig,
uniswapHelperConfig,
owner
).data!)
paymasterAddress = await create2Factory.deploy(paymasterInit, 0)
const paymaster = TokenPaymaster__factory.connect(paymasterAddress, ethersSigner)
await paymaster.addStake(1, { value: 1 })
await g.entryPoint().depositTo(paymaster.address, { value: parseEther('10') })
await paymaster.updateCachedPrice(true)
await g.createAccounts1(11)
await token.sudoMint(await ethersSigner.getAddress(), parseEther('20'))
await token.transfer(paymaster.address, parseEther('0.1'))
for (const address of g.createdAccounts) {
await token.transfer(address, parseEther('1'))
await token.sudoApprove(address, paymaster.address, ethers.constants.MaxUint256)
}

console.log('==addresses:', {
ethersSigner: await ethersSigner.getAddress(),
paymasterAddress,
nativeAssetOracleAddress,
tokenOracleAddress,
tokenAddress,
owner,
createdAccounts: g.createdAccounts
})
})

it('token paymaster', async function () {
await g.addTestRow({ title: 'token paymaster', count: 1, paymaster: paymasterAddress, diffLastGas: false })
await g.addTestRow({
title: 'token paymaster with diff',
count: 2,
paymaster: paymasterAddress,
diffLastGas: true
})
})

it('token paymaster 10', async function () {
if (g.skipLong()) this.skip()

await g.addTestRow({ title: 'token paymaster', count: 10, paymaster: paymasterAddress, diffLastGas: false })
await g.addTestRow({
title: 'token paymaster with diff',
count: 11,
paymaster: paymasterAddress,
diffLastGas: true
})
})
})
22 changes: 22 additions & 0 deletions gascalc/6-simple-wallet-token-transfer.gas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { GasCheckCollector } from './GasChecker'
import { createAddress } from '../test/testutils'
import { ethers } from 'hardhat'
import { TestERC20, TestERC20__factory } from '../typechain'

// TODO: NOTE: Must be executed separately as otherwise test will reuse SimpleAccount
context('ERC-20 Token related', function () {
let token: TestERC20

before(async function () {
await GasCheckCollector.init()
GasCheckCollector.inst.createJsonResult = true
token = await new TestERC20__factory(ethers.provider.getSigner()).deploy(18)
})

it('simple 1', async function () {
const destEoa = createAddress()
const tx = await token.transfer(destEoa, 100)
const receipt = await ethers.provider.getTransactionReceipt(tx.hash)
console.log(`ERC-20 EOA -> EOA transfer: status = ${receipt.status}; gasUsed = ${receipt.gasUsed.toString()}; txid = ${receipt.transactionHash}`)
})
})
Loading
Loading