Skip to content

Commit

Permalink
common: rename verkleCrypto to verkle in common customCrypto (#3797)
Browse files Browse the repository at this point in the history
* common: rename verkleCrypto to verkle in common customCrypto

* verkle: ci fixes

* verkle: fix example
  • Loading branch information
gabrocheleau authored Nov 15, 2024
1 parent 564020a commit 94d72e5
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 42 deletions.
10 changes: 7 additions & 3 deletions packages/client/test/rpc/engine/kaustinen6.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 () => {
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 10 additions & 3 deletions packages/evm/src/verkleAccessWitness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,19 @@ 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(
address: Address,
treeIndex: number | bigint,
subIndex: number | Uint8Array,
): bigint {
return this.touchAddressAndChargeGas(address, treeIndex, subIndex, { isWrite: false })
return this.touchAddressAndChargeGas(address, treeIndex, subIndex, {
isWrite: false,
})
}

touchAddressAndChargeGas(
Expand Down Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/test/verkle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
11 changes: 7 additions & 4 deletions packages/statemanager/src/statefulVerkleStateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ 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')
}

this.common = opts.common
this._trie =
opts.trie ??
new VerkleTree({
verkleCrypto: opts.common.customCrypto.verkleCrypto,
verkleCrypto: opts.common.customCrypto.verkle,
db: new MapDB<Uint8Array, Uint8Array>(),
useRootPersistence: false,
cacheSize: 0,
Expand All @@ -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
}

/**
Expand Down Expand Up @@ -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<Uint8Array> => {
Expand Down
4 changes: 2 additions & 2 deletions packages/statemanager/src/statelessVerkleStateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
16 changes: 10 additions & 6 deletions packages/statemanager/test/statefulVerkleStateManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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 })

Expand All @@ -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')
Expand Down Expand Up @@ -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')
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions packages/statemanager/test/statelessVerkleStateManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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(),
Expand Down Expand Up @@ -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)

Expand All @@ -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: {
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion packages/verkle/test/internalNode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions packages/verkle/test/interop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion packages/verkle/test/proof.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
{
Expand Down
5 changes: 4 additions & 1 deletion packages/verkle/test/verkle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions packages/vm/src/runBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ export async function runBlock(vm: VM, opts: RunBlockOpts): Promise<RunBlockResu
if (vm.common.isActivatedEIP(6800)) {
// Initialize the access witness

if (vm.common.customCrypto.verkleCrypto === undefined) {
if (vm.common.customCrypto.verkle === undefined) {
throw Error('verkleCrypto required when EIP-6800 is active')
}
vm.evm.verkleAccessWitness = new VerkleAccessWitness({
verkleCrypto: vm.common.customCrypto.verkleCrypto,
verkleCrypto: vm.common.customCrypto.verkle,
})

if (typeof stateManager.initVerkleExecutionWitness !== 'function') {
Expand Down Expand Up @@ -757,7 +757,9 @@ export async function rewardAccount(
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.verkleAccessWitness.touchTxTargetAndComputeGas(address, {
sendsValue: true,
})
}
return account
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/test/api/EIPs/eip-6800-verkle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const customChainParams = { name: 'custom', chainId: 69420 }
const common = createCustomCommon(customChainParams, Mainnet, {
hardfork: Hardfork.Cancun,
eips: [2935, 4895, 6800],
customCrypto: { verkleCrypto: verkle },
customCrypto: { verkle },
})
const decodedTxs = verkleKaustinen6Block72Data.transactions?.map((tx) =>
createTxFromRLP(hexToBytes(tx), { common }),
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 94d72e5

Please sign in to comment.