Skip to content

Use Fr for leafValue everywhere in our API #3172

@benesjan

Description

@benesjan

Currently we use type Buffer to pass around leaf in plenty of the places in our codebase, e.g.:

public async findLeafIndex(treeId: MerkleTreeId, leafValue: Buffer): Promise<bigint | undefined>;

and in other places we use Fr:

  public async getCommitmentIndex(commitment: Fr): Promise<bigint | undefined> {
    return await this.db.findLeafIndex(MerkleTreeId.NOTE_HASH_TREE, commitment.toBuffer());
  }

I think it would be better to always use Fr (and serialize it to a buffer when inserting the leaf) because otherwise there is a risk of serialization issues (I just did this mistake when I use copilot's solution of serializing bigint to a buffer instead of using our own).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions