Skip to content

fix(fns): fixed computing of function tree root#217

Merged
spalladino merged 2 commits into
masterfrom
arv/fix_compute_fn_tree_root
Apr 10, 2023
Merged

fix(fns): fixed computing of function tree root#217
spalladino merged 2 commits into
masterfrom
arv/fix_compute_fn_tree_root

Conversation

@sirasistant

@sirasistant sirasistant commented Apr 10, 2023

Copy link
Copy Markdown
Contributor

Description

getFunctionTreeRoot has a serialization bug
https://github.com/AztecProtocol/aztec3-packages/blob/master/yarn-project/circuits.js/src/abis/abis.ts#L49
It's serializing as vector an array of buffers that is not read as a vector on the CPP side. IIUC vectors on the cpp side expect to have the length as the first 32 bits, but in CPP we're reading that as a raw buffer, without the leading length:
https://github.com/AztecProtocol/aztec3-circuits/blob/fdd7a3577deb2bc6fd90bb68b16c654695331d08/cpp/src/aztec3/circuits/abis/c_bind.cpp#L252
This caused that the computed root didn't match the root from computing the whole tree here
https://github.com/AztecProtocol/aztec3-packages/blob/master/yarn-project/aztec-rpc/src/aztec_rpc_server/aztec_rpc_server.ts#L262

I have also changed the signature of the leaves to be Frs, to be consistent with the signature of computing the function tree and that way reducing the conversions buffer <> Fr upstream

Also added a test to a test to ensure that compute function tree and compute function tree root generate the same tree root

Checklist:

  • I have reviewed my diff in github, line by line.
  • Every change is related to the PR description.
  • I have linked this pull request to the issue(s) that it resolves.
  • There are no unexpected formatting changes, superfluous debug logs, or commented-out code.
  • The branch has been merged or rebased against the head of its merge target.
  • I'm happy for the PR to be merged at the reviewer's next convenience.

@spalladino spalladino left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I'm curious why this didn't pop up in any of the e2e tests. Are we not using this function atm?

@sirasistant

sirasistant commented Apr 10, 2023

Copy link
Copy Markdown
Contributor Author

Good catch! I'm curious why this didn't pop up in any of the e2e tests. Are we not using this function atm?

Because we are not verifying yet merkle memberships of functions in the tree :)

@spalladino spalladino merged commit 1693ae2 into master Apr 10, 2023
@spalladino spalladino deleted the arv/fix_compute_fn_tree_root branch April 10, 2023 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants