fix(fns): fixed computing of function tree root#217
Merged
Conversation
spalladino
approved these changes
Apr 10, 2023
spalladino
left a comment
Contributor
There was a problem hiding this comment.
Good catch! I'm curious why this didn't pop up in any of the e2e tests. Are we not using this function atm?
Contributor
Author
Because we are not verifying yet merkle memberships of functions in the tree :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: