Skip to content

Commit

Permalink
common: rename verkleCrypto to verkle in common customCrypto
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrocheleau committed Nov 14, 2024
1 parent 564020a commit 1e5ce29
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 44 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,
}

Check warning on line 337 in packages/evm/src/verkleAccessWitness.ts

View check run for this annotation

Codecov / codecov/patch

packages/evm/src/verkleAccessWitness.ts#L334-L337

Added lines #L334 - L337 were not covered by tests
} 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,

Check warning on line 104 in packages/statemanager/src/statefulVerkleStateManager.ts

View check run for this annotation

Codecov / codecov/patch

packages/statemanager/src/statefulVerkleStateManager.ts#L104

Added line #L104 was not covered by tests
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
2 changes: 1 addition & 1 deletion packages/verkle/examples/diyVerkle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const main = async () => {
cacheSize: 0,
db: new MapDB<Uint8Array, Uint8Array>(),
useRootPersistence: false,
verkleCrypto: verkle,
verkle,
})
await tree.createRootNode()
console.log(bytesToHex(tree.root())) // 0x0000000000000000000000000000000000000000000000000000000000000000
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
4 changes: 2 additions & 2 deletions packages/verkle/test/interop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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({ 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 +35,7 @@ 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({ verkle, db: new MapDB() })
await trie.put(stem, [key[31]], [new Uint8Array(32)])
let path = await trie.findPath(stem)
assert.equal(
Expand Down
2 changes: 1 addition & 1 deletion packages/verkle/test/leafNode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('verkle node - leaf', () => {
commitment,
stem,
values,
verkleCrypto: verkle,
verkle,
})

assert.ok(isLeafVerkleNode(node), 'typeguard should return true')
Expand Down
2 changes: 1 addition & 1 deletion packages/verkle/test/proof.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('lets make proofs', () => {
}
})
it('should pass for empty trie', async () => {
const trie = await createVerkleTree({ verkleCrypto: verkle, db: new MapDB() })
const trie = await createVerkleTree({ 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) {

Check warning on line 140 in packages/vm/src/runBlock.ts

View check run for this annotation

Codecov / codecov/patch

packages/vm/src/runBlock.ts#L140

Added line #L140 was not covered by tests
throw Error('verkleCrypto required when EIP-6800 is active')
}
vm.evm.verkleAccessWitness = new VerkleAccessWitness({
verkleCrypto: vm.common.customCrypto.verkleCrypto,
verkleCrypto: vm.common.customCrypto.verkle,

Check warning on line 144 in packages/vm/src/runBlock.ts

View check run for this annotation

Codecov / codecov/patch

packages/vm/src/runBlock.ts#L144

Added line #L144 was not covered by tests
})

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,
})

Check warning on line 762 in packages/vm/src/runBlock.ts

View check run for this annotation

Codecov / codecov/patch

packages/vm/src/runBlock.ts#L760-L762

Added lines #L760 - L762 were not covered by tests
}
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 1e5ce29

Please sign in to comment.