diff --git a/package-lock.json b/package-lock.json index 92c89aa71f..2d3b307f24 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12071,9 +12071,9 @@ } }, "node_modules/nanoid": { - "version": "3.3.7", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", - "integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==", + "version": "3.3.8", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.8.tgz", + "integrity": "sha512-WNLf5Sd8oZxOm+TzppcYk8gVOgP+l58xNy58D0nbUnOxOWRWvlcCV4kUF7ltmI6PsrLl/BgKEyS4mqsGChFN0w==", "devOptional": true, "funding": [ { @@ -12081,6 +12081,7 @@ "url": "https://github.com/sponsors/ai" } ], + "license": "MIT", "bin": { "nanoid": "bin/nanoid.cjs" }, @@ -17931,6 +17932,7 @@ "@ethereumjs/statemanager": "^3.0.0-alpha.1", "@ethereumjs/tx": "^6.0.0-alpha.1", "@ethereumjs/util": "^10.0.0-alpha.1", + "@ethereumjs/verkle": "^0.2.0-alpha.1", "debug": "^4.3.3", "ethereum-cryptography": "^3.0.0", "eventemitter3": "^5.0.1" diff --git a/packages/block/src/block/block.ts b/packages/block/src/block/block.ts index 00467923c2..ed39eae880 100644 --- a/packages/block/src/block/block.ts +++ b/packages/block/src/block/block.ts @@ -249,7 +249,7 @@ export class Block { } } if (this.common.isActivatedEIP(4844)) { - const blobGasLimit = this.common.param('maxblobGasPerBlock') + const blobGasLimit = this.common.param('maxBlobGasPerBlock') const blobGasPerBlob = this.common.param('blobGasPerBlob') if (tx instanceof Blob4844Tx) { blobGasUsed += BigInt(tx.numBlobs()) * blobGasPerBlob @@ -354,7 +354,7 @@ export class Block { */ validateBlobTransactions(parentHeader: BlockHeader) { if (this.common.isActivatedEIP(4844)) { - const blobGasLimit = this.common.param('maxblobGasPerBlock') + const blobGasLimit = this.common.param('maxBlobGasPerBlock') const blobGasPerBlob = this.common.param('blobGasPerBlob') let blobGasUsed = BIGINT_0 diff --git a/packages/block/src/helpers.ts b/packages/block/src/helpers.ts index ace0a7435b..a1aa9a5639 100644 --- a/packages/block/src/helpers.ts +++ b/packages/block/src/helpers.ts @@ -172,7 +172,10 @@ export function genRequestsRoot( let flatRequests = new Uint8Array() for (const req of requests) { - flatRequests = concatBytes(flatRequests, sha256Function(req.bytes)) + if (req.bytes.length > 1) { + // Only append requests if they have content + flatRequests = concatBytes(flatRequests, sha256Function(req.bytes)) + } } return sha256Function(flatRequests) diff --git a/packages/block/src/params.ts b/packages/block/src/params.ts index d4277f3329..0ebfa7ff09 100644 --- a/packages/block/src/params.ts +++ b/packages/block/src/params.ts @@ -10,7 +10,7 @@ export const paramsBlock: ParamsDict = { gasLimitBoundDivisor: 1024, // The bound divisor of the gas limit, used in update calculations targetBlobGasPerBlock: 0, // Base value needed here since called pre-4844 in BlockHeader.calcNextExcessBlobGas() blobGasPerBlob: 0, - maxblobGasPerBlock: 0, + maxBlobGasPerBlock: 0, // format maxExtraDataSize: 32, // Maximum size extra data may be after Genesis // pow @@ -72,7 +72,7 @@ export const paramsBlock: ParamsDict = { // gasConfig targetBlobGasPerBlock: 393216, // The target blob gas consumed per block blobGasPerBlob: 131072, // The base fee for blob gas per blob - maxblobGasPerBlock: 786432, // The max blob gas allowable per block + maxBlobGasPerBlock: 786432, // The max blob gas allowable per block blobGasPriceUpdateFraction: 3338477, // The denominator used in the exponential when calculating a blob gas price // gasPrices simplePerBlobGas: 12000, // The basic gas fee for each blob @@ -85,4 +85,13 @@ export const paramsBlock: ParamsDict = { // pow difficultyBombDelay: 11400000, // the amount of blocks to delay the difficulty bomb with }, + /** +. * Blob throughput increase +. */ + 7691: { + // gasConfig + targetBlobGasPerBlock: 786432, // The target blob gas consumed per block + maxBlobGasPerBlock: 1179648, // The max blob gas allowable per block + blobGasPriceUpdateFraction: 5007716, // The denominator used in the exponential when calculating a blob gas price + }, } diff --git a/packages/client/src/miner/pendingBlock.ts b/packages/client/src/miner/pendingBlock.ts index 15ba431dc1..4d9e8deb2e 100644 --- a/packages/client/src/miner/pendingBlock.ts +++ b/packages/client/src/miner/pendingBlock.ts @@ -192,7 +192,7 @@ export class PendingBlock { // Get if and how many blobs are allowed in the tx let allowedBlobs if (vm.common.isActivatedEIP(4844)) { - const blobGasLimit = vm.common.param('maxblobGasPerBlock') + const blobGasLimit = vm.common.param('maxBlobGasPerBlock') const blobGasPerBlob = vm.common.param('blobGasPerBlob') allowedBlobs = Number(blobGasLimit / blobGasPerBlob) } else { @@ -270,7 +270,7 @@ export class PendingBlock { let allowedBlobs if (vm.common.isActivatedEIP(4844)) { const bundle = this.blobsBundles.get(payloadId) ?? { blobs: [], commitments: [], proofs: [] } - const blobGasLimit = vm.common.param('maxblobGasPerBlock') + const blobGasLimit = vm.common.param('maxBlobGasPerBlock') const blobGasPerBlob = vm.common.param('blobGasPerBlob') allowedBlobs = Number(blobGasLimit / blobGasPerBlob) - bundle.blobs.length } else { diff --git a/packages/client/src/rpc/helpers.ts b/packages/client/src/rpc/helpers.ts index 24cc138b40..0fee280adb 100644 --- a/packages/client/src/rpc/helpers.ts +++ b/packages/client/src/rpc/helpers.ts @@ -3,6 +3,7 @@ import { BIGINT_0, bigIntToHex, bytesToHex, intToHex } from '@ethereumjs/util' import { INTERNAL_ERROR, INVALID_BLOCK, INVALID_PARAMS } from './error-code.js' import type { Chain } from '../blockchain/index.js' +import type { RPCMethod } from './types.js' import type { Block } from '@ethereumjs/block' import type { JSONRPCTx, TypedTransaction } from '@ethereumjs/tx' @@ -13,7 +14,7 @@ type RPCError = { data?: string } -export function callWithStackTrace(handler: Function, debug: boolean) { +export function callWithStackTrace(handler: Function, debug: boolean): RPCMethod { return async (...args: any) => { try { const res = await handler(...args) diff --git a/packages/client/src/rpc/modules/admin.ts b/packages/client/src/rpc/modules/admin.ts index 9760a23bdf..f6f82a16e6 100644 --- a/packages/client/src/rpc/modules/admin.ts +++ b/packages/client/src/rpc/modules/admin.ts @@ -31,8 +31,8 @@ export class Admin { this._client = client this._rpcDebug = rpcDebug - this.nodeInfo = middleware(callWithStackTrace(this.nodeInfo.bind(this), this._rpcDebug), 0, []) - this.peers = middleware(callWithStackTrace(this.peers.bind(this), this._rpcDebug), 0, []) + this.nodeInfo = callWithStackTrace(this.nodeInfo.bind(this), this._rpcDebug) + this.peers = callWithStackTrace(this.peers.bind(this), this._rpcDebug) this.addPeer = middleware(callWithStackTrace(this.addPeer.bind(this), this._rpcDebug), 1, [ [ validators.object({ diff --git a/packages/client/src/rpc/modules/debug.ts b/packages/client/src/rpc/modules/debug.ts index c99331957c..9562c5cf3f 100644 --- a/packages/client/src/rpc/modules/debug.ts +++ b/packages/client/src/rpc/modules/debug.ts @@ -148,6 +148,9 @@ export class Debug { 1, [[validators.hex]], ) + this.setHead = middleware(callWithStackTrace(this.setHead.bind(this), this._rpcDebug), 1, [ + [validators.blockOption], + ]) this.verbosity = middleware(callWithStackTrace(this.verbosity.bind(this), this._rpcDebug), 1, [ [validators.unsignedInteger], ]) @@ -457,4 +460,30 @@ export class Debug { this.client.config.logger.configure({ level: logLevels[level] }) return `level: ${this.client.config.logger.level}` } + + /** + * Sets the current head of the local chain by block number. Note, this is a + * destructive action and may severely damage your chain. Use with extreme + * caution. + * @param blockOpt Block number or tag to set as head of chain + */ + async setHead(params: [string]) { + const [blockOpt] = params + if (blockOpt === 'pending') { + throw { + code: INVALID_PARAMS, + message: `"pending" is not supported`, + } + } + + const block = await getBlockByOption(blockOpt, this.chain) + try { + await this.service.skeleton?.setHead(block, true) + await this.service.execution.setHead([block]) + } catch (e) { + throw { + code: INTERNAL_ERROR, + } + } + } } diff --git a/packages/client/src/rpc/modules/engine/util/getPayload.ts b/packages/client/src/rpc/modules/engine/util/getPayload.ts index fec0814f2d..615fbe04f7 100644 --- a/packages/client/src/rpc/modules/engine/util/getPayload.ts +++ b/packages/client/src/rpc/modules/engine/util/getPayload.ts @@ -25,9 +25,20 @@ export const blockToExecutionPayload = ( // ethereumjs does not provide any transaction censoring detection (yet) to suggest // overriding builder/mev-boost blocks const shouldOverrideBuilder = false + + let executionRequests = undefined + if (requests !== undefined) { + executionRequests = [] + for (const request of requests) { + if (request.bytes.length > 1) { + executionRequests.push(bytesToHex(request.bytes)) + } + } + } + return { executionPayload, - executionRequests: requests?.map((req) => bytesToHex(req.data)), + executionRequests, blockValue: bigIntToHex(value), blobsBundle, shouldOverrideBuilder, diff --git a/packages/client/src/rpc/modules/engine/util/newPayload.ts b/packages/client/src/rpc/modules/engine/util/newPayload.ts index 5155ddfc5a..b387274027 100644 --- a/packages/client/src/rpc/modules/engine/util/newPayload.ts +++ b/packages/client/src/rpc/modules/engine/util/newPayload.ts @@ -57,30 +57,35 @@ export const validateAndGen7685RequestsHash = ( common: Common, executionRequests: PrefixedHexString[], ): PrefixedHexString => { - let validationError: string | null = null - const requests: CLRequest[] = [] - let requestIndex = 0 - if (common.isActivatedEIP(6110)) { - requests.push(new CLRequest(CLRequestType.Deposit, hexToBytes(executionRequests[requestIndex]))) - requestIndex++ - } - if (common.isActivatedEIP(7002)) { - requests.push( - new CLRequest(CLRequestType.Withdrawal, hexToBytes(executionRequests[requestIndex])), - ) - requestIndex++ - } - if (common.isActivatedEIP(7251)) { - requests.push( - new CLRequest(CLRequestType.Consolidation, hexToBytes(executionRequests[requestIndex])), - ) - requestIndex++ - } - if (requestIndex !== executionRequests.length) { - validationError = `Invalid executionRequests=${executionRequests.length} expected=${requestIndex}` - throw validationError + for (const request of executionRequests) { + const bytes = hexToBytes(request) + if (bytes.length === 0) { + throw new Error('Got a request without a request-identifier') + } + switch (bytes[0]) { + case CLRequestType.Deposit: + if (!common.isActivatedEIP(6110)) { + throw new Error(`Deposit requests are not active`) + } + requests.push(new CLRequest(CLRequestType.Deposit, bytes.slice(1))) + break + case CLRequestType.Withdrawal: + if (!common.isActivatedEIP(7002)) { + throw new Error(`Withdrawal requests are not active`) + } + requests.push(new CLRequest(CLRequestType.Withdrawal, bytes.slice(1))) + break + case CLRequestType.Consolidation: + if (!common.isActivatedEIP(7251)) { + throw new Error(`Consolidation requests are not active`) + } + requests.push(new CLRequest(CLRequestType.Consolidation, bytes.slice(1))) + break + default: + throw new Error(`Unknown request identifier: got ${bytes[0]}`) + } } const sha256Function = common.customCrypto.sha256 ?? sha256 diff --git a/packages/client/src/rpc/modules/eth.ts b/packages/client/src/rpc/modules/eth.ts index 6c5dc49b8c..a5c7880b2d 100644 --- a/packages/client/src/rpc/modules/eth.ts +++ b/packages/client/src/rpc/modules/eth.ts @@ -315,17 +315,14 @@ export class Eth { const ethProtocol = this.service.protocols.find((p) => p.name === 'eth') as EthProtocol this.ethVersion = Math.max(...ethProtocol.versions) - this.blockNumber = middleware( - callWithStackTrace(this.blockNumber.bind(this), this._rpcDebug), - 0, - ) + this.blockNumber = callWithStackTrace(this.blockNumber.bind(this), this._rpcDebug) this.call = middleware(callWithStackTrace(this.call.bind(this), this._rpcDebug), 2, [ [validators.transaction()], [validators.blockOption], ]) - this.chainId = middleware(callWithStackTrace(this.chainId.bind(this), this._rpcDebug), 0, []) + this.chainId = callWithStackTrace(this.chainId.bind(this), this._rpcDebug) this.estimateGas = middleware( callWithStackTrace(this.estimateGas.bind(this), this._rpcDebug), @@ -339,7 +336,7 @@ export class Eth { [[validators.address], [validators.blockOption]], ) - this.coinbase = middleware(callWithStackTrace(this.coinbase.bind(this), this._rpcDebug), 0, []) + this.coinbase = callWithStackTrace(this.coinbase.bind(this), this._rpcDebug) this.getBlockByNumber = middleware( callWithStackTrace(this.getBlockByNumber.bind(this), this._rpcDebug), @@ -443,13 +440,9 @@ export class Eth { [[validators.hex]], ) - this.protocolVersion = middleware( - callWithStackTrace(this.protocolVersion.bind(this), this._rpcDebug), - 0, - [], - ) + this.protocolVersion = callWithStackTrace(this.protocolVersion.bind(this), this._rpcDebug) - this.syncing = middleware(callWithStackTrace(this.syncing.bind(this), this._rpcDebug), 0, []) + this.syncing = callWithStackTrace(this.syncing.bind(this), this._rpcDebug) this.getProof = middleware(callWithStackTrace(this.getProof.bind(this), this._rpcDebug), 3, [ [validators.address], @@ -463,7 +456,7 @@ export class Eth { [[validators.blockOption]], ) - this.gasPrice = middleware(callWithStackTrace(this.gasPrice.bind(this), this._rpcDebug), 0, []) + this.gasPrice = callWithStackTrace(this.gasPrice.bind(this), this._rpcDebug) this.feeHistory = middleware( callWithStackTrace(this.feeHistory.bind(this), this._rpcDebug), @@ -475,18 +468,13 @@ export class Eth { ], ) - this.blobBaseFee = middleware( - callWithStackTrace(this.blobBaseFee.bind(this), this._rpcDebug), - 0, - [], - ) + this.blobBaseFee = callWithStackTrace(this.blobBaseFee.bind(this), this._rpcDebug) } /** * Returns number of the most recent block. - * @param params An empty array */ - async blockNumber(_params = []) { + async blockNumber() { return bigIntToHex(this._chain.headers.latest?.number ?? BIGINT_0) } @@ -540,10 +528,9 @@ export class Eth { /** * Returns the currently configured chain id, a value used in replay-protected transaction signing as introduced by EIP-155. - * @param _params An empty array * @returns The chain ID. */ - async chainId(_params = []) { + async chainId() { const chainId = this._chain.config.chainCommon.chainId() return bigIntToHex(chainId) } @@ -660,10 +647,9 @@ export class Eth { /** * Returns the currently configured coinbase address. - * @param _params An empty array * @returns The chain ID. */ - async coinbase(_params = []) { + async coinbase() { const cb = this.client.config.minerCoinbase if (cb === undefined) { throw { @@ -905,9 +891,8 @@ export class Eth { /** * Returns the current ethereum protocol version as a hex-encoded string - * @param params An empty array */ - protocolVersion(_params = []) { + protocolVersion() { return intToHex(this.ethVersion) } @@ -1175,7 +1160,7 @@ export class Eth { // Blob Transactions sent over RPC are expected to be in Network Wrapper format tx = createBlob4844TxFromSerializedNetworkWrapper(txBuf, { common }) - const blobGasLimit = tx.common.param('maxblobGasPerBlock') + const blobGasLimit = tx.common.param('maxBlobGasPerBlock') const blobGasPerBlob = tx.common.param('blobGasPerBlob') if (BigInt((tx.blobs ?? []).length) * blobGasPerBlob > blobGasLimit) { @@ -1272,13 +1257,12 @@ export class Eth { /** * Returns an object with data about the sync status or false. - * @param params An empty array * @returns An object with sync status data or false (when not syncing) * * startingBlock - The block at which the import started (will only be reset after the sync reached his head) * * currentBlock - The current block, same as eth_blockNumber * * highestBlock - The estimated highest block */ - async syncing(_params = []) { + async syncing() { if (this.client.config.synchronized) { return false } @@ -1418,7 +1402,7 @@ export class Eth { let blobGasUsedRatio = 0 if (b.header.excessBlobGas !== undefined) { baseFeePerBlobGas = b.header.getBlobGasPrice() - const max = b.common.param('maxblobGasPerBlock') + const max = b.common.param('maxBlobGasPerBlock') blobGasUsedRatio = Number(blobGasUsed) / Number(max) } diff --git a/packages/client/src/rpc/modules/net.ts b/packages/client/src/rpc/modules/net.ts index bc50608781..726de62e38 100644 --- a/packages/client/src/rpc/modules/net.ts +++ b/packages/client/src/rpc/modules/net.ts @@ -1,7 +1,6 @@ import { addHexPrefix } from '@ethereumjs/util' import { callWithStackTrace } from '../helpers.js' -import { middleware } from '../validation.js' import type { Chain } from '../../blockchain/index.js' import type { EthereumClient } from '../../index.js' @@ -29,40 +28,29 @@ export class Net { this._peerPool = service.pool this._rpcDebug = rpcDebug - this.version = middleware(callWithStackTrace(this.version.bind(this), this._rpcDebug), 0, []) - this.listening = middleware( - callWithStackTrace(this.listening.bind(this), this._rpcDebug), - 0, - [], - ) - this.peerCount = middleware( - callWithStackTrace(this.peerCount.bind(this), this._rpcDebug), - 0, - [], - ) + this.version = callWithStackTrace(this.version.bind(this), this._rpcDebug) + this.listening = callWithStackTrace(this.listening.bind(this), this._rpcDebug) + this.peerCount = callWithStackTrace(this.peerCount.bind(this), this._rpcDebug) } /** * Returns the current network id - * @param params An empty array */ - version(_params = []) { + version() { return this._chain.config.chainCommon.chainId().toString() } /** * Returns true if client is actively listening for network connections - * @param params An empty array */ - listening(_params = []) { + listening() { return this._client.opened } /** * Returns number of peers currently connected to the client - * @param params An empty array */ - peerCount(_params = []) { + peerCount() { return addHexPrefix(this._peerPool.peers.length.toString(16)) } } diff --git a/packages/client/src/rpc/modules/txpool.ts b/packages/client/src/rpc/modules/txpool.ts index b026eea061..694ea31ea1 100644 --- a/packages/client/src/rpc/modules/txpool.ts +++ b/packages/client/src/rpc/modules/txpool.ts @@ -1,5 +1,4 @@ import { callWithStackTrace, toJSONRPCTx } from '../helpers.js' -import { middleware } from '../validation.js' import type { EthereumClient } from '../../index.js' import type { FullEthereumService } from '../../service/index.js' @@ -25,14 +24,13 @@ export class TxPool { this._vm = service.execution.vm this._rpcDebug = rpcDebug - this.content = middleware(callWithStackTrace(this.content.bind(this), this._rpcDebug), 0, []) + this.content = callWithStackTrace(this.content.bind(this), this._rpcDebug) } /** * Returns the contents of the transaction pool - * @param params An empty array */ - content(_params = []) { + content() { const pending = new Map() for (const pool of this._txpool.pool) { const pendingForAcct = new Map() diff --git a/packages/client/src/rpc/types.ts b/packages/client/src/rpc/types.ts index 78c9506ff4..68893552dc 100644 --- a/packages/client/src/rpc/types.ts +++ b/packages/client/src/rpc/types.ts @@ -45,3 +45,5 @@ export function toRPCTx(t: TxResult): RPCTx { t.to !== null && (rpcTx.to = t.to) return rpcTx } + +export type RPCMethod = (...params: any) => any diff --git a/packages/client/src/rpc/validation.ts b/packages/client/src/rpc/validation.ts index d66616e9da..dcde5ebb7c 100644 --- a/packages/client/src/rpc/validation.ts +++ b/packages/client/src/rpc/validation.ts @@ -1,18 +1,21 @@ import { INVALID_PARAMS } from './error-code.js' +import type { RPCMethod } from './types.js' + /** * middleware for parameters validation * @memberof module:rpc * @param method function to add middleware * @param requiredParamsCount required parameters count * @param validators array of validators + * @param names Optional parameter names for error messages, length must be equal to requiredParamsCount */ export function middleware( method: any, requiredParamsCount: number, validators: any[] = [], names: string[] = [], -): any { +): RPCMethod { return function (params: any[] = []) { return new Promise((resolve, reject) => { if (params.length < requiredParamsCount) { diff --git a/packages/client/src/service/txpool.ts b/packages/client/src/service/txpool.ts index 6a1ef4201a..fe2d36c176 100644 --- a/packages/client/src/service/txpool.ts +++ b/packages/client/src/service/txpool.ts @@ -399,7 +399,7 @@ export class TxPool { } pruneBlobsAndProofsCache() { - const blobGasLimit = this.config.chainCommon.param('maxblobGasPerBlock') + const blobGasLimit = this.config.chainCommon.param('maxBlobGasPerBlock') const blobGasPerBlob = this.config.chainCommon.param('blobGasPerBlob') const allowedBlobsPerBlock = Number(blobGasLimit / blobGasPerBlob) diff --git a/packages/client/test/execution/vmexecution.spec.ts b/packages/client/test/execution/vmexecution.spec.ts index 4b30946748..50c9db8fd6 100644 --- a/packages/client/test/execution/vmexecution.spec.ts +++ b/packages/client/test/execution/vmexecution.spec.ts @@ -8,7 +8,7 @@ import { assert, describe, it } from 'vitest' import { Chain } from '../../src/blockchain/index.js' import { Config } from '../../src/config.js' import { VMExecution } from '../../src/execution/index.js' -import { closeRPC, setupChain } from '../rpc/helpers.js' +import { closeRPC, setupChain, testSetup } from '../rpc/helpers.js' import { goerliData } from '../testdata/blocks/goerli.js' import { mainnetData } from '../testdata/blocks/mainnet.js' import { testnetData } from '../testdata/common/testnet.js' @@ -94,15 +94,6 @@ describe('[VMExecution]', () => { assert.equal(exec.vm, vm, 'should use vm provided') }) - async function testSetup(blockchain: Blockchain, common?: Common) { - const config = new Config({ common, accountCache: 10000, storageCache: 1000 }) - const chain = await Chain.create({ config, blockchain }) - const exec = new VMExecution({ config, chain }) - await chain.open() - await exec.open() - return exec - } - it('Block execution / Hardforks PoW (mainnet)', async () => { let blockchain = await createBlockchain({ validateBlocks: true, diff --git a/packages/client/test/miner/pendingBlock.spec.ts b/packages/client/test/miner/pendingBlock.spec.ts index 7d295a4515..91354c83f6 100644 --- a/packages/client/test/miner/pendingBlock.spec.ts +++ b/packages/client/test/miner/pendingBlock.spec.ts @@ -366,7 +366,7 @@ describe('[PendingBlock]', async () => { const fillProofs = blobsToProofs(kzg, fillBlobs, fillCommitments) const fillBlobAndProof = { blob: fillBlobs[0], proof: fillProofs[0] } - const blobGasLimit = txPool['config'].chainCommon.param('maxblobGasPerBlock') + const blobGasLimit = txPool['config'].chainCommon.param('maxBlobGasPerBlock') const blobGasPerBlob = txPool['config'].chainCommon.param('blobGasPerBlob') const allowedBlobsPerBlock = Number(blobGasLimit / blobGasPerBlob) const allowedLength = allowedBlobsPerBlock * txPool['config'].blobsAndProofsCacheBlocks diff --git a/packages/client/test/rpc/debug/setHead.spec.ts b/packages/client/test/rpc/debug/setHead.spec.ts new file mode 100644 index 0000000000..48fa950b14 --- /dev/null +++ b/packages/client/test/rpc/debug/setHead.spec.ts @@ -0,0 +1,88 @@ +import { createBlockchainFromBlocksData } from '@ethereumjs/blockchain' +import { assert, describe, it } from 'vitest' + +import { mainnetData } from '../../testdata/blocks/mainnet.js' +import { createClient, createManager, getRPCClient, startRPC, testSetup } from '../helpers.js' + +import type { Blockchain } from '@ethereumjs/blockchain' + +const method = 'debug_setHead' + +describe(method, async () => { + it('call with valid arguments', async () => { + const blockchain = await createBlockchainFromBlocksData(mainnetData, { + validateBlocks: true, + validateConsensus: false, + }) + const blocks = await blockchain.getBlocks(0, 6, 0, false) + const exec = await testSetup(blockchain) + await exec.run() + const newHead = await (exec.vm.blockchain as Blockchain).getIteratorHead!() + assert.equal(newHead.header.number, BigInt(mainnetData.length), 'should run all blocks') + + const client = await createClient({ blockchain }) + await client.service.skeleton?.open() + ;(client.service.execution as any) = exec + + const manager = createManager(client) + const rpc = getRPCClient(startRPC(manager.getMethods())) + assert.equal( + await client.service.skeleton?.headHash(), + undefined, + 'should return undefined when head is not set', + ) + for (let i = 0; i < blocks.length; i++) { + await rpc.request(method, [`0x${i}`]) + assert.deepEqual( + await client.service.skeleton?.headHash()!, + blocks[i].header.hash(), + `skeleton chain should return hash of block number ${i} set as head`, + ) + assert.deepEqual( + client.service.execution.chainStatus?.hash!, + blocks[i].header.hash(), + `vm execution should set hash to new head`, + ) + } + }, 30000) + + it('should return error for pending block', async () => { + const blockchain = await createBlockchainFromBlocksData(mainnetData, { + validateBlocks: true, + validateConsensus: false, + }) + + const client = await createClient({ blockchain }) + + const manager = createManager(client) + const rpc = getRPCClient(startRPC(manager.getMethods())) + const result = await rpc.request(method, ['pending']) + assert.equal(result.error.code, -32602) + assert.equal(result.error.message, '"pending" is not supported') + }) + + it('should handle internal errors', async () => { + const blockchain = await createBlockchainFromBlocksData(mainnetData, { + validateBlocks: true, + validateConsensus: false, + }) + const exec = await testSetup(blockchain) + await exec.run() + const newHead = await (exec.vm.blockchain as Blockchain).getIteratorHead!() + assert.equal(newHead.header.number, BigInt(mainnetData.length), 'should run all blocks') + + const client = await createClient({ blockchain }) + ;(client.service.skeleton as any) = { + open: async () => { + throw new Error('open failed') + }, + } + + const manager = createManager(client) + const rpc = getRPCClient(startRPC(manager.getMethods())) + + const result = await rpc.request(method, ['0x1']) + assert.equal(result.error.code, -32603) + assert.equal(result.error.message, 'Internal error') + }) +}) diff --git a/packages/client/test/rpc/engine/newPayloadV4.spec.ts b/packages/client/test/rpc/engine/newPayloadV4.spec.ts index 4538a2d95b..db29e70c69 100644 --- a/packages/client/test/rpc/engine/newPayloadV4.spec.ts +++ b/packages/client/test/rpc/engine/newPayloadV4.spec.ts @@ -12,9 +12,9 @@ const [blockData] = beaconData const parentBeaconBlockRoot = '0x42942949c4ed512cd85c2cb54ca88591338cbb0564d3a2bea7961a639ef29d64' const validForkChoiceState = { - headBlockHash: '0x6abe4c2777a6a1e994d83920cfb95229b071174b95c89343f54b926f733789f2', - safeBlockHash: '0x6abe4c2777a6a1e994d83920cfb95229b071174b95c89343f54b926f733789f2', - finalizedBlockHash: '0x6abe4c2777a6a1e994d83920cfb95229b071174b95c89343f54b926f733789f2', + headBlockHash: '0x5bc7efe14c04eed7572809bb9c11d48d872139384097b95e04f8ab1b01ae8ecc', + safeBlockHash: '0x5bc7efe14c04eed7572809bb9c11d48d872139384097b95e04f8ab1b01ae8ecc', + finalizedBlockHash: '0x5bc7efe14c04eed7572809bb9c11d48d872139384097b95e04f8ab1b01ae8ecc', } const validPayloadAttributes = { timestamp: '0x64ba84fd', @@ -35,26 +35,24 @@ const electraGenesisContracts = { // sender corresponding to the priv key 0x9c9996335451aab4fc4eac58e31a8c300e095cdbcee532d53d09280e83360355 '0x610adc49ecd66cbf176a8247ebd59096c031bd9f': { balance: '0x6d6172697573766477000000' }, // eip 2925 contract - '0x0aae40965e6800cd9b1f4b05ff21581047e3f91e': { + '0x0f792be4b0c0cb4dae440ef133e90c0ecd48cccc': { balance: '0', nonce: '1', - code: '0x3373fffffffffffffffffffffffffffffffffffffffe1460575767ffffffffffffffff5f3511605357600143035f3511604b575f35612000014311604b57611fff5f3516545f5260205ff35b5f5f5260205ff35b5f5ffd5b5f35611fff60014303165500', + code: '0x3373fffffffffffffffffffffffffffffffffffffffe14604657602036036042575f35600143038111604257611fff81430311604257611fff9006545f5260205ff35b5f5ffd5b5f35611fff60014303065500', }, // consolidation requests contract - '0x00706203067988Ab3E2A2ab626EdCD6f28bDBbbb': { - balance: '0', - nonce: '1', - code: '0x3373fffffffffffffffffffffffffffffffffffffffe1460cf573615156028575f545f5260205ff35b366060141561019a5760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1461019a57600182026001905f5b5f821115608057810190830284830290049160010191906065565b90939004341061019a57600154600101600155600354806004026004013381556001015f358155600101602035815560010160403590553360601b5f5260605f60143760745fa0600101600355005b6003546002548082038060011160e3575060015b5f5b8181146101295780607402838201600402600401805490600101805490600101805490600101549260601b84529083601401528260340152906054015260010160e5565b910180921461013b5790600255610146565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff141561017357505f5b6001546001828201116101885750505f61018e565b01600190035b5f555f6001556074025ff35b5f5ffd', + '0x00431f263ce400f4455c2dcf564e53007ca4bbbb': { + nonce: '0x01', + balance: '0x00', + code: '0x3373fffffffffffffffffffffffffffffffffffffffe1460d35760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1461019a57600182026001905f5b5f82111560685781019083028483029004916001019190604d565b9093900492505050366060146088573661019a573461019a575f5260205ff35b341061019a57600154600101600155600354806004026004013381556001015f358155600101602035815560010160403590553360601b5f5260605f60143760745fa0600101600355005b6003546002548082038060021160e7575060025b5f5b8181146101295782810160040260040181607402815460601b815260140181600101548152602001816002015481526020019060030154905260010160e9565b910180921461013b5790600255610146565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff141561017357505f5b6001546001828201116101885750505f61018e565b01600190035b5f555f6001556074025ff35b5f5ffd', + storage: {}, }, // withdrawals request contract - '0x05F27129610CB42103b665629CB5c8C00296AaAa': { - balance: '0', - nonce: '1', - code: '0x3373fffffffffffffffffffffffffffffffffffffffe1460c7573615156028575f545f5260205ff35b36603814156101f05760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f057600182026001905f5b5f821115608057810190830284830290049160010191906065565b9093900434106101f057600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160db575060105b5f5b81811461017f5780604c02838201600302600401805490600101805490600101549160601b83528260140152807fffffffffffffffffffffffffffffffff0000000000000000000000000000000016826034015260401c906044018160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160dd565b9101809214610191579060025561019c565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101c957505f5b6001546002828201116101de5750505f6101e4565b01600290035b5f555f600155604c025ff35b5f5ffd', - storage: { - '0x0000000000000000000000000000000000000000000000000000000000000000': - '0x000000000000000000000000000000000000000000000000000000000000049d', - }, + '0x0c15f14308530b7cdb8460094bbb9cc28b9aaaaa': { + nonce: '0x01', + balance: '0x00', + code: '0x3373fffffffffffffffffffffffffffffffffffffffe1460cb5760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f457600182026001905f5b5f82111560685781019083028483029004916001019190604d565b909390049250505036603814608857366101f457346101f4575f5260205ff35b34106101f457600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160df575060105b5f5b8181146101835782810160030260040181604c02815460601b8152601401816001015481526020019060020154807fffffffffffffffffffffffffffffffff00000000000000000000000000000000168252906010019060401c908160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160e1565b910180921461019557906002556101a0565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101cd57505f5b6001546002828201116101e25750505f6101e8565b01600290035b5f555f600155604c025ff35b5f5ffd', + storage: {}, }, // beacon deposit contract for deposit receipts '0x00000000219ab540356cBB839Cbe05303d7705Fa': { @@ -160,9 +158,9 @@ describe(`${method}: call with executionPayloadV4`, () => { withdrawals: [], blobGasUsed: '0x0', excessBlobGas: '0x0', - parentHash: '0x6abe4c2777a6a1e994d83920cfb95229b071174b95c89343f54b926f733789f2', - stateRoot: '0x7aa6e46df1f78988a3141b5e7da8abee78d1daca175f43fe8866b2d1bf8d8ef8', - blockHash: '0x9a5903d803e6e7c3631cd76cb7279f93d7facc995c53eaffadf4e225504b18eb', + parentHash: '0x5bc7efe14c04eed7572809bb9c11d48d872139384097b95e04f8ab1b01ae8ecc', + stateRoot: '0xebe157ea5c3dc6fb5970f67b76266903282aee9772030f06c112348f32037fd9', + blockHash: '0x725c21032b68ae7d2f143581d0196cfbfd14dbc45c14eaeab15443831de489b7', } const oldMethods = ['engine_newPayloadV1', 'engine_newPayloadV2', 'engine_newPayloadV3'] @@ -180,7 +178,7 @@ describe(`${method}: call with executionPayloadV4`, () => { assert.ok(res.error.message.includes(expectedError)) } - res = await rpc.request(method, [validBlock, [], parentBeaconBlockRoot, ['0x', '0x', '0x']]) + res = await rpc.request(method, [validBlock, [], parentBeaconBlockRoot, []]) assert.equal(res.result.status, 'VALID') res = await rpc.request('engine_forkchoiceUpdatedV3', validPayload) @@ -201,9 +199,20 @@ describe(`${method}: call with executionPayloadV4`, () => { res = await rpc.request('engine_getPayloadV4', [payloadId]) const { executionPayload, executionRequests } = res.result + + assert.ok( + executionRequests?.length === 1, + 'executionRequests should have the deposit request, and should exclude the other requests (these are empty)', + ) + + const depositRequestBytes = hexToBytes(executionRequests[0]) + assert.ok( + depositRequestBytes[0] === 0x00, + 'deposit request byte 0 is the deposit request identifier byte (0x00)', + ) assert.ok( - executionRequests?.length === 3, - 'executionRequests should have 3 entries for each request type', + depositRequestBytes.length > 1, + 'deposit request includes data (and is thus not empty)', ) res = await rpc.request(method, [ diff --git a/packages/client/test/rpc/helpers.ts b/packages/client/test/rpc/helpers.ts index 71d71d5251..5796bc4441 100644 --- a/packages/client/test/rpc/helpers.ts +++ b/packages/client/test/rpc/helpers.ts @@ -348,3 +348,12 @@ export const batchBlocks = async (rpc: HttpClient, inputBlocks: any[]) => { assert.equal(res.result.status, 'VALID') } } + +export async function testSetup(blockchain: Blockchain, common?: Common) { + const config = new Config({ common, accountCache: 10000, storageCache: 1000 }) + const chain = await Chain.create({ config, blockchain }) + const exec = new VMExecution({ config, chain }) + await chain.open() + await exec.open() + return exec +} diff --git a/packages/common/src/chains.ts b/packages/common/src/chains.ts index b463c81d1b..eb1cb3b21f 100644 --- a/packages/common/src/chains.ts +++ b/packages/common/src/chains.ts @@ -117,6 +117,10 @@ export const Mainnet: ChainConfig = { name: 'prague', block: null, }, + { + name: 'osaka', + block: null, + }, ], bootstrapNodes: [ { diff --git a/packages/common/src/common.ts b/packages/common/src/common.ts index ce36db6d25..80e632ec4b 100644 --- a/packages/common/src/common.ts +++ b/packages/common/src/common.ts @@ -317,8 +317,8 @@ export class Common { for (const hfChanges of this.HARDFORK_CHANGES) { // EIP-referencing HF config (e.g. for berlin) if ('eips' in hfChanges[1]) { - const hfEIPs = hfChanges[1]['eips'] - for (const eip of hfEIPs!) { + const hfEIPs = hfChanges[1].eips ?? [] + for (const eip of hfEIPs) { this._mergeWithParamsCache(this._params[eip] ?? {}) } } @@ -337,7 +337,7 @@ export class Common { for (const [name, hf] of this.HARDFORK_CHANGES) { if (this.gteHardfork(name) && 'eips' in hf) { - this._activatedEIPsCache = this._activatedEIPsCache.concat(hf['eips'] as number[]) + this._activatedEIPsCache = this._activatedEIPsCache.concat(hf.eips ?? []) } } this._activatedEIPsCache = this._activatedEIPsCache.concat(this._eips) diff --git a/packages/common/src/eips.ts b/packages/common/src/eips.ts index 091fae9ce4..1c6e31aab0 100644 --- a/packages/common/src/eips.ts +++ b/packages/common/src/eips.ts @@ -405,6 +405,15 @@ export const eipsDict: EIPsDict = { */ requiredEIPs: [3540, 3541, 3670], }, + /** + * Description : Increase calldata cost to reduce maximum block size + * URL : https://github.com/ethereum/EIPs/blob/da2a86bf15044416e8eb0301c9bdb8d561feeb32/EIPS/eip-7623.md + * Status : Review + */ + 7623: { + minimumHardfork: Hardfork.Chainstart, + requiredEIPs: [], + }, /** * Description : General purpose execution layer requests * URL : https://eips.ethereum.org/EIPS/eip-7685 @@ -415,6 +424,15 @@ export const eipsDict: EIPsDict = { minimumHardfork: Hardfork.Cancun, requiredEIPs: [3675], }, + /** + * Description : Blob throughput increase + * URL : https://eips.ethereum.org/EIPS/eip-7691 + * Status : Review + */ + 7691: { + minimumHardfork: Hardfork.Paris, + requiredEIPs: [4844], + }, /** * Description : EVM Object Format (EOFv1) Meta * URL : https://github.com/ethereum/EIPs/blob/4153e95befd0264082de3c4c2fe3a85cc74d3152/EIPS/eip-7692.md diff --git a/packages/common/src/enums.ts b/packages/common/src/enums.ts index 3ef732f922..8f4f673d57 100644 --- a/packages/common/src/enums.ts +++ b/packages/common/src/enums.ts @@ -71,6 +71,7 @@ export enum Hardfork { Shanghai = 'shanghai', Cancun = 'cancun', Prague = 'prague', + Osaka = 'osaka', Verkle = 'verkle', } diff --git a/packages/common/src/hardforks.ts b/packages/common/src/hardforks.ts index 1f3a8fbf8e..fd11ca6876 100644 --- a/packages/common/src/hardforks.ts +++ b/packages/common/src/hardforks.ts @@ -158,9 +158,10 @@ export const hardforksDict: HardforksDict = { * Status : Final */ prague: { - // TODO update this accordingly to the right devnet setup - //eips: [663, 3540, 3670, 4200, 4750, 5450, 6206, 7069, 7480, 7620, 7692, 7698], // This is EOF-only - eips: [2537, 2935, 6110, 7002, 7251, 7685, 7702], // This is current prague without EOF + eips: [2537, 2935, 6110, 7002, 7251, 7623, 7685, 7691, 7702], + }, + osaka: { + eips: [663, 3540, 3670, 4200, 4750, 5450, 6206, 7069, 7480, 7620, 7692, 7698], }, /** * Description: Next feature hardfork after prague, internally used for verkle testing/implementation (incomplete/experimental) @@ -168,6 +169,6 @@ export const hardforksDict: HardforksDict = { * Status : Final */ verkle: { - eips: [4762, 6800], + eips: [2935, 4762, 6800], }, } diff --git a/packages/common/src/interfaces.ts b/packages/common/src/interfaces.ts index fe17f65564..42909d050d 100644 --- a/packages/common/src/interfaces.ts +++ b/packages/common/src/interfaces.ts @@ -101,38 +101,20 @@ export type VerkleAccessedStateWithAddress = VerkleAccessedState & { export interface VerkleAccessWitnessInterface { accesses(): Generator rawAccesses(): Generator - touchAndChargeProofOfAbsence(address: Address): bigint - touchAndChargeMessageCall(address: Address): bigint - touchAndChargeValueTransfer(target: Address): bigint - touchAndChargeContractCreateInit(address: Address): bigint - touchAndChargeContractCreateCompleted(address: Address): bigint - touchTxOriginAndComputeGas(origin: Address): bigint - touchTxTargetAndComputeGas(target: Address, { sendsValue }: { sendsValue?: boolean }): bigint - touchCodeChunksRangeOnReadAndChargeGas(contact: Address, startPc: number, endPc: number): bigint - touchCodeChunksRangeOnWriteAndChargeGas(contact: Address, startPc: number, endPc: number): bigint - touchAddressOnWriteAndComputeGas( - address: Address, - treeIndex: number | bigint, - subIndex: number | Uint8Array, - ): bigint - touchAddressOnReadAndComputeGas( - address: Address, - treeIndex: number | bigint, - subIndex: number | Uint8Array, - ): bigint - touchAddressAndChargeGas( - address: Address, - treeIndex: number | bigint, - subIndex: number | Uint8Array, - { isWrite }: { isWrite?: boolean }, - ): bigint - touchAddress( - address: Address, - treeIndex: number | bigint, - subIndex: number | Uint8Array, - { isWrite }: { isWrite?: boolean }, - ): AccessEventFlags + debugWitnessCost(): void + readAccountBasicData(address: Address): bigint + writeAccountBasicData(address: Address): bigint + readAccountCodeHash(address: Address): bigint + writeAccountCodeHash(address: Address): bigint + readAccountHeader(address: Address): bigint + writeAccountHeader(address: Address): bigint + readAccountCodeChunks(contract: Address, startPc: number, endPc: number): bigint + writeAccountCodeChunks(contract: Address, startPc: number, endPc: number): bigint + readAccountStorage(contract: Address, storageSlot: bigint): bigint + writeAccountStorage(contract: Address, storageSlot: bigint): bigint merge(accessWitness: VerkleAccessWitnessInterface): void + commit(): void + revert(): void } /* diff --git a/packages/evm/src/chunkCache.ts b/packages/evm/src/chunkCache.ts new file mode 100644 index 0000000000..5831e75a09 --- /dev/null +++ b/packages/evm/src/chunkCache.ts @@ -0,0 +1,35 @@ +import type { ChunkAccessEvent } from './verkleAccessWitness.js' +import type { PrefixedHexString } from '@ethereumjs/util' +export class ChunkCache { + cache: Map + + constructor() { + this.cache = new Map() + } + + set(stemKey: PrefixedHexString, accessedStem: ChunkAccessEvent) { + this.cache.set(stemKey, accessedStem) + } + + get(stemHex: PrefixedHexString): ChunkAccessEvent | undefined { + return this.cache.get(stemHex) + } + + del(stemHex: PrefixedHexString): void { + this.cache.delete(stemHex) + } + + commit(): [PrefixedHexString, ChunkAccessEvent][] { + const items: [PrefixedHexString, ChunkAccessEvent][] = Array.from(this.cache.entries()) + this.clear() + return items + } + + clear(): void { + this.cache.clear() + } + + size() { + return this.cache.size + } +} diff --git a/packages/evm/src/eof/container.ts b/packages/evm/src/eof/container.ts index fe4a08e83d..3f8a1cddeb 100644 --- a/packages/evm/src/eof/container.ts +++ b/packages/evm/src/eof/container.ts @@ -368,6 +368,10 @@ class EOFBody { } } else { dataSection = stream.readRemainder() + + if (dataSection.length > header.dataSize) { + validationError(EOFError.DanglingBytes) + } } // Write all data to the object diff --git a/packages/evm/src/eof/errors.ts b/packages/evm/src/eof/errors.ts index e3182f1c97..7b7cf9798a 100644 --- a/packages/evm/src/eof/errors.ts +++ b/packages/evm/src/eof/errors.ts @@ -63,6 +63,7 @@ export enum EOFError { InvalidStackHeight = 'invalid stack height', InvalidJUMPF = 'invalid jumpf target (output count)', InvalidReturningSection = 'invalid returning code section: section is not returning', + ReturningNoReturn = 'invalid section: section should return but has no RETF/JUMP to return', RJUMPVTableSize0 = 'invalid RJUMPV: table size 0', UnreachableCodeSections = 'unreachable code sections', UnreachableCode = 'unreachable code (by forward jumps)', diff --git a/packages/evm/src/eof/verify.ts b/packages/evm/src/eof/verify.ts index ac0e632050..e6c4ecaa15 100644 --- a/packages/evm/src/eof/verify.ts +++ b/packages/evm/src/eof/verify.ts @@ -61,31 +61,9 @@ function validateOpcodes( evm: EVM, mode: ContainerSectionType = ContainerSectionType.RuntimeCode, ) { - // Track the intermediate bytes - const intermediateBytes = new Set() - // Track the jump locations (for forward jumps it is unknown at the first pass if the byte is intermediate) - const jumpLocations = new Set() - // Track the type of the container targets // Should at the end of the analysis have all the containers const containerTypeMap = new Map() - - function addJump(location: number) { - if (intermediateBytes.has(location)) { - // When trying to JUMP into an intermediate byte: this is invalid - validationError(EOFError.InvalidRJUMP) - } - jumpLocations.add(location) - } - - function addIntermediate(location: number) { - if (jumpLocations.has(location)) { - // When trying to add an intermediate to a location already JUMPed to: this is invalid - validationError(EOFError.InvalidRJUMP) - } - intermediateBytes.add(location) - } - // TODO (?) -> stackDelta currently only has active EOF opcodes, can use it directly (?) // (so no need to generate the valid opcodeNumbers) @@ -156,11 +134,42 @@ function validateOpcodes( let codeSection = -1 for (const code of container.body.codeSections) { + // Track the intermediate bytes + const intermediateBytes = new Set() + // Track the jump locations (for forward jumps it is unknown at the first pass if the byte is intermediate) + const jumpLocations = new Set() + + // eslint-disable-next-line no-inner-declarations + function addJump(location: number) { + if (intermediateBytes.has(location)) { + // When trying to JUMP into an intermediate byte: this is invalid + validationError(EOFError.InvalidRJUMP) + } + jumpLocations.add(location) + } + + // eslint-disable-next-line no-inner-declarations + function addIntermediate(location: number) { + if (jumpLocations.has(location)) { + // When trying to add an intermediate to a location already JUMPed to: this is invalid + validationError(EOFError.InvalidRJUMP) + } + intermediateBytes.add(location) + } + codeSection++ reachableSections[codeSection] = new Set() - const returningFunction = container.body.typeSections[codeSection].outputs === 0x80 + // Section is marked as "non-returning": it does never "return" to another code section + // it rather exits the current EVM call frame + const nonReturningFunction = container.body.typeSections[codeSection].outputs === 0x80 + + // Boolean flag to mark if this section has a returning opcode: + // RETF + // Or JUMPF into a returning section + // Each returning section should contain a returning opcode + let sectionHasReturningOpcode = false // Tracking set of reachable opcodes const reachableOpcodes = new Set() @@ -212,12 +221,12 @@ function validateOpcodes( let minStackNext = minStackCurrent + delta let maxStackNext = maxStackCurrent + delta - if (maxStackNext > 1023) { + if (maxStackNext > 1024) { // TODO verify if 1023 or 1024 is the right constant validationError(EOFError.StackOverflow) } - if (returningFunction && opcode === 0xe4) { + if (nonReturningFunction && opcode === 0xe4) { validationError(EOFError.InvalidReturningSection) } @@ -328,7 +337,7 @@ function validateOpcodes( validationError(EOFError.InvalidJUMPF) } - if (returningFunction && targetOutputs <= 0x7f) { + if (nonReturningFunction && targetOutputs <= 0x7f) { // Current function is returning, but target is not, cannot jump into this validationError(EOFError.InvalidReturningSection) } @@ -344,12 +353,12 @@ function validateOpcodes( if (!(minStackCurrent === maxStackCurrent && maxStackCurrent === expectedStack)) { validationError(EOFError.InvalidStackHeight) } + sectionHasReturningOpcode = true } if ( maxStackCurrent + container.body.typeSections[target].maxStackHeight - targetInputs > 1024 ) { - //console.log(maxStackCurrent, targetOutputs, targetInputs, targetNonReturning) validationError(EOFError.StackOverflow) } } @@ -360,6 +369,7 @@ function validateOpcodes( if (!(minStackCurrent === maxStackCurrent && maxStackCurrent === outputs)) { validationError(EOFError.InvalidStackHeight) } + sectionHasReturningOpcode = true } else if (opcode === 0xe6) { // DUPN const toDup = code[ptr + 1] @@ -369,9 +379,7 @@ function validateOpcodes( } else if (opcode === 0xe7) { // SWAPN const toSwap = code[ptr + 1] - // TODO: EVMONEs test wants this to be `toSwap + 2`, but that seems to be incorrect - // Will keep `toSwap + 1` for now - if (toSwap + 1 > minStackCurrent) { + if (toSwap + 2 > minStackCurrent) { validationError(EOFError.StackUnderflow) } } else if (opcode === 0xe8) { @@ -485,10 +493,15 @@ function validateOpcodes( if (container.body.typeSections[codeSection].maxStackHeight !== maxStackHeight) { validationError(EOFError.MaxStackHeightViolation) } - if (maxStackHeight > 1023) { + if (maxStackHeight > 1024) { // TODO verify if 1023 or 1024 is the right constant validationError(EOFError.MaxStackHeightLimit) } + + // Validate that if the section is returning, there is a returning opcode + if (!sectionHasReturningOpcode && !nonReturningFunction) { + validationError(EOFError.ReturningNoReturn) + } } // Verify that each code section can be reached from code section 0 diff --git a/packages/evm/src/evm.ts b/packages/evm/src/evm.ts index 9d22e1bed1..e45eb138f0 100644 --- a/packages/evm/src/evm.ts +++ b/packages/evm/src/evm.ts @@ -86,6 +86,7 @@ export class EVM implements EVMInterface { Hardfork.Shanghai, Hardfork.Cancun, Hardfork.Prague, + Hardfork.Osaka, Hardfork.Verkle, ] protected _tx?: { @@ -101,6 +102,7 @@ export class EVM implements EVMInterface { public blockchain: EVMMockBlockchainInterface public journal: Journal public verkleAccessWitness?: VerkleAccessWitness + public systemVerkleAccessWitness?: VerkleAccessWitness public readonly transientStorage: TransientStorage @@ -182,7 +184,7 @@ export class EVM implements EVMInterface { const supportedEIPs = [ 663, 1153, 1559, 2537, 2565, 2718, 2929, 2930, 2935, 3198, 3529, 3540, 3541, 3607, 3651, 3670, 3855, 3860, 4200, 4399, 4750, 4788, 4844, 4895, 5133, 5450, 5656, 6110, 6206, 6780, 6800, - 7002, 7069, 7251, 7480, 7516, 7620, 7685, 7692, 7698, 7702, 7709, + 7002, 7069, 7251, 7480, 7516, 7620, 7685, 7691, 7692, 7698, 7702, 7709, ] for (const eip of this.common.eips()) { @@ -274,29 +276,35 @@ export class EVM implements EVMInterface { } const sendsValue = message.value !== BIGINT_0 if (message.depth === 0) { - const originAccessGas = message.accessWitness.touchTxOriginAndComputeGas(fromAddress) + const originAccessGas = message.accessWitness.readAccountHeader(fromAddress) debugGas(`originAccessGas=${originAccessGas} waived off for origin at depth=0`) - const destAccessGas = message.accessWitness.touchTxTargetAndComputeGas(message.to, { - sendsValue, - }) + let destAccessGas = message.accessWitness.readAccountCodeHash(message.to) + if (sendsValue) { + destAccessGas += message.accessWitness.writeAccountBasicData(message.to) + } else { + destAccessGas += message.accessWitness.readAccountBasicData(message.to) + } + debugGas(`destAccessGas=${destAccessGas} waived off for target at depth=0`) } - let callAccessGas = message.accessWitness.touchAndChargeMessageCall(message.to) + let callAccessGas = message.accessWitness.readAccountBasicData(message.to) if (sendsValue) { - callAccessGas += message.accessWitness.touchAndChargeValueTransfer(message.to) + callAccessGas += message.accessWitness.writeAccountBasicData(message.to) } gasLimit -= callAccessGas if (gasLimit < BIGINT_0) { if (this.DEBUG) { debugGas(`callAccessGas charged(${callAccessGas}) caused OOG (-> ${gasLimit})`) } + message.accessWitness.revert() return { execResult: OOGResult(message.gasLimit) } } else { if (this.DEBUG) { debugGas(`callAccessGas used (${callAccessGas} gas (-> ${gasLimit}))`) } + message.accessWitness.commit() } } @@ -318,9 +326,7 @@ export class EVM implements EVMInterface { let toAccount = await this.stateManager.getAccount(message.to) if (!toAccount) { if (this.common.isActivatedEIP(6800)) { - const absenceProofAccessGas = message.accessWitness!.touchAndChargeProofOfAbsence( - message.to, - ) + const absenceProofAccessGas = message.accessWitness!.readAccountHeader(message.to) gasLimit -= absenceProofAccessGas if (gasLimit < BIGINT_0) { if (this.DEBUG) { @@ -328,11 +334,13 @@ export class EVM implements EVMInterface { `Proof of absence access charged(${absenceProofAccessGas}) caused OOG (-> ${gasLimit})`, ) } + message.accessWitness?.revert() return { execResult: OOGResult(message.gasLimit) } } else { if (this.DEBUG) { debugGas(`Proof of absence access used (${absenceProofAccessGas} gas (-> ${gasLimit}))`) } + message.accessWitness?.commit() } } toAccount = new Account() @@ -419,7 +427,7 @@ export class EVM implements EVMInterface { if (this.common.isActivatedEIP(6800)) { if (message.depth === 0) { - const originAccessGas = message.accessWitness!.touchTxOriginAndComputeGas(fromAddress) + const originAccessGas = message.accessWitness!.readAccountHeader(fromAddress) debugGas(`originAccessGas=${originAccessGas} waived off for origin at depth=0`) } } @@ -468,21 +476,23 @@ export class EVM implements EVMInterface { } if (this.common.isActivatedEIP(6800)) { - const contractCreateAccessGas = message.accessWitness!.touchAndChargeContractCreateInit( - message.to, - ) + const contractCreateAccessGas = + message.accessWitness!.writeAccountBasicData(message.to) + + message.accessWitness!.readAccountCodeHash(message.to) gasLimit -= contractCreateAccessGas if (gasLimit < BIGINT_0) { if (this.DEBUG) { debugGas( `ContractCreateInit charge(${contractCreateAccessGas}) caused OOG (-> ${gasLimit})`, ) + message.accessWitness?.revert() } return { execResult: OOGResult(message.gasLimit) } } else { if (this.DEBUG) { debugGas(`ContractCreateInit charged (${contractCreateAccessGas} gas (-> ${gasLimit}))`) } + message.accessWitness?.commit() } } @@ -555,8 +565,7 @@ export class EVM implements EVMInterface { if (exit) { if (this.common.isActivatedEIP(6800)) { - const createCompleteAccessGas = - message.accessWitness!.touchAndChargeContractCreateCompleted(message.to) + const createCompleteAccessGas = message.accessWitness!.writeAccountHeader(message.to) gasLimit -= createCompleteAccessGas if (gasLimit < BIGINT_0) { if (this.DEBUG) { @@ -564,11 +573,15 @@ export class EVM implements EVMInterface { `ContractCreateComplete access gas (${createCompleteAccessGas}) caused OOG (-> ${gasLimit})`, ) } + message.accessWitness?.revert() return { execResult: OOGResult(message.gasLimit) } } else { - debug( - `ContractCreateComplete access used (${createCompleteAccessGas}) gas (-> ${gasLimit})`, - ) + if (this.DEBUG) { + debug( + `ContractCreateComplete access used (${createCompleteAccessGas}) gas (-> ${gasLimit})`, + ) + } + message.accessWitness?.commit() } } @@ -646,6 +659,7 @@ export class EVM implements EVMInterface { if (this.DEBUG) { debug(`Contract creation: out of gas`) } + message.accessWitness?.revert() result = { ...result, ...OOGResult(message.gasLimit) } } } else { @@ -655,12 +669,14 @@ export class EVM implements EVMInterface { if (this.DEBUG) { debug(`Not enough gas to pay the code deposit fee (Frontier)`) } + message.accessWitness?.revert() result = { ...result, ...COOGResult(totalGas - returnFee) } CodestoreOOG = true } else { if (this.DEBUG) { debug(`Contract creation: out of gas`) } + message.accessWitness?.revert() result = { ...result, ...OOGResult(message.gasLimit) } } } @@ -669,9 +685,7 @@ export class EVM implements EVMInterface { // get the fresh gas limit for the rest of the ops gasLimit = message.gasLimit - result.executionGasUsed if (!result.exceptionError && this.common.isActivatedEIP(6800)) { - const createCompleteAccessGas = message.accessWitness!.touchAndChargeContractCreateCompleted( - message.to, - ) + const createCompleteAccessGas = message.accessWitness!.writeAccountHeader(message.to) gasLimit -= createCompleteAccessGas if (gasLimit < BIGINT_0) { if (this.DEBUG) { @@ -679,6 +693,7 @@ export class EVM implements EVMInterface { `ContractCreateComplete access gas (${createCompleteAccessGas}) caused OOG (-> ${gasLimit})`, ) } + message.accessWitness?.revert() result = { ...result, ...OOGResult(message.gasLimit) } } else { debug( @@ -696,12 +711,11 @@ export class EVM implements EVMInterface { ) { // Add access charges for writing this code to the state if (this.common.isActivatedEIP(6800)) { - const byteCodeWriteAccessfee = - message.accessWitness!.touchCodeChunksRangeOnWriteAndChargeGas( - message.to, - 0, - result.returnValue.length - 1, - ) + const byteCodeWriteAccessfee = message.accessWitness!.writeAccountCodeChunks( + message.to, + 0, + result.returnValue.length - 1, + ) gasLimit -= byteCodeWriteAccessfee if (gasLimit < BIGINT_0) { if (this.DEBUG) { @@ -709,9 +723,11 @@ export class EVM implements EVMInterface { `byteCodeWrite access gas (${byteCodeWriteAccessfee}) caused OOG (-> ${gasLimit})`, ) } + message.accessWitness?.revert() result = { ...result, ...OOGResult(message.gasLimit) } } else { debug(`byteCodeWrite access used (${byteCodeWriteAccessfee}) gas (-> ${gasLimit})`) + message.accessWitness?.commit() result.executionGasUsed += byteCodeWriteAccessfee } } @@ -813,6 +829,7 @@ export class EVM implements EVMInterface { } } + message.accessWitness?.commit() return { ...result, runState: { @@ -845,11 +862,11 @@ export class EVM implements EVMInterface { let callerAccount if (!message) { this._block = opts.block ?? defaultBlock() + const caller = opts.caller ?? createZeroAddress() this._tx = { gasPrice: opts.gasPrice ?? BIGINT_0, - origin: opts.origin ?? opts.caller ?? createZeroAddress(), + origin: opts.origin ?? caller, } - const caller = opts.caller ?? createZeroAddress() const value = opts.value ?? BIGINT_0 if (opts.skipBalance === true) { @@ -927,7 +944,7 @@ export class EVM implements EVMInterface { result = await this._executeCall(message as MessageWithTo) } else { if (this.DEBUG) { - debug(`Message CREATE execution (to undefined)`) + debug(`Message CREATE execution (to: undefined)`) } result = await this._executeCreate(message) } @@ -976,6 +993,7 @@ export class EVM implements EVMInterface { this.performanceLogger.stopTimer(timer!, 0) } + message.accessWitness?.commit() return result } @@ -1109,11 +1127,10 @@ export class EVM implements EVMInterface { } toAccount.balance = newBalance // putAccount as the nonce may have changed for contract creation - const result = this.journal.putAccount(message.to, toAccount) + await this.journal.putAccount(message.to, toAccount) if (this.DEBUG) { debug(`Added toAccount (${message.to}) balance (-> ${toAccount.balance})`) } - return result } /** diff --git a/packages/evm/src/interpreter.ts b/packages/evm/src/interpreter.ts index 14cb31b64a..2d55ca2b16 100644 --- a/packages/evm/src/interpreter.ts +++ b/packages/evm/src/interpreter.ts @@ -339,6 +339,8 @@ export class Interpreter { this.performanceLogger.unpauseTimer(overheadTimer) } } catch (e: any) { + // Revert access witness changes if we revert - per EIP-4762 + this._runState.env.accessWitness?.revert() if (overheadTimer !== undefined) { this.performanceLogger.unpauseTimer(overheadTimer) } @@ -387,17 +389,6 @@ export class Interpreter { // It needs the base fee, for correct gas limit calculation for the CALL opcodes gas = await opEntry.gasHandler(this._runState, gas, this.common) } - if (this.common.isActivatedEIP(6800) && this._env.chargeCodeAccesses === true) { - const contract = this._runState.interpreter.getAddress() - const statelessGas = - this._runState.env.accessWitness!.touchCodeChunksRangeOnReadAndChargeGas( - contract, - this._runState.programCounter, - this._runState.programCounter, - ) - gas += statelessGas - debugGas(`codechunk accessed statelessGas=${statelessGas} (-> ${gas})`) - } if (this._evm.events.listenerCount('step') > 0 || this._evm.DEBUG) { // Only run this stepHook function if there is an event listener (e.g. test runner) @@ -405,6 +396,17 @@ export class Interpreter { await this._runStepHook(gas, this.getGasLeft()) } + if (this.common.isActivatedEIP(6800) && this._env.chargeCodeAccesses === true) { + const contract = this._runState.interpreter.getAddress() + const statelessGas = this._runState.env.accessWitness!.readAccountCodeChunks( + contract, + this._runState.programCounter, + this._runState.programCounter, + ) + gas += statelessGas + debugGas(`codechunk accessed statelessGas=${statelessGas} (-> ${gas})`) + } + // Check for invalid opcode if (opInfo.isInvalid) { throw new EvmError({ @@ -427,6 +429,7 @@ export class Interpreter { } else { opFn.apply(null, [this._runState, this.common]) } + this._runState.env.accessWitness?.commit() } finally { if (this.profilerOpts?.enabled === true) { this.performanceLogger.stopTimer( diff --git a/packages/evm/src/opcodes/EIP2929.ts b/packages/evm/src/opcodes/EIP2929.ts index a273d96baa..bbfe382032 100644 --- a/packages/evm/src/opcodes/EIP2929.ts +++ b/packages/evm/src/opcodes/EIP2929.ts @@ -31,6 +31,10 @@ export function accessAddressEIP2929( // if verkle not activated if (chargeGas && !common.isActivatedEIP(6800)) { return common.param('coldaccountaccessGas') + } else if (chargeGas && common.isActivatedEIP(6800)) { + // If Verkle is active, then the warmstoragereadGas should still be charged + // This is because otherwise opcodes will have cost 0 (this is thus the base fee) + return common.param('warmstoragereadGas') } // Warm: (selfdestruct beneficiary address reads are not charged when warm) } else if (chargeGas && !isSelfdestruct) { diff --git a/packages/evm/src/opcodes/functions.ts b/packages/evm/src/opcodes/functions.ts index b87147c7b9..52bc925b81 100644 --- a/packages/evm/src/opcodes/functions.ts +++ b/packages/evm/src/opcodes/functions.ts @@ -24,7 +24,7 @@ import { bytesToInt, concatBytes, equalsBytes, - getVerkleTreeIndicesForStorageSlot, + hexToBytes, setLengthLeft, } from '@ethereumjs/util' import { keccak256 } from 'ethereum-cryptography/keccak.js' @@ -61,16 +61,39 @@ export interface AsyncOpHandler { export type OpHandler = SyncOpHandler | AsyncOpHandler +// The PR https://github.com/ethereum/EIPs/pull/8969 has two definitions of the +// designator: the original (0xef0100) and the designator added in the changes (0xef01) +const eip7702Designator = hexToBytes('0xef01') +const eip7702HashBigInt = bytesToBigInt(keccak256(eip7702Designator)) + function getEIP7702DelegatedAddress(code: Uint8Array) { if (equalsBytes(code.slice(0, 3), DELEGATION_7702_FLAG)) { return new Address(code.slice(3, 24)) } } -async function eip7702CodeCheck(runState: RunState, code: Uint8Array) { +/** + * This method performs checks to transform the code which the EVM observes regarding EIP-7702. + * If the code is 7702-delegated code, it will retrieve the code of the designated address + * in case of an executable operation (`isReadOperation` == false), or the 7702 designator + * code in case of a read operation + * @param runState + * @param code + * @param isReadOperation Boolean to determine if the target code is meant to be read or executed (default: `false`) + * @returns + */ +async function eip7702CodeCheck( + runState: RunState, + code: Uint8Array, + isReadOperation: boolean = false, +) { const address = getEIP7702DelegatedAddress(code) if (address !== undefined) { - return runState.stateManager.getCode(address) + if (isReadOperation) { + return eip7702Designator + } else { + return runState.stateManager.getCode(address) + } } return code @@ -538,7 +561,7 @@ export const handlers: Map = new Map([ runState.stack.push(BigInt(EOFBYTES.length)) return } else if (common.isActivatedEIP(7702)) { - code = await eip7702CodeCheck(runState, code) + code = await eip7702CodeCheck(runState, code, true) } const size = BigInt(code.length) @@ -560,7 +583,7 @@ export const handlers: Map = new Map([ // In legacy code, the target code is treated as to be "EOFBYTES" code code = EOFBYTES } else if (common.isActivatedEIP(7702)) { - code = await eip7702CodeCheck(runState, code) + code = await eip7702CodeCheck(runState, code, true) } const data = getDataSlice(code, codeOffset, dataLength) @@ -587,16 +610,8 @@ export const handlers: Map = new Map([ } else if (common.isActivatedEIP(7702)) { const possibleDelegatedAddress = getEIP7702DelegatedAddress(code) if (possibleDelegatedAddress !== undefined) { - const account = await runState.stateManager.getAccount(possibleDelegatedAddress) - if (!account || account.isEmpty()) { - runState.stack.push(BIGINT_0) - return - } - - runState.stack.push(BigInt(bytesToHex(account.codeHash))) - return - } else { - runState.stack.push(bytesToBigInt(keccak256(code))) + // The account is delegated by an EIP-7702 tx. Push the EIP-7702 designator hash to the stack + runState.stack.push(eip7702HashBigInt) return } } @@ -670,12 +685,10 @@ export const handlers: Map = new Map([ const key = setLengthLeft(bigIntToBytes(number % historyServeWindow), 32) if (common.isActivatedEIP(6800)) { - const { treeIndex, subIndex } = getVerkleTreeIndicesForStorageSlot(number) // create witnesses and charge gas - const statelessGas = runState.env.accessWitness!.touchAddressOnReadAndComputeGas( + const statelessGas = runState.env.accessWitness!.readAccountStorage( historyAddress, - treeIndex, - subIndex, + number, ) runState.interpreter.useGas(statelessGas, `BLOCKHASH`) } @@ -982,23 +995,12 @@ export const handlers: Map = new Map([ 0x60, function (runState, common) { const numToPush = runState.opCode - 0x5f - if ( - runState.programCounter + numToPush > runState.code.length && - common.isActivatedEIP(3540) - ) { - trap( - new EvmError({ - code: EvmErrorCode.RUNTIME_ERROR, - reason: RuntimeErrorMessage.OUT_OF_RANGE, - }), - ) - } if (common.isActivatedEIP(6800) && runState.env.chargeCodeAccesses === true) { const contract = runState.interpreter.getAddress() const startOffset = Math.min(runState.code.length, runState.programCounter + 1) const endOffset = Math.min(runState.code.length, startOffset + numToPush - 1) - const statelessGas = runState.env.accessWitness!.touchCodeChunksRangeOnReadAndChargeGas( + const statelessGas = runState.env.accessWitness!.readAccountCodeChunks( contract, startOffset, endOffset, @@ -1058,7 +1060,7 @@ export const handlers: Map = new Map([ // 0xd0: DATALOAD [ 0xd0, - function (runState, _common) { + function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1088,7 +1090,7 @@ export const handlers: Map = new Map([ // 0xd1: DATALOADN [ 0xd1, - function (runState, _common) { + function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1111,7 +1113,7 @@ export const handlers: Map = new Map([ // 0xd2: DATASIZE [ 0xd2, - function (runState, _common) { + function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1127,7 +1129,7 @@ export const handlers: Map = new Map([ // 0xd3: DATACOPY [ 0xd3, - function (runState, _common) { + function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1149,7 +1151,7 @@ export const handlers: Map = new Map([ // 0xe0: RJUMP [ 0xe0, - function (runState, _common) { + function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1168,7 +1170,7 @@ export const handlers: Map = new Map([ // 0xe1: RJUMPI [ 0xe1, - function (runState, _common) { + function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1193,7 +1195,7 @@ export const handlers: Map = new Map([ // 0xe2: RJUMPV [ 0xe2, - function (runState, _common) { + function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1225,7 +1227,7 @@ export const handlers: Map = new Map([ // 0xe3: CALLF [ 0xe3, - function (runState, _common) { + function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1240,7 +1242,7 @@ export const handlers: Map = new Map([ ) const stackItems = runState.stack.length const typeSection = runState.env.eof!.container.body.typeSections[sectionTarget] - if (1024 < stackItems + typeSection?.inputs - typeSection?.maxStackHeight) { + if (stackItems > 1024 - typeSection.maxStackHeight + typeSection.inputs) { trap(new EvmError({ code: EvmErrorCode.RUNTIME_ERROR, reason: EOFError.StackOverflow })) } if (runState.env.eof!.eofRunState.returnStack.length >= 1024) { @@ -1257,7 +1259,7 @@ export const handlers: Map = new Map([ // 0xe4: RETF [ 0xe4, - function (runState, _common) { + function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1278,7 +1280,7 @@ export const handlers: Map = new Map([ // 0xe5: JUMPF [ 0xe5, - function (runState, _common) { + function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1296,7 +1298,7 @@ export const handlers: Map = new Map([ ) const stackItems = runState.stack.length const typeSection = runState.env.eof!.container.body.typeSections[sectionTarget] - if (1024 < stackItems + typeSection?.inputs - typeSection?.maxStackHeight) { + if (stackItems > 1024 - typeSection.maxStackHeight + typeSection.inputs) { trap(new EvmError({ code: EvmErrorCode.RUNTIME_ERROR, reason: EOFError.StackOverflow })) } /*if (runState.env.eof!.eofRunState.returnStack.length >= 1024) { @@ -1311,7 +1313,7 @@ export const handlers: Map = new Map([ // 0xe6: DUPN [ 0xe6, - function (runState, _common) { + function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1334,7 +1336,7 @@ export const handlers: Map = new Map([ // 0xe7: SWAPN [ 0xe7, - function (runState, _common) { + function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1357,7 +1359,7 @@ export const handlers: Map = new Map([ // 0xe8: EXCHANGE [ 0xe8, - function (runState, _common) { + function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1379,7 +1381,7 @@ export const handlers: Map = new Map([ // 0xec: EOFCREATE [ 0xec, - async function (runState, _common) { + async function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1389,6 +1391,14 @@ export const handlers: Map = new Map([ }), ) } else { + if (runState.interpreter.isStatic()) { + trap( + new EvmError({ + code: EvmErrorCode.RUNTIME_ERROR, + reason: RuntimeErrorMessage.STATIC_STATE_CHANGE, + }), + ) + } // Read container index const containerIndex = runState.env.code[runState.programCounter] const containerCode = runState.env.eof!.container.body.containerSections[containerIndex] @@ -1420,7 +1430,7 @@ export const handlers: Map = new Map([ // 0xee: RETURNCONTRACT [ 0xee, - async function (runState, _common) { + async function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1650,10 +1660,39 @@ export const handlers: Map = new Map([ runState.stack.push(ret) }, ], + // 0xf7: RETURNDATALOAD + [ + 0xf7, + function (runState) { + if (runState.env.eof === undefined) { + // Opcode not available in legacy contracts + trap( + new EvmError({ + code: EvmErrorCode.RUNTIME_ERROR, + reason: RuntimeErrorMessage.INVALID_OPCODE, + }), + ) + } + const pos = runState.stack.pop() + if (pos > runState.interpreter.getReturnDataSize()) { + runState.stack.push(BIGINT_0) + return + } + + const i = Number(pos) + let loaded = runState.interpreter.getReturnData().subarray(i, i + 32) + loaded = loaded.length ? loaded : Uint8Array.from([0]) + let r = bytesToBigInt(loaded) + if (loaded.length < 32) { + r = r << (BIGINT_8 * BigInt(32 - loaded.length)) + } + runState.stack.push(r) + }, + ], // 0xf8: EXTCALL [ 0xf8, - async function (runState, _common) { + async function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1692,7 +1731,7 @@ export const handlers: Map = new Map([ // 0xf9: EXTDELEGATECALL [ 0xf9, - async function (runState, _common) { + async function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( @@ -1722,6 +1761,7 @@ export const handlers: Map = new Map([ if (!isEOF(code)) { // EXTDELEGATECALL cannot call legacy contracts runState.stack.push(BIGINT_1) + runState.returnBytes = new Uint8Array(0) return } @@ -1761,7 +1801,7 @@ export const handlers: Map = new Map([ // 0xfb: EXTSTATICCALL [ 0xfb, - async function (runState, _common) { + async function (runState) { if (runState.env.eof === undefined) { // Opcode not available in legacy contracts trap( diff --git a/packages/evm/src/opcodes/gas.ts b/packages/evm/src/opcodes/gas.ts index 3264e6f78d..6d98738c97 100644 --- a/packages/evm/src/opcodes/gas.ts +++ b/packages/evm/src/opcodes/gas.ts @@ -6,11 +6,8 @@ import { BIGINT_31, BIGINT_32, BIGINT_64, - VERKLE_BASIC_DATA_LEAF_KEY, - VERKLE_CODE_HASH_LEAF_KEY, bigIntToBytes, equalsBytes, - getVerkleTreeIndicesForStorageSlot, setLengthLeft, } from '@ethereumjs/util' @@ -111,11 +108,7 @@ export const dynamicGasHandlers: Map { + if (runState.env.eof === undefined) { + // Opcode not available in legacy contracts + trap( + new EvmError({ + code: EvmErrorCode.RUNTIME_ERROR, + reason: RuntimeErrorMessage.STATIC_STATE_CHANGE, + }), + ) + } // Note: TX_CREATE_COST is in the base fee (this is 32000 and same as CREATE / CREATE2) // Note: in `gas.ts` programCounter is not yet incremented (which it is in `functions.ts`) @@ -618,16 +601,11 @@ export const dynamicGasHandlers: Map { + if (runState.env.eof === undefined) { + // Opcode not available in legacy contracts + trap( + new EvmError({ + code: EvmErrorCode.RUNTIME_ERROR, + reason: RuntimeErrorMessage.STATIC_STATE_CHANGE, + }), + ) + } // Charge WARM_STORAGE_READ_COST (100) -> done in accessAddressEIP2929 // Peek stack values @@ -945,6 +931,15 @@ export const dynamicGasHandlers: Map { + if (runState.env.eof === undefined) { + // Opcode not available in legacy contracts + trap( + new EvmError({ + code: EvmErrorCode.RUNTIME_ERROR, + reason: RuntimeErrorMessage.STATIC_STATE_CHANGE, + }), + ) + } // Charge WARM_STORAGE_READ_COST (100) -> done in accessAddressEIP2929 // Peek stack values @@ -1006,10 +1001,12 @@ export const dynamicGasHandlers: Map { + if (runState.env.eof === undefined) { + // Opcode not available in legacy contracts + trap( + new EvmError({ + code: EvmErrorCode.RUNTIME_ERROR, + reason: RuntimeErrorMessage.STATIC_STATE_CHANGE, + }), + ) + } // Charge WARM_STORAGE_READ_COST (100) -> done in accessAddressEIP2929 // Peek stack values @@ -1150,32 +1156,16 @@ export const dynamicGasHandlers: Map BIGINT_0) { - gas += runState.env.accessWitness!.touchAddressOnWriteAndComputeGas( - contractAddress, - 0, - VERKLE_BASIC_DATA_LEAF_KEY, - ) + gas += runState.env.accessWitness!.writeAccountBasicData(contractAddress) } let selfDestructToColdAccessGas = - runState.env.accessWitness!.touchAddressOnReadAndComputeGas( - selfdestructToAddress, - 0, - VERKLE_BASIC_DATA_LEAF_KEY, - ) + runState.env.accessWitness!.readAccountBasicData(selfdestructToAddress) if (balance > BIGINT_0) { selfDestructToColdAccessGas += - runState.env.accessWitness!.touchAddressOnWriteAndComputeGas( - selfdestructToAddress, - 0, - VERKLE_BASIC_DATA_LEAF_KEY, - ) + runState.env.accessWitness!.writeAccountBasicData(selfdestructToAddress) } gas += selfDestructToColdAccessGas diff --git a/packages/evm/src/params.ts b/packages/evm/src/params.ts index 397e746e20..1d405a5114 100644 --- a/packages/evm/src/params.ts +++ b/packages/evm/src/params.ts @@ -234,14 +234,14 @@ export const paramsEVM: ParamsDict = { */ 2537: { // gasPrices - bls12381G1AddGas: 500, // Gas cost of a single BLS12-381 G1 addition precompile-call + bls12381G1AddGas: 375, // Gas cost of a single BLS12-381 G1 addition precompile-call bls12381G1MulGas: 12000, // Gas cost of a single BLS12-381 G1 multiplication precompile-call - bls12381G2AddGas: 800, // Gas cost of a single BLS12-381 G2 addition precompile-call - bls12381G2MulGas: 45000, // Gas cost of a single BLS12-381 G2 multiplication precompile-call - bls12381PairingBaseGas: 65000, // Base gas cost of BLS12-381 pairing check - bls12381PairingPerPairGas: 43000, // Per-pair gas cost of BLS12-381 pairing check + bls12381G2AddGas: 600, // Gas cost of a single BLS12-381 G2 addition precompile-call + bls12381G2MulGas: 22500, // Gas cost of a single BLS12-381 G2 multiplication precompile-call + bls12381PairingBaseGas: 37700, // Base gas cost of BLS12-381 pairing check + bls12381PairingPerPairGas: 32600, // Per-pair gas cost of BLS12-381 pairing check bls12381MapG1Gas: 5500, // Gas cost of BLS12-381 map field element to G1 - bls12381MapG2Gas: 75000, // Gas cost of BLS12-381 map field element to G2 + bls12381MapG2Gas: 23800, // Gas cost of BLS12-381 map field element to G2 }, /** . * Gas cost increases for state access opcodes @@ -274,6 +274,7 @@ export const paramsEVM: ParamsDict = { // evm historyStorageAddress: '0x0aae40965e6800cd9b1f4b05ff21581047e3f91e', // The address where the historical blockhashes are stored historyServeWindow: 8192, // The amount of blocks to be served by the historical blockhash contract + systemAddress: '0xfffffffffffffffffffffffffffffffffffffffe', // The system address }, /** . * BASEFEE opcode diff --git a/packages/evm/src/precompiles/0d-bls12-g1msm.ts b/packages/evm/src/precompiles/0c-bls12-g1msm.ts similarity index 91% rename from packages/evm/src/precompiles/0d-bls12-g1msm.ts rename to packages/evm/src/precompiles/0c-bls12-g1msm.ts index ea841d1038..cba9b30aee 100644 --- a/packages/evm/src/precompiles/0d-bls12-g1msm.ts +++ b/packages/evm/src/precompiles/0c-bls12-g1msm.ts @@ -3,7 +3,11 @@ import { bytesToHex } from '@ethereumjs/util' import { EvmError, EvmErrorCode, RuntimeErrorMessage } from '../errors.js' import { EvmErrorResult, OOGResult } from '../evm.js' -import { leading16ZeroBytesCheck, msmGasUsed } from './bls12_381/index.js' +import { + BLS_GAS_DISCOUNT_PAIRS_G1, + leading16ZeroBytesCheck, + msmGasUsed, +} from './bls12_381/index.js' import { gasLimitCheck, moduloLengthCheck } from './util.js' import { getPrecompileName } from './index.js' @@ -11,7 +15,7 @@ import { getPrecompileName } from './index.js' import type { EVMBLSInterface, ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' -export async function precompile0d(opts: PrecompileInput): Promise { +export async function precompile0c(opts: PrecompileInput): Promise { const pName = getPrecompileName('0d') const bls = (opts._EVM)._bls! as EVMBLSInterface @@ -35,7 +39,7 @@ export async function precompile0d(opts: PrecompileInput): Promise { // validation (same for g2msm) const numPairs = Math.floor(inputData.length / 160) const gasUsedPerPair = opts.common.paramByEIP('bls12381G1MulGas', 2537) ?? BigInt(0) - const gasUsed = msmGasUsed(numPairs, gasUsedPerPair) + const gasUsed = msmGasUsed(numPairs, gasUsedPerPair, BLS_GAS_DISCOUNT_PAIRS_G1) if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) diff --git a/packages/evm/src/precompiles/0c-bls12-g1mul.ts b/packages/evm/src/precompiles/0c-bls12-g1mul.ts deleted file mode 100644 index b1416c8612..0000000000 --- a/packages/evm/src/precompiles/0c-bls12-g1mul.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { bytesToHex } from '@ethereumjs/util' - -import { EvmError, EvmErrorCode, RuntimeErrorMessage } from '../errors.js' -import { EvmErrorResult, OOGResult } from '../evm.js' - -import { leading16ZeroBytesCheck } from './bls12_381/index.js' -import { equalityLengthCheck, gasLimitCheck } from './util.js' - -import { getPrecompileName } from './index.js' - -import type { EVMBLSInterface, ExecResult } from '../types.js' -import type { PrecompileInput } from './types.js' - -export async function precompile0c(opts: PrecompileInput): Promise { - const pName = getPrecompileName('0c') - const bls = (opts._EVM)._bls! as EVMBLSInterface - - // note: the gas used is constant; even if the input is incorrect. - const gasUsed = opts.common.paramByEIP('bls12381G1MulGas', 2537) ?? BigInt(0) - if (!gasLimitCheck(opts, gasUsed, pName)) { - return OOGResult(opts.gasLimit) - } - - if (!equalityLengthCheck(opts, 160, pName)) { - return EvmErrorResult( - new EvmError({ - code: EvmErrorCode.RUNTIME_ERROR, - reason: RuntimeErrorMessage.BLS_12_381_INVALID_INPUT_LENGTH, - }), - opts.gasLimit, - ) - } - - // check if some parts of input are zero bytes. - const zeroByteRanges = [ - [0, 16], - [64, 80], - ] - if (!leading16ZeroBytesCheck(opts, zeroByteRanges, pName)) { - return EvmErrorResult( - new EvmError({ - code: EvmErrorCode.RUNTIME_ERROR, - reason: RuntimeErrorMessage.BLS_12_381_POINT_NOT_ON_CURVE, - }), - opts.gasLimit, - ) - } - - let returnValue - try { - returnValue = bls.mulG1(opts.data) - } catch (e: any) { - if (opts._debug !== undefined) { - opts._debug(`${pName} failed: ${e.message}`) - } - return EvmErrorResult(e, opts.gasLimit) - } - - if (opts._debug !== undefined) { - opts._debug(`${pName} return value=${bytesToHex(returnValue)}`) - } - - return { - executionGasUsed: gasUsed, - returnValue, - } -} diff --git a/packages/evm/src/precompiles/0e-bls12-g2add.ts b/packages/evm/src/precompiles/0d-bls12-g2add.ts similarity index 96% rename from packages/evm/src/precompiles/0e-bls12-g2add.ts rename to packages/evm/src/precompiles/0d-bls12-g2add.ts index 41b4c3f392..1343d84ab8 100644 --- a/packages/evm/src/precompiles/0e-bls12-g2add.ts +++ b/packages/evm/src/precompiles/0d-bls12-g2add.ts @@ -11,7 +11,7 @@ import { getPrecompileName } from './index.js' import type { EVMBLSInterface, ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' -export async function precompile0e(opts: PrecompileInput): Promise { +export async function precompile0d(opts: PrecompileInput): Promise { const pName = getPrecompileName('0e') const bls = (opts._EVM)._bls! as EVMBLSInterface diff --git a/packages/evm/src/precompiles/10-bls12-g2msm.ts b/packages/evm/src/precompiles/0e-bls12-g2msm.ts similarity index 89% rename from packages/evm/src/precompiles/10-bls12-g2msm.ts rename to packages/evm/src/precompiles/0e-bls12-g2msm.ts index a9d120df5d..078d54c528 100644 --- a/packages/evm/src/precompiles/10-bls12-g2msm.ts +++ b/packages/evm/src/precompiles/0e-bls12-g2msm.ts @@ -3,7 +3,11 @@ import { bytesToHex } from '@ethereumjs/util' import { EvmError, EvmErrorCode, RuntimeErrorMessage } from '../errors.js' import { EvmErrorResult, OOGResult } from '../evm.js' -import { leading16ZeroBytesCheck, msmGasUsed } from './bls12_381/index.js' +import { + BLS_GAS_DISCOUNT_PAIRS_G2, + leading16ZeroBytesCheck, + msmGasUsed, +} from './bls12_381/index.js' import { gasLimitCheck, moduloLengthCheck } from './util.js' import { getPrecompileName } from './index.js' @@ -11,7 +15,7 @@ import { getPrecompileName } from './index.js' import type { EVMBLSInterface, ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' -export async function precompile10(opts: PrecompileInput): Promise { +export async function precompile0e(opts: PrecompileInput): Promise { const pName = getPrecompileName('10') const bls = (opts._EVM)._bls! as EVMBLSInterface @@ -30,7 +34,7 @@ export async function precompile10(opts: PrecompileInput): Promise { const numPairs = Math.floor(opts.data.length / 288) const gasUsedPerPair = opts.common.paramByEIP('bls12381G2MulGas', 2537) ?? BigInt(0) - const gasUsed = msmGasUsed(numPairs, gasUsedPerPair) + const gasUsed = msmGasUsed(numPairs, gasUsedPerPair, BLS_GAS_DISCOUNT_PAIRS_G2) if (!gasLimitCheck(opts, gasUsed, pName)) { return OOGResult(opts.gasLimit) diff --git a/packages/evm/src/precompiles/0f-bls12-g2mul.ts b/packages/evm/src/precompiles/0f-bls12-g2mul.ts deleted file mode 100644 index ecb3fd128a..0000000000 --- a/packages/evm/src/precompiles/0f-bls12-g2mul.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { bytesToHex } from '@ethereumjs/util' - -import { EvmError, EvmErrorCode, RuntimeErrorMessage } from '../errors.js' -import { EvmErrorResult, OOGResult } from '../evm.js' - -import { leading16ZeroBytesCheck } from './bls12_381/index.js' -import { equalityLengthCheck, gasLimitCheck } from './util.js' - -import { getPrecompileName } from './index.js' - -import type { EVMBLSInterface, ExecResult } from '../types.js' -import type { PrecompileInput } from './types.js' - -export async function precompile0f(opts: PrecompileInput): Promise { - const pName = getPrecompileName('0f') - const bls = (opts._EVM)._bls! as EVMBLSInterface - - // note: the gas used is constant; even if the input is incorrect. - const gasUsed = opts.common.paramByEIP('bls12381G2MulGas', 2537) ?? BigInt(0) - if (!gasLimitCheck(opts, gasUsed, pName)) { - return OOGResult(opts.gasLimit) - } - - if (!equalityLengthCheck(opts, 288, pName)) { - return EvmErrorResult( - new EvmError({ - code: EvmErrorCode.RUNTIME_ERROR, - reason: RuntimeErrorMessage.BLS_12_381_INVALID_INPUT_LENGTH, - }), - opts.gasLimit, - ) - } - - // check if some parts of input are zero bytes. - const zeroByteRanges = [ - [0, 16], - [64, 80], - [128, 144], - [192, 208], - ] - if (!leading16ZeroBytesCheck(opts, zeroByteRanges, pName)) { - return EvmErrorResult( - new EvmError({ - code: EvmErrorCode.RUNTIME_ERROR, - reason: RuntimeErrorMessage.BLS_12_381_POINT_NOT_ON_CURVE, - }), - opts.gasLimit, - ) - } - - // TODO: verify that point is on G2 - - let returnValue - try { - returnValue = bls.mulG2(opts.data) - } catch (e: any) { - if (opts._debug !== undefined) { - opts._debug(`${pName} failed: ${e.message}`) - } - return EvmErrorResult(e, opts.gasLimit) - } - - if (opts._debug !== undefined) { - opts._debug(`${pName} return value=${bytesToHex(returnValue)}`) - } - - return { - executionGasUsed: gasUsed, - returnValue, - } -} diff --git a/packages/evm/src/precompiles/11-bls12-pairing.ts b/packages/evm/src/precompiles/0f-bls12-pairing.ts similarity index 97% rename from packages/evm/src/precompiles/11-bls12-pairing.ts rename to packages/evm/src/precompiles/0f-bls12-pairing.ts index cffeeb9760..40ded273f6 100644 --- a/packages/evm/src/precompiles/11-bls12-pairing.ts +++ b/packages/evm/src/precompiles/0f-bls12-pairing.ts @@ -11,7 +11,7 @@ import { getPrecompileName } from './index.js' import type { EVMBLSInterface, ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' -export async function precompile11(opts: PrecompileInput): Promise { +export async function precompile0f(opts: PrecompileInput): Promise { const pName = getPrecompileName('11') const bls = (opts._EVM)._bls! as EVMBLSInterface diff --git a/packages/evm/src/precompiles/12-bls12-map-fp-to-g1.ts b/packages/evm/src/precompiles/10-bls12-map-fp-to-g1.ts similarity index 96% rename from packages/evm/src/precompiles/12-bls12-map-fp-to-g1.ts rename to packages/evm/src/precompiles/10-bls12-map-fp-to-g1.ts index 7bc27c48fd..46c8264a4e 100644 --- a/packages/evm/src/precompiles/12-bls12-map-fp-to-g1.ts +++ b/packages/evm/src/precompiles/10-bls12-map-fp-to-g1.ts @@ -11,7 +11,7 @@ import { getPrecompileName } from './index.js' import type { EVMBLSInterface, ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' -export async function precompile12(opts: PrecompileInput): Promise { +export async function precompile10(opts: PrecompileInput): Promise { const pName = getPrecompileName('12') const bls = (opts._EVM)._bls! as EVMBLSInterface diff --git a/packages/evm/src/precompiles/13-bls12-map-fp2-to-g2.ts b/packages/evm/src/precompiles/11-bls12-map-fp2-to-g2.ts similarity index 96% rename from packages/evm/src/precompiles/13-bls12-map-fp2-to-g2.ts rename to packages/evm/src/precompiles/11-bls12-map-fp2-to-g2.ts index aa5ae64f65..f8002ca99a 100644 --- a/packages/evm/src/precompiles/13-bls12-map-fp2-to-g2.ts +++ b/packages/evm/src/precompiles/11-bls12-map-fp2-to-g2.ts @@ -11,7 +11,7 @@ import { getPrecompileName } from './index.js' import type { EVMBLSInterface, ExecResult } from '../types.js' import type { PrecompileInput } from './types.js' -export async function precompile13(opts: PrecompileInput): Promise { +export async function precompile11(opts: PrecompileInput): Promise { const pName = getPrecompileName('13') const bls = (opts._EVM)._bls! as EVMBLSInterface diff --git a/packages/evm/src/precompiles/bls12_381/constants.ts b/packages/evm/src/precompiles/bls12_381/constants.ts index a869e7cb5b..f143bd053f 100644 --- a/packages/evm/src/precompiles/bls12_381/constants.ts +++ b/packages/evm/src/precompiles/bls12_381/constants.ts @@ -14,134 +14,265 @@ export const BLS_G2_INFINITY_POINT_BYTES = new Uint8Array(BLS_G2_POINT_BYTE_LENG export const BLS_ZERO_BUFFER = new Uint8Array(32) export const BLS_ONE_BUFFER = concatBytes(new Uint8Array(31), hexToBytes('0x01')) -// gas discount pairs taken from EIP-2537 `bls12381MultiExpGasDiscount` parameter -export const BLS_GAS_DISCOUNT_PAIRS = [ - [1, 1200], - [2, 888], - [3, 764], - [4, 641], - [5, 594], - [6, 547], - [7, 500], - [8, 453], - [9, 438], - [10, 423], - [11, 408], - [12, 394], - [13, 379], - [14, 364], - [15, 349], - [16, 334], - [17, 330], - [18, 326], - [19, 322], - [20, 318], - [21, 314], - [22, 310], - [23, 306], - [24, 302], - [25, 298], - [26, 294], - [27, 289], - [28, 285], - [29, 281], - [30, 277], - [31, 273], - [32, 269], - [33, 268], - [34, 266], - [35, 265], - [36, 263], - [37, 262], - [38, 260], - [39, 259], - [40, 257], - [41, 256], - [42, 254], - [43, 253], - [44, 251], - [45, 250], - [46, 248], - [47, 247], - [48, 245], - [49, 244], - [50, 242], - [51, 241], - [52, 239], - [53, 238], - [54, 236], - [55, 235], - [56, 233], - [57, 232], - [58, 231], - [59, 229], - [60, 228], - [61, 226], - [62, 225], - [63, 223], - [64, 222], - [65, 221], - [66, 220], - [67, 219], - [68, 219], - [69, 218], - [70, 217], - [71, 216], - [72, 216], - [73, 215], - [74, 214], - [75, 213], - [76, 213], - [77, 212], - [78, 211], - [79, 211], - [80, 210], - [81, 209], - [82, 208], - [83, 208], - [84, 207], - [85, 206], - [86, 205], - [87, 205], - [88, 204], - [89, 203], - [90, 202], - [91, 202], - [92, 201], - [93, 200], - [94, 199], - [95, 199], - [96, 198], - [97, 197], - [98, 196], - [99, 196], - [100, 195], - [101, 194], - [102, 193], - [103, 193], - [104, 192], - [105, 191], - [106, 191], - [107, 190], - [108, 189], - [109, 188], - [110, 188], - [111, 187], - [112, 186], - [113, 185], - [114, 185], - [115, 184], - [116, 183], - [117, 182], - [118, 182], - [119, 181], - [120, 180], - [121, 179], - [122, 179], - [123, 178], - [124, 177], - [125, 176], - [126, 176], - [127, 175], - [128, 174], +// G1/G2 MSM discount constants taken from EIP-2537 +export const BLS_GAS_DISCOUNT_PAIRS_G1: [number, number][] = [ + [1, 1000], + [2, 949], + [3, 848], + [4, 797], + [5, 764], + [6, 750], + [7, 738], + [8, 728], + [9, 719], + [10, 712], + [11, 705], + [12, 698], + [13, 692], + [14, 687], + [15, 682], + [16, 677], + [17, 673], + [18, 669], + [19, 665], + [20, 661], + [21, 658], + [22, 654], + [23, 651], + [24, 648], + [25, 645], + [26, 642], + [27, 640], + [28, 637], + [29, 635], + [30, 632], + [31, 630], + [32, 627], + [33, 625], + [34, 623], + [35, 621], + [36, 619], + [37, 617], + [38, 615], + [39, 613], + [40, 611], + [41, 609], + [42, 608], + [43, 606], + [44, 604], + [45, 603], + [46, 601], + [47, 599], + [48, 598], + [49, 596], + [50, 595], + [51, 593], + [52, 592], + [53, 591], + [54, 589], + [55, 588], + [56, 586], + [57, 585], + [58, 584], + [59, 582], + [60, 581], + [61, 580], + [62, 579], + [63, 577], + [64, 576], + [65, 575], + [66, 574], + [67, 573], + [68, 572], + [69, 570], + [70, 569], + [71, 568], + [72, 567], + [73, 566], + [74, 565], + [75, 564], + [76, 563], + [77, 562], + [78, 561], + [79, 560], + [80, 559], + [81, 558], + [82, 557], + [83, 556], + [84, 555], + [85, 554], + [86, 553], + [87, 552], + [88, 551], + [89, 550], + [90, 549], + [91, 548], + [92, 547], + [93, 547], + [94, 546], + [95, 545], + [96, 544], + [97, 543], + [98, 542], + [99, 541], + [100, 540], + [101, 540], + [102, 539], + [103, 538], + [104, 537], + [105, 536], + [106, 536], + [107, 535], + [108, 534], + [109, 533], + [110, 532], + [111, 532], + [112, 531], + [113, 530], + [114, 529], + [115, 528], + [116, 528], + [117, 527], + [118, 526], + [119, 525], + [120, 525], + [121, 524], + [122, 523], + [123, 522], + [124, 522], + [125, 521], + [126, 520], + [127, 520], + [128, 519], +] + +export const BLS_GAS_DISCOUNT_PAIRS_G2: [number, number][] = [ + [1, 1000], + [2, 1000], + [3, 923], + [4, 884], + [5, 855], + [6, 832], + [7, 812], + [8, 796], + [9, 782], + [10, 770], + [11, 759], + [12, 749], + [13, 740], + [14, 732], + [15, 724], + [16, 717], + [17, 711], + [18, 704], + [19, 699], + [20, 693], + [21, 688], + [22, 683], + [23, 679], + [24, 674], + [25, 670], + [26, 666], + [27, 663], + [28, 659], + [29, 655], + [30, 652], + [31, 649], + [32, 646], + [33, 643], + [34, 640], + [35, 637], + [36, 634], + [37, 632], + [38, 629], + [39, 627], + [40, 624], + [41, 622], + [42, 620], + [43, 618], + [44, 615], + [45, 613], + [46, 611], + [47, 609], + [48, 607], + [49, 606], + [50, 604], + [51, 602], + [52, 600], + [53, 598], + [54, 597], + [55, 595], + [56, 593], + [57, 592], + [58, 590], + [59, 589], + [60, 587], + [61, 586], + [62, 584], + [63, 583], + [64, 582], + [65, 580], + [66, 579], + [67, 578], + [68, 576], + [69, 575], + [70, 574], + [71, 573], + [72, 571], + [73, 570], + [74, 569], + [75, 568], + [76, 567], + [77, 566], + [78, 565], + [79, 563], + [80, 562], + [81, 561], + [82, 560], + [83, 559], + [84, 558], + [85, 557], + [86, 556], + [87, 555], + [88, 554], + [89, 553], + [90, 552], + [91, 552], + [92, 551], + [93, 550], + [94, 549], + [95, 548], + [96, 547], + [97, 546], + [98, 545], + [99, 545], + [100, 544], + [101, 543], + [102, 542], + [103, 541], + [104, 541], + [105, 540], + [106, 539], + [107, 538], + [108, 537], + [109, 537], + [110, 536], + [111, 535], + [112, 535], + [113, 534], + [114, 533], + [115, 532], + [116, 532], + [117, 531], + [118, 530], + [119, 530], + [120, 529], + [121, 528], + [122, 528], + [123, 527], + [124, 526], + [125, 526], + [126, 525], + [127, 524], + [128, 524], ] diff --git a/packages/evm/src/precompiles/bls12_381/util.ts b/packages/evm/src/precompiles/bls12_381/util.ts index d6dbb2f8ef..e4d449033d 100644 --- a/packages/evm/src/precompiles/bls12_381/util.ts +++ b/packages/evm/src/precompiles/bls12_381/util.ts @@ -1,7 +1,5 @@ import { equalsBytes } from '@ethereumjs/util' -import { BLS_GAS_DISCOUNT_PAIRS } from './constants.js' - import type { PrecompileInput } from '../types.js' const ZERO_BYTES_16 = new Uint8Array(16) @@ -14,15 +12,19 @@ const ZERO_BYTES_16 = new Uint8Array(16) * @param gasUsedPerPair * @returns */ -export const msmGasUsed = (numPairs: number, gasUsedPerPair: bigint) => { - const gasDiscountMax = BLS_GAS_DISCOUNT_PAIRS[BLS_GAS_DISCOUNT_PAIRS.length - 1][1] +export const msmGasUsed = ( + numPairs: number, + gasUsedPerPair: bigint, + discountTable: [number, number][], +) => { + const gasDiscountMax = discountTable[discountTable.length - 1][1] let gasDiscountMultiplier - if (numPairs <= BLS_GAS_DISCOUNT_PAIRS.length) { + if (numPairs <= discountTable.length) { if (numPairs === 0) { gasDiscountMultiplier = 0 // this implicitly sets gasUsed to 0 as per the EIP. } else { - gasDiscountMultiplier = BLS_GAS_DISCOUNT_PAIRS[numPairs - 1][1] + gasDiscountMultiplier = discountTable[numPairs - 1][1] } } else { gasDiscountMultiplier = gasDiscountMax diff --git a/packages/evm/src/precompiles/index.ts b/packages/evm/src/precompiles/index.ts index 03fef4f1c9..55c25c95b1 100644 --- a/packages/evm/src/precompiles/index.ts +++ b/packages/evm/src/precompiles/index.ts @@ -12,14 +12,12 @@ import { precompile08 } from './08-bn254-pairing.js' import { precompile09 } from './09-blake2f.js' import { precompile0a } from './0a-kzg-point-evaluation.js' import { precompile0b } from './0b-bls12-g1add.js' -import { precompile0c } from './0c-bls12-g1mul.js' -import { precompile0d } from './0d-bls12-g1msm.js' -import { precompile0e } from './0e-bls12-g2add.js' -import { precompile0f } from './0f-bls12-g2mul.js' -import { precompile10 } from './10-bls12-g2msm.js' -import { precompile11 } from './11-bls12-pairing.js' -import { precompile12 } from './12-bls12-map-fp-to-g1.js' -import { precompile13 } from './13-bls12-map-fp2-to-g2.js' +import { precompile0c } from './0c-bls12-g1msm.js' +import { precompile0d } from './0d-bls12-g2add.js' +import { precompile0e } from './0e-bls12-g2msm.js' +import { precompile0f } from './0f-bls12-pairing.js' +import { precompile10 } from './10-bls12-map-fp-to-g1.js' +import { precompile11 } from './11-bls12-map-fp2-to-g2.js' import { MCLBLS, NobleBLS } from './bls12_381/index.js' import { NobleBN254, RustBN254 } from './bn254/index.js' @@ -165,7 +163,7 @@ const precompileEntries: PrecompileEntry[] = [ param: 2537, }, precompile: precompile0c, - name: 'BLS12_G1MUL (0x0c)', + name: 'BLS12_G1MSM (0x0c)', }, { address: BYTES_19 + '0d', @@ -174,7 +172,7 @@ const precompileEntries: PrecompileEntry[] = [ param: 2537, }, precompile: precompile0d, - name: 'BLS12_G1MSM (0x0d)', + name: 'BLS12_G2ADD (0x0d)', }, { address: BYTES_19 + '0e', @@ -183,7 +181,7 @@ const precompileEntries: PrecompileEntry[] = [ param: 2537, }, precompile: precompile0e, - name: 'BLS12_G2ADD (0x0e)', + name: 'BLS12_G2MSM (0x0e)', }, { address: BYTES_19 + '0f', @@ -192,7 +190,7 @@ const precompileEntries: PrecompileEntry[] = [ param: 2537, }, precompile: precompile0f, - name: 'BLS12_G2MUL (0x0f)', + name: 'BLS12_PAIRING (0x0f)', }, { address: BYTES_19 + '10', @@ -201,7 +199,7 @@ const precompileEntries: PrecompileEntry[] = [ param: 2537, }, precompile: precompile10, - name: 'BLS12_G2MSM (0x10)', + name: 'BLS12_MAP_FP_TO_G1 (0x10)', }, { address: BYTES_19 + '11', @@ -210,25 +208,7 @@ const precompileEntries: PrecompileEntry[] = [ param: 2537, }, precompile: precompile11, - name: 'BLS12_PAIRING (0x11)', - }, - { - address: BYTES_19 + '12', - check: { - type: PrecompileAvailabilityCheck.EIP, - param: 2537, - }, - precompile: precompile12, - name: 'BLS12_MAP_FP_TO_G1 (0x12)', - }, - { - address: BYTES_19 + '13', - check: { - type: PrecompileAvailabilityCheck.EIP, - param: 2537, - }, - precompile: precompile13, - name: 'BLS12_MAP_FP2_TO_G2 (0x13)', + name: 'BLS12_MAP_FP_TO_G2 (0x11)', }, ] @@ -250,8 +230,6 @@ const precompiles: Precompiles = { [BYTES_19 + '0f']: precompile0f, [BYTES_19 + '10']: precompile10, [BYTES_19 + '11']: precompile11, - [BYTES_19 + '12']: precompile12, - [BYTES_19 + '13']: precompile13, } type DeletePrecompile = { diff --git a/packages/evm/src/stemCache.ts b/packages/evm/src/stemCache.ts new file mode 100644 index 0000000000..67710025bb --- /dev/null +++ b/packages/evm/src/stemCache.ts @@ -0,0 +1,44 @@ +import type { StemAccessEvent, StemMeta } from './verkleAccessWitness.js' +import type { PrefixedHexString } from '@ethereumjs/util' +export class StemCache { + cache: Map + + constructor() { + this.cache = new Map() + } + + set(stemKey: PrefixedHexString, accessedStem: StemAccessEvent & StemMeta) { + this.cache.set(stemKey, accessedStem) + } + + get(stemHex: PrefixedHexString): (StemAccessEvent & StemMeta) | undefined { + return this.cache.get(stemHex) + } + + del(stemHex: PrefixedHexString): void { + this.cache.delete(stemHex) + } + + commit(): [PrefixedHexString, StemAccessEvent & StemMeta][] { + const items: [PrefixedHexString, StemAccessEvent & StemMeta][] = Array.from( + this.cache.entries(), + ) + this.clear() + return items + } + + /** + * Clear cache + */ + clear(): void { + this.cache.clear() + } + + /** + * Returns the size of the cache + * @returns + */ + size() { + return this.cache.size + } +} diff --git a/packages/evm/src/types.ts b/packages/evm/src/types.ts index 32c73a0d8f..b85ea4329e 100644 --- a/packages/evm/src/types.ts +++ b/packages/evm/src/types.ts @@ -167,6 +167,7 @@ export interface EVMInterface { runCode(opts: EVMRunCodeOpts): Promise events?: EventEmitter verkleAccessWitness?: VerkleAccessWitnessInterface + systemVerkleAccessWitness?: VerkleAccessWitnessInterface } export type EVMProfilerOpts = { diff --git a/packages/evm/src/verkleAccessWitness.ts b/packages/evm/src/verkleAccessWitness.ts index 65a9f77ad7..33cb7184ac 100644 --- a/packages/evm/src/verkleAccessWitness.ts +++ b/packages/evm/src/verkleAccessWitness.ts @@ -11,10 +11,14 @@ import { getVerkleKey, getVerkleStem, getVerkleTreeIndicesForCodeChunk, + getVerkleTreeIndicesForStorageSlot, intToBytes, } from '@ethereumjs/util' import debugDefault from 'debug' +import { ChunkCache } from './chunkCache.js' +import { StemCache } from './stemCache.js' + import type { AccessEventFlags, RawVerkleAccessedState, @@ -36,13 +40,13 @@ const WitnessChunkWriteCost = BigInt(500) const WitnessChunkFillCost = BigInt(6200) // read is a default access event if stem or chunk is present -type StemAccessEvent = { write?: boolean } +export type StemAccessEvent = { write?: boolean } // chunk fill access event is not being charged right now in kaustinen but will be rectified // in upcoming iterations -type ChunkAccessEvent = StemAccessEvent & { fill?: boolean } +export type ChunkAccessEvent = StemAccessEvent & { fill?: boolean } // Since stem is pedersen hashed, it is useful to maintain the reverse relationship -type StemMeta = { address: Address; treeIndex: number | bigint } +export type StemMeta = { address: Address; treeIndex: number | bigint } export function decodeAccessedState( treeIndex: number | bigint, @@ -82,6 +86,8 @@ export function decodeAccessedState( export class VerkleAccessWitness implements VerkleAccessWitnessInterface { stems: Map chunks: Map + stemCache: StemCache = new StemCache() + chunkCache: ChunkCache = new ChunkCache() verkleCrypto: VerkleCrypto constructor(opts: { verkleCrypto: VerkleCrypto @@ -96,99 +102,74 @@ export class VerkleAccessWitness implements VerkleAccessWitnessInterface { this.chunks = opts.chunks ?? new Map() } - touchAndChargeProofOfAbsence(address: Address): bigint { - let gas = BIGINT_0 - - gas += this.touchAddressOnReadAndComputeGas(address, 0, VERKLE_BASIC_DATA_LEAF_KEY) - gas += this.touchAddressOnReadAndComputeGas(address, 0, VERKLE_CODE_HASH_LEAF_KEY) - - return gas + readAccountBasicData(address: Address): bigint { + return this.touchAddressOnReadAndComputeGas(address, 0, VERKLE_BASIC_DATA_LEAF_KEY) } - touchAndChargeMessageCall(address: Address): bigint { - let gas = BIGINT_0 - - gas += this.touchAddressOnReadAndComputeGas(address, 0, VERKLE_BASIC_DATA_LEAF_KEY) - - return gas - } - - touchAndChargeValueTransfer(target: Address): bigint { - let gas = BIGINT_0 - - gas += this.touchAddressOnWriteAndComputeGas(target, 0, VERKLE_BASIC_DATA_LEAF_KEY) - - return gas + writeAccountBasicData(address: Address): bigint { + return this.touchAddressOnWriteAndComputeGas(address, 0, VERKLE_BASIC_DATA_LEAF_KEY) } - touchAndChargeContractCreateInit(address: Address): bigint { - let gas = BIGINT_0 - - gas += this.touchAddressOnWriteAndComputeGas(address, 0, VERKLE_BASIC_DATA_LEAF_KEY) - - return gas + readAccountCodeHash(address: Address): bigint { + return this.touchAddressOnReadAndComputeGas(address, 0, VERKLE_CODE_HASH_LEAF_KEY) } - touchAndChargeContractCreateCompleted(address: Address): bigint { - let gas = BIGINT_0 - - gas += this.touchAddressOnWriteAndComputeGas(address, 0, VERKLE_BASIC_DATA_LEAF_KEY) - gas += this.touchAddressOnWriteAndComputeGas(address, 0, VERKLE_CODE_HASH_LEAF_KEY) - - return gas + writeAccountCodeHash(address: Address): bigint { + return this.touchAddressOnWriteAndComputeGas(address, 0, VERKLE_CODE_HASH_LEAF_KEY) } - touchTxOriginAndComputeGas(origin: Address): bigint { + readAccountHeader(address: Address): bigint { let gas = BIGINT_0 - gas += this.touchAddressOnReadAndComputeGas(origin, 0, VERKLE_BASIC_DATA_LEAF_KEY) - gas += this.touchAddressOnReadAndComputeGas(origin, 0, VERKLE_CODE_HASH_LEAF_KEY) + gas += this.readAccountBasicData(address) + gas += this.readAccountCodeHash(address) return gas } - touchTxTargetAndComputeGas(target: Address, { sendsValue }: { sendsValue?: boolean } = {}) { + writeAccountHeader(address: Address): bigint { let gas = BIGINT_0 - gas += this.touchAddressOnReadAndComputeGas(target, 0, VERKLE_CODE_HASH_LEAF_KEY) - - if (sendsValue === true) { - gas += this.touchAddressOnWriteAndComputeGas(target, 0, VERKLE_BASIC_DATA_LEAF_KEY) - } else { - gas += this.touchAddressOnReadAndComputeGas(target, 0, VERKLE_BASIC_DATA_LEAF_KEY) - } + gas += this.writeAccountBasicData(address) + gas += this.writeAccountCodeHash(address) return gas } - touchCodeChunksRangeOnReadAndChargeGas(contact: Address, startPc: number, endPc: number): bigint { + readAccountCodeChunks(contract: Address, startPc: number, endPc: number): bigint { let gas = BIGINT_0 for (let chunkNum = Math.floor(startPc / 31); chunkNum <= Math.floor(endPc / 31); chunkNum++) { const { treeIndex, subIndex } = getVerkleTreeIndicesForCodeChunk(chunkNum) - gas += this.touchAddressOnReadAndComputeGas(contact, treeIndex, subIndex) + gas += this.touchAddressOnReadAndComputeGas(contract, treeIndex, subIndex) } return gas } - touchCodeChunksRangeOnWriteAndChargeGas( - contact: Address, - startPc: number, - endPc: number, - ): bigint { + writeAccountCodeChunks(contract: Address, startPc: number, endPc: number): bigint { let gas = BIGINT_0 for (let chunkNum = Math.floor(startPc / 31); chunkNum <= Math.floor(endPc / 31); chunkNum++) { const { treeIndex, subIndex } = getVerkleTreeIndicesForCodeChunk(chunkNum) - gas += this.touchAddressOnWriteAndComputeGas(contact, treeIndex, subIndex) + gas += this.touchAddressOnWriteAndComputeGas(contract, treeIndex, subIndex) } return gas } + readAccountStorage(address: Address, storageSlot: bigint): bigint { + const { treeIndex, subIndex } = getVerkleTreeIndicesForStorageSlot(storageSlot) + return this.touchAddressOnReadAndComputeGas(address, treeIndex, subIndex) + } + + writeAccountStorage(address: Address, storageSlot: bigint): bigint { + const { treeIndex, subIndex } = getVerkleTreeIndicesForStorageSlot(storageSlot) + return this.touchAddressOnWriteAndComputeGas(address, treeIndex, subIndex) + } + touchAddressOnWriteAndComputeGas( address: Address, treeIndex: number | bigint, subIndex: number | Uint8Array, ): bigint { - return this.touchAddressAndChargeGas(address, treeIndex, subIndex, { + return this.touchAddressAndComputeGas(address, treeIndex, subIndex, { isWrite: true, }) } @@ -198,12 +179,12 @@ export class VerkleAccessWitness implements VerkleAccessWitnessInterface { treeIndex: number | bigint, subIndex: number | Uint8Array, ): bigint { - return this.touchAddressAndChargeGas(address, treeIndex, subIndex, { + return this.touchAddressAndComputeGas(address, treeIndex, subIndex, { isWrite: false, }) } - touchAddressAndChargeGas( + touchAddressAndComputeGas( address: Address, treeIndex: number | bigint, subIndex: number | Uint8Array, @@ -236,7 +217,7 @@ export class VerkleAccessWitness implements VerkleAccessWitnessInterface { } debug( - `touchAddressAndChargeGas=${gas} address=${address} treeIndex=${treeIndex} subIndex=${subIndex}`, + `touchAddressAndComputeGas=${gas} address=${address} treeIndex=${treeIndex} subIndex=${subIndex}`, ) return gas @@ -258,11 +239,11 @@ export class VerkleAccessWitness implements VerkleAccessWitnessInterface { const accessedStemKey = getVerkleStem(this.verkleCrypto, address, treeIndex) const accessedStemHex = bytesToHex(accessedStemKey) - let accessedStem = this.stems.get(accessedStemHex) + let accessedStem = this.stemCache.get(accessedStemHex) ?? this.stems.get(accessedStemHex) if (accessedStem === undefined) { stemRead = true accessedStem = { address, treeIndex } - this.stems.set(accessedStemHex, accessedStem) + this.stemCache.set(accessedStemHex, accessedStem) } const accessedChunkKey = getVerkleKey( @@ -270,11 +251,12 @@ export class VerkleAccessWitness implements VerkleAccessWitnessInterface { typeof subIndex === 'number' ? intToBytes(subIndex) : subIndex, ) const accessedChunkKeyHex = bytesToHex(accessedChunkKey) - let accessedChunk = this.chunks.get(accessedChunkKeyHex) + let accessedChunk = + this.chunkCache.get(accessedChunkKeyHex) ?? this.chunks.get(accessedChunkKeyHex) if (accessedChunk === undefined) { chunkRead = true accessedChunk = {} - this.chunks.set(accessedChunkKeyHex, accessedChunk) + this.chunkCache.set(accessedChunkKeyHex, accessedChunk) } if (isWrite === true) { @@ -322,6 +304,56 @@ export class VerkleAccessWitness implements VerkleAccessWitnessInterface { } } + commit(): void { + const cachedStems = this.stemCache.commit() + for (const [stemKey, stemValue] of cachedStems) { + this.stems.set(stemKey, stemValue) + } + + const cachedChunks = this.chunkCache.commit() + for (const [chunkKey, chunkValue] of cachedChunks) { + this.chunks.set(chunkKey, chunkValue) + } + } + + revert(): void { + this.stemCache.clear() + this.chunkCache.clear() + } + + debugWitnessCost(): void { + // Calculate the aggregate gas cost for verkle access witness per type + let stemReads = 0, + stemWrites = 0, + chunkReads = 0, + chunkWrites = 0 + + for (const [_, { write }] of this.stems.entries()) { + stemReads++ + if (write === true) { + stemWrites++ + } + } + for (const [_, { write }] of this.chunks.entries()) { + chunkReads++ + if (write === true) { + chunkWrites++ + } + } + debug( + `${stemReads} stem reads, totalling ${BigInt(stemReads) * WitnessBranchReadCost} gas units`, + ) + debug( + `${stemWrites} stem writes, totalling ${BigInt(stemWrites) * WitnessBranchWriteCost} gas units`, + ) + debug( + `${chunkReads} chunk reads, totalling ${BigInt(chunkReads) * WitnessChunkReadCost} gas units`, + ) + debug( + `${chunkWrites} chunk writes, totalling ${BigInt(chunkWrites) * WitnessChunkWriteCost} gas units`, + ) + } + *rawAccesses(): Generator { for (const chunkKey of this.chunks.keys()) { // drop the last byte diff --git a/packages/evm/test/eips/eof-header-validation.ts b/packages/evm/test/eips/eof-header-validation.ts index 5b51da3ead..3dcd19ca27 100644 --- a/packages/evm/test/eips/eof-header-validation.ts +++ b/packages/evm/test/eips/eof-header-validation.ts @@ -52,8 +52,8 @@ await new Promise((resolve, reject) => { const code = hexToBytes(test.code) - const expected = test.results.Prague.result - const _exception = test.results.Prague.exception + const expected = test.results.Osaka.result + const _exception = test.results.Osaka.exception let containerSectionType = ContainerSectionType.RuntimeCode let eofContainerMode = EOFContainerMode.Default diff --git a/packages/evm/test/precompiles/bls/add_G1_bls.json b/packages/evm/test/precompiles/bls/add_G1_bls.json index b09475db24..b947ccd2de 100644 --- a/packages/evm/test/precompiles/bls/add_G1_bls.json +++ b/packages/evm/test/precompiles/bls/add_G1_bls.json @@ -3,63 +3,63 @@ "Input": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e100000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a21", "Name": "bls_g1add_g1+p1", "Expected": "000000000000000000000000000000000a40300ce2dec9888b60690e9a41d3004fda4886854573974fab73b046d3147ba5b7a5bde85279ffede1b45b3918d82d0000000000000000000000000000000006d3d887e9f53b9ec4eb6cedf5607226754b07c01ace7834f57f3e7315faefb739e59018e22c492006190fba4a870025", - "Gas": 500, + "Gas": 375, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a210000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1", "Name": "bls_g1add_p1+g1", "Expected": "000000000000000000000000000000000a40300ce2dec9888b60690e9a41d3004fda4886854573974fab73b046d3147ba5b7a5bde85279ffede1b45b3918d82d0000000000000000000000000000000006d3d887e9f53b9ec4eb6cedf5607226754b07c01ace7834f57f3e7315faefb739e59018e22c492006190fba4a870025", - "Gas": 500, + "Gas": 375, "NoBenchmark": false }, { "Input": "000000000000000000000000000000000123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef00000000000000000000000000000000193fb7cedb32b2c3adc06ec11a96bc0d661869316f5e4a577a9f7c179593987beb4fb2ee424dbb2f5dd891e228b46c4a0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1", "Name": "bls_g1add_g1_wrong_order+g1", "Expected": "000000000000000000000000000000000abe7ae4ae2b092a5cc1779b1f5605d904fa6ec59b0f084907d1f5e4d2663e117a3810e027210a72186159a21271df3e0000000000000000000000000000000001e1669f00e10205f2e2f1195d65c21022f6a9a6de21f329756309815281a4434b2864d34ebcbc1d7e7cfaaee3feeea2", - "Gas": 500, + "Gas": 375, "NoBenchmark": false }, { "Input": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "Name": "bls_g1add_(g1+0=g1)", "Expected": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1", - "Gas": 500, + "Gas": 375, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a210000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "Name": "bls_g1add_(p1+0=p1)", "Expected": "00000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a21", - "Gas": 500, + "Gas": 375, "NoBenchmark": false }, { "Input": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb00000000000000000000000000000000114d1d6855d545a8aa7d76c8cf2e21f267816aef1db507c96655b9d5caac42364e6f38ba0ecb751bad54dcd6b939c2ca", "Name": "bls_g1add_(g1-g1=0)", "Expected": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "Gas": 500, + "Gas": 375, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a2100000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca9426000000000000000000000000000000000195e911162921ba5ed055b496420f197693d36569ec34c63d7c0529a097d49e543070afba4b707e878e53c2b779208a", "Name": "bls_g1add_(p1-p1=0)", "Expected": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "Gas": 500, + "Gas": 375, "NoBenchmark": false }, { "Input": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1", "Name": "bls_g1add_(g1+g1=2*g1)", "Expected": "000000000000000000000000000000000572cbea904d67468808c8eb50a9450c9721db309128012543902d0ac358a62ae28f75bb8f1c7c42c39a8c5529bf0f4e00000000000000000000000000000000166a9d8cabc673a322fda673779d8e3822ba3ecb8670e461f73bb9021d5fd76a4c56d9d4cd16bd1bba86881979749d28", - "Gas": 500, + "Gas": 375, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a2100000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a21", "Name": "bls_g1add_(p1+p1=2*p1)", "Expected": "0000000000000000000000000000000015222cddbabdd764c4bee0b3720322a65ff4712c86fc4b1588d0c209210a0884fa9468e855d261c483091b2bf7de6a630000000000000000000000000000000009f9edb99bc3b75d7489735c98b16ab78b9386c5f7a1f76c7e96ac6eb5bbde30dbca31a74ec6e0f0b12229eecea33c39", - "Gas": 500, + "Gas": 375, "NoBenchmark": false } ] diff --git a/packages/evm/test/precompiles/bls/add_G2_bls.json b/packages/evm/test/precompiles/bls/add_G2_bls.json index edce01f5e7..0fcc5dc7b2 100644 --- a/packages/evm/test/precompiles/bls/add_G2_bls.json +++ b/packages/evm/test/precompiles/bls/add_G2_bls.json @@ -3,63 +3,63 @@ "Input": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d878451", "Name": "bls_g2add_g2+p2", "Expected": "000000000000000000000000000000000b54a8a7b08bd6827ed9a797de216b8c9057b3a9ca93e2f88e7f04f19accc42da90d883632b9ca4dc38d013f71ede4db00000000000000000000000000000000077eba4eecf0bd764dce8ed5f45040dd8f3b3427cb35230509482c14651713282946306247866dfe39a8e33016fcbe520000000000000000000000000000000014e60a76a29ef85cbd69f251b9f29147b67cfe3ed2823d3f9776b3a0efd2731941d47436dc6d2b58d9e65f8438bad073000000000000000000000000000000001586c3c910d95754fef7a732df78e279c3d37431c6a2b77e67a00c7c130a8fcd4d19f159cbeb997a178108fffffcbd20", - "Gas": 800, + "Gas": 600, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d87845100000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be", "Name": "bls_g2add_p2+g2", "Expected": "000000000000000000000000000000000b54a8a7b08bd6827ed9a797de216b8c9057b3a9ca93e2f88e7f04f19accc42da90d883632b9ca4dc38d013f71ede4db00000000000000000000000000000000077eba4eecf0bd764dce8ed5f45040dd8f3b3427cb35230509482c14651713282946306247866dfe39a8e33016fcbe520000000000000000000000000000000014e60a76a29ef85cbd69f251b9f29147b67cfe3ed2823d3f9776b3a0efd2731941d47436dc6d2b58d9e65f8438bad073000000000000000000000000000000001586c3c910d95754fef7a732df78e279c3d37431c6a2b77e67a00c7c130a8fcd4d19f159cbeb997a178108fffffcbd20", - "Gas": 800, + "Gas": 600, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000197bfd0342bbc8bee2beced2f173e1a87be576379b343e93232d6cef98d84b1d696e5612ff283ce2cfdccb2cfb65fa0c00000000000000000000000000000000184e811f55e6f9d84d77d2f79102fd7ea7422f4759df5bf7f6331d550245e3f1bcf6a30e3b29110d85e0ca16f9f6ae7a000000000000000000000000000000000f10e1eb3c1e53d2ad9cf2d398b2dc22c5842fab0a74b174f691a7e914975da3564d835cd7d2982815b8ac57f507348f000000000000000000000000000000000767d1c453890f1b9110fda82f5815c27281aba3f026ee868e4176a0654feea41a96575e0c4d58a14dbfbcc05b5010b100000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be", "Name": "bls_g2add_g2_wrong_order+g2", "Expected": "0000000000000000000000000000000011f00077935238fc57086414804303b20fab5880bc29f35ebda22c13dd44e586c8a889fe2ba799082c8458d861ac10cf0000000000000000000000000000000007318be09b19be000fe5df77f6e664a8286887ad8373005d7f7a203fcc458c28004042780146d3e43fa542d921c69512000000000000000000000000000000001287eab085d6f8a29f1f1aedb5ad9e8546963f0b11865e05454d86b9720c281db567682a233631f63a2794432a5596ae0000000000000000000000000000000012ec87cea1bacb75aa97728bcd64b27c7a42dd2319a2e17fe3837a05f85d089c5ebbfb73c1d08b7007e2b59ec9c8e065", - "Gas": 800, + "Gas": 600, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "Name": "bls_g2add_(g2+0=g2)", "Expected": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be", - "Gas": 800, + "Gas": 600, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d87845100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "Name": "bls_g2add_(p2+0=p2)", "Expected": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d878451", - "Gas": 800, + "Gas": 600, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000d1b3cc2c7027888be51d9ef691d77bcb679afda66c73f17f9ee3837a55024f78c71363275a75d75d86bab79f74782aa0000000000000000000000000000000013fa4d4a0ad8b1ce186ed5061789213d993923066dddaf1040bc3ff59f825c78df74f2d75467e25e0f55f8a00fa030ed", "Name": "bls_g2add_(g2-g2=0)", "Expected": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "Gas": 800, + "Gas": 600, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d87845100000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000a6296409115572426717c73668335a949829d739cff2cb4ab043710d28f8e772f6ef41aac4806c9cb273c490384032d000000000000000000000000000000000cde4e850c721fa94e8890d500e3655b442d5c0dc4fff1b694c6f8dd68f6d8dc1bc3251a37d27e7af96f65a96278265a", "Name": "bls_g2add_(p2-p2=0)", "Expected": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "Gas": 800, + "Gas": 600, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be", "Name": "bls_g2add_(g2+g2=2*g2)", "Expected": "000000000000000000000000000000001638533957d540a9d2370f17cc7ed5863bc0b995b8825e0ee1ea1e1e4d00dbae81f14b0bf3611b78c952aacab827a053000000000000000000000000000000000a4edef9c1ed7f729f520e47730a124fd70662a904ba1074728114d1031e1572c6c886f6b57ec72a6178288c47c33577000000000000000000000000000000000468fb440d82b0630aeb8dca2b5256789a66da69bf91009cbfe6bd221e47aa8ae88dece9764bf3bd999d95d71e4c9899000000000000000000000000000000000f6d4552fa65dd2638b361543f887136a43253d9c66c411697003f7a13c308f5422e1aa0a59c8967acdefd8b6e36ccf3", - "Gas": 800, + "Gas": 600, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d87845100000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d878451", "Name": "bls_g2add_(p2+p2=2*p2)", "Expected": "000000000000000000000000000000000b76fcbb604082a4f2d19858a7befd6053fa181c5119a612dfec83832537f644e02454f2b70d40985ebb08042d1620d40000000000000000000000000000000019a4a02c0ae51365d964c73be7babb719db1c69e0ddbf9a8a335b5bed3b0a4b070d2d5df01d2da4a3f1e56aae2ec106d000000000000000000000000000000000d18322f821ac72d3ca92f92b000483cf5b7d9e5d06873a44071c4e7e81efd904f210208fe0b9b4824f01c65bc7e62080000000000000000000000000000000004e563d53609a2d1e216aaaee5fbc14ef460160db8d1fdc5e1bd4e8b54cd2f39abf6f925969fa405efb9e700b01c7085", - "Gas": 800, + "Gas": 600, "NoBenchmark": false } ] diff --git a/packages/evm/test/precompiles/bls/map_fp2_to_G2_bls.json b/packages/evm/test/precompiles/bls/map_fp2_to_G2_bls.json index ab17304ee8..0014a8974d 100644 --- a/packages/evm/test/precompiles/bls/map_fp2_to_G2_bls.json +++ b/packages/evm/test/precompiles/bls/map_fp2_to_G2_bls.json @@ -3,35 +3,35 @@ "Input": "0000000000000000000000000000000007355d25caf6e7f2f0cb2812ca0e513bd026ed09dda65b177500fa31714e09ea0ded3a078b526bed3307f804d4b93b040000000000000000000000000000000002829ce3c021339ccb5caf3e187f6370e1e2a311dec9b75363117063ab2015603ff52c3d3b98f19c2f65575e99e8b78c", "Name": "bls_g2map_", "Expected": "0000000000000000000000000000000000e7f4568a82b4b7dc1f14c6aaa055edf51502319c723c4dc2688c7fe5944c213f510328082396515734b6612c4e7bb700000000000000000000000000000000126b855e9e69b1f691f816e48ac6977664d24d99f8724868a184186469ddfd4617367e94527d4b74fc86413483afb35b000000000000000000000000000000000caead0fd7b6176c01436833c79d305c78be307da5f6af6c133c47311def6ff1e0babf57a0fb5539fce7ee12407b0a42000000000000000000000000000000001498aadcf7ae2b345243e281ae076df6de84455d766ab6fcdaad71fab60abb2e8b980a440043cd305db09d283c895e3d", - "Gas": 75000, + "Gas": 23800, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000138879a9559e24cecee8697b8b4ad32cced053138ab913b99872772dc753a2967ed50aabc907937aefb2439ba06cc50c000000000000000000000000000000000a1ae7999ea9bab1dcc9ef8887a6cb6e8f1e22566015428d220b7eec90ffa70ad1f624018a9ad11e78d588bd3617f9f2", "Name": "bls_g2map_616263", "Expected": "00000000000000000000000000000000108ed59fd9fae381abfd1d6bce2fd2fa220990f0f837fa30e0f27914ed6e1454db0d1ee957b219f61da6ff8be0d6441f000000000000000000000000000000000296238ea82c6d4adb3c838ee3cb2346049c90b96d602d7bb1b469b905c9228be25c627bffee872def773d5b2a2eb57d00000000000000000000000000000000033f90f6057aadacae7963b0a0b379dd46750c1c94a6357c99b65f63b79e321ff50fe3053330911c56b6ceea08fee65600000000000000000000000000000000153606c417e59fb331b7ae6bce4fbf7c5190c33ce9402b5ebe2b70e44fca614f3f1382a3625ed5493843d0b0a652fc3f", - "Gas": 75000, + "Gas": 23800, "NoBenchmark": false }, { "Input": "0000000000000000000000000000000018c16fe362b7dbdfa102e42bdfd3e2f4e6191d479437a59db4eb716986bf08ee1f42634db66bde97d6c16bbfd342b3b8000000000000000000000000000000000e37812ce1b146d998d5f92bdd5ada2a31bfd63dfe18311aa91637b5f279dd045763166aa1615e46a50d8d8f475f184e", "Name": "bls_g2map_6162636465663031", "Expected": "00000000000000000000000000000000038af300ef34c7759a6caaa4e69363cafeed218a1f207e93b2c70d91a1263d375d6730bd6b6509dcac3ba5b567e85bf3000000000000000000000000000000000da75be60fb6aa0e9e3143e40c42796edf15685cafe0279afd2a67c3dff1c82341f17effd402e4f1af240ea90f4b659b0000000000000000000000000000000019b148cbdf163cf0894f29660d2e7bfb2b68e37d54cc83fd4e6e62c020eaa48709302ef8e746736c0e19342cc1ce3df4000000000000000000000000000000000492f4fed741b073e5a82580f7c663f9b79e036b70ab3e51162359cec4e77c78086fe879b65ca7a47d34374c8315ac5e", - "Gas": 75000, + "Gas": 23800, "NoBenchmark": false }, { "Input": "0000000000000000000000000000000008d4a0997b9d52fecf99427abb721f0fa779479963315fe21c6445250de7183e3f63bfdf86570da8929489e421d4ee950000000000000000000000000000000016cb4ccad91ec95aab070f22043916cd6a59c4ca94097f7f510043d48515526dc8eaaea27e586f09151ae613688d5a89", "Name": "bls_g2map_713132385f717171", "Expected": "000000000000000000000000000000000c5ae723be00e6c3f0efe184fdc0702b64588fe77dda152ab13099a3bacd3876767fa7bbad6d6fd90b3642e902b208f90000000000000000000000000000000012c8c05c1d5fc7bfa847f4d7d81e294e66b9a78bc9953990c358945e1f042eedafce608b67fdd3ab0cb2e6e263b9b1ad0000000000000000000000000000000004e77ddb3ede41b5ec4396b7421dd916efc68a358a0d7425bddd253547f2fb4830522358491827265dfc5bcc1928a5690000000000000000000000000000000011c624c56dbe154d759d021eec60fab3d8b852395a89de497e48504366feedd4662d023af447d66926a28076813dd646", - "Gas": 75000, + "Gas": 23800, "NoBenchmark": false }, { "Input": "0000000000000000000000000000000003f80ce4ff0ca2f576d797a3660e3f65b274285c054feccc3215c879e2c0589d376e83ede13f93c32f05da0f68fd6a1000000000000000000000000000000000006488a837c5413746d868d1efb7232724da10eca410b07d8b505b9363bdccf0a1fc0029bad07d65b15ccfe6dd25e20d", "Name": "bls_g2map_613531325f616161", "Expected": "000000000000000000000000000000000ea4e7c33d43e17cc516a72f76437c4bf81d8f4eac69ac355d3bf9b71b8138d55dc10fd458be115afa798b55dac34be1000000000000000000000000000000001565c2f625032d232f13121d3cfb476f45275c303a037faa255f9da62000c2c864ea881e2bcddd111edc4a3c0da3e88d00000000000000000000000000000000043b6f5fe4e52c839148dc66f2b3751e69a0f6ebb3d056d6465d50d4108543ecd956e10fa1640dfd9bc0030cc2558d28000000000000000000000000000000000f8991d2a1ad662e7b6f58ab787947f1fa607fce12dde171bc17903b012091b657e15333e11701edcf5b63ba2a561247", - "Gas": 75000, + "Gas": 23800, "NoBenchmark": false } ] diff --git a/packages/evm/test/precompiles/bls/mul_G2_bls.json b/packages/evm/test/precompiles/bls/mul_G2_bls.json index 7f927d8955..c1b79098bf 100644 --- a/packages/evm/test/precompiles/bls/mul_G2_bls.json +++ b/packages/evm/test/precompiles/bls/mul_G2_bls.json @@ -3,77 +3,77 @@ "Input": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0000000000000000000000000000000000000000000000000000000000000002", "Name": "bls_g2mul_(g2+g2=2*g2)", "Expected": "000000000000000000000000000000001638533957d540a9d2370f17cc7ed5863bc0b995b8825e0ee1ea1e1e4d00dbae81f14b0bf3611b78c952aacab827a053000000000000000000000000000000000a4edef9c1ed7f729f520e47730a124fd70662a904ba1074728114d1031e1572c6c886f6b57ec72a6178288c47c33577000000000000000000000000000000000468fb440d82b0630aeb8dca2b5256789a66da69bf91009cbfe6bd221e47aa8ae88dece9764bf3bd999d95d71e4c9899000000000000000000000000000000000f6d4552fa65dd2638b361543f887136a43253d9c66c411697003f7a13c308f5422e1aa0a59c8967acdefd8b6e36ccf3", - "Gas": 45000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d8784510000000000000000000000000000000000000000000000000000000000000002", "Name": "bls_g2mul_(p2+p2=2*p2)", "Expected": "000000000000000000000000000000000b76fcbb604082a4f2d19858a7befd6053fa181c5119a612dfec83832537f644e02454f2b70d40985ebb08042d1620d40000000000000000000000000000000019a4a02c0ae51365d964c73be7babb719db1c69e0ddbf9a8a335b5bed3b0a4b070d2d5df01d2da4a3f1e56aae2ec106d000000000000000000000000000000000d18322f821ac72d3ca92f92b000483cf5b7d9e5d06873a44071c4e7e81efd904f210208fe0b9b4824f01c65bc7e62080000000000000000000000000000000004e563d53609a2d1e216aaaee5fbc14ef460160db8d1fdc5e1bd4e8b54cd2f39abf6f925969fa405efb9e700b01c7085", - "Gas": 45000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0000000000000000000000000000000000000000000000000000000000000001", "Name": "bls_g2mul_(1*g2=g2)", "Expected": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be", - "Gas": 45000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d8784510000000000000000000000000000000000000000000000000000000000000001", "Name": "bls_g2mul_(1*p2=p2)", "Expected": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d878451", - "Gas": 45000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0000000000000000000000000000000000000000000000000000000000000000", "Name": "bls_g2mul_(0*g2=inf)", "Expected": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "Gas": 45000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d8784510000000000000000000000000000000000000000000000000000000000000000", "Name": "bls_g2mul_(0*p2=inf)", "Expected": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "Gas": 45000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011", "Name": "bls_g2mul_(x*inf=inf)", "Expected": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "Gas": 45000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be263dbd792f5b1be47ed85f8938c0f29586af0d3ac7b977f21c278fe1462040e3", "Name": "bls_g2mul_random*g2", "Expected": "0000000000000000000000000000000014856c22d8cdb2967c720e963eedc999e738373b14172f06fc915769d3cc5ab7ae0a1b9c38f48b5585fb09d4bd2733bb000000000000000000000000000000000c400b70f6f8cd35648f5c126cce5417f3be4d8eefbd42ceb4286a14df7e03135313fe5845e3a575faab3e8b949d248800000000000000000000000000000000149a0aacc34beba2beb2f2a19a440166e76e373194714f108e4ab1c3fd331e80f4e73e6b9ea65fe3ec96d7136de81544000000000000000000000000000000000e4622fef26bdb9b1e8ef6591a7cc99f5b73164500c1ee224b6a761e676b8799b09a3fd4fa7e242645cc1a34708285e4", - "Gas": 45000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d878451263dbd792f5b1be47ed85f8938c0f29586af0d3ac7b977f21c278fe1462040e3", "Name": "bls_g2mul_random*p2", "Expected": "00000000000000000000000000000000036074dcbbd0e987531bfe0e45ddfbe09fd015665990ee0c352e8e403fe6af971d8f42141970d9ab14b4dd04874409e600000000000000000000000000000000019705637f24ba2f398f32c3a3e20d6a1cd0fd63e6f8f071cf603a8334f255744927e7bfdfdb18519e019c49ff6e914500000000000000000000000000000000008e74fcff4c4278c9accfb60809ed69bbcbe3d6213ef2304e078d15ec7d6decb4f462b24b8e7cc38cc11b6f2c9e0486000000000000000000000000000000001331d40100f38c1070afd832445881b47cf4d63894666d9907c85ac66604aab5ad329980938cc3c167ccc5b6bc1b8f30", - "Gas": 45000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be9a2b64cc58f8992cb21237914262ca9ada6cb13dc7b7d3f11c278fe0462040e4", "Name": "bls_g2mul_random*g2_unnormalized_scalar", "Expected": "0000000000000000000000000000000014856c22d8cdb2967c720e963eedc999e738373b14172f06fc915769d3cc5ab7ae0a1b9c38f48b5585fb09d4bd2733bb000000000000000000000000000000000c400b70f6f8cd35648f5c126cce5417f3be4d8eefbd42ceb4286a14df7e03135313fe5845e3a575faab3e8b949d248800000000000000000000000000000000149a0aacc34beba2beb2f2a19a440166e76e373194714f108e4ab1c3fd331e80f4e73e6b9ea65fe3ec96d7136de81544000000000000000000000000000000000e4622fef26bdb9b1e8ef6591a7cc99f5b73164500c1ee224b6a761e676b8799b09a3fd4fa7e242645cc1a34708285e4", - "Gas": 45000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d8784519a2b64cc58f8992cb21237914262ca9ada6cb13dc7b7d3f11c278fe0462040e4", "Name": "bls_g2mul_random*p2_unnormalized_scalar", "Expected": "00000000000000000000000000000000036074dcbbd0e987531bfe0e45ddfbe09fd015665990ee0c352e8e403fe6af971d8f42141970d9ab14b4dd04874409e600000000000000000000000000000000019705637f24ba2f398f32c3a3e20d6a1cd0fd63e6f8f071cf603a8334f255744927e7bfdfdb18519e019c49ff6e914500000000000000000000000000000000008e74fcff4c4278c9accfb60809ed69bbcbe3d6213ef2304e078d15ec7d6decb4f462b24b8e7cc38cc11b6f2c9e0486000000000000000000000000000000001331d40100f38c1070afd832445881b47cf4d63894666d9907c85ac66604aab5ad329980938cc3c167ccc5b6bc1b8f30", - "Gas": 45000, + "Gas": 22500, "NoBenchmark": false } ] diff --git a/packages/evm/test/precompiles/bls/multiexp_G1_bls.json b/packages/evm/test/precompiles/bls/multiexp_G1_bls.json index 19f0884004..e3ba0d8557 100644 --- a/packages/evm/test/precompiles/bls/multiexp_G1_bls.json +++ b/packages/evm/test/precompiles/bls/multiexp_G1_bls.json @@ -3,77 +3,91 @@ "Input": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000000000000000000000000000000000002", "Name": "bls_g1multiexp_(g1+g1=2*g1)", "Expected": "000000000000000000000000000000000572cbea904d67468808c8eb50a9450c9721db309128012543902d0ac358a62ae28f75bb8f1c7c42c39a8c5529bf0f4e00000000000000000000000000000000166a9d8cabc673a322fda673779d8e3822ba3ecb8670e461f73bb9021d5fd76a4c56d9d4cd16bd1bba86881979749d28", - "Gas": 14400, + "Gas": 12000, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a210000000000000000000000000000000000000000000000000000000000000002", "Name": "bls_g1multiexp_(p1+p1=2*p1)", "Expected": "0000000000000000000000000000000015222cddbabdd764c4bee0b3720322a65ff4712c86fc4b1588d0c209210a0884fa9468e855d261c483091b2bf7de6a630000000000000000000000000000000009f9edb99bc3b75d7489735c98b16ab78b9386c5f7a1f76c7e96ac6eb5bbde30dbca31a74ec6e0f0b12229eecea33c39", - "Gas": 14400, + "Gas": 12000, "NoBenchmark": false }, { "Input": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000000000000000000000000000000000001", "Name": "bls_g1multiexp_(1*g1=g1)", "Expected": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1", - "Gas": 14400, + "Gas": 12000, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a210000000000000000000000000000000000000000000000000000000000000001", "Name": "bls_g1multiexp_(1*p1=p1)", "Expected": "00000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a21", - "Gas": 14400, + "Gas": 12000, "NoBenchmark": false }, { "Input": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000000000000000000000000000000000000", "Name": "bls_g1multiexp_(0*g1=inf)", "Expected": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "Gas": 14400, + "Gas": 12000, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a210000000000000000000000000000000000000000000000000000000000000000", "Name": "bls_g1multiexp_(0*p1=inf)", "Expected": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "Gas": 14400, + "Gas": 12000, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011", "Name": "bls_g1multiexp_(x*inf=inf)", "Expected": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "Gas": 14400, + "Gas": 12000, "NoBenchmark": false }, { "Input": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000000000000000000000000000000000000", "Name": "bls_g1multiexp_(2g1+inf)", "Expected": "000000000000000000000000000000000572cbea904d67468808c8eb50a9450c9721db309128012543902d0ac358a62ae28f75bb8f1c7c42c39a8c5529bf0f4e00000000000000000000000000000000166a9d8cabc673a322fda673779d8e3822ba3ecb8670e461f73bb9021d5fd76a4c56d9d4cd16bd1bba86881979749d28", - "Gas": 21312, + "Gas": 22776, "NoBenchmark": false }, { "Input": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e10000000000000000000000000000000000000000000000000000000000000000", "Name": "bls_g1multiexp_(inf+inf)", "Expected": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "Gas": 21312, + "Gas": 22776, "NoBenchmark": false }, { "Input": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a210000000000000000000000000000000000000000000000000000000000000002", "Name": "bls_g1multiexp_(2g1+2p1)", "Expected": "00000000000000000000000000000000148f92dced907361b4782ab542a75281d4b6f71f65c8abf94a5a9082388c64662d30fd6a01ced724feef3e284752038c0000000000000000000000000000000015c3634c3b67bc18e19150e12bfd8a1769306ed010f59be645a0823acb5b38f39e8e0d86e59b6353fdafc59ca971b769", - "Gas": 21312, + "Gas": 22776, "NoBenchmark": false }, { "Input": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1263dbd792f5b1be47ed85f8938c0f29586af0d3ac7b977f21c278fe1462040e300000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a2147b8192d77bf871b62e87859d653922725724a5c031afeabc60bcef5ff66513800000000000000000000000000000000184bb665c37ff561a89ec2122dd343f20e0f4cbcaec84e3c3052ea81d1834e192c426074b02ed3dca4e7676ce4ce48ba0000000000000000000000000000000004407b8d35af4dacc809927071fc0405218f1401a6d15af775810e4e460064bcc9468beeba82fdc751be70476c888bf3328388aff0d4a5b7dc9205abd374e7e98f3cd9f3418edb4eafda5fb16473d21600000000000000000000000000000000009769f3ab59bfd551d53a5f846b9984c59b97d6842b20a2c565baa167945e3d026a3755b6345df8ec7e6acb6868ae6d000000000000000000000000000000001532c00cf61aa3d0ce3e5aa20c3b531a2abd2c770a790a2613818303c6b830ffc0ecf6c357af3317b9575c567f11cd2c263dbd792f5b1be47ed85f8938c0f29586af0d3ac7b977f21c278fe1462040e2000000000000000000000000000000001974dbb8e6b5d20b84df7e625e2fbfecb2cdb5f77d5eae5fb2955e5ce7313cae8364bc2fff520a6c25619739c6bdcb6a0000000000000000000000000000000015f9897e11c6441eaa676de141c8d83c37aab8667173cbe1dfd6de74d11861b961dccebcd9d289ac633455dfcc7013a347b8192d77bf871b62e87859d653922725724a5c031afeabc60bcef5ff665131000000000000000000000000000000000a7a047c4a8397b3446450642c2ac64d7239b61872c9ae7a59707a8f4f950f101e766afe58223b3bff3a19a7f754027c000000000000000000000000000000001383aebba1e4327ccff7cf9912bda0dbc77de048b71ef8c8a81111d71dc33c5e3aa6edee9cf6f5fe525d50cc50b77cc9328388aff0d4a5b7dc9205abd374e7e98f3cd9f3418edb4eafda5fb16473d211000000000000000000000000000000000e7a16a975904f131682edbb03d9560d3e48214c9986bd50417a77108d13dc957500edf96462a3d01e62dc6cd468ef11000000000000000000000000000000000ae89e677711d05c30a48d6d75e76ca9fb70fe06c6dd6ff988683d89ccde29ac7d46c53bb97a59b1901abf1db66052db55b53c4669f19f0fc7431929bc0363d7d8fb432435fcde2635fdba334424e9f5", "Name": "bls_g1multiexp_multiple", "Expected": "00000000000000000000000000000000053fbdb09b6b5faa08bfe7b7069454247ad4d8bd57e90e2d2ebaa04003dcf110aa83072c07f480ab2107cca2ccff6091000000000000000000000000000000001654537b7c96fe64d13906066679c3d45808cb666452b55d1b909c230cc4b423c3f932c58754b9b762dc49fcc825522c", - "Gas": 42000, + "Gas": 61992, + "NoBenchmark": false + }, + { + "Input": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e19a2b64cc58f8992cb21237914262ca9ada6cb13dc7b7d3f11c278fe0462040e4", + "Name": "bls_g1multiexp_random*g1_unnormalized_scalar", + "Expected": "000000000000000000000000000000000491d1b0ecd9bb917989f0e74f0dea0422eac4a873e5e2644f368dffb9a6e20fd6e10c1b77654d067c0618f6e5a7f79a0000000000000000000000000000000017cd7061575d3e8034fcea62adaa1a3bc38dca4b50e4c5c01d04dd78037c9cee914e17944ea99e7ad84278e5d49f36c4", + "Gas": 12000, + "NoBenchmark": false + }, + { + "Input": "00000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a219a2b64cc58f8992cb21237914262ca9ada6cb13dc7b7d3f11c278fe0462040e4", + "Name": "bls_g1multiexp_random*p1_unnormalized_scalar", + "Expected": "0000000000000000000000000000000006ee9c9331228753bcb148d0ca8623447701bb0aa6eafb0340aa7f81543923474e00f2a225de65c62dd1d8303270220c0000000000000000000000000000000018dd7be47eb4e80985d7a0d2cc96c8b004250b36a5c3ec0217705d453d3ecc6d0d3d1588722da51b40728baba1e93804", + "Gas": 12000, "NoBenchmark": false } ] diff --git a/packages/evm/test/precompiles/bls/multiexp_G2_bls.json b/packages/evm/test/precompiles/bls/multiexp_G2_bls.json index 1655e68bff..8357cc406e 100644 --- a/packages/evm/test/precompiles/bls/multiexp_G2_bls.json +++ b/packages/evm/test/precompiles/bls/multiexp_G2_bls.json @@ -3,84 +3,98 @@ "Input": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0000000000000000000000000000000000000000000000000000000000000002", "Name": "bls_g2multiexp_(g2+g2=2*g2)", "Expected": "000000000000000000000000000000001638533957d540a9d2370f17cc7ed5863bc0b995b8825e0ee1ea1e1e4d00dbae81f14b0bf3611b78c952aacab827a053000000000000000000000000000000000a4edef9c1ed7f729f520e47730a124fd70662a904ba1074728114d1031e1572c6c886f6b57ec72a6178288c47c33577000000000000000000000000000000000468fb440d82b0630aeb8dca2b5256789a66da69bf91009cbfe6bd221e47aa8ae88dece9764bf3bd999d95d71e4c9899000000000000000000000000000000000f6d4552fa65dd2638b361543f887136a43253d9c66c411697003f7a13c308f5422e1aa0a59c8967acdefd8b6e36ccf3", - "Gas": 54000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d8784510000000000000000000000000000000000000000000000000000000000000002", "Name": "bls_g2multiexp_(p2+p2=2*p2)", "Expected": "000000000000000000000000000000000b76fcbb604082a4f2d19858a7befd6053fa181c5119a612dfec83832537f644e02454f2b70d40985ebb08042d1620d40000000000000000000000000000000019a4a02c0ae51365d964c73be7babb719db1c69e0ddbf9a8a335b5bed3b0a4b070d2d5df01d2da4a3f1e56aae2ec106d000000000000000000000000000000000d18322f821ac72d3ca92f92b000483cf5b7d9e5d06873a44071c4e7e81efd904f210208fe0b9b4824f01c65bc7e62080000000000000000000000000000000004e563d53609a2d1e216aaaee5fbc14ef460160db8d1fdc5e1bd4e8b54cd2f39abf6f925969fa405efb9e700b01c7085", - "Gas": 54000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0000000000000000000000000000000000000000000000000000000000000001", "Name": "bls_g2multiexp_(1*g2=g2)", "Expected": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be", - "Gas": 54000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d8784510000000000000000000000000000000000000000000000000000000000000001", "Name": "bls_g2multiexp_(1*p2=p2)", "Expected": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d878451", - "Gas": 54000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0000000000000000000000000000000000000000000000000000000000000000", "Name": "bls_g2multiexp_(0*g2=inf)", "Expected": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "Gas": 54000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d8784510000000000000000000000000000000000000000000000000000000000000000", "Name": "bls_g2multiexp_(0*p2=inf)", "Expected": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "Gas": 54000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011", "Name": "bls_g2multiexp_(x*inf=inf)", "Expected": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "Gas": 54000, + "Gas": 22500, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002", "Name": "bls_g2multiexp_(2g2+inf)", "Expected": "000000000000000000000000000000001638533957d540a9d2370f17cc7ed5863bc0b995b8825e0ee1ea1e1e4d00dbae81f14b0bf3611b78c952aacab827a053000000000000000000000000000000000a4edef9c1ed7f729f520e47730a124fd70662a904ba1074728114d1031e1572c6c886f6b57ec72a6178288c47c33577000000000000000000000000000000000468fb440d82b0630aeb8dca2b5256789a66da69bf91009cbfe6bd221e47aa8ae88dece9764bf3bd999d95d71e4c9899000000000000000000000000000000000f6d4552fa65dd2638b361543f887136a43253d9c66c411697003f7a13c308f5422e1aa0a59c8967acdefd8b6e36ccf3", - "Gas": 79920, + "Gas": 45000, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d8784510000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002", "Name": "bls_g2multiexp_(2p2+inf)", "Expected": "000000000000000000000000000000000b76fcbb604082a4f2d19858a7befd6053fa181c5119a612dfec83832537f644e02454f2b70d40985ebb08042d1620d40000000000000000000000000000000019a4a02c0ae51365d964c73be7babb719db1c69e0ddbf9a8a335b5bed3b0a4b070d2d5df01d2da4a3f1e56aae2ec106d000000000000000000000000000000000d18322f821ac72d3ca92f92b000483cf5b7d9e5d06873a44071c4e7e81efd904f210208fe0b9b4824f01c65bc7e62080000000000000000000000000000000004e563d53609a2d1e216aaaee5fbc14ef460160db8d1fdc5e1bd4e8b54cd2f39abf6f925969fa405efb9e700b01c7085", - "Gas": 79920, + "Gas": 45000, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d878451000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d8784510000000000000000000000000000000000000000000000000000000000000000", "Name": "bls_g1multiexp_(inf+inf)", "Expected": "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "Gas": 79920, + "Gas": 45000, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d8784510000000000000000000000000000000000000000000000000000000000000002", "Name": "bls_g2multiexp_(2g2+2p2)", "Expected": "00000000000000000000000000000000009cc9ed6635623ba19b340cbc1b0eb05c3a58770623986bb7e041645175b0a38d663d929afb9a949f7524656043bccc000000000000000000000000000000000c0fb19d3f083fd5641d22a861a11979da258003f888c59c33005cb4a2df4df9e5a2868832063ac289dfa3e997f21f8a00000000000000000000000000000000168bf7d87cef37cf1707849e0a6708cb856846f5392d205ae7418dd94d94ef6c8aa5b424af2e99d957567654b9dae1d90000000000000000000000000000000017e0fa3c3b2665d52c26c7d4cea9f35443f4f9007840384163d3aa3c7d4d18b21b65ff4380cf3f3b48e94b5eecb221dd", - "Gas": 79920, + "Gas": 45000, "NoBenchmark": false }, { "Input": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be263dbd792f5b1be47ed85f8938c0f29586af0d3ac7b977f21c278fe1462040e300000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d87845147b8192d77bf871b62e87859d653922725724a5c031afeabc60bcef5ff66513800000000000000000000000000000000108ed59fd9fae381abfd1d6bce2fd2fa220990f0f837fa30e0f27914ed6e1454db0d1ee957b219f61da6ff8be0d6441f000000000000000000000000000000000296238ea82c6d4adb3c838ee3cb2346049c90b96d602d7bb1b469b905c9228be25c627bffee872def773d5b2a2eb57d00000000000000000000000000000000033f90f6057aadacae7963b0a0b379dd46750c1c94a6357c99b65f63b79e321ff50fe3053330911c56b6ceea08fee65600000000000000000000000000000000153606c417e59fb331b7ae6bce4fbf7c5190c33ce9402b5ebe2b70e44fca614f3f1382a3625ed5493843d0b0a652fc3f328388aff0d4a5b7dc9205abd374e7e98f3cd9f3418edb4eafda5fb16473d21600000000000000000000000000000000038af300ef34c7759a6caaa4e69363cafeed218a1f207e93b2c70d91a1263d375d6730bd6b6509dcac3ba5b567e85bf3000000000000000000000000000000000da75be60fb6aa0e9e3143e40c42796edf15685cafe0279afd2a67c3dff1c82341f17effd402e4f1af240ea90f4b659b0000000000000000000000000000000019b148cbdf163cf0894f29660d2e7bfb2b68e37d54cc83fd4e6e62c020eaa48709302ef8e746736c0e19342cc1ce3df4000000000000000000000000000000000492f4fed741b073e5a82580f7c663f9b79e036b70ab3e51162359cec4e77c78086fe879b65ca7a47d34374c8315ac5e263dbd792f5b1be47ed85f8938c0f29586af0d3ac7b977f21c278fe1462040e2000000000000000000000000000000000c5ae723be00e6c3f0efe184fdc0702b64588fe77dda152ab13099a3bacd3876767fa7bbad6d6fd90b3642e902b208f90000000000000000000000000000000012c8c05c1d5fc7bfa847f4d7d81e294e66b9a78bc9953990c358945e1f042eedafce608b67fdd3ab0cb2e6e263b9b1ad0000000000000000000000000000000004e77ddb3ede41b5ec4396b7421dd916efc68a358a0d7425bddd253547f2fb4830522358491827265dfc5bcc1928a5690000000000000000000000000000000011c624c56dbe154d759d021eec60fab3d8b852395a89de497e48504366feedd4662d023af447d66926a28076813dd64647b8192d77bf871b62e87859d653922725724a5c031afeabc60bcef5ff665131000000000000000000000000000000000ea4e7c33d43e17cc516a72f76437c4bf81d8f4eac69ac355d3bf9b71b8138d55dc10fd458be115afa798b55dac34be1000000000000000000000000000000001565c2f625032d232f13121d3cfb476f45275c303a037faa255f9da62000c2c864ea881e2bcddd111edc4a3c0da3e88d00000000000000000000000000000000043b6f5fe4e52c839148dc66f2b3751e69a0f6ebb3d056d6465d50d4108543ecd956e10fa1640dfd9bc0030cc2558d28000000000000000000000000000000000f8991d2a1ad662e7b6f58ab787947f1fa607fce12dde171bc17903b012091b657e15333e11701edcf5b63ba2a561247328388aff0d4a5b7dc9205abd374e7e98f3cd9f3418edb4eafda5fb16473d211", "Name": "bls_g2multiexp_multiple", "Expected": "0000000000000000000000000000000016cf5fd2c2f1b2e01cc48a6d03e8e6d7f3ad754d6c7d4000f806c18c28d8d559cf529dd159c74946a7713d1906894718000000000000000000000000000000000628d42142df8d620d1f3709ac01f382ba950eaf14c12863885af5838067deec4bb363ffda427fcbdd2b8ec6cc5784ae0000000000000000000000000000000018168dec2441ef462e9a769c782f81acdc7fa49dffebb996764ba9fa96b9200ceb5edd9e96b33c383bd042b4e6af191a000000000000000000000000000000001065aaea2c4aa1d2bee7f1e82a2138ae7016dbbade8383ad912d81eca5fb260086238f95f8cef8f2f491969d4cefa2c3", - "Gas": 147690, + "Gas": 112320, + "NoBenchmark": false + }, + { + "Input": "00000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be9a2b64cc58f8992cb21237914262ca9ada6cb13dc7b7d3f11c278fe0462040e4", + "Name": "bls_g2multiexp_random*g2_unnormalized_scalar", + "Expected": "0000000000000000000000000000000014856c22d8cdb2967c720e963eedc999e738373b14172f06fc915769d3cc5ab7ae0a1b9c38f48b5585fb09d4bd2733bb000000000000000000000000000000000c400b70f6f8cd35648f5c126cce5417f3be4d8eefbd42ceb4286a14df7e03135313fe5845e3a575faab3e8b949d248800000000000000000000000000000000149a0aacc34beba2beb2f2a19a440166e76e373194714f108e4ab1c3fd331e80f4e73e6b9ea65fe3ec96d7136de81544000000000000000000000000000000000e4622fef26bdb9b1e8ef6591a7cc99f5b73164500c1ee224b6a761e676b8799b09a3fd4fa7e242645cc1a34708285e4", + "Gas": 22500, + "NoBenchmark": false + }, + { + "Input": "00000000000000000000000000000000103121a2ceaae586d240843a398967325f8eb5a93e8fea99b62b9f88d8556c80dd726a4b30e84a36eeabaf3592937f2700000000000000000000000000000000086b990f3da2aeac0a36143b7d7c824428215140db1bb859338764cb58458f081d92664f9053b50b3fbd2e4723121b68000000000000000000000000000000000f9e7ba9a86a8f7624aa2b42dcc8772e1af4ae115685e60abc2c9b90242167acef3d0be4050bf935eed7c3b6fc7ba77e000000000000000000000000000000000d22c3652d0dc6f0fc9316e14268477c2049ef772e852108d269d9c38dba1d4802e8dae479818184c08f9a569d8784519a2b64cc58f8992cb21237914262ca9ada6cb13dc7b7d3f11c278fe0462040e4", + "Name": "bls_g2multiexp_random*p2_unnormalized_scalar", + "Expected": "00000000000000000000000000000000036074dcbbd0e987531bfe0e45ddfbe09fd015665990ee0c352e8e403fe6af971d8f42141970d9ab14b4dd04874409e600000000000000000000000000000000019705637f24ba2f398f32c3a3e20d6a1cd0fd63e6f8f071cf603a8334f255744927e7bfdfdb18519e019c49ff6e914500000000000000000000000000000000008e74fcff4c4278c9accfb60809ed69bbcbe3d6213ef2304e078d15ec7d6decb4f462b24b8e7cc38cc11b6f2c9e0486000000000000000000000000000000001331d40100f38c1070afd832445881b47cf4d63894666d9907c85ac66604aab5ad329980938cc3c167ccc5b6bc1b8f30", + "Gas": 22500, "NoBenchmark": false } ] diff --git a/packages/evm/test/precompiles/bls/pairing_check_bls.json b/packages/evm/test/precompiles/bls/pairing_check_bls.json index 6e80a69d17..70ab731461 100644 --- a/packages/evm/test/precompiles/bls/pairing_check_bls.json +++ b/packages/evm/test/precompiles/bls/pairing_check_bls.json @@ -3,42 +3,42 @@ "Input": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be", "Name": "bls_pairing_e(G1,0)=e(0,G2)", "Expected": "0000000000000000000000000000000000000000000000000000000000000001", - "Gas": 151000, + "Gas": 102900, "NoBenchmark": false }, { "Input": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e100000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be", "Name": "bls_pairing_non-degeneracy", "Expected": "0000000000000000000000000000000000000000000000000000000000000000", - "Gas": 108000, + "Gas": 70300, "NoBenchmark": false }, { "Input": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e100000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be00000000000000000000000000000000112b98340eee2777cc3c14163dea3ec97977ac3dc5c70da32e6e87578f44912e902ccef9efe28d4a78b8999dfbca942600000000000000000000000000000000186b28d92356c4dfec4b5201ad099dbdede3781f8998ddf929b4cd7756192185ca7b8f4ef7088f813270ac3d48868a2100000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be000000000000000000000000000000000a40300ce2dec9888b60690e9a41d3004fda4886854573974fab73b046d3147ba5b7a5bde85279ffede1b45b3918d82d0000000000000000000000000000000006d3d887e9f53b9ec4eb6cedf5607226754b07c01ace7834f57f3e7315faefb739e59018e22c492006190fba4a87002500000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000d1b3cc2c7027888be51d9ef691d77bcb679afda66c73f17f9ee3837a55024f78c71363275a75d75d86bab79f74782aa0000000000000000000000000000000013fa4d4a0ad8b1ce186ed5061789213d993923066dddaf1040bc3ff59f825c78df74f2d75467e25e0f55f8a00fa030ed", "Name": "bls_pairing_bilinearity", "Expected": "0000000000000000000000000000000000000000000000000000000000000001", - "Gas": 194000, + "Gas": 135500, "NoBenchmark": false }, { "Input": "0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e100000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801000000000000000000000000000000000606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be0000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb0000000000000000000000000000000008b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e100000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000d1b3cc2c7027888be51d9ef691d77bcb679afda66c73f17f9ee3837a55024f78c71363275a75d75d86bab79f74782aa0000000000000000000000000000000013fa4d4a0ad8b1ce186ed5061789213d993923066dddaf1040bc3ff59f825c78df74f2d75467e25e0f55f8a00fa030ed", "Name": "bls_pairing_e(G1,-G2)=e(-G1,G2)", "Expected": "0000000000000000000000000000000000000000000000000000000000000001", - "Gas": 151000, + "Gas": 102900, "NoBenchmark": false }, { "Input": "000000000000000000000000000000000491d1b0ecd9bb917989f0e74f0dea0422eac4a873e5e2644f368dffb9a6e20fd6e10c1b77654d067c0618f6e5a7f79a0000000000000000000000000000000017cd7061575d3e8034fcea62adaa1a3bc38dca4b50e4c5c01d04dd78037c9cee914e17944ea99e7ad84278e5d49f36c4000000000000000000000000000000000bc2357c6782bbb6a078d9e171fc7a81f7bd8ca73eb485e76317359908bb09bd372fd362a637512a9d48019b383e54890000000000000000000000000000000004b8f49c3bac0247a09487049492b0ed99cf90c56263141daa35f011330d3ced3f3ad78d252c51a3bb42fc7d8f182594000000000000000000000000000000000982d17b17404ac198a0ff5f2dffa56a328d95ec4732d9cca9da420ec7cf716dc63d56d0f5179a8b1ec71fe0328fe88200000000000000000000000000000000147c92cb19e43943bb20c5360a6c4347411eb8ffb3d6f19cc428a8dc0cb3fd1eb3ad02b1c21e21c78f65a7691ee63de90000000000000000000000000000000016cae74dc6523e5273dbd2d9d25c53f1e2c453e6d9ba3f605021cfb514fa0bdf721b05f2200f32591d733e739fabf438000000000000000000000000000000001405df65fb71b738510b3a2fc31c33ef3d884ccc84efb1017341a368bf40727b7ad8cdc8e3fd6b0eb94102488c5cb77000000000000000000000000000000000024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb80000000000000000000000000000000013e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e000000000000000000000000000000000d1b3cc2c7027888be51d9ef691d77bcb679afda66c73f17f9ee3837a55024f78c71363275a75d75d86bab79f74782aa0000000000000000000000000000000013fa4d4a0ad8b1ce186ed5061789213d993923066dddaf1040bc3ff59f825c78df74f2d75467e25e0f55f8a00fa030ed", "Name": "bls_pairing_e(aG1,bG2)=e(abG1,G2)", "Expected": "0000000000000000000000000000000000000000000000000000000000000001", - "Gas": 151000, + "Gas": 102900, "NoBenchmark": false }, { "Input": "000000000000000000000000000000000491d1b0ecd9bb917989f0e74f0dea0422eac4a873e5e2644f368dffb9a6e20fd6e10c1b77654d067c0618f6e5a7f79a0000000000000000000000000000000017cd7061575d3e8034fcea62adaa1a3bc38dca4b50e4c5c01d04dd78037c9cee914e17944ea99e7ad84278e5d49f36c4000000000000000000000000000000000bc2357c6782bbb6a078d9e171fc7a81f7bd8ca73eb485e76317359908bb09bd372fd362a637512a9d48019b383e54890000000000000000000000000000000004b8f49c3bac0247a09487049492b0ed99cf90c56263141daa35f011330d3ced3f3ad78d252c51a3bb42fc7d8f182594000000000000000000000000000000000982d17b17404ac198a0ff5f2dffa56a328d95ec4732d9cca9da420ec7cf716dc63d56d0f5179a8b1ec71fe0328fe88200000000000000000000000000000000147c92cb19e43943bb20c5360a6c4347411eb8ffb3d6f19cc428a8dc0cb3fd1eb3ad02b1c21e21c78f65a7691ee63de90000000000000000000000000000000017f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb00000000000000000000000000000000114d1d6855d545a8aa7d76c8cf2e21f267816aef1db507c96655b9d5caac42364e6f38ba0ecb751bad54dcd6b939c2ca00000000000000000000000000000000166335679f3b3e2617b70c22c48e820e2c6a35149c4f96293035c1494a1ce4591f7a44bce94e9d76def50a71c9e7fa41000000000000000000000000000000000ef11c636091748476331159c8259c064da712ffec033c89299384b4c11b801893026726d992aacdc8e0a28db1a3ab82000000000000000000000000000000000fd8d4944030f480f44ce0d2d4fb67ff6264d30a0f3193cc218b062e5114cf9e4ce847489f7be94b0d4a9fc0c550fdc60000000000000000000000000000000000edba2c166be3d673ea77016163ae5cdf7b3c9bd480e733eb5c08a5f1c798793d339cb503005f5a9e586ea5aabf9695", "Name": "bls_pairing_e(aG1,bG2)=e(G1,abG2)", "Expected": "0000000000000000000000000000000000000000000000000000000000000001", - "Gas": 151000, + "Gas": 102900, "NoBenchmark": false } ] diff --git a/packages/evm/test/precompiles/eip-2537-bls.spec.ts b/packages/evm/test/precompiles/eip-2537-bls.spec.ts index 7f552e74c5..ac37ebb851 100644 --- a/packages/evm/test/precompiles/eip-2537-bls.spec.ts +++ b/packages/evm/test/precompiles/eip-2537-bls.spec.ts @@ -15,23 +15,23 @@ const files = readdirSync(dir) const precompileMap: { [key: string]: string } = { 'add_G1_bls.json': '000000000000000000000000000000000000000b', - 'add_G2_bls.json': '000000000000000000000000000000000000000e', + 'add_G2_bls.json': '000000000000000000000000000000000000000d', 'fail-add_G1_bls.json': '000000000000000000000000000000000000000b', - 'fail-add_G2_bls.json': '000000000000000000000000000000000000000e', - 'fail-map_fp2_to_G2_bls.json': '0000000000000000000000000000000000000013', - 'fail-map_fp_to_G1_bls.json': '0000000000000000000000000000000000000012', + 'fail-add_G2_bls.json': '000000000000000000000000000000000000000d', + 'fail-map_fp2_to_G2_bls.json': '0000000000000000000000000000000000000011', + 'fail-map_fp_to_G1_bls.json': '0000000000000000000000000000000000000010', 'fail-mul_G1_bls.json': '000000000000000000000000000000000000000c', - 'fail-mul_G2_bls.json': '000000000000000000000000000000000000000f', + 'fail-mul_G2_bls.json': '000000000000000000000000000000000000000e', 'fail-multiexp_G1_bls.json': '000000000000000000000000000000000000000c', - 'fail-multiexp_G2_bls.json': '0000000000000000000000000000000000000010', - 'fail-pairing_check_bls.json': '0000000000000000000000000000000000000011', - 'map_fp2_to_G2_bls.json': '0000000000000000000000000000000000000013', - 'map_fp_to_G1_bls.json': '0000000000000000000000000000000000000012', + 'fail-multiexp_G2_bls.json': '000000000000000000000000000000000000000e', + 'fail-pairing_check_bls.json': '000000000000000000000000000000000000000f', + 'map_fp2_to_G2_bls.json': '0000000000000000000000000000000000000011', + 'map_fp_to_G1_bls.json': '0000000000000000000000000000000000000010', 'mul_G1_bls.json': '000000000000000000000000000000000000000c', - 'mul_G2_bls.json': '000000000000000000000000000000000000000f', - 'multiexp_G1_bls.json': '000000000000000000000000000000000000000d', - 'multiexp_G2_bls.json': '0000000000000000000000000000000000000010', - 'pairing_check_bls.json': '0000000000000000000000000000000000000011', + 'mul_G2_bls.json': '000000000000000000000000000000000000000e', + 'multiexp_G1_bls.json': '000000000000000000000000000000000000000c', + 'multiexp_G2_bls.json': '000000000000000000000000000000000000000e', + 'pairing_check_bls.json': '000000000000000000000000000000000000000f', } const common = new Common({ chain: Mainnet, hardfork: Hardfork.Berlin, eips: [2537] }) @@ -82,8 +82,8 @@ for (const bls of [undefined, mclbls]) { 'return value should match testVectorResult', ) assert.equal(result.executionGasUsed, BigInt(data.Gas)) - } catch (e) { - assert.fail('The precompile should not throw') + } catch (e: any) { + assert.fail(e.message) } } }) @@ -93,7 +93,7 @@ for (const bls of [undefined, mclbls]) { } const precompileAddressStart = 0x0b -const precompileAddressEnd = 0x13 +const precompileAddressEnd = 0x11 const precompiles: PrefixedHexString[] = [] diff --git a/packages/evm/test/verkle.spec.ts b/packages/evm/test/verkle.spec.ts index 67452ba197..36ed5ee102 100644 --- a/packages/evm/test/verkle.spec.ts +++ b/packages/evm/test/verkle.spec.ts @@ -42,4 +42,70 @@ describe('verkle tests', () => { const retrievedValue = await sm.getStorage(address, setLengthLeft(bigIntToBytes(2n), 32)) assert.deepEqual(retrievedValue, setLengthLeft(bigIntToBytes(1n), 32)) }) + + it('should revert and access witness should not contain a write access due to OOG', async () => { + // This tests executes some very simple bytecode that stores the value 1 in slot 2 + const common = new Common({ + chain: Mainnet, + customCrypto: { verkle }, + eips: [6800], + hardfork: Hardfork.Cancun, + }) + const trie = await createVerkleTree() + const sm = new StatefulVerkleStateManager({ common, trie }) + const address = createAddressFromString('0x9e5ef720fa2cdfa5291eb7e711cfd2e62196f4b3') + const account = createAccount({ nonce: 3n, balance: 0xffffffffn }) + await sm.putAccount(address, account) + const evm = await createEVM({ common, stateManager: sm }) + // Initialize verkleAccess Witness manually (in real context, it is done by the VM, but we are bypassing that here) + evm.verkleAccessWitness = new VerkleAccessWitness({ + verkleCrypto: verkle, + }) + const code = hexToBytes('0x6001600255') // PUSH1 01 PUSH1 02 SSTORE + const res = await evm.runCall({ + code, + caller: address, + to: address, + gasLimit: BigInt(5), // too little gas for bytecode + gasPrice: BigInt(1), + }) + const writtenChunks = Array.from(evm.verkleAccessWitness.chunks.entries()).filter( + ([_, chunk]) => chunk.write !== undefined, + ) + assert.ok(writtenChunks.length === 0) + assert.equal(res.execResult.exceptionError?.error, 'out of gas') + }) + + it('access witness should contain a write access', async () => { + // This tests executes some very simple bytecode that stores the value 1 in slot 2 + const common = new Common({ + chain: Mainnet, + customCrypto: { verkle }, + eips: [6800], + hardfork: Hardfork.Cancun, + }) + const trie = await createVerkleTree() + const sm = new StatefulVerkleStateManager({ common, trie }) + const address = createAddressFromString('0x9e5ef720fa2cdfa5291eb7e711cfd2e62196f4b3') + const account = createAccount({ nonce: 3n, balance: 0xffffffffn }) + await sm.putAccount(address, account) + const evm = await createEVM({ common, stateManager: sm }) + // Initialize verkleAccess Witness manually (in real context, it is done by the VM, but we are bypassing that here) + evm.verkleAccessWitness = new VerkleAccessWitness({ + verkleCrypto: verkle, + }) + const code = hexToBytes('0x6001600255') // PUSH1 01 PUSH1 02 SSTORE + const res = await evm.runCall({ + code, + caller: address, + to: address, + gasLimit: BigInt(21000), // sufficient gas for bytecode + gasPrice: BigInt(1), + }) + const writtenChunks = Array.from(evm.verkleAccessWitness.chunks.entries()).filter( + ([_, chunk]) => chunk.write !== undefined, + ) + assert.ok(writtenChunks.length === 1) + assert.equal(res.execResult.exceptionError?.error, undefined) + }) }) diff --git a/packages/statemanager/src/statefulVerkleStateManager.ts b/packages/statemanager/src/statefulVerkleStateManager.ts index 6f435233d9..80e645e84e 100644 --- a/packages/statemanager/src/statefulVerkleStateManager.ts +++ b/packages/statemanager/src/statefulVerkleStateManager.ts @@ -218,6 +218,9 @@ export class StatefulVerkleStateManager implements StateManagerInterface { }, {}) this._postState = postState + + this._debug(`initVerkleExecutionWitness preState=${JSON.stringify(this._preState)}`) + this._debug(`initVerkleExecutionWitness postState=${JSON.stringify(this._postState)}`) } /** @@ -315,7 +318,7 @@ export class StatefulVerkleStateManager implements StateManagerInterface { chunkStems[0], chunkSuffixes.slice( 0, - codeChunks.length <= VERKLE_CODE_OFFSET ? codeChunks.length : VERKLE_CODE_OFFSET, + chunkSuffixes.length <= VERKLE_CODE_OFFSET ? chunkSuffixes.length : VERKLE_CODE_OFFSET, ), codeChunks.slice( 0, @@ -395,13 +398,16 @@ export class StatefulVerkleStateManager implements StateManagerInterface { for (let x = 0; x < chunks.length; x++) { if (chunks[x] === undefined) throw new Error(`expected code chunk at ID ${x}, got undefined`) + let lastChunkByteIndex = VERKLE_CODE_CHUNK_SIZE // Determine code ending byte (if we're on the last chunk) - let sliceEnd = 32 if (x === chunks.length - 1) { - // On the last chunk, the end of the slice is either codeSize (if only one chunk) or codeSize % chunkSize - sliceEnd = (x === 0 ? codeSize : codeSize % VERKLE_CODE_CHUNK_SIZE) + 1 + // On the last chunk, the slice either ends on a partial chunk (if codeSize doesn't exactly fit in full chunks), or a full chunk + lastChunkByteIndex = codeSize % VERKLE_CODE_CHUNK_SIZE || VERKLE_CODE_CHUNK_SIZE } - code.set(chunks[x]!.slice(1, sliceEnd), code.byteOffset + x * VERKLE_CODE_CHUNK_SIZE) + code.set( + chunks[x]!.slice(1, lastChunkByteIndex + 1), + code.byteOffset + x * VERKLE_CODE_CHUNK_SIZE, + ) } this._caches?.code?.put(address, code) @@ -595,10 +601,14 @@ export class StatefulVerkleStateManager implements StateManagerInterface { // we can only compare the actual code because to compare the first byte would // be very tricky and impossible in certain scenarios like when the previous code chunk // was not accessed and hence not even provided in the witness + // We are left-padding with two zeroes to get a 32-byte length, but these bytes should not be considered reliable return bytesToHex( - setLengthRight( - code.slice(codeOffset, codeOffset + VERKLE_CODE_CHUNK_SIZE), - VERKLE_CODE_CHUNK_SIZE, + setLengthLeft( + setLengthRight( + code.slice(codeOffset, codeOffset + VERKLE_CODE_CHUNK_SIZE), + VERKLE_CODE_CHUNK_SIZE, + ), + VERKLE_CODE_CHUNK_SIZE + 1, ), ) } @@ -642,12 +652,12 @@ export class StatefulVerkleStateManager implements StateManagerInterface { const { chunkKey } = accessedState accessedChunks.set(chunkKey, true) - const computedValue: PrefixedHexString | null | undefined = + let computedValue: PrefixedHexString | null | undefined = await this.getComputedValue(accessedState) if (computedValue === undefined) { this.DEBUG && this._debug( - `Block accesses missing in canonical address=${address} type=${type} ${extraMeta} chunkKey=${chunkKey}`, + `Missing computed value for address=${address} type=${type} ${extraMeta} chunkKey=${chunkKey}`, ) postFailures++ continue @@ -658,7 +668,7 @@ export class StatefulVerkleStateManager implements StateManagerInterface { if (canonicalValue === undefined) { this.DEBUG && this._debug( - `Block accesses missing in canonical address=${address} type=${type} ${extraMeta} chunkKey=${chunkKey}`, + `Block accesses missing from postState for address=${address} type=${type} ${extraMeta} chunkKey=${chunkKey}`, ) postFailures++ continue @@ -667,7 +677,7 @@ export class StatefulVerkleStateManager implements StateManagerInterface { // if the access type is code, then we can't match the first byte because since the computed value // doesn't has the first byte for push data since previous chunk code itself might not be available if (accessedState.type === VerkleAccessedStateType.Code) { - // computedValue = computedValue !== null ? `0x${computedValue.slice(4)}` : null + computedValue = computedValue !== null ? `0x${computedValue.slice(4)}` : null canonicalValue = canonicalValue !== null ? `0x${canonicalValue.slice(4)}` : null } else if ( accessedState.type === VerkleAccessedStateType.Storage && @@ -677,6 +687,7 @@ export class StatefulVerkleStateManager implements StateManagerInterface { canonicalValue = ZEROVALUE } + this._debug(`computed ${computedValue} canonical ${canonicalValue}`) if (computedValue !== canonicalValue) { if (type === VerkleAccessedStateType.BasicData) { this.DEBUG && diff --git a/packages/tx/src/4844/tx.ts b/packages/tx/src/4844/tx.ts index f1af09dc11..f8082b5148 100644 --- a/packages/tx/src/4844/tx.ts +++ b/packages/tx/src/4844/tx.ts @@ -15,7 +15,6 @@ import * as EIP1559 from '../capabilities/eip1559.js' import * as EIP2718 from '../capabilities/eip2718.js' import * as EIP2930 from '../capabilities/eip2930.js' import * as Legacy from '../capabilities/legacy.js' -import { LIMIT_BLOBS_PER_TX } from '../constants.js' import { getBaseJSON, sharedConstructor, valueBoundaryCheck } from '../features/util.js' import { TransactionType } from '../types.js' import { AccessLists, validateNotArray } from '../util.js' @@ -172,13 +171,17 @@ export class Blob4844Tx implements TransactionInterface LIMIT_BLOBS_PER_TX) { - const msg = Legacy.errorMsg(this, `tx can contain at most ${LIMIT_BLOBS_PER_TX} blobs`) + + const limitBlobsPerTx = + this.common.param('maxBlobGasPerBlock') / this.common.param('blobGasPerBlob') + if (this.blobVersionedHashes.length > limitBlobsPerTx) { + const msg = Legacy.errorMsg(this, `tx can contain at most ${limitBlobsPerTx} blobs`) throw new Error(msg) } else if (this.blobVersionedHashes.length === 0) { const msg = Legacy.errorMsg(this, `tx should contain at least one blob`) throw new Error(msg) } + if (this.to === undefined) { const msg = Legacy.errorMsg( this, diff --git a/packages/tx/src/capabilities/legacy.ts b/packages/tx/src/capabilities/legacy.ts index be56064168..39813721e9 100644 --- a/packages/tx/src/capabilities/legacy.ts +++ b/packages/tx/src/capabilities/legacy.ts @@ -2,6 +2,7 @@ import { Address, BIGINT_0, SECP256K1_ORDER_DIV_2, + bigIntMax, bigIntToUnpaddedBytes, bytesToHex, ecrecover, @@ -167,8 +168,20 @@ export function getValidationErrors(tx: LegacyTxInterface): string[] { errors.push('Invalid Signature') } - if (tx.getIntrinsicGas() > tx.gasLimit) { - errors.push(`gasLimit is too low. given ${tx.gasLimit}, need at least ${tx.getIntrinsicGas()}`) + let intrinsicGas = tx.getIntrinsicGas() + if (tx.common.isActivatedEIP(7623)) { + let tokens = 0 + for (let i = 0; i < tx.data.length; i++) { + tokens += tx.data[i] === 0 ? 1 : 4 + } + const floorCost = + tx.common.param('txGas') + tx.common.param('totalCostFloorPerToken') * BigInt(tokens) + intrinsicGas = bigIntMax(intrinsicGas, floorCost) + } + if (intrinsicGas > tx.gasLimit) { + errors.push( + `gasLimit is too low. The gasLimit is lower than the minimum gas limit of ${tx.getIntrinsicGas()}, the gas limit is: ${tx.gasLimit}`, + ) } return errors diff --git a/packages/tx/src/constants.ts b/packages/tx/src/constants.ts index e3f73893f9..828ebb6ba0 100644 --- a/packages/tx/src/constants.ts +++ b/packages/tx/src/constants.ts @@ -3,7 +3,6 @@ export const MAX_CALLDATA_SIZE = 16777216 // 2 ** 24 export const MAX_ACCESS_LIST_SIZE = 16777216 // 2 ** 24 export const MAX_VERSIONED_HASHES_LIST_SIZE = 16777216 // 2 ** 24 -export const LIMIT_BLOBS_PER_TX = 6 // 786432 / 2^17 (`MAX_BLOB_GAS_PER_BLOCK` / `GAS_PER_BLOB`) export const MAX_TX_WRAP_KZG_COMMITMENTS = 16777216 // 2 ** 24 export const FIELD_ELEMENTS_PER_BLOB = 4096 // This is also in the Common 4844 parameters but needed here since types can't access Common params export const BYTES_PER_FIELD_ELEMENT = 32 diff --git a/packages/tx/src/params.ts b/packages/tx/src/params.ts index 66ce2302bb..8b97c8f703 100644 --- a/packages/tx/src/params.ts +++ b/packages/tx/src/params.ts @@ -42,6 +42,14 @@ export const paramsTx: ParamsDict = { . */ 4844: { blobCommitmentVersionKzg: 1, // The number indicated a versioned hash is a KZG commitment + blobGasPerBlob: 131072, // The base fee for blob gas per blob + maxBlobGasPerBlock: 786432, // The max blob gas allowable per block + }, + /** + * Increase calldata cost to reduce maximum block size + */ + 7623: { + totalCostFloorPerToken: 10, }, /** . * Set EOA account code for one transaction @@ -52,4 +60,10 @@ export const paramsTx: ParamsDict = { perAuthBaseGas: 12500, // Gas cost of each authority item, provided the authority exists in the trie perEmptyAccountCost: 25000, // Gas cost of each authority item, in case the authority does not exist in the trie }, + /** + . * Shard Blob Transactions + . */ + 7691: { + maxBlobGasPerBlock: 1179648, // The max blob gas allowable per block + }, } diff --git a/packages/tx/src/util.ts b/packages/tx/src/util.ts index 983111fdae..5a051167a4 100644 --- a/packages/tx/src/util.ts +++ b/packages/tx/src/util.ts @@ -210,8 +210,8 @@ export class AuthorizationLists { if (address.length !== 20) { throw new Error('Invalid EIP-7702 transaction: address length should be 20 bytes') } - if (bytesToBigInt(chainId) > MAX_UINT64) { - throw new Error('Invalid EIP-7702 transaction: chainId exceeds 2^64 - 1') + if (bytesToBigInt(chainId) > MAX_INTEGER) { + throw new Error('Invalid EIP-7702 transaction: chainId exceeds 2^256 - 1') } if (bytesToBigInt(nonce) > MAX_UINT64) { throw new Error('Invalid EIP-7702 transaction: nonce exceeds 2^64 - 1') diff --git a/packages/tx/test/transactionRunner.spec.ts b/packages/tx/test/transactionRunner.spec.ts index 7941133744..4be2980adf 100644 --- a/packages/tx/test/transactionRunner.spec.ts +++ b/packages/tx/test/transactionRunner.spec.ts @@ -14,6 +14,10 @@ const argv = minimist(process.argv.slice(2)) const file: string | undefined = argv.file const forkNames: ForkName[] = [ + 'Prague', + 'Cancun', + 'Shanghai', + 'Paris', 'London+3860', 'London', 'Berlin', @@ -28,7 +32,11 @@ const forkNames: ForkName[] = [ ] const forkNameMap: ForkNamesMap = { + Prague: 'prague', 'London+3860': 'london', + Cancun: 'cancun', + Shanghai: 'shanghai', + Paris: 'paris', London: 'london', Berlin: 'berlin', Istanbul: 'istanbul', diff --git a/packages/tx/test/types.ts b/packages/tx/test/types.ts index f99dfc815a..37fc111f1f 100644 --- a/packages/tx/test/types.ts +++ b/packages/tx/test/types.ts @@ -1,4 +1,8 @@ export type ForkName = + | 'Prague' + | 'Cancun' + | 'Shanghai' + | 'Paris' | 'London+3860' | 'London' | 'Berlin' diff --git a/packages/verkle/src/node/util.ts b/packages/verkle/src/node/util.ts index 80d8459ac8..4213197aa7 100644 --- a/packages/verkle/src/node/util.ts +++ b/packages/verkle/src/node/util.ts @@ -41,7 +41,7 @@ export function isInternalVerkleNode(node: VerkleNode): node is InternalVerkleNo export const createZeroesLeafValue = () => new Uint8Array(32) -export const createDefaultLeafVerkleValues = () => new Array(256).fill(0) +export const createDefaultLeafVerkleValues: () => number[] = () => new Array(256).fill(0) /*** * Converts 128 32byte values of a leaf node into an array of 256 32 byte values representing diff --git a/packages/vm/package.json b/packages/vm/package.json index 44482b319e..11f73f6104 100644 --- a/packages/vm/package.json +++ b/packages/vm/package.json @@ -63,6 +63,7 @@ "@ethereumjs/statemanager": "^3.0.0-alpha.1", "@ethereumjs/tx": "^6.0.0-alpha.1", "@ethereumjs/util": "^10.0.0-alpha.1", + "@ethereumjs/verkle": "^0.2.0-alpha.1", "debug": "^4.3.3", "ethereum-cryptography": "^3.0.0", "eventemitter3": "^5.0.1" diff --git a/packages/vm/src/buildBlock.ts b/packages/vm/src/buildBlock.ts index 60535a28c6..ee5614a99d 100644 --- a/packages/vm/src/buildBlock.ts +++ b/packages/vm/src/buildBlock.ts @@ -232,7 +232,7 @@ export class BlockBuilder { // cannot be greater than the remaining gas in the block const blockGasLimit = toType(this.headerData.gasLimit, TypeOutput.BigInt) - const blobGasLimit = this.vm.common.param('maxblobGasPerBlock') + const blobGasLimit = this.vm.common.param('maxBlobGasPerBlock') const blobGasPerBlob = this.vm.common.param('blobGasPerBlob') const blockGasRemaining = blockGasLimit - this.gasUsed diff --git a/packages/vm/src/params.ts b/packages/vm/src/params.ts index dfaa021cda..96f63b194c 100644 --- a/packages/vm/src/params.ts +++ b/packages/vm/src/params.ts @@ -8,7 +8,7 @@ export const paramsVM: ParamsDict = { // gasConfig maxRefundQuotient: 2, // Maximum refund quotient; max tx refund is min(tx.gasUsed/maxRefundQuotient, tx.gasRefund) blobGasPerBlob: 0, - maxblobGasPerBlock: 0, + maxBlobGasPerBlock: 0, // pow minerReward: '5000000000000000000', // the amount a miner get rewarded for mining a block }, @@ -39,8 +39,9 @@ export const paramsVM: ParamsDict = { */ 2935: { // config - historyStorageAddress: '0x0aae40965e6800cd9b1f4b05ff21581047e3f91e', // The address where the historical blockhashes are stored - historyServeWindow: 8192, // The amount of blocks to be served by the historical blockhash contract + historyStorageAddress: '0x0F792be4B0c0cb4DAE440Ef133E90C0eCD48CCCC', // The address where the historical blockhashes are stored + historyServeWindow: 8191, // The amount of blocks to be served by the historical blockhash contract + systemAddress: '0xfffffffffffffffffffffffffffffffffffffffe', // The system address }, /** . * Reduction in refunds @@ -54,7 +55,7 @@ export const paramsVM: ParamsDict = { . */ 4844: { blobGasPerBlob: 131072, // The base fee for blob gas per blob - maxblobGasPerBlock: 786432, // The max blob gas allowable per block + maxBlobGasPerBlock: 786432, // The max blob gas allowable per block }, /** . * Beacon block root in the EVM @@ -67,10 +68,8 @@ export const paramsVM: ParamsDict = { * Ethereum state using a unified verkle tree (experimental) */ 6800: { - // kaustinen 6 current uses this address, however this will be updated to correct address - // in next iteration // config - historyStorageAddress: '0xfffffffffffffffffffffffffffffffffffffffe', // The address where the historical blockhashes are stored + historyStorageAddress: '0x0aae40965e6800cd9b1f4b05ff21581047e3f91e', // The address where the historical blockhashes are stored }, /** * Execution layer triggerable withdrawals (experimental) @@ -79,7 +78,7 @@ export const paramsVM: ParamsDict = { // config systemAddress: '0xfffffffffffffffffffffffffffffffffffffffe', // The system address to perform operations on the withdrawal requests predeploy address // See: https://github.com/ethereum/EIPs/pull/8934/files - withdrawalRequestPredeployAddress: '0x09Fc772D0857550724b07B850a4323f39112aAaA', // Address of the validator excess address + withdrawalRequestPredeployAddress: '0x0c15F14308530b7CDB8460094BbB9cC28b9AaaAA', // Address of the validator excess address }, /** @@ -89,6 +88,12 @@ export const paramsVM: ParamsDict = { // config systemAddress: '0xfffffffffffffffffffffffffffffffffffffffe', // The system address to perform operations on the consolidation requests predeploy address // See: https://github.com/ethereum/EIPs/pull/8934/files - consolidationRequestPredeployAddress: '0x01aBEa29659e5e97C95107F20bb753cD3e09bBBb', // Address of the consolidations contract + consolidationRequestPredeployAddress: '0x00431F263cE400f4455c2dCf564e53007Ca4bbBb', // Address of the consolidations contract + }, + /** +. * Shard Blob Transactions +. */ + 7691: { + maxBlobGasPerBlock: 1179648, // The max blob gas allowable per block }, } diff --git a/packages/vm/src/runBlock.ts b/packages/vm/src/runBlock.ts index 424d373491..0d8c1f122f 100644 --- a/packages/vm/src/runBlock.ts +++ b/packages/vm/src/runBlock.ts @@ -19,7 +19,6 @@ import { concatBytes, createAddressFromString, equalsBytes, - getVerkleTreeIndicesForStorageSlot, hexToBytes, intToBytes, setLengthLeft, @@ -143,6 +142,9 @@ export async function runBlock(vm: VM, opts: RunBlockOpts): Promise { let account = await evm.stateManager.getAccount(address) if (account === undefined) { - if (common?.isActivatedEIP(6800) === true) { - if (evm.verkleAccessWitness === undefined) { + if (common.isActivatedEIP(6800) === true && reward !== BIGINT_0) { + if (evm.systemVerkleAccessWitness === undefined) { throw Error(`verkleAccessWitness required if verkle (EIP-6800) is activated`) } - evm.verkleAccessWitness.touchAndChargeProofOfAbsence(address) + evm.systemVerkleAccessWitness.writeAccountHeader(address) } account = new Account() } account.balance += reward await evm.journal.putAccount(address, account) - if (common?.isActivatedEIP(6800) === true) { - if (evm.verkleAccessWitness === undefined) { + if (common.isActivatedEIP(6800) === true && reward !== BIGINT_0) { + if (evm.systemVerkleAccessWitness === undefined) { throw Error(`verkleAccessWitness required if verkle (EIP-6800) is activated`) } // use vm utility to build access but the computed gas is not charged and hence free - evm.verkleAccessWitness.touchTxTargetAndComputeGas(address, { - sendsValue: true, - }) + evm.systemVerkleAccessWitness.writeAccountBasicData(address) + evm.systemVerkleAccessWitness.readAccountCodeHash(address) } return account } diff --git a/packages/vm/src/runTx.ts b/packages/vm/src/runTx.ts index 3697f810ad..fa4d6565a7 100644 --- a/packages/vm/src/runTx.ts +++ b/packages/vm/src/runTx.ts @@ -12,6 +12,7 @@ import { KECCAK256_NULL, MAX_UINT64, SECP256K1_ORDER_DIV_2, + bigIntMax, bytesToBigInt, bytesToHex, bytesToUnprefixedHex, @@ -249,11 +250,24 @@ async function _runTx(vm: VM, opts: RunTxOpts): Promise { // Validate gas limit against tx base fee (DataFee + TxFee + Creation Fee) const intrinsicGas = tx.getIntrinsicGas() + let floorCost = BIGINT_0 + + if (vm.common.isActivatedEIP(7623)) { + // Tx should at least cover the floor price for tx data + let tokens = 0 + for (let i = 0; i < tx.data.length; i++) { + tokens += tx.data[i] === 0 ? 1 : 4 + } + floorCost = + tx.common.param('txGas') + tx.common.param('totalCostFloorPerToken') * BigInt(tokens) + } + let gasLimit = tx.gasLimit - if (gasLimit < intrinsicGas) { + const minGasLimit = bigIntMax(intrinsicGas, floorCost) + if (gasLimit < minGasLimit) { const msg = _errorMsg( `tx gas limit ${Number(gasLimit)} is lower than the minimum gas limit of ${Number( - intrinsicGas, + minGasLimit, )}`, vm, block, @@ -621,7 +635,7 @@ async function _runTx(vm: VM, opts: RunTxOpts): Promise { // Process any gas refund gasRefund += results.execResult.gasRefund ?? BIGINT_0 - results.gasRefund = gasRefund + results.gasRefund = gasRefund // TODO: this field could now be incorrect with the introduction of 7623 const maxRefundQuotient = vm.common.param('maxRefundQuotient') if (gasRefund !== BIGINT_0) { const maxRefund = results.totalGasSpent / maxRefundQuotient @@ -635,6 +649,19 @@ async function _runTx(vm: VM, opts: RunTxOpts): Promise { debug(`No tx gasRefund`) } } + + if (vm.common.isActivatedEIP(7623)) { + if (results.totalGasSpent < floorCost) { + if (vm.DEBUG) { + debugGas( + `tx floorCost ${floorCost} is higher than to total execution gas spent (-> ${results.totalGasSpent}), setting floor as gas paid`, + ) + } + results.gasRefund = BIGINT_0 + results.totalGasSpent = floorCost + } + } + results.amountSpent = results.totalGasSpent * gasPrice // Update sender's balance @@ -661,14 +688,16 @@ async function _runTx(vm: VM, opts: RunTxOpts): Promise { } let minerAccount = await state.getAccount(miner) + const minerAccountExists = minerAccount !== undefined if (minerAccount === undefined) { if (vm.common.isActivatedEIP(6800)) { if (vm.evm.verkleAccessWitness === undefined) { throw Error(`verkleAccessWitness required if verkle (EIP-6800) is activated`) } - vm.evm.verkleAccessWitness.touchAndChargeProofOfAbsence(miner) } minerAccount = new Account() + // Add the miner account to the system verkle access witness + vm.evm.systemVerkleAccessWitness?.writeAccountHeader(miner) } // add the amount spent on gas to the miner's account results.minerValue = vm.common.isActivatedEIP(1559) @@ -676,14 +705,17 @@ async function _runTx(vm: VM, opts: RunTxOpts): Promise { : results.amountSpent minerAccount.balance += results.minerValue - if (vm.common.isActivatedEIP(6800)) { + if (vm.common.isActivatedEIP(6800) && results.minerValue !== BIGINT_0) { if (vm.evm.verkleAccessWitness === undefined) { throw Error(`verkleAccessWitness required if verkle (EIP-6800) is activated`) } - // use vm utility to build access but the computed gas is not charged and hence free - vm.evm.verkleAccessWitness.touchTxTargetAndComputeGas(miner, { - sendsValue: true, - }) + if (minerAccountExists) { + // use vm utility to build access but the computed gas is not charged and hence free + vm.evm.verkleAccessWitness.writeAccountBasicData(miner) + vm.evm.verkleAccessWitness.readAccountCodeHash(miner) + } else { + vm.evm.verkleAccessWitness.writeAccountHeader(miner) + } } // Put the miner account into the state. If the balance of the miner account remains zero, note that @@ -802,6 +834,11 @@ async function _runTx(vm: VM, opts: RunTxOpts): Promise { ) } + if (vm.common.isActivatedEIP(6800)) { + // commit all access witness changes + vm.evm.verkleAccessWitness?.commit() + } + return results } diff --git a/packages/vm/test/api/EIPs/eip-7002.spec.ts b/packages/vm/test/api/EIPs/eip-7002.spec.ts index 35d064686d..40d8838100 100644 --- a/packages/vm/test/api/EIPs/eip-7002.spec.ts +++ b/packages/vm/test/api/EIPs/eip-7002.spec.ts @@ -32,11 +32,11 @@ const deploymentTxData = { gasLimit: BigInt('0x3d090'), gasPrice: BigInt('0xe8d4a51000'), data: hexToBytes( - '0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5f556101f480602d5f395ff33373fffffffffffffffffffffffffffffffffffffffe1460c7573615156028575f545f5260205ff35b36603814156101f05760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f057600182026001905f5b5f821115608057810190830284830290049160010191906065565b9093900434106101f057600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160db575060105b5f5b81811461017f5780604c02838201600302600401805490600101805490600101549160601b83528260140152807fffffffffffffffffffffffffffffffff0000000000000000000000000000000016826034015260401c906044018160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160dd565b9101809214610191579060025561019c565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101c957505f5b6001546002828201116101de5750505f6101e4565b01600290035b5f555f600155604c025ff35b5f5ffd', + '0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5f556101f880602d5f395ff33373fffffffffffffffffffffffffffffffffffffffe1460cb5760115f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff146101f457600182026001905f5b5f82111560685781019083028483029004916001019190604d565b909390049250505036603814608857366101f457346101f4575f5260205ff35b34106101f457600154600101600155600354806003026004013381556001015f35815560010160203590553360601b5f5260385f601437604c5fa0600101600355005b6003546002548082038060101160df575060105b5f5b8181146101835782810160030260040181604c02815460601b8152601401816001015481526020019060020154807fffffffffffffffffffffffffffffffff00000000000000000000000000000000168252906010019060401c908160381c81600701538160301c81600601538160281c81600501538160201c81600401538160181c81600301538160101c81600201538160081c81600101535360010160e1565b910180921461019557906002556101a0565b90505f6002555f6003555b5f54807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14156101cd57505f5b6001546002828201116101e25750505f6101e8565b01600290035b5f555f600155604c025ff35b5f5ffd', ), v: BigInt('0x1b'), r: BigInt('0x539'), - s: BigInt('0x10e740537d4d36b9'), + s: BigInt('0xeb793ed1dcd82833'), } const deploymentTx = createLegacyTx(deploymentTxData) diff --git a/packages/vm/test/api/EIPs/eip-7623.spec.ts b/packages/vm/test/api/EIPs/eip-7623.spec.ts new file mode 100644 index 0000000000..f362cb8b66 --- /dev/null +++ b/packages/vm/test/api/EIPs/eip-7623.spec.ts @@ -0,0 +1,125 @@ +import { createBlock } from '@ethereumjs/block' +import { Common, Hardfork, Mainnet } from '@ethereumjs/common' +import { createLegacyTx } from '@ethereumjs/tx' +import { Account, Address, createZeroAddress, hexToBytes, privateToAddress } from '@ethereumjs/util' +import { assert, describe, it } from 'vitest' + +import { createVM, runTx } from '../../../src/index.js' + +const common = new Common({ chain: Mainnet, hardfork: Hardfork.Prague }) + +const pkey = hexToBytes(`0x${'20'.repeat(32)}`) +const GWEI = BigInt(1000000000) +const sender = new Address(privateToAddress(pkey)) + +const coinbase = new Address(hexToBytes(`0x${'ff'.repeat(20)}`)) + +const block = createBlock( + { + header: { + baseFeePerGas: 7, + coinbase, + }, + }, + { common }, +) + +const code = hexToBytes('0x60008080806001415AF100') +const contractAddress = new Address(hexToBytes(`0x${'ee'.repeat(20)}`)) + +async function getVM(common: Common) { + const vm = await createVM({ common }) + await vm.stateManager.putAccount(sender, new Account()) + const account = await vm.stateManager.getAccount(sender) + const balance = GWEI * BigInt(21000) * BigInt(10000000) + account!.balance = balance + await vm.stateManager.putAccount(sender, account!) + + await vm.stateManager.putCode(contractAddress, code) + return vm +} + +describe('EIP 7623 calldata cost increase tests', () => { + it('charges floor gas', async () => { + const vm = await getVM(common) + + const tx = createLegacyTx( + { + to: createZeroAddress(), + data: new Uint8Array(100).fill(1), + gasLimit: 1000000, + gasPrice: 10, + }, + { common }, + ).sign(pkey) + + const result = await runTx(vm, { + block, + tx, + skipHardForkValidation: true, + }) + + const baseCost = tx.common.param('txGas') + const floorCost = tx.common.param('totalCostFloorPerToken') + + const expected = baseCost + BigInt(tx.data.length) * BigInt(4) * floorCost + + assert.equal(result.totalGasSpent, expected) + }) + it('rejects transactions having a gas limit below the floor gas limit', async () => { + const vm = await getVM(common) + + const tx = createLegacyTx( + { + to: createZeroAddress(), + data: new Uint8Array(100).fill(1), + gasLimit: 21000 + 100 * 4, + gasPrice: 10, + }, + { common }, + ).sign(pkey) + try { + await runTx(vm, { + block, + tx, + skipHardForkValidation: true, + }) + assert.fail('runTx should throw') + } catch (e) { + assert.ok('Successfully failed') + } + }) + it('correctly charges execution gas instead of floor gas when execution gas exceeds the floor gas', async () => { + const vm = await getVM(common) + const to = createZeroAddress() + + // Store 1 in slot 1 + await vm.stateManager.putCode(to, hexToBytes('0x6001600155')) + + const tx = createLegacyTx( + { + to: createZeroAddress(), + data: new Uint8Array(100).fill(1), + gasLimit: 1000000, + gasPrice: 10, + }, + { common }, + ).sign(pkey) + + const result = await runTx(vm, { + block, + tx, + skipHardForkValidation: true, + }) + + const baseCost = tx.common.param('txGas') + + const expected = + baseCost + + BigInt(tx.data.length) * tx.common.param('txDataNonZeroGas') + + BigInt(2 * 3) + + BigInt(22_100) + + assert.equal(result.totalGasSpent, expected) + }) +}) diff --git a/packages/vm/test/api/EIPs/eip-7685.spec.ts b/packages/vm/test/api/EIPs/eip-7685.spec.ts index 99b0f4c2d2..9be6ec60fa 100644 --- a/packages/vm/test/api/EIPs/eip-7685.spec.ts +++ b/packages/vm/test/api/EIPs/eip-7685.spec.ts @@ -1,7 +1,7 @@ import { createBlock, genRequestsRoot } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { Common, Hardfork, Mainnet } from '@ethereumjs/common' -import { createCLRequest, hexToBytes } from '@ethereumjs/util' +import { createCLRequest, equalsBytes, hexToBytes } from '@ethereumjs/util' import { sha256 } from 'ethereum-cryptography/sha256' import { assert, describe, expect, it } from 'vitest' @@ -31,6 +31,9 @@ describe('EIP-7685 runBlock tests', () => { generate: true, }) assert.equal(res.gasUsed, 0n) + // Verify that if the requests are empty, the byte-types are not appended to the to-be-hashed flat array + // I.e. the flat array to-be-hashed is not `0x 00 01 02`, but is now the empty bytes array, `0x` + assert.ok(equalsBytes(res.requestsHash!, sha256(new Uint8Array()))) }) it('should error when an invalid requestsHash is provided', async () => { const vm = await setupVM({ common }) diff --git a/packages/vm/test/api/EIPs/eip-7702.spec.ts b/packages/vm/test/api/EIPs/eip-7702.spec.ts index 9acc136e7e..72adf7a816 100644 --- a/packages/vm/test/api/EIPs/eip-7702.spec.ts +++ b/packages/vm/test/api/EIPs/eip-7702.spec.ts @@ -25,6 +25,9 @@ import type { VM } from '../../../src/index.js' import type { AuthorizationListBytesItem } from '@ethereumjs/tx' import type { PrefixedHexString } from '@ethereumjs/util' +// EIP-7702 code designator. If code starts with these bytes, it is a 7702-delegated address +const eip7702Designator = hexToBytes('0xef01') + const common = new Common({ chain: Mainnet, hardfork: Hardfork.Cancun, eips: [7702] }) const defaultAuthPkey = hexToBytes(`0x${'20'.repeat(32)}`) @@ -248,21 +251,21 @@ describe('test EIP-7702 opcodes', () => { { // PUSH20 EXTCODESIZE PUSH0 SSTORE STOP code: `0x73${defaultAuthAddr.toString().slice(2)}3b5f5500`, - expectedStorage: bigIntToUnpaddedBytes(BigInt(randomCode.length)), + expectedStorage: bigIntToUnpaddedBytes(BigInt(eip7702Designator.length)), name: 'EXTCODESIZE', }, // EXTCODEHASH { // PUSH20 EXTCODEHASH PUSH0 SSTORE STOP code: `0x73${defaultAuthAddr.toString().slice(2)}3f5f5500`, - expectedStorage: keccak256(randomCode), + expectedStorage: keccak256(eip7702Designator), name: 'EXTCODEHASH', }, // EXTCODECOPY { // PUSH1 32 PUSH0 PUSH0 PUSH20 EXTCODEHASH PUSH0 MLOAD PUSH0 SSTORE STOP code: `0x60205f5f73${defaultAuthAddr.toString().slice(2)}3c5f515f5500`, - expectedStorage: setLengthRight(randomCode, 32), + expectedStorage: setLengthRight(eip7702Designator, 32), name: 'EXTCODECOPY', }, ] diff --git a/packages/vm/test/t8n/t8ntool.ts b/packages/vm/test/t8n/t8ntool.ts index 19605a8fe1..bfb93d3b79 100644 --- a/packages/vm/test/t8n/t8ntool.ts +++ b/packages/vm/test/t8n/t8ntool.ts @@ -171,6 +171,9 @@ export class TransitionTool { for (const txData of this.txsData) { try { const tx = createTx(txData, { common: this.common }) + if (!tx.isValid()) { + throw new Error(tx.getValidationErrors().join(', ')) + } // Set `allowNoBlobs` to `true`, since the test might not have the blob // The 4844-tx at this should still be valid, since it has the `blobHashes` field await builder.addTransaction(tx, { allowNoBlobs: true }) @@ -303,7 +306,12 @@ export class TransitionTool { if (requests !== undefined) { // NOTE: EEST currently wants the raw request bytes, **excluding** the type - output.requests = requests.map((request) => bytesToHex(request.bytes.slice(1))) + output.requests = [] + for (const request of requests) { + if (request.bytes.length > 1) { + output.requests.push(bytesToHex(request.bytes.slice(1))) + } + } } if (this.rejected.length > 0) { diff --git a/packages/vm/test/tester/config.ts b/packages/vm/test/tester/config.ts index 608dcb2752..71aa1d4f9b 100644 --- a/packages/vm/test/tester/config.ts +++ b/packages/vm/test/tester/config.ts @@ -108,6 +108,7 @@ const normalHardforks = [ 'arrowGlacier', // This network has no tests, but need to add it due to common generation logic 'cancun', 'prague', + 'osaka', ] const transitionNetworks = {