Skip to content

Commit

Permalink
Touch up verkle util docs (#3646)
Browse files Browse the repository at this point in the history
* Update example to have non-default data

* Update comment in example

* Update docstrings

* Update documentation wording

* Update packages/util/src/verkle.ts

---------

Co-authored-by: Gabriel Rocheleau <[email protected]>
  • Loading branch information
scorbajio and gabrocheleau committed Sep 10, 2024
1 parent 8a0afb0 commit 7d9444e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/util/examples/verkle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {

const state = {
'0xdf67dea9181141d6255ac05c7ada5a590fb30a375023f16c31223f067319e300':
'0x0000000000000000000000000000000000000000000000000000000000000000',
'0x0100000001000000000000000000000001000000000000000000000000000000',
'0xdf67dea9181141d6255ac05c7ada5a590fb30a375023f16c31223f067319e301':
'0x923672e5275a0104000000000000000000000000000000000000000000000000',
'0xdf67dea9181141d6255ac05c7ada5a590fb30a375023f16c31223f067319e302':
Expand All @@ -24,4 +24,4 @@ const basicDataKey = getVerkleKey(stem, VerkleLeafType.BasicData)
const basicDataRaw = state[bytesToHex(basicDataKey)]
const basicData = decodeVerkleLeafBasicData(hexToBytes(basicDataRaw!))

console.log(basicData) // { version: 0, nonce: 0n, codeSize: 0, balance: 0n }
console.log(basicData) // { version: 1, nonce: 1n, codeSize: 0, balance: 1n }
8 changes: 4 additions & 4 deletions packages/util/src/verkle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const getVerkleKey = (stem: Uint8Array, leaf: VerkleLeafType | Uint8Array
* Calculates the position of the storage key in the Verkle tree, determining
* both the tree index (the node in the tree) and the subindex (the position within the node).
* @param {bigint} storageKey - The key representing a specific storage slot.
* @returns {Object} - An object containing:
* @returns {Object} - An object containing the tree index and subindex
*/
export function getVerkleTreeIndicesForStorageSlot(storageKey: bigint): {
treeIndex: bigint
Expand All @@ -200,7 +200,7 @@ export function getVerkleTreeIndicesForStorageSlot(storageKey: bigint): {
* Calculates the position of the code chunks in the Verkle tree, determining
* both the tree index (the node in the tree) and the subindex (the position within the node).
* @param {bigint} chunkId - The ID representing a specific chunk.
* @returns {Object} - An object containing:
* @returns {Object} - An object containing the tree index and subindex
*/
export function getVerkleTreeIndicesForCodeChunk(chunkId: number) {
const treeIndex = Math.floor((VERKLE_CODE_OFFSET + chunkId) / VERKLE_NODE_WIDTH)
Expand Down Expand Up @@ -257,7 +257,7 @@ export const getVerkleTreeKeyForStorageSlot = async (
* from the `encodedBasicData` array based on predefined offsets and lengths, and then converted
* to its appropriate type (integer or BigInt).
* @param {Uint8Array} encodedBasicData - The encoded Verkle leaf basic data containing the version, nonce,
* code size, and balance in a compact binary format.
* code size, and balance in a compact Uint8Array format.
* @returns {VerkleLeafBasicData} - An object containing the decoded version, nonce, code size, and balance.
*/
export function decodeVerkleLeafBasicData(encodedBasicData: Uint8Array): VerkleLeafBasicData {
Expand Down Expand Up @@ -291,7 +291,7 @@ export function decodeVerkleLeafBasicData(encodedBasicData: Uint8Array): VerkleL
* in EIP-6800.
* @param {VerkleLeafBasicData} basicData - An object containing the version, nonce,
* code size, and balance to be encoded.
* @returns {Uint8Array} - A compact, binary-encoded representation of the account header basic data.
* @returns {Uint8Array} - A compact bytes representation of the account header basic data.
*/
export function encodeVerkleLeafBasicData(basicData: VerkleLeafBasicData): Uint8Array {
const encodedVersion = setLengthLeft(int32ToBytes(basicData.version), VERKLE_VERSION_BYTES_LENGTH)
Expand Down

0 comments on commit 7d9444e

Please sign in to comment.