Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Use msgpack to reduce redundancy #612

Merged
merged 18 commits into from
Jul 19, 2023

Conversation

ludamad
Copy link
Collaborator

@ludamad ludamad commented Jul 17, 2023

Description

Going through lists-of-fields now that we have poor-man's reflection.

This currently DOES NOT switch barretenberg's serialization to msgpack. This instead uses msgpack common reflection utils to derive such read and write functions.

For example:
MSGPACK_FIELDS(arg1, arg2);

is now used to define

void read(buf, obj) {
   read(buf, obj.arg1);
   read(buf, obj.arg2);
}

for any object that has a MSGPACK_FIELDS macro. This is also used for write

Also removes a debug utility I introduced during the hackathon that has not really been used, fine to remove

Checklist:

  • [*] I have reviewed my diff in github, line by line.
  • [*] Every change is related to the PR description.
  • [*] The branch has been merged with/rebased against the head of its merge target.
  • [*] There are no unexpected formatting changes, superfluous debug logs, or commented-out code.
  • [*] There are no circuit changes, OR a cryptographer has been assigned for review.
  • [*] New functions, classes, etc. have been documented according to the doxygen comment format. Classes and structs must have @brief describing the intended functionality.
  • [*] If existing code has been modified, such documentation has been added or updated.
  • [*] No superfluous include directives have been added.
  • [*] I have linked to any issue(s) it resolves.
  • [*] I'm happy for the PR to be merged at the reviewer's next convenience.

Args args; // Args instance
R ret; // Holds return type
MSGPACK_FIELDS(args, ret); // Macro from msgpack library to serialize/deserialize fields
typedef std::tuple<typename std::decay<Vs>::type...> Args; // Define a tuple type that holds all argument types
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Needed to support const Type& args

@ludamad ludamad changed the title chore: Use msgpack to reduce redundancy (WIP) chore: Use msgpack to reduce redundancy Jul 18, 2023
@ludamad ludamad force-pushed the chore/reduce-redundancy-msgpack branch from 065f83f to 077245a Compare July 18, 2023 21:05
@ludamad ludamad requested a review from charlielye July 18, 2023 21:06
@@ -120,24 +120,25 @@ TEST(ECDSASecp256r1, test_hardcoded)

size_t num_variables =
generate_r1_constraints(ecdsa_r1_constraint, witness_values, pub_key_x, pub_key_y, hashed_message, signature);

acir_format constraint_system{
.varnum = static_cast<uint32_t>(num_variables),
.public_inputs = {},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reordered to match serialization order (hard to work around doing this)

@ludamad ludamad requested a review from spalladino July 18, 2023 21:33
Copy link
Contributor

@spalladino spalladino left a comment

Choose a reason for hiding this comment

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

LGTM, but don't count it as an approval since much of the cpp magic used here still escapes me.

cpp/src/barretenberg/common/serialize.hpp Show resolved Hide resolved
cpp/src/barretenberg/crypto/schnorr/c_bind.cpp Outdated Show resolved Hide resolved
@ludamad
Copy link
Collaborator Author

ludamad commented Jul 18, 2023

LGTM, but don't count it as an approval since much of the cpp magic used here still escapes me.

Foiled again! It's almost like I should avoid C++ magic

@ludamad ludamad added noir-ci Run the Noir CI and removed noir-ci Run the Noir CI labels Jul 19, 2023
@dbanks12
Copy link
Contributor

Cannot parse "This currently DOES NOT switch barretenberg's serialization to msgpack. This instead uses msgpack common reflection utils to derive such read and write functions."

Could you explain this like im a 5 year old?

Copy link
Contributor

@dbanks12 dbanks12 left a comment

Choose a reason for hiding this comment

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

LGTM, left some minor comments.

cpp/src/barretenberg/common/serialize.hpp Outdated Show resolved Hide resolved
cpp/src/barretenberg/common/serialize.hpp Outdated Show resolved Hide resolved
Comment on lines 8 to 12
* @brief Passthrough method for better error reporting.
*/
template <msgpack_concepts::HasMsgPack T> void msgpack_apply(const auto& func, auto&... args)
{
std::apply(func, msgpack::drop_keys(std::tie(args...)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you expand on this comment a bit (or the fn below)? What does it mean that they are passthrough methods and how might they be used?

@ludamad
Copy link
Collaborator Author

ludamad commented Jul 19, 2023

Cannot parse "This currently DOES NOT switch barretenberg's serialization to msgpack. This instead uses msgpack common reflection utils to derive such read and write functions."

Could you explain this like im a 5 year old?

I hope the edited text now makes more sense

@ludamad ludamad merged commit 2838de6 into master Jul 19, 2023
2 checks passed
@ludamad ludamad deleted the chore/reduce-redundancy-msgpack branch July 19, 2023 15:35
ludamad added a commit to AztecProtocol/aztec-packages that referenced this pull request Jul 22, 2023
ludamad added a commit to AztecProtocol/aztec-packages that referenced this pull request Jul 24, 2023
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.

4 participants