From 94d72e5fe0d04b0e03c829ed1d53771683fc7fb4 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Fri, 15 Nov 2024 03:50:22 -0700 Subject: [PATCH] common: rename verkleCrypto to verkle in common customCrypto (#3797) * common: rename verkleCrypto to verkle in common customCrypto * verkle: ci fixes * verkle: fix example --- .../client/test/rpc/engine/kaustinen6.spec.ts | 10 +++++-- packages/common/src/types.ts | 2 +- packages/evm/src/verkleAccessWitness.ts | 13 +++++++-- packages/evm/test/verkle.spec.ts | 2 +- .../src/statefulVerkleStateManager.ts | 11 +++++--- .../src/statelessVerkleStateManager.ts | 4 +-- .../test/statefulVerkleStateManager.spec.ts | 16 +++++++---- .../test/statelessVerkleStateManager.spec.ts | 14 +++++----- packages/verkle/test/internalNode.spec.ts | 5 +++- packages/verkle/test/interop.spec.ts | 10 +++++-- packages/verkle/test/proof.spec.ts | 5 +++- packages/verkle/test/verkle.spec.ts | 5 +++- packages/vm/src/runBlock.ts | 8 ++++-- .../vm/test/api/EIPs/eip-6800-verkle.spec.ts | 4 +-- packages/vm/test/api/runBlock.spec.ts | 28 +++++++++++++++---- 15 files changed, 95 insertions(+), 42 deletions(-) diff --git a/packages/client/test/rpc/engine/kaustinen6.spec.ts b/packages/client/test/rpc/engine/kaustinen6.spec.ts index 464cb14982..bf03ffc450 100644 --- a/packages/client/test/rpc/engine/kaustinen6.spec.ts +++ b/packages/client/test/rpc/engine/kaustinen6.spec.ts @@ -62,7 +62,9 @@ async function runBlock( const parentPayload = isBeaconData === true ? executionPayloadFromBeaconPayload(parent as any) : parent - const parentBlock = await createBlockFromExecutionPayload(parentPayload, { common }) + const parentBlock = await createBlockFromExecutionPayload(parentPayload, { + common, + }) blockCache.remoteBlocks.set(parentPayload.blockHash.slice(2), parentBlock) blockCache.executedBlocks.set(parentPayload.blockHash.slice(2), parentBlock) @@ -81,7 +83,7 @@ describe(`valid verkle network setup`, async () => { const { server, chain, common } = await setupChain(kaustinen6Data, 'post-merge', { engine: true, genesisStateRoot: genesisVerkleStateRoot, - customCrypto: { verkleCrypto: verkle }, + customCrypto: { verkle }, }) const rpc = getRPCClient(server) it('genesis should be correctly setup', async () => { @@ -148,7 +150,9 @@ describe(`valid verkle network setup`, async () => { if (process.env.TEST_GETH_VEC_DIR !== undefined) { // eslint-disable-next-line @typescript-eslint/no-use-before-define - const gethVectors = await loadGethVectors(process.env.TEST_GETH_VEC_DIR, { common }) + const gethVectors = await loadGethVectors(process.env.TEST_GETH_VEC_DIR, { + common, + }) let parent = gethVectors[0] for (let i = 1; i < gethVectors.length; i++) { const execute = gethVectors[i] diff --git a/packages/common/src/types.ts b/packages/common/src/types.ts index ed6bc980fd..9ea7c68008 100644 --- a/packages/common/src/types.ts +++ b/packages/common/src/types.ts @@ -95,7 +95,7 @@ export interface CustomCrypto { ecdsaSign?: (msg: Uint8Array, pk: Uint8Array) => { signature: Uint8Array; recid: number } ecdsaRecover?: (sig: Uint8Array, recId: number, hash: Uint8Array) => Uint8Array kzg?: KZG - verkleCrypto?: VerkleCrypto + verkle?: VerkleCrypto } export interface BaseOpts { diff --git a/packages/evm/src/verkleAccessWitness.ts b/packages/evm/src/verkleAccessWitness.ts index 3f51d64b4e..be83cbaba2 100644 --- a/packages/evm/src/verkleAccessWitness.ts +++ b/packages/evm/src/verkleAccessWitness.ts @@ -153,7 +153,9 @@ export class VerkleAccessWitness implements VerkleAccessWitnessInterface { treeIndex: number | bigint, subIndex: number | Uint8Array, ): bigint { - return this.touchAddressAndChargeGas(address, treeIndex, subIndex, { isWrite: true }) + return this.touchAddressAndChargeGas(address, treeIndex, subIndex, { + isWrite: true, + }) } touchAddressOnReadAndComputeGas( @@ -161,7 +163,9 @@ export class VerkleAccessWitness implements VerkleAccessWitnessInterface { treeIndex: number | bigint, subIndex: number | Uint8Array, ): bigint { - return this.touchAddressAndChargeGas(address, treeIndex, subIndex, { isWrite: false }) + return this.touchAddressAndChargeGas(address, treeIndex, subIndex, { + isWrite: false, + }) } touchAddressAndChargeGas( @@ -327,7 +331,10 @@ export function decodeAccessedState( return { type: VerkleAccessedStateType.Storage, slot } } else if (position >= VERKLE_CODE_OFFSET && position < VERKLE_MAIN_STORAGE_OFFSET) { const codeChunkIdx = Number(position) - VERKLE_CODE_OFFSET - return { type: VerkleAccessedStateType.Code, codeOffset: codeChunkIdx * 31 } + return { + type: VerkleAccessedStateType.Code, + codeOffset: codeChunkIdx * 31, + } } else if (position >= VERKLE_MAIN_STORAGE_OFFSET) { const slot = BigInt(position - VERKLE_MAIN_STORAGE_OFFSET) return { type: VerkleAccessedStateType.Storage, slot } diff --git a/packages/evm/test/verkle.spec.ts b/packages/evm/test/verkle.spec.ts index 24689af3a5..67452ba197 100644 --- a/packages/evm/test/verkle.spec.ts +++ b/packages/evm/test/verkle.spec.ts @@ -18,7 +18,7 @@ describe('verkle tests', () => { // This tests executes some very simple bytecode that stores the value 1 in slot 2 const common = new Common({ chain: Mainnet, - customCrypto: { verkleCrypto: verkle }, + customCrypto: { verkle }, eips: [6800], hardfork: Hardfork.Cancun, }) diff --git a/packages/statemanager/src/statefulVerkleStateManager.ts b/packages/statemanager/src/statefulVerkleStateManager.ts index 4d437a9c1f..6d4bfe681c 100644 --- a/packages/statemanager/src/statefulVerkleStateManager.ts +++ b/packages/statemanager/src/statefulVerkleStateManager.ts @@ -93,7 +93,7 @@ export class StatefulVerkleStateManager implements StateManagerInterface { throw new Error('EIP-6800 required for verkle state management') } - if (opts.common.customCrypto.verkleCrypto === undefined) { + if (opts.common.customCrypto.verkle === undefined) { throw new Error('verkle crypto required') } @@ -101,7 +101,7 @@ export class StatefulVerkleStateManager implements StateManagerInterface { this._trie = opts.trie ?? new VerkleTree({ - verkleCrypto: opts.common.customCrypto.verkleCrypto, + verkleCrypto: opts.common.customCrypto.verkle, db: new MapDB(), useRootPersistence: false, cacheSize: 0, @@ -110,7 +110,7 @@ export class StatefulVerkleStateManager implements StateManagerInterface { this.originalStorageCache = new OriginalStorageCache(this.getStorage.bind(this)) this._caches = opts.caches this.keccakFunction = opts.common.customCrypto.keccak256 ?? keccak256 - this.verkleCrypto = opts.common.customCrypto.verkleCrypto + this.verkleCrypto = opts.common.customCrypto.verkle } /** @@ -329,7 +329,10 @@ export class StatefulVerkleStateManager implements StateManagerInterface { codeChunks.slice(sliceStart, sliceEnd), ) } - await this.modifyAccountFields(address, { codeHash, codeSize: value.length }) + await this.modifyAccountFields(address, { + codeHash, + codeSize: value.length, + }) } getCode = async (address: Address): Promise => { diff --git a/packages/statemanager/src/statelessVerkleStateManager.ts b/packages/statemanager/src/statelessVerkleStateManager.ts index 900b1e0594..18c8bb6fbb 100644 --- a/packages/statemanager/src/statelessVerkleStateManager.ts +++ b/packages/statemanager/src/statelessVerkleStateManager.ts @@ -119,13 +119,13 @@ export class StatelessVerkleStateManager implements StateManagerInterface { throw new Error('EIP-6800 required for stateless verkle state management') } - if (opts.common.customCrypto.verkleCrypto === undefined) { + if (opts.common.customCrypto.verkle === undefined) { throw new Error('verkle crypto required') } this.common = opts.common this.keccakFunction = opts.common.customCrypto.keccak256 ?? keccak256 - this.verkleCrypto = opts.common.customCrypto.verkleCrypto + this.verkleCrypto = opts.common.customCrypto.verkle this._debug = debugDefault('statemanager:verkle:stateless') diff --git a/packages/statemanager/test/statefulVerkleStateManager.spec.ts b/packages/statemanager/test/statefulVerkleStateManager.spec.ts index 54e0de0c2c..e6df97a87c 100644 --- a/packages/statemanager/test/statefulVerkleStateManager.spec.ts +++ b/packages/statemanager/test/statefulVerkleStateManager.spec.ts @@ -25,7 +25,7 @@ describe('Verkle Tree API tests', () => { const common = new Common({ chain: Mainnet, eips: [6800], - customCrypto: { verkleCrypto: verkle }, + customCrypto: { verkle }, }) const sm = new StatefulVerkleStateManager({ common, trie }) const address = createAddressFromString('0x9e5ef720fa2cdfa5291eb7e711cfd2e62196f4b3') @@ -44,7 +44,7 @@ describe('Verkle Tree API tests', () => { const common = new Common({ chain: Mainnet, eips: [6800], - customCrypto: { verkleCrypto: verkle }, + customCrypto: { verkle }, }) const sm = new StatefulVerkleStateManager({ common, trie }) @@ -70,7 +70,7 @@ describe('Verkle Tree API tests', () => { const common = new Common({ chain: Mainnet, eips: [6800], - customCrypto: { verkleCrypto: verkle }, + customCrypto: { verkle }, }) const sm = new StatefulVerkleStateManager({ common, trie }) const address = createAddressFromString('0x9e5ef720fa2cdfa5291eb7e711cfd2e62196f4b3') @@ -104,7 +104,7 @@ describe('Verkle Tree API tests', () => { const common = new Common({ chain: Mainnet, eips: [6800], - customCrypto: { verkleCrypto: verkle }, + customCrypto: { verkle }, }) const sm = new StatefulVerkleStateManager({ common, trie }) const address = createAddressFromString('0x9e5ef720fa2cdfa5291eb7e711cfd2e62196f4b3') @@ -121,9 +121,13 @@ describe('caching functionality works', () => { const common = new Common({ chain: Mainnet, eips: [6800], - customCrypto: { verkleCrypto: verkle }, + customCrypto: { verkle }, + }) + const sm = new StatefulVerkleStateManager({ + common, + trie, + caches: new Caches(), }) - const sm = new StatefulVerkleStateManager({ common, trie, caches: new Caches() }) const address = createAddressFromString('0x9e5ef720fa2cdfa5291eb7e711cfd2e62196f4b3') const account = createAccount({ nonce: 3n, balance: 0xfffn }) await sm.putAccount(address, account) diff --git a/packages/statemanager/test/statelessVerkleStateManager.spec.ts b/packages/statemanager/test/statelessVerkleStateManager.spec.ts index a78fda81ed..eaed204813 100644 --- a/packages/statemanager/test/statelessVerkleStateManager.spec.ts +++ b/packages/statemanager/test/statelessVerkleStateManager.spec.ts @@ -25,7 +25,7 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { const common = createCommonFromGethGenesis(testnetVerkleKaustinenData, { chain: 'customChain', eips: [2935, 4895, 6800], - customCrypto: { verkleCrypto: verkle }, + customCrypto: { verkle }, }) const decodedTxs = verkleKaustinen6Block72Data.transactions?.map((tx) => @@ -39,7 +39,7 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { ) it('initPreState()', async () => { - common.customCrypto.verkleCrypto = verkle + common.customCrypto.verkle = verkle const stateManager = new StatelessVerkleStateManager({ common }) stateManager.initVerkleExecutionWitness(block.header.number, block.executionWitness) @@ -48,7 +48,7 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { // TODO: Turn back on once we have kaustinen7 data it.skip('getAccount()', async () => { - common.customCrypto.verkleCrypto = verkle + common.customCrypto.verkle = verkle const stateManager = new StatelessVerkleStateManager({ common }) stateManager.initVerkleExecutionWitness(block.header.number, block.executionWitness) @@ -67,7 +67,7 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { }) it('put/delete/modify account', async () => { - common.customCrypto.verkleCrypto = verkle + common.customCrypto.verkle = verkle const stateManager = new StatelessVerkleStateManager({ common, caches: new Caches(), @@ -117,7 +117,7 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { }) it('getKey function', async () => { - common.customCrypto.verkleCrypto = verkle + common.customCrypto.verkle = verkle const stateManager = new StatelessVerkleStateManager({ common }) stateManager.initVerkleExecutionWitness(block.header.number, block.executionWitness) @@ -141,7 +141,7 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { }) it(`copy()`, async () => { - common.customCrypto.verkleCrypto = verkle + common.customCrypto.verkle = verkle const stateManager = new StatelessVerkleStateManager({ caches: new Caches({ account: { @@ -171,7 +171,7 @@ describe('StatelessVerkleStateManager: Kaustinen Verkle Block', () => { // TODO contract storage functions not yet completely implemented test.skip('get/put/clear contract storage', async () => { - common.customCrypto.verkleCrypto = verkle + common.customCrypto.verkle = verkle const stateManager = new StatelessVerkleStateManager({ common }) stateManager.initVerkleExecutionWitness(block.header.number, block.executionWitness) diff --git a/packages/verkle/test/internalNode.spec.ts b/packages/verkle/test/internalNode.spec.ts index 4d5f7ebd48..bf07f6b12b 100644 --- a/packages/verkle/test/internalNode.spec.ts +++ b/packages/verkle/test/internalNode.spec.ts @@ -49,7 +49,10 @@ describe('verkle node - internal', () => { commitment: randomBytes(64), path: randomBytes(10), } - const children = new Array(256).fill({ commitment: new Uint8Array(64), path: new Uint8Array() }) + const children = new Array(256).fill({ + commitment: new Uint8Array(64), + path: new Uint8Array(), + }) children[0] = child const node = new InternalVerkleNode({ children, diff --git a/packages/verkle/test/interop.spec.ts b/packages/verkle/test/interop.spec.ts index 03dfb67a07..87bfcb41d1 100644 --- a/packages/verkle/test/interop.spec.ts +++ b/packages/verkle/test/interop.spec.ts @@ -13,7 +13,10 @@ describe('rust-verkle test vectors', () => { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, ]) - const trie = await createVerkleTree({ verkleCrypto: verkle, db: new MapDB() }) + const trie = await createVerkleTree({ + verkleCrypto: verkle, + db: new MapDB(), + }) await trie.put(key.slice(0, 31), [key[31]], [key]) const path = await trie.findPath(key.slice(0, 31)) @@ -35,7 +38,10 @@ describe('rust-verkle test vectors', () => { 27, 28, 29, 30, 31, 32, ]) const stem = key.slice(0, 31) - const trie = await createVerkleTree({ verkleCrypto: verkle, db: new MapDB() }) + const trie = await createVerkleTree({ + verkleCrypto: verkle, + db: new MapDB(), + }) await trie.put(stem, [key[31]], [new Uint8Array(32)]) let path = await trie.findPath(stem) assert.equal( diff --git a/packages/verkle/test/proof.spec.ts b/packages/verkle/test/proof.spec.ts index 5e924c33d4..b64dba9074 100644 --- a/packages/verkle/test/proof.spec.ts +++ b/packages/verkle/test/proof.spec.ts @@ -62,7 +62,10 @@ describe('lets make proofs', () => { } }) it('should pass for empty trie', async () => { - const trie = await createVerkleTree({ verkleCrypto: verkle, db: new MapDB() }) + const trie = await createVerkleTree({ + verkleCrypto: verkle, + db: new MapDB(), + }) const proof = verkle.createProof([ { diff --git a/packages/verkle/test/verkle.spec.ts b/packages/verkle/test/verkle.spec.ts index 2c02769a4d..afc5914280 100644 --- a/packages/verkle/test/verkle.spec.ts +++ b/packages/verkle/test/verkle.spec.ts @@ -155,7 +155,10 @@ describe('Verkle tree', () => { const rawNode = await trie['_db'].get(trie.root()) const rootNode = decodeVerkleNode(rawNode!, verkle) as InternalVerkleNode // Update root node with commitment from leaf node - rootNode.setChild(stem1[0], { commitment: leafNode1.commitment, path: stem1 }) + rootNode.setChild(stem1[0], { + commitment: leafNode1.commitment, + path: stem1, + }) trie.root(verkle.serializeCommitment(rootNode.commitment)) putStack.push([trie.root(), rootNode]) await trie.saveStack(putStack) diff --git a/packages/vm/src/runBlock.ts b/packages/vm/src/runBlock.ts index 24b0926335..424d373491 100644 --- a/packages/vm/src/runBlock.ts +++ b/packages/vm/src/runBlock.ts @@ -137,11 +137,11 @@ export async function runBlock(vm: VM, opts: RunBlockOpts): Promise createTxFromRLP(hexToBytes(tx), { common }), @@ -34,7 +34,7 @@ const block = createBlock( describe('EIP 6800 tests', () => { // TODO: Turn back on once we have kaustinen7 block data it.skip('successfully run transactions statelessly using the block witness', async () => { - common.customCrypto.verkleCrypto = verkle + common.customCrypto.verkle = verkle const verkleStateManager = new StatelessVerkleStateManager({ caches: new Caches(), common, diff --git a/packages/vm/test/api/runBlock.spec.ts b/packages/vm/test/api/runBlock.spec.ts index b7b65af2ea..30d91605c6 100644 --- a/packages/vm/test/api/runBlock.spec.ts +++ b/packages/vm/test/api/runBlock.spec.ts @@ -232,7 +232,11 @@ describe('runBlock() -> API parameter usage/data errors', async () => { // The mocked VM uses a mocked runTx // which always returns an error. - await runBlock(vm, { block, skipBlockValidation: true, skipHardForkValidation: true }) + await runBlock(vm, { + block, + skipBlockValidation: true, + skipHardForkValidation: true, + }) .then(() => assert.fail('should have returned error')) .catch((e) => assert.ok(e.message.includes("sender doesn't have enough funds to send tx"))) }) @@ -391,7 +395,12 @@ describe('runBlock() -> runtime behavior', async () => { { common }, ) - await runBlock(vm, { block, skipNonce: true, skipBlockValidation: true, generate: true }) + await runBlock(vm, { + block, + skipNonce: true, + skipBlockValidation: true, + generate: true, + }) const account = await vm.stateManager.getAccount(signer.address) assert.equal( account!.balance, @@ -431,7 +440,11 @@ it('should correctly reflect generated fields', async () => { // which is a well known constant. const bytes32Zeros = new Uint8Array(32) const block = createBlock({ - header: { receiptTrie: bytes32Zeros, transactionsTrie: bytes32Zeros, gasUsed: BigInt(1) }, + header: { + receiptTrie: bytes32Zeros, + transactionsTrie: bytes32Zeros, + gasUsed: BigInt(1), + }, }) const results = await runBlockAndGetAfterBlockEvent(vm, { @@ -688,7 +701,7 @@ describe.skip('run a verkle block', () => { const common = new Common({ chain: Mainnet, - customCrypto: { verkleCrypto: verkle }, + customCrypto: { verkle }, hardfork: Hardfork.Shanghai, eips: [2935, 3607, 6800], }) @@ -702,7 +715,12 @@ describe.skip('run a verkle block', () => { const sm = new StatefulVerkleStateManager({ common }) await sm['_trie'].createRootNode() const blockchain = await createBlockchain({ common }) - const vm = await setupVM({ common, stateManager: sm, blockchain, genesisBlock }) + const vm = await setupVM({ + common, + stateManager: sm, + blockchain, + genesisBlock, + }) await setupPreConditions(vm.stateManager, verkleJSON) const witness = { ...verkleJSON.blocks[0].witness,